]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - kernel/patches/grsecurity-3.0-3.17.1-201410281754.patch
Merge branch 'batman'
[people/ms/ipfire-3.x.git] / kernel / patches / grsecurity-3.0-3.17.1-201410281754.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index 764f599..c600e2f 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index 1edd5fd..84fd32e 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1155,6 +1155,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2175,6 +2179,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2467,6 +2475,25 @@ 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 + 0/1 to disable/enable slab object sanitization (enabled by
352 + default).
353 +
354 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
355 +
356 + pax_extra_latent_entropy
357 + Enable a very simple form of latent entropy extraction
358 + from the first 4GB of memory as the bootmem allocator
359 + passes the memory pages to the buddy allocator.
360 +
361 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
362 + when the processor supports PCID.
363 +
364 pcbit= [HW,ISDN]
365
366 pcd. [PARIDE]
367 diff --git a/Makefile b/Makefile
368 index 4669409..95d8745 100644
369 --- a/Makefile
370 +++ b/Makefile
371 @@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
372
373 HOSTCC = gcc
374 HOSTCXX = g++
375 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
376 -HOSTCXXFLAGS = -O2
377 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
378 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
379 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
380
381 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
382 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
383 @@ -450,8 +451,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
384 # Rules shared between *config targets and build targets
385
386 # Basic helpers built in scripts/
387 -PHONY += scripts_basic
388 -scripts_basic:
389 +PHONY += scripts_basic gcc-plugins
390 +scripts_basic: gcc-plugins
391 $(Q)$(MAKE) $(build)=scripts/basic
392 $(Q)rm -f .tmp_quiet_recordmcount
393
394 @@ -625,6 +626,72 @@ endif
395 # Tell gcc to never replace conditional load with a non-conditional one
396 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
397
398 +ifndef DISABLE_PAX_PLUGINS
399 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
400 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
401 +else
402 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
403 +endif
404 +ifneq ($(PLUGINCC),)
405 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
406 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
407 +endif
408 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
409 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
410 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
411 +endif
412 +ifdef CONFIG_KALLOCSTAT_PLUGIN
413 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
414 +endif
415 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
416 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
417 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
418 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
419 +endif
420 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
421 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
422 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
423 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
424 +endif
425 +endif
426 +ifdef CONFIG_CHECKER_PLUGIN
427 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
428 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
429 +endif
430 +endif
431 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
432 +ifdef CONFIG_PAX_SIZE_OVERFLOW
433 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
434 +endif
435 +ifdef CONFIG_PAX_LATENT_ENTROPY
436 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
437 +endif
438 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
439 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
440 +endif
441 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
442 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
443 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
444 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
445 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
446 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
447 +ifeq ($(KBUILD_EXTMOD),)
448 +gcc-plugins:
449 + $(Q)$(MAKE) $(build)=tools/gcc
450 +else
451 +gcc-plugins: ;
452 +endif
453 +else
454 +gcc-plugins:
455 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
456 + $(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.))
457 +else
458 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
459 +endif
460 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
461 +endif
462 +endif
463 +
464 ifdef CONFIG_READABLE_ASM
465 # Disable optimizations that make assembler listings hard to read.
466 # reorder blocks reorders the control in the function
467 @@ -717,7 +784,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
468 else
469 KBUILD_CFLAGS += -g
470 endif
471 -KBUILD_AFLAGS += -Wa,-gdwarf-2
472 +KBUILD_AFLAGS += -Wa,--gdwarf-2
473 endif
474 ifdef CONFIG_DEBUG_INFO_DWARF4
475 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
476 @@ -867,7 +934,7 @@ export mod_sign_cmd
477
478
479 ifeq ($(KBUILD_EXTMOD),)
480 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
481 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
482
483 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
484 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
485 @@ -916,6 +983,8 @@ endif
486
487 # The actual objects are generated when descending,
488 # make sure no implicit rule kicks in
489 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
490 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
491 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
492
493 # Handle descending into subdirectories listed in $(vmlinux-dirs)
494 @@ -925,7 +994,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
495 # Error messages still appears in the original language
496
497 PHONY += $(vmlinux-dirs)
498 -$(vmlinux-dirs): prepare scripts
499 +$(vmlinux-dirs): gcc-plugins prepare scripts
500 $(Q)$(MAKE) $(build)=$@
501
502 define filechk_kernel.release
503 @@ -968,10 +1037,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
504
505 archprepare: archheaders archscripts prepare1 scripts_basic
506
507 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
508 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
509 prepare0: archprepare FORCE
510 $(Q)$(MAKE) $(build)=.
511
512 # All the preparing..
513 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
514 prepare: prepare0
515
516 # Generate some files
517 @@ -1086,6 +1158,8 @@ all: modules
518 # using awk while concatenating to the final file.
519
520 PHONY += modules
521 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
522 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
523 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
524 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
525 @$(kecho) ' Building modules, stage 2.';
526 @@ -1101,7 +1175,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
527
528 # Target to prepare building external modules
529 PHONY += modules_prepare
530 -modules_prepare: prepare scripts
531 +modules_prepare: gcc-plugins prepare scripts
532
533 # Target to install modules
534 PHONY += modules_install
535 @@ -1167,7 +1241,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
536 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
537 signing_key.priv signing_key.x509 x509.genkey \
538 extra_certificates signing_key.x509.keyid \
539 - signing_key.x509.signer include/linux/version.h
540 + signing_key.x509.signer include/linux/version.h \
541 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
542 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
543 + tools/gcc/randomize_layout_seed.h
544
545 # clean - Delete most, but leave enough to build external modules
546 #
547 @@ -1206,7 +1283,7 @@ distclean: mrproper
548 @find $(srctree) $(RCS_FIND_IGNORE) \
549 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
550 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
551 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
552 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
553 -type f -print | xargs rm -f
554
555
556 @@ -1372,6 +1449,8 @@ PHONY += $(module-dirs) modules
557 $(module-dirs): crmodverdir $(objtree)/Module.symvers
558 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
559
560 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
561 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
562 modules: $(module-dirs)
563 @$(kecho) ' Building modules, stage 2.';
564 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
565 @@ -1512,17 +1591,21 @@ else
566 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
567 endif
568
569 -%.s: %.c prepare scripts FORCE
570 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
571 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
572 +%.s: %.c gcc-plugins prepare scripts FORCE
573 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
574 %.i: %.c prepare scripts FORCE
575 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
576 -%.o: %.c prepare scripts FORCE
577 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
578 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
579 +%.o: %.c gcc-plugins prepare scripts FORCE
580 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
581 %.lst: %.c prepare scripts FORCE
582 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
583 -%.s: %.S prepare scripts FORCE
584 +%.s: %.S gcc-plugins prepare scripts FORCE
585 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
586 -%.o: %.S prepare scripts FORCE
587 +%.o: %.S gcc-plugins prepare scripts FORCE
588 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
589 %.symtypes: %.c prepare scripts FORCE
590 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
591 @@ -1532,11 +1615,15 @@ endif
592 $(cmd_crmodverdir)
593 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
594 $(build)=$(build-dir)
595 -%/: prepare scripts FORCE
596 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
597 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
598 +%/: gcc-plugins prepare scripts FORCE
599 $(cmd_crmodverdir)
600 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
601 $(build)=$(build-dir)
602 -%.ko: prepare scripts FORCE
603 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
604 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
605 +%.ko: gcc-plugins prepare scripts FORCE
606 $(cmd_crmodverdir)
607 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
608 $(build)=$(build-dir) $(@:.ko=.o)
609 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
610 index ed60a1e..47f1a55 100644
611 --- a/arch/alpha/include/asm/atomic.h
612 +++ b/arch/alpha/include/asm/atomic.h
613 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
614 #define atomic_dec(v) atomic_sub(1,(v))
615 #define atomic64_dec(v) atomic64_sub(1,(v))
616
617 +#define atomic64_read_unchecked(v) atomic64_read(v)
618 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
619 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
620 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
621 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
622 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
623 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
624 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
625 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
626 +
627 #endif /* _ALPHA_ATOMIC_H */
628 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
629 index ad368a9..fbe0f25 100644
630 --- a/arch/alpha/include/asm/cache.h
631 +++ b/arch/alpha/include/asm/cache.h
632 @@ -4,19 +4,19 @@
633 #ifndef __ARCH_ALPHA_CACHE_H
634 #define __ARCH_ALPHA_CACHE_H
635
636 +#include <linux/const.h>
637
638 /* Bytes per L1 (data) cache line. */
639 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
640 -# define L1_CACHE_BYTES 64
641 # define L1_CACHE_SHIFT 6
642 #else
643 /* Both EV4 and EV5 are write-through, read-allocate,
644 direct-mapped, physical.
645 */
646 -# define L1_CACHE_BYTES 32
647 # define L1_CACHE_SHIFT 5
648 #endif
649
650 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
651 #define SMP_CACHE_BYTES L1_CACHE_BYTES
652
653 #endif
654 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
655 index 968d999..d36b2df 100644
656 --- a/arch/alpha/include/asm/elf.h
657 +++ b/arch/alpha/include/asm/elf.h
658 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
659
660 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
661
662 +#ifdef CONFIG_PAX_ASLR
663 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
664 +
665 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
666 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
667 +#endif
668 +
669 /* $0 is set by ld.so to a pointer to a function which might be
670 registered using atexit. This provides a mean for the dynamic
671 linker to call DT_FINI functions for shared libraries that have
672 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
673 index aab14a0..b4fa3e7 100644
674 --- a/arch/alpha/include/asm/pgalloc.h
675 +++ b/arch/alpha/include/asm/pgalloc.h
676 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
677 pgd_set(pgd, pmd);
678 }
679
680 +static inline void
681 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
682 +{
683 + pgd_populate(mm, pgd, pmd);
684 +}
685 +
686 extern pgd_t *pgd_alloc(struct mm_struct *mm);
687
688 static inline void
689 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
690 index d8f9b7e..f6222fa 100644
691 --- a/arch/alpha/include/asm/pgtable.h
692 +++ b/arch/alpha/include/asm/pgtable.h
693 @@ -102,6 +102,17 @@ struct vm_area_struct;
694 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
695 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
696 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
697 +
698 +#ifdef CONFIG_PAX_PAGEEXEC
699 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
700 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
701 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
702 +#else
703 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
704 +# define PAGE_COPY_NOEXEC PAGE_COPY
705 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
706 +#endif
707 +
708 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
709
710 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
711 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
712 index 2fd00b7..cfd5069 100644
713 --- a/arch/alpha/kernel/module.c
714 +++ b/arch/alpha/kernel/module.c
715 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
716
717 /* The small sections were sorted to the end of the segment.
718 The following should definitely cover them. */
719 - gp = (u64)me->module_core + me->core_size - 0x8000;
720 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
721 got = sechdrs[me->arch.gotsecindex].sh_addr;
722
723 for (i = 0; i < n; i++) {
724 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
725 index 1402fcc..0b1abd2 100644
726 --- a/arch/alpha/kernel/osf_sys.c
727 +++ b/arch/alpha/kernel/osf_sys.c
728 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
729 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
730
731 static unsigned long
732 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
733 - unsigned long limit)
734 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
735 + unsigned long limit, unsigned long flags)
736 {
737 struct vm_unmapped_area_info info;
738 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
739
740 info.flags = 0;
741 info.length = len;
742 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
743 info.high_limit = limit;
744 info.align_mask = 0;
745 info.align_offset = 0;
746 + info.threadstack_offset = offset;
747 return vm_unmapped_area(&info);
748 }
749
750 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
751 merely specific addresses, but regions of memory -- perhaps
752 this feature should be incorporated into all ports? */
753
754 +#ifdef CONFIG_PAX_RANDMMAP
755 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
756 +#endif
757 +
758 if (addr) {
759 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
760 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
761 if (addr != (unsigned long) -ENOMEM)
762 return addr;
763 }
764
765 /* Next, try allocating at TASK_UNMAPPED_BASE. */
766 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
767 - len, limit);
768 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
769 +
770 if (addr != (unsigned long) -ENOMEM)
771 return addr;
772
773 /* Finally, try allocating in low memory. */
774 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
775 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
776
777 return addr;
778 }
779 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
780 index 98838a0..b304fb4 100644
781 --- a/arch/alpha/mm/fault.c
782 +++ b/arch/alpha/mm/fault.c
783 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
784 __reload_thread(pcb);
785 }
786
787 +#ifdef CONFIG_PAX_PAGEEXEC
788 +/*
789 + * PaX: decide what to do with offenders (regs->pc = fault address)
790 + *
791 + * returns 1 when task should be killed
792 + * 2 when patched PLT trampoline was detected
793 + * 3 when unpatched PLT trampoline was detected
794 + */
795 +static int pax_handle_fetch_fault(struct pt_regs *regs)
796 +{
797 +
798 +#ifdef CONFIG_PAX_EMUPLT
799 + int err;
800 +
801 + do { /* PaX: patched PLT emulation #1 */
802 + unsigned int ldah, ldq, jmp;
803 +
804 + err = get_user(ldah, (unsigned int *)regs->pc);
805 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
806 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
807 +
808 + if (err)
809 + break;
810 +
811 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
812 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
813 + jmp == 0x6BFB0000U)
814 + {
815 + unsigned long r27, addr;
816 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
817 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
818 +
819 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
820 + err = get_user(r27, (unsigned long *)addr);
821 + if (err)
822 + break;
823 +
824 + regs->r27 = r27;
825 + regs->pc = r27;
826 + return 2;
827 + }
828 + } while (0);
829 +
830 + do { /* PaX: patched PLT emulation #2 */
831 + unsigned int ldah, lda, br;
832 +
833 + err = get_user(ldah, (unsigned int *)regs->pc);
834 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
835 + err |= get_user(br, (unsigned int *)(regs->pc+8));
836 +
837 + if (err)
838 + break;
839 +
840 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
841 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
842 + (br & 0xFFE00000U) == 0xC3E00000U)
843 + {
844 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
845 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
846 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
847 +
848 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
849 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
850 + return 2;
851 + }
852 + } while (0);
853 +
854 + do { /* PaX: unpatched PLT emulation */
855 + unsigned int br;
856 +
857 + err = get_user(br, (unsigned int *)regs->pc);
858 +
859 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
860 + unsigned int br2, ldq, nop, jmp;
861 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
862 +
863 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
864 + err = get_user(br2, (unsigned int *)addr);
865 + err |= get_user(ldq, (unsigned int *)(addr+4));
866 + err |= get_user(nop, (unsigned int *)(addr+8));
867 + err |= get_user(jmp, (unsigned int *)(addr+12));
868 + err |= get_user(resolver, (unsigned long *)(addr+16));
869 +
870 + if (err)
871 + break;
872 +
873 + if (br2 == 0xC3600000U &&
874 + ldq == 0xA77B000CU &&
875 + nop == 0x47FF041FU &&
876 + jmp == 0x6B7B0000U)
877 + {
878 + regs->r28 = regs->pc+4;
879 + regs->r27 = addr+16;
880 + regs->pc = resolver;
881 + return 3;
882 + }
883 + }
884 + } while (0);
885 +#endif
886 +
887 + return 1;
888 +}
889 +
890 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
891 +{
892 + unsigned long i;
893 +
894 + printk(KERN_ERR "PAX: bytes at PC: ");
895 + for (i = 0; i < 5; i++) {
896 + unsigned int c;
897 + if (get_user(c, (unsigned int *)pc+i))
898 + printk(KERN_CONT "???????? ");
899 + else
900 + printk(KERN_CONT "%08x ", c);
901 + }
902 + printk("\n");
903 +}
904 +#endif
905
906 /*
907 * This routine handles page faults. It determines the address,
908 @@ -133,8 +251,29 @@ retry:
909 good_area:
910 si_code = SEGV_ACCERR;
911 if (cause < 0) {
912 - if (!(vma->vm_flags & VM_EXEC))
913 + if (!(vma->vm_flags & VM_EXEC)) {
914 +
915 +#ifdef CONFIG_PAX_PAGEEXEC
916 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
917 + goto bad_area;
918 +
919 + up_read(&mm->mmap_sem);
920 + switch (pax_handle_fetch_fault(regs)) {
921 +
922 +#ifdef CONFIG_PAX_EMUPLT
923 + case 2:
924 + case 3:
925 + return;
926 +#endif
927 +
928 + }
929 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
930 + do_group_exit(SIGKILL);
931 +#else
932 goto bad_area;
933 +#endif
934 +
935 + }
936 } else if (!cause) {
937 /* Allow reads even for write-only mappings */
938 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
939 diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
940 index a2ff5c5..ecf6a78 100644
941 --- a/arch/arc/kernel/kgdb.c
942 +++ b/arch/arc/kernel/kgdb.c
943 @@ -158,11 +158,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
944 return -1;
945 }
946
947 -unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
948 -{
949 - return instruction_pointer(regs);
950 -}
951 -
952 int kgdb_arch_init(void)
953 {
954 single_step_data.armed = 0;
955 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
956 index 32cbbd5..c102df9 100644
957 --- a/arch/arm/Kconfig
958 +++ b/arch/arm/Kconfig
959 @@ -1719,7 +1719,7 @@ config ALIGNMENT_TRAP
960
961 config UACCESS_WITH_MEMCPY
962 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
963 - depends on MMU
964 + depends on MMU && !PAX_MEMORY_UDEREF
965 default y if CPU_FEROCEON
966 help
967 Implement faster copy_to_user and clear_user methods for CPU
968 @@ -1983,6 +1983,7 @@ config XIP_PHYS_ADDR
969 config KEXEC
970 bool "Kexec system call (EXPERIMENTAL)"
971 depends on (!SMP || PM_SLEEP_SMP)
972 + depends on !GRKERNSEC_KMEM
973 help
974 kexec is a system call that implements the ability to shutdown your
975 current kernel, and to start another kernel. It is like a reboot
976 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
977 index 3040359..cf3bab0 100644
978 --- a/arch/arm/include/asm/atomic.h
979 +++ b/arch/arm/include/asm/atomic.h
980 @@ -18,17 +18,35 @@
981 #include <asm/barrier.h>
982 #include <asm/cmpxchg.h>
983
984 +#ifdef CONFIG_GENERIC_ATOMIC64
985 +#include <asm-generic/atomic64.h>
986 +#endif
987 +
988 #define ATOMIC_INIT(i) { (i) }
989
990 #ifdef __KERNEL__
991
992 +#define _ASM_EXTABLE(from, to) \
993 +" .pushsection __ex_table,\"a\"\n"\
994 +" .align 3\n" \
995 +" .long " #from ", " #to"\n" \
996 +" .popsection"
997 +
998 /*
999 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1000 * strex/ldrex monitor on some implementations. The reason we can use it for
1001 * atomic_set() is the clrex or dummy strex done on every exception return.
1002 */
1003 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1004 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1005 +{
1006 + return v->counter;
1007 +}
1008 #define atomic_set(v,i) (((v)->counter) = (i))
1009 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1010 +{
1011 + v->counter = i;
1012 +}
1013
1014 #if __LINUX_ARM_ARCH__ >= 6
1015
1016 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
1017
1018 prefetchw(&v->counter);
1019 __asm__ __volatile__("@ atomic_add\n"
1020 +"1: ldrex %1, [%3]\n"
1021 +" adds %0, %1, %4\n"
1022 +
1023 +#ifdef CONFIG_PAX_REFCOUNT
1024 +" bvc 3f\n"
1025 +"2: bkpt 0xf103\n"
1026 +"3:\n"
1027 +#endif
1028 +
1029 +" strex %1, %0, [%3]\n"
1030 +" teq %1, #0\n"
1031 +" bne 1b"
1032 +
1033 +#ifdef CONFIG_PAX_REFCOUNT
1034 +"\n4:\n"
1035 + _ASM_EXTABLE(2b, 4b)
1036 +#endif
1037 +
1038 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1039 + : "r" (&v->counter), "Ir" (i)
1040 + : "cc");
1041 +}
1042 +
1043 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1044 +{
1045 + unsigned long tmp;
1046 + int result;
1047 +
1048 + prefetchw(&v->counter);
1049 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1050 "1: ldrex %0, [%3]\n"
1051 " add %0, %0, %4\n"
1052 " strex %1, %0, [%3]\n"
1053 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1054 prefetchw(&v->counter);
1055
1056 __asm__ __volatile__("@ atomic_add_return\n"
1057 +"1: ldrex %1, [%3]\n"
1058 +" adds %0, %1, %4\n"
1059 +
1060 +#ifdef CONFIG_PAX_REFCOUNT
1061 +" bvc 3f\n"
1062 +" mov %0, %1\n"
1063 +"2: bkpt 0xf103\n"
1064 +"3:\n"
1065 +#endif
1066 +
1067 +" strex %1, %0, [%3]\n"
1068 +" teq %1, #0\n"
1069 +" bne 1b"
1070 +
1071 +#ifdef CONFIG_PAX_REFCOUNT
1072 +"\n4:\n"
1073 + _ASM_EXTABLE(2b, 4b)
1074 +#endif
1075 +
1076 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1077 + : "r" (&v->counter), "Ir" (i)
1078 + : "cc");
1079 +
1080 + smp_mb();
1081 +
1082 + return result;
1083 +}
1084 +
1085 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1086 +{
1087 + unsigned long tmp;
1088 + int result;
1089 +
1090 + smp_mb();
1091 + prefetchw(&v->counter);
1092 +
1093 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1094 "1: ldrex %0, [%3]\n"
1095 " add %0, %0, %4\n"
1096 " strex %1, %0, [%3]\n"
1097 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1098
1099 prefetchw(&v->counter);
1100 __asm__ __volatile__("@ atomic_sub\n"
1101 +"1: ldrex %1, [%3]\n"
1102 +" subs %0, %1, %4\n"
1103 +
1104 +#ifdef CONFIG_PAX_REFCOUNT
1105 +" bvc 3f\n"
1106 +"2: bkpt 0xf103\n"
1107 +"3:\n"
1108 +#endif
1109 +
1110 +" strex %1, %0, [%3]\n"
1111 +" teq %1, #0\n"
1112 +" bne 1b"
1113 +
1114 +#ifdef CONFIG_PAX_REFCOUNT
1115 +"\n4:\n"
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1120 + : "r" (&v->counter), "Ir" (i)
1121 + : "cc");
1122 +}
1123 +
1124 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1125 +{
1126 + unsigned long tmp;
1127 + int result;
1128 +
1129 + prefetchw(&v->counter);
1130 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1131 "1: ldrex %0, [%3]\n"
1132 " sub %0, %0, %4\n"
1133 " strex %1, %0, [%3]\n"
1134 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1135 prefetchw(&v->counter);
1136
1137 __asm__ __volatile__("@ atomic_sub_return\n"
1138 -"1: ldrex %0, [%3]\n"
1139 -" sub %0, %0, %4\n"
1140 +"1: ldrex %1, [%3]\n"
1141 +" subs %0, %1, %4\n"
1142 +
1143 +#ifdef CONFIG_PAX_REFCOUNT
1144 +" bvc 3f\n"
1145 +" mov %0, %1\n"
1146 +"2: bkpt 0xf103\n"
1147 +"3:\n"
1148 +#endif
1149 +
1150 " strex %1, %0, [%3]\n"
1151 " teq %1, #0\n"
1152 " bne 1b"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +"\n4:\n"
1156 + _ASM_EXTABLE(2b, 4b)
1157 +#endif
1158 +
1159 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1160 : "r" (&v->counter), "Ir" (i)
1161 : "cc");
1162 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1163 __asm__ __volatile__ ("@ atomic_add_unless\n"
1164 "1: ldrex %0, [%4]\n"
1165 " teq %0, %5\n"
1166 -" beq 2f\n"
1167 -" add %1, %0, %6\n"
1168 +" beq 4f\n"
1169 +" adds %1, %0, %6\n"
1170 +
1171 +#ifdef CONFIG_PAX_REFCOUNT
1172 +" bvc 3f\n"
1173 +"2: bkpt 0xf103\n"
1174 +"3:\n"
1175 +#endif
1176 +
1177 " strex %2, %1, [%4]\n"
1178 " teq %2, #0\n"
1179 " bne 1b\n"
1180 -"2:"
1181 +"4:"
1182 +
1183 +#ifdef CONFIG_PAX_REFCOUNT
1184 + _ASM_EXTABLE(2b, 4b)
1185 +#endif
1186 +
1187 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1188 : "r" (&v->counter), "r" (u), "r" (a)
1189 : "cc");
1190 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1191 return oldval;
1192 }
1193
1194 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1195 +{
1196 + unsigned long oldval, res;
1197 +
1198 + smp_mb();
1199 +
1200 + do {
1201 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1202 + "ldrex %1, [%3]\n"
1203 + "mov %0, #0\n"
1204 + "teq %1, %4\n"
1205 + "strexeq %0, %5, [%3]\n"
1206 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1207 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1208 + : "cc");
1209 + } while (res);
1210 +
1211 + smp_mb();
1212 +
1213 + return oldval;
1214 +}
1215 +
1216 #else /* ARM_ARCH_6 */
1217
1218 #ifdef CONFIG_SMP
1219 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1220
1221 return val;
1222 }
1223 +
1224 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1225 +{
1226 + return atomic_add_return(i, v);
1227 +}
1228 +
1229 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1230 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1231 +{
1232 + (void) atomic_add_return(i, v);
1233 +}
1234
1235 static inline int atomic_sub_return(int i, atomic_t *v)
1236 {
1237 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1238 return val;
1239 }
1240 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1241 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1242 +{
1243 + (void) atomic_sub_return(i, v);
1244 +}
1245
1246 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1247 {
1248 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1249 return ret;
1250 }
1251
1252 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1253 +{
1254 + return atomic_cmpxchg(v, old, new);
1255 +}
1256 +
1257 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1258 {
1259 int c, old;
1260 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1261 #endif /* __LINUX_ARM_ARCH__ */
1262
1263 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1264 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1265 +{
1266 + return xchg(&v->counter, new);
1267 +}
1268
1269 #define atomic_inc(v) atomic_add(1, v)
1270 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1271 +{
1272 + atomic_add_unchecked(1, v);
1273 +}
1274 #define atomic_dec(v) atomic_sub(1, v)
1275 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1276 +{
1277 + atomic_sub_unchecked(1, v);
1278 +}
1279
1280 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1281 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1282 +{
1283 + return atomic_add_return_unchecked(1, v) == 0;
1284 +}
1285 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1286 #define atomic_inc_return(v) (atomic_add_return(1, v))
1287 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1288 +{
1289 + return atomic_add_return_unchecked(1, v);
1290 +}
1291 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1292 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1293
1294 @@ -246,6 +448,14 @@ typedef struct {
1295 long long counter;
1296 } atomic64_t;
1297
1298 +#ifdef CONFIG_PAX_REFCOUNT
1299 +typedef struct {
1300 + long long counter;
1301 +} atomic64_unchecked_t;
1302 +#else
1303 +typedef atomic64_t atomic64_unchecked_t;
1304 +#endif
1305 +
1306 #define ATOMIC64_INIT(i) { (i) }
1307
1308 #ifdef CONFIG_ARM_LPAE
1309 @@ -262,6 +472,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1310 return result;
1311 }
1312
1313 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1314 +{
1315 + long long result;
1316 +
1317 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1318 +" ldrd %0, %H0, [%1]"
1319 + : "=&r" (result)
1320 + : "r" (&v->counter), "Qo" (v->counter)
1321 + );
1322 +
1323 + return result;
1324 +}
1325 +
1326 static inline void atomic64_set(atomic64_t *v, long long i)
1327 {
1328 __asm__ __volatile__("@ atomic64_set\n"
1329 @@ -270,6 +493,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1330 : "r" (&v->counter), "r" (i)
1331 );
1332 }
1333 +
1334 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1335 +{
1336 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1337 +" strd %2, %H2, [%1]"
1338 + : "=Qo" (v->counter)
1339 + : "r" (&v->counter), "r" (i)
1340 + );
1341 +}
1342 #else
1343 static inline long long atomic64_read(const atomic64_t *v)
1344 {
1345 @@ -284,6 +516,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1346 return result;
1347 }
1348
1349 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1350 +{
1351 + long long result;
1352 +
1353 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1354 +" ldrexd %0, %H0, [%1]"
1355 + : "=&r" (result)
1356 + : "r" (&v->counter), "Qo" (v->counter)
1357 + );
1358 +
1359 + return result;
1360 +}
1361 +
1362 static inline void atomic64_set(atomic64_t *v, long long i)
1363 {
1364 long long tmp;
1365 @@ -298,6 +543,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1366 : "r" (&v->counter), "r" (i)
1367 : "cc");
1368 }
1369 +
1370 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1371 +{
1372 + long long tmp;
1373 +
1374 + prefetchw(&v->counter);
1375 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1376 +"1: ldrexd %0, %H0, [%2]\n"
1377 +" strexd %0, %3, %H3, [%2]\n"
1378 +" teq %0, #0\n"
1379 +" bne 1b"
1380 + : "=&r" (tmp), "=Qo" (v->counter)
1381 + : "r" (&v->counter), "r" (i)
1382 + : "cc");
1383 +}
1384 #endif
1385
1386 static inline void atomic64_add(long long i, atomic64_t *v)
1387 @@ -309,6 +569,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1388 __asm__ __volatile__("@ atomic64_add\n"
1389 "1: ldrexd %0, %H0, [%3]\n"
1390 " adds %Q0, %Q0, %Q4\n"
1391 +" adcs %R0, %R0, %R4\n"
1392 +
1393 +#ifdef CONFIG_PAX_REFCOUNT
1394 +" bvc 3f\n"
1395 +"2: bkpt 0xf103\n"
1396 +"3:\n"
1397 +#endif
1398 +
1399 +" strexd %1, %0, %H0, [%3]\n"
1400 +" teq %1, #0\n"
1401 +" bne 1b"
1402 +
1403 +#ifdef CONFIG_PAX_REFCOUNT
1404 +"\n4:\n"
1405 + _ASM_EXTABLE(2b, 4b)
1406 +#endif
1407 +
1408 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1409 + : "r" (&v->counter), "r" (i)
1410 + : "cc");
1411 +}
1412 +
1413 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1414 +{
1415 + long long result;
1416 + unsigned long tmp;
1417 +
1418 + prefetchw(&v->counter);
1419 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1420 +"1: ldrexd %0, %H0, [%3]\n"
1421 +" adds %Q0, %Q0, %Q4\n"
1422 " adc %R0, %R0, %R4\n"
1423 " strexd %1, %0, %H0, [%3]\n"
1424 " teq %1, #0\n"
1425 @@ -329,6 +620,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1426 __asm__ __volatile__("@ atomic64_add_return\n"
1427 "1: ldrexd %0, %H0, [%3]\n"
1428 " adds %Q0, %Q0, %Q4\n"
1429 +" adcs %R0, %R0, %R4\n"
1430 +
1431 +#ifdef CONFIG_PAX_REFCOUNT
1432 +" bvc 3f\n"
1433 +" mov %0, %1\n"
1434 +" mov %H0, %H1\n"
1435 +"2: bkpt 0xf103\n"
1436 +"3:\n"
1437 +#endif
1438 +
1439 +" strexd %1, %0, %H0, [%3]\n"
1440 +" teq %1, #0\n"
1441 +" bne 1b"
1442 +
1443 +#ifdef CONFIG_PAX_REFCOUNT
1444 +"\n4:\n"
1445 + _ASM_EXTABLE(2b, 4b)
1446 +#endif
1447 +
1448 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1449 + : "r" (&v->counter), "r" (i)
1450 + : "cc");
1451 +
1452 + smp_mb();
1453 +
1454 + return result;
1455 +}
1456 +
1457 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1458 +{
1459 + long long result;
1460 + unsigned long tmp;
1461 +
1462 + smp_mb();
1463 +
1464 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1465 +"1: ldrexd %0, %H0, [%3]\n"
1466 +" adds %Q0, %Q0, %Q4\n"
1467 " adc %R0, %R0, %R4\n"
1468 " strexd %1, %0, %H0, [%3]\n"
1469 " teq %1, #0\n"
1470 @@ -351,6 +680,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1471 __asm__ __volatile__("@ atomic64_sub\n"
1472 "1: ldrexd %0, %H0, [%3]\n"
1473 " subs %Q0, %Q0, %Q4\n"
1474 +" sbcs %R0, %R0, %R4\n"
1475 +
1476 +#ifdef CONFIG_PAX_REFCOUNT
1477 +" bvc 3f\n"
1478 +"2: bkpt 0xf103\n"
1479 +"3:\n"
1480 +#endif
1481 +
1482 +" strexd %1, %0, %H0, [%3]\n"
1483 +" teq %1, #0\n"
1484 +" bne 1b"
1485 +
1486 +#ifdef CONFIG_PAX_REFCOUNT
1487 +"\n4:\n"
1488 + _ASM_EXTABLE(2b, 4b)
1489 +#endif
1490 +
1491 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1492 + : "r" (&v->counter), "r" (i)
1493 + : "cc");
1494 +}
1495 +
1496 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1497 +{
1498 + long long result;
1499 + unsigned long tmp;
1500 +
1501 + prefetchw(&v->counter);
1502 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1503 +"1: ldrexd %0, %H0, [%3]\n"
1504 +" subs %Q0, %Q0, %Q4\n"
1505 " sbc %R0, %R0, %R4\n"
1506 " strexd %1, %0, %H0, [%3]\n"
1507 " teq %1, #0\n"
1508 @@ -371,10 +731,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1509 __asm__ __volatile__("@ atomic64_sub_return\n"
1510 "1: ldrexd %0, %H0, [%3]\n"
1511 " subs %Q0, %Q0, %Q4\n"
1512 -" sbc %R0, %R0, %R4\n"
1513 +" sbcs %R0, %R0, %R4\n"
1514 +
1515 +#ifdef CONFIG_PAX_REFCOUNT
1516 +" bvc 3f\n"
1517 +" mov %0, %1\n"
1518 +" mov %H0, %H1\n"
1519 +"2: bkpt 0xf103\n"
1520 +"3:\n"
1521 +#endif
1522 +
1523 " strexd %1, %0, %H0, [%3]\n"
1524 " teq %1, #0\n"
1525 " bne 1b"
1526 +
1527 +#ifdef CONFIG_PAX_REFCOUNT
1528 +"\n4:\n"
1529 + _ASM_EXTABLE(2b, 4b)
1530 +#endif
1531 +
1532 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1533 : "r" (&v->counter), "r" (i)
1534 : "cc");
1535 @@ -410,6 +785,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1536 return oldval;
1537 }
1538
1539 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1540 + long long new)
1541 +{
1542 + long long oldval;
1543 + unsigned long res;
1544 +
1545 + smp_mb();
1546 +
1547 + do {
1548 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1549 + "ldrexd %1, %H1, [%3]\n"
1550 + "mov %0, #0\n"
1551 + "teq %1, %4\n"
1552 + "teqeq %H1, %H4\n"
1553 + "strexdeq %0, %5, %H5, [%3]"
1554 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1555 + : "r" (&ptr->counter), "r" (old), "r" (new)
1556 + : "cc");
1557 + } while (res);
1558 +
1559 + smp_mb();
1560 +
1561 + return oldval;
1562 +}
1563 +
1564 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1565 {
1566 long long result;
1567 @@ -435,21 +835,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1568 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1569 {
1570 long long result;
1571 - unsigned long tmp;
1572 + u64 tmp;
1573
1574 smp_mb();
1575 prefetchw(&v->counter);
1576
1577 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1578 -"1: ldrexd %0, %H0, [%3]\n"
1579 -" subs %Q0, %Q0, #1\n"
1580 -" sbc %R0, %R0, #0\n"
1581 +"1: ldrexd %1, %H1, [%3]\n"
1582 +" subs %Q0, %Q1, #1\n"
1583 +" sbcs %R0, %R1, #0\n"
1584 +
1585 +#ifdef CONFIG_PAX_REFCOUNT
1586 +" bvc 3f\n"
1587 +" mov %Q0, %Q1\n"
1588 +" mov %R0, %R1\n"
1589 +"2: bkpt 0xf103\n"
1590 +"3:\n"
1591 +#endif
1592 +
1593 " teq %R0, #0\n"
1594 -" bmi 2f\n"
1595 +" bmi 4f\n"
1596 " strexd %1, %0, %H0, [%3]\n"
1597 " teq %1, #0\n"
1598 " bne 1b\n"
1599 -"2:"
1600 +"4:\n"
1601 +
1602 +#ifdef CONFIG_PAX_REFCOUNT
1603 + _ASM_EXTABLE(2b, 4b)
1604 +#endif
1605 +
1606 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1607 : "r" (&v->counter)
1608 : "cc");
1609 @@ -473,13 +887,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1610 " teq %0, %5\n"
1611 " teqeq %H0, %H5\n"
1612 " moveq %1, #0\n"
1613 -" beq 2f\n"
1614 +" beq 4f\n"
1615 " adds %Q0, %Q0, %Q6\n"
1616 -" adc %R0, %R0, %R6\n"
1617 +" adcs %R0, %R0, %R6\n"
1618 +
1619 +#ifdef CONFIG_PAX_REFCOUNT
1620 +" bvc 3f\n"
1621 +"2: bkpt 0xf103\n"
1622 +"3:\n"
1623 +#endif
1624 +
1625 " strexd %2, %0, %H0, [%4]\n"
1626 " teq %2, #0\n"
1627 " bne 1b\n"
1628 -"2:"
1629 +"4:\n"
1630 +
1631 +#ifdef CONFIG_PAX_REFCOUNT
1632 + _ASM_EXTABLE(2b, 4b)
1633 +#endif
1634 +
1635 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1636 : "r" (&v->counter), "r" (u), "r" (a)
1637 : "cc");
1638 @@ -492,10 +918,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1639
1640 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1641 #define atomic64_inc(v) atomic64_add(1LL, (v))
1642 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1643 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1644 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1645 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1646 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1647 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1648 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1649 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1650 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1651 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1652 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1653 index c6a3e73..35cca85 100644
1654 --- a/arch/arm/include/asm/barrier.h
1655 +++ b/arch/arm/include/asm/barrier.h
1656 @@ -63,7 +63,7 @@
1657 do { \
1658 compiletime_assert_atomic_type(*p); \
1659 smp_mb(); \
1660 - ACCESS_ONCE(*p) = (v); \
1661 + ACCESS_ONCE_RW(*p) = (v); \
1662 } while (0)
1663
1664 #define smp_load_acquire(p) \
1665 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1666 index 75fe66b..ba3dee4 100644
1667 --- a/arch/arm/include/asm/cache.h
1668 +++ b/arch/arm/include/asm/cache.h
1669 @@ -4,8 +4,10 @@
1670 #ifndef __ASMARM_CACHE_H
1671 #define __ASMARM_CACHE_H
1672
1673 +#include <linux/const.h>
1674 +
1675 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1676 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1677 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1678
1679 /*
1680 * Memory returned by kmalloc() may be used for DMA, so we must make
1681 @@ -24,5 +26,6 @@
1682 #endif
1683
1684 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1685 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1686
1687 #endif
1688 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1689 index 10e78d0..dc8505d 100644
1690 --- a/arch/arm/include/asm/cacheflush.h
1691 +++ b/arch/arm/include/asm/cacheflush.h
1692 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1693 void (*dma_unmap_area)(const void *, size_t, int);
1694
1695 void (*dma_flush_range)(const void *, const void *);
1696 -};
1697 +} __no_const;
1698
1699 /*
1700 * Select the calling method
1701 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1702 index 5233151..87a71fa 100644
1703 --- a/arch/arm/include/asm/checksum.h
1704 +++ b/arch/arm/include/asm/checksum.h
1705 @@ -37,7 +37,19 @@ __wsum
1706 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1707
1708 __wsum
1709 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1710 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1711 +
1712 +static inline __wsum
1713 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1714 +{
1715 + __wsum ret;
1716 + pax_open_userland();
1717 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1718 + pax_close_userland();
1719 + return ret;
1720 +}
1721 +
1722 +
1723
1724 /*
1725 * Fold a partial checksum without adding pseudo headers
1726 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1727 index abb2c37..96db950 100644
1728 --- a/arch/arm/include/asm/cmpxchg.h
1729 +++ b/arch/arm/include/asm/cmpxchg.h
1730 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1731
1732 #define xchg(ptr,x) \
1733 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1734 +#define xchg_unchecked(ptr,x) \
1735 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1736
1737 #include <asm-generic/cmpxchg-local.h>
1738
1739 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1740 index 6ddbe44..b5e38b1 100644
1741 --- a/arch/arm/include/asm/domain.h
1742 +++ b/arch/arm/include/asm/domain.h
1743 @@ -48,18 +48,37 @@
1744 * Domain types
1745 */
1746 #define DOMAIN_NOACCESS 0
1747 -#define DOMAIN_CLIENT 1
1748 #ifdef CONFIG_CPU_USE_DOMAINS
1749 +#define DOMAIN_USERCLIENT 1
1750 +#define DOMAIN_KERNELCLIENT 1
1751 #define DOMAIN_MANAGER 3
1752 +#define DOMAIN_VECTORS DOMAIN_USER
1753 #else
1754 +
1755 +#ifdef CONFIG_PAX_KERNEXEC
1756 #define DOMAIN_MANAGER 1
1757 +#define DOMAIN_KERNEXEC 3
1758 +#else
1759 +#define DOMAIN_MANAGER 1
1760 +#endif
1761 +
1762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1763 +#define DOMAIN_USERCLIENT 0
1764 +#define DOMAIN_UDEREF 1
1765 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1766 +#else
1767 +#define DOMAIN_USERCLIENT 1
1768 +#define DOMAIN_VECTORS DOMAIN_USER
1769 +#endif
1770 +#define DOMAIN_KERNELCLIENT 1
1771 +
1772 #endif
1773
1774 #define domain_val(dom,type) ((type) << (2*(dom)))
1775
1776 #ifndef __ASSEMBLY__
1777
1778 -#ifdef CONFIG_CPU_USE_DOMAINS
1779 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1780 static inline void set_domain(unsigned val)
1781 {
1782 asm volatile(
1783 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1784 isb();
1785 }
1786
1787 -#define modify_domain(dom,type) \
1788 - do { \
1789 - struct thread_info *thread = current_thread_info(); \
1790 - unsigned int domain = thread->cpu_domain; \
1791 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1792 - thread->cpu_domain = domain | domain_val(dom, type); \
1793 - set_domain(thread->cpu_domain); \
1794 - } while (0)
1795 -
1796 +extern void modify_domain(unsigned int dom, unsigned int type);
1797 #else
1798 static inline void set_domain(unsigned val) { }
1799 static inline void modify_domain(unsigned dom, unsigned type) { }
1800 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1801 index afb9caf..9a0bac0 100644
1802 --- a/arch/arm/include/asm/elf.h
1803 +++ b/arch/arm/include/asm/elf.h
1804 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1805 the loader. We need to make sure that it is out of the way of the program
1806 that it will "exec", and that there is sufficient room for the brk. */
1807
1808 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1809 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1810 +
1811 +#ifdef CONFIG_PAX_ASLR
1812 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1813 +
1814 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1815 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1816 +#endif
1817
1818 /* When the program starts, a1 contains a pointer to a function to be
1819 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1820 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1821 extern void elf_set_personality(const struct elf32_hdr *);
1822 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1823
1824 -struct mm_struct;
1825 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1826 -#define arch_randomize_brk arch_randomize_brk
1827 -
1828 #ifdef CONFIG_MMU
1829 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1830 struct linux_binprm;
1831 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1832 index de53547..52b9a28 100644
1833 --- a/arch/arm/include/asm/fncpy.h
1834 +++ b/arch/arm/include/asm/fncpy.h
1835 @@ -81,7 +81,9 @@
1836 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1837 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1838 \
1839 + pax_open_kernel(); \
1840 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1841 + pax_close_kernel(); \
1842 flush_icache_range((unsigned long)(dest_buf), \
1843 (unsigned long)(dest_buf) + (size)); \
1844 \
1845 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1846 index 53e69da..3fdc896 100644
1847 --- a/arch/arm/include/asm/futex.h
1848 +++ b/arch/arm/include/asm/futex.h
1849 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1850 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1851 return -EFAULT;
1852
1853 + pax_open_userland();
1854 +
1855 smp_mb();
1856 /* Prefetching cannot fault */
1857 prefetchw(uaddr);
1858 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1859 : "cc", "memory");
1860 smp_mb();
1861
1862 + pax_close_userland();
1863 +
1864 *uval = val;
1865 return ret;
1866 }
1867 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1868 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1869 return -EFAULT;
1870
1871 + pax_open_userland();
1872 +
1873 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1874 "1: " TUSER(ldr) " %1, [%4]\n"
1875 " teq %1, %2\n"
1876 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1877 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1878 : "cc", "memory");
1879
1880 + pax_close_userland();
1881 +
1882 *uval = val;
1883 return ret;
1884 }
1885 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1886 return -EFAULT;
1887
1888 pagefault_disable(); /* implies preempt_disable() */
1889 + pax_open_userland();
1890
1891 switch (op) {
1892 case FUTEX_OP_SET:
1893 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1894 ret = -ENOSYS;
1895 }
1896
1897 + pax_close_userland();
1898 pagefault_enable(); /* subsumes preempt_enable() */
1899
1900 if (!ret) {
1901 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1902 index 83eb2f7..ed77159 100644
1903 --- a/arch/arm/include/asm/kmap_types.h
1904 +++ b/arch/arm/include/asm/kmap_types.h
1905 @@ -4,6 +4,6 @@
1906 /*
1907 * This is the "bare minimum". AIO seems to require this.
1908 */
1909 -#define KM_TYPE_NR 16
1910 +#define KM_TYPE_NR 17
1911
1912 #endif
1913 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1914 index 9e614a1..3302cca 100644
1915 --- a/arch/arm/include/asm/mach/dma.h
1916 +++ b/arch/arm/include/asm/mach/dma.h
1917 @@ -22,7 +22,7 @@ struct dma_ops {
1918 int (*residue)(unsigned int, dma_t *); /* optional */
1919 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1920 const char *type;
1921 -};
1922 +} __do_const;
1923
1924 struct dma_struct {
1925 void *addr; /* single DMA address */
1926 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1927 index f98c7f3..e5c626d 100644
1928 --- a/arch/arm/include/asm/mach/map.h
1929 +++ b/arch/arm/include/asm/mach/map.h
1930 @@ -23,17 +23,19 @@ struct map_desc {
1931
1932 /* types 0-3 are defined in asm/io.h */
1933 enum {
1934 - MT_UNCACHED = 4,
1935 - MT_CACHECLEAN,
1936 - MT_MINICLEAN,
1937 + MT_UNCACHED_RW = 4,
1938 + MT_CACHECLEAN_RO,
1939 + MT_MINICLEAN_RO,
1940 MT_LOW_VECTORS,
1941 MT_HIGH_VECTORS,
1942 - MT_MEMORY_RWX,
1943 + __MT_MEMORY_RWX,
1944 MT_MEMORY_RW,
1945 - MT_ROM,
1946 - MT_MEMORY_RWX_NONCACHED,
1947 + MT_MEMORY_RX,
1948 + MT_ROM_RX,
1949 + MT_MEMORY_RW_NONCACHED,
1950 + MT_MEMORY_RX_NONCACHED,
1951 MT_MEMORY_RW_DTCM,
1952 - MT_MEMORY_RWX_ITCM,
1953 + MT_MEMORY_RX_ITCM,
1954 MT_MEMORY_RW_SO,
1955 MT_MEMORY_DMA_READY,
1956 };
1957 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1958 index 891a56b..48f337e 100644
1959 --- a/arch/arm/include/asm/outercache.h
1960 +++ b/arch/arm/include/asm/outercache.h
1961 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1962
1963 /* This is an ARM L2C thing */
1964 void (*write_sec)(unsigned long, unsigned);
1965 -};
1966 +} __no_const;
1967
1968 extern struct outer_cache_fns outer_cache;
1969
1970 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1971 index 4355f0e..cd9168e 100644
1972 --- a/arch/arm/include/asm/page.h
1973 +++ b/arch/arm/include/asm/page.h
1974 @@ -23,6 +23,7 @@
1975
1976 #else
1977
1978 +#include <linux/compiler.h>
1979 #include <asm/glue.h>
1980
1981 /*
1982 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1983 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1984 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1985 unsigned long vaddr, struct vm_area_struct *vma);
1986 -};
1987 +} __no_const;
1988
1989 #ifdef MULTI_USER
1990 extern struct cpu_user_fns cpu_user;
1991 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1992 index 78a7793..e3dc06c 100644
1993 --- a/arch/arm/include/asm/pgalloc.h
1994 +++ b/arch/arm/include/asm/pgalloc.h
1995 @@ -17,6 +17,7 @@
1996 #include <asm/processor.h>
1997 #include <asm/cacheflush.h>
1998 #include <asm/tlbflush.h>
1999 +#include <asm/system_info.h>
2000
2001 #define check_pgt_cache() do { } while (0)
2002
2003 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2004 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2005 }
2006
2007 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2008 +{
2009 + pud_populate(mm, pud, pmd);
2010 +}
2011 +
2012 #else /* !CONFIG_ARM_LPAE */
2013
2014 /*
2015 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2016 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2017 #define pmd_free(mm, pmd) do { } while (0)
2018 #define pud_populate(mm,pmd,pte) BUG()
2019 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2020
2021 #endif /* CONFIG_ARM_LPAE */
2022
2023 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2024 __free_page(pte);
2025 }
2026
2027 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2028 +{
2029 +#ifdef CONFIG_ARM_LPAE
2030 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2031 +#else
2032 + if (addr & SECTION_SIZE)
2033 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2034 + else
2035 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2036 +#endif
2037 + flush_pmd_entry(pmdp);
2038 +}
2039 +
2040 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2041 pmdval_t prot)
2042 {
2043 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2044 static inline void
2045 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2046 {
2047 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2048 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2049 }
2050 #define pmd_pgtable(pmd) pmd_page(pmd)
2051
2052 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2053 index 5cfba15..f415e1a 100644
2054 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2055 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2056 @@ -20,12 +20,15 @@
2057 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2058 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2059 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2060 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2061 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2062 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2063 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2064 +
2065 /*
2066 * - section
2067 */
2068 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2069 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2070 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2071 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2072 @@ -37,6 +40,7 @@
2073 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2074 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2075 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2076 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2077
2078 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2079 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2080 @@ -66,6 +70,7 @@
2081 * - extended small page/tiny page
2082 */
2083 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2084 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2085 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2086 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2087 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2088 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2089 index 219ac88..73ec32a 100644
2090 --- a/arch/arm/include/asm/pgtable-2level.h
2091 +++ b/arch/arm/include/asm/pgtable-2level.h
2092 @@ -126,6 +126,9 @@
2093 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2094 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2095
2096 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2097 +#define L_PTE_PXN (_AT(pteval_t, 0))
2098 +
2099 /*
2100 * These are the memory types, defined to be compatible with
2101 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2102 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2103 index 9fd61c7..f8f1cff 100644
2104 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2105 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2106 @@ -76,6 +76,7 @@
2107 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2108 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2109 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2110 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2111 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2112
2113 /*
2114 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2115 index 06e0bc0..e60c2d3 100644
2116 --- a/arch/arm/include/asm/pgtable-3level.h
2117 +++ b/arch/arm/include/asm/pgtable-3level.h
2118 @@ -81,6 +81,7 @@
2119 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
2120 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2121 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2122 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2123 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2124 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2125 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2126 @@ -96,6 +97,7 @@
2127 /*
2128 * To be used in assembly code with the upper page attributes.
2129 */
2130 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2131 #define L_PTE_XN_HIGH (1 << (54 - 32))
2132 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2133
2134 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2135 index 01baef0..73c156e 100644
2136 --- a/arch/arm/include/asm/pgtable.h
2137 +++ b/arch/arm/include/asm/pgtable.h
2138 @@ -33,6 +33,9 @@
2139 #include <asm/pgtable-2level.h>
2140 #endif
2141
2142 +#define ktla_ktva(addr) (addr)
2143 +#define ktva_ktla(addr) (addr)
2144 +
2145 /*
2146 * Just any arbitrary offset to the start of the vmalloc VM area: the
2147 * current 8MB value just means that there will be a 8MB "hole" after the
2148 @@ -48,6 +51,9 @@
2149 #define LIBRARY_TEXT_START 0x0c000000
2150
2151 #ifndef __ASSEMBLY__
2152 +extern pteval_t __supported_pte_mask;
2153 +extern pmdval_t __supported_pmd_mask;
2154 +
2155 extern void __pte_error(const char *file, int line, pte_t);
2156 extern void __pmd_error(const char *file, int line, pmd_t);
2157 extern void __pgd_error(const char *file, int line, pgd_t);
2158 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2159 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2160 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2161
2162 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2163 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2164 +
2165 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2166 +#include <asm/domain.h>
2167 +#include <linux/thread_info.h>
2168 +#include <linux/preempt.h>
2169 +
2170 +static inline int test_domain(int domain, int domaintype)
2171 +{
2172 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2173 +}
2174 +#endif
2175 +
2176 +#ifdef CONFIG_PAX_KERNEXEC
2177 +static inline unsigned long pax_open_kernel(void) {
2178 +#ifdef CONFIG_ARM_LPAE
2179 + /* TODO */
2180 +#else
2181 + preempt_disable();
2182 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2183 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2184 +#endif
2185 + return 0;
2186 +}
2187 +
2188 +static inline unsigned long pax_close_kernel(void) {
2189 +#ifdef CONFIG_ARM_LPAE
2190 + /* TODO */
2191 +#else
2192 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2193 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2194 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2195 + preempt_enable_no_resched();
2196 +#endif
2197 + return 0;
2198 +}
2199 +#else
2200 +static inline unsigned long pax_open_kernel(void) { return 0; }
2201 +static inline unsigned long pax_close_kernel(void) { return 0; }
2202 +#endif
2203 +
2204 /*
2205 * This is the lowest virtual address we can permit any user space
2206 * mapping to be mapped at. This is particularly important for
2207 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2208 /*
2209 * The pgprot_* and protection_map entries will be fixed up in runtime
2210 * to include the cachable and bufferable bits based on memory policy,
2211 - * as well as any architecture dependent bits like global/ASID and SMP
2212 - * shared mapping bits.
2213 + * as well as any architecture dependent bits like global/ASID, PXN,
2214 + * and SMP shared mapping bits.
2215 */
2216 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2217
2218 @@ -269,7 +317,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2219 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2220 {
2221 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2222 - L_PTE_NONE | L_PTE_VALID;
2223 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2224 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2225 return pte;
2226 }
2227 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2228 index c25ef3e..735f14b 100644
2229 --- a/arch/arm/include/asm/psci.h
2230 +++ b/arch/arm/include/asm/psci.h
2231 @@ -32,7 +32,7 @@ struct psci_operations {
2232 int (*affinity_info)(unsigned long target_affinity,
2233 unsigned long lowest_affinity_level);
2234 int (*migrate_info_type)(void);
2235 -};
2236 +} __no_const;
2237
2238 extern struct psci_operations psci_ops;
2239 extern struct smp_operations psci_smp_ops;
2240 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2241 index 2ec765c..beb1fe16 100644
2242 --- a/arch/arm/include/asm/smp.h
2243 +++ b/arch/arm/include/asm/smp.h
2244 @@ -113,7 +113,7 @@ struct smp_operations {
2245 int (*cpu_disable)(unsigned int cpu);
2246 #endif
2247 #endif
2248 -};
2249 +} __no_const;
2250
2251 struct of_cpu_method {
2252 const char *method;
2253 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2254 index fc44d37..acc63c4 100644
2255 --- a/arch/arm/include/asm/thread_info.h
2256 +++ b/arch/arm/include/asm/thread_info.h
2257 @@ -89,9 +89,9 @@ struct thread_info {
2258 .flags = 0, \
2259 .preempt_count = INIT_PREEMPT_COUNT, \
2260 .addr_limit = KERNEL_DS, \
2261 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2262 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2263 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2264 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2265 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2266 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2267 .restart_block = { \
2268 .fn = do_no_restart_syscall, \
2269 }, \
2270 @@ -165,7 +165,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2271 #define TIF_SYSCALL_AUDIT 9
2272 #define TIF_SYSCALL_TRACEPOINT 10
2273 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2274 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2275 +/* within 8 bits of TIF_SYSCALL_TRACE
2276 + * to meet flexible second operand requirements
2277 + */
2278 +#define TIF_GRSEC_SETXID 12
2279 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2280 #define TIF_USING_IWMMXT 17
2281 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2282 #define TIF_RESTORE_SIGMASK 20
2283 @@ -179,10 +183,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2284 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2285 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2286 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2287 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2288
2289 /* Checks for any syscall work in entry-common.S */
2290 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2291 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2292 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2293
2294 /*
2295 * Change these and you break ASM code in entry-common.S
2296 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2297 index 5f833f7..76e6644 100644
2298 --- a/arch/arm/include/asm/tls.h
2299 +++ b/arch/arm/include/asm/tls.h
2300 @@ -3,6 +3,7 @@
2301
2302 #include <linux/compiler.h>
2303 #include <asm/thread_info.h>
2304 +#include <asm/pgtable.h>
2305
2306 #ifdef __ASSEMBLY__
2307 #include <asm/asm-offsets.h>
2308 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2309 * at 0xffff0fe0 must be used instead. (see
2310 * entry-armv.S for details)
2311 */
2312 + pax_open_kernel();
2313 *((unsigned int *)0xffff0ff0) = val;
2314 + pax_close_kernel();
2315 #endif
2316 }
2317
2318 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2319 index 4767eb9..bf00668 100644
2320 --- a/arch/arm/include/asm/uaccess.h
2321 +++ b/arch/arm/include/asm/uaccess.h
2322 @@ -18,6 +18,7 @@
2323 #include <asm/domain.h>
2324 #include <asm/unified.h>
2325 #include <asm/compiler.h>
2326 +#include <asm/pgtable.h>
2327
2328 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2329 #include <asm-generic/uaccess-unaligned.h>
2330 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2331 static inline void set_fs(mm_segment_t fs)
2332 {
2333 current_thread_info()->addr_limit = fs;
2334 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2335 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2336 }
2337
2338 #define segment_eq(a,b) ((a) == (b))
2339
2340 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2341 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2342 +
2343 +static inline void pax_open_userland(void)
2344 +{
2345 +
2346 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2347 + if (segment_eq(get_fs(), USER_DS)) {
2348 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2349 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2350 + }
2351 +#endif
2352 +
2353 +}
2354 +
2355 +static inline void pax_close_userland(void)
2356 +{
2357 +
2358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2359 + if (segment_eq(get_fs(), USER_DS)) {
2360 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2361 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2362 + }
2363 +#endif
2364 +
2365 +}
2366 +
2367 #define __addr_ok(addr) ({ \
2368 unsigned long flag; \
2369 __asm__("cmp %2, %0; movlo %0, #0" \
2370 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2371
2372 #define get_user(x,p) \
2373 ({ \
2374 + int __e; \
2375 might_fault(); \
2376 - __get_user_check(x,p); \
2377 + pax_open_userland(); \
2378 + __e = __get_user_check(x,p); \
2379 + pax_close_userland(); \
2380 + __e; \
2381 })
2382
2383 extern int __put_user_1(void *, unsigned int);
2384 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2385
2386 #define put_user(x,p) \
2387 ({ \
2388 + int __e; \
2389 might_fault(); \
2390 - __put_user_check(x,p); \
2391 + pax_open_userland(); \
2392 + __e = __put_user_check(x,p); \
2393 + pax_close_userland(); \
2394 + __e; \
2395 })
2396
2397 #else /* CONFIG_MMU */
2398 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2399
2400 #endif /* CONFIG_MMU */
2401
2402 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2403 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2404
2405 #define user_addr_max() \
2406 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2407 #define __get_user(x,ptr) \
2408 ({ \
2409 long __gu_err = 0; \
2410 + pax_open_userland(); \
2411 __get_user_err((x),(ptr),__gu_err); \
2412 + pax_close_userland(); \
2413 __gu_err; \
2414 })
2415
2416 #define __get_user_error(x,ptr,err) \
2417 ({ \
2418 + pax_open_userland(); \
2419 __get_user_err((x),(ptr),err); \
2420 + pax_close_userland(); \
2421 (void) 0; \
2422 })
2423
2424 @@ -368,13 +409,17 @@ do { \
2425 #define __put_user(x,ptr) \
2426 ({ \
2427 long __pu_err = 0; \
2428 + pax_open_userland(); \
2429 __put_user_err((x),(ptr),__pu_err); \
2430 + pax_close_userland(); \
2431 __pu_err; \
2432 })
2433
2434 #define __put_user_error(x,ptr,err) \
2435 ({ \
2436 + pax_open_userland(); \
2437 __put_user_err((x),(ptr),err); \
2438 + pax_close_userland(); \
2439 (void) 0; \
2440 })
2441
2442 @@ -474,11 +519,44 @@ do { \
2443
2444
2445 #ifdef CONFIG_MMU
2446 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2447 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2448 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2449 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2450 +
2451 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2452 +{
2453 + unsigned long ret;
2454 +
2455 + check_object_size(to, n, false);
2456 + pax_open_userland();
2457 + ret = ___copy_from_user(to, from, n);
2458 + pax_close_userland();
2459 + return ret;
2460 +}
2461 +
2462 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2463 +{
2464 + unsigned long ret;
2465 +
2466 + check_object_size(from, n, true);
2467 + pax_open_userland();
2468 + ret = ___copy_to_user(to, from, n);
2469 + pax_close_userland();
2470 + return ret;
2471 +}
2472 +
2473 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2474 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2475 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2476 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2477 +
2478 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2479 +{
2480 + unsigned long ret;
2481 + pax_open_userland();
2482 + ret = ___clear_user(addr, n);
2483 + pax_close_userland();
2484 + return ret;
2485 +}
2486 +
2487 #else
2488 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2489 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2490 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2491
2492 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2493 {
2494 + if ((long)n < 0)
2495 + return n;
2496 +
2497 if (access_ok(VERIFY_READ, from, n))
2498 n = __copy_from_user(to, from, n);
2499 else /* security hole - plug it */
2500 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2501
2502 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2503 {
2504 + if ((long)n < 0)
2505 + return n;
2506 +
2507 if (access_ok(VERIFY_WRITE, to, n))
2508 n = __copy_to_user(to, from, n);
2509 return n;
2510 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2511 index 5af0ed1..cea83883 100644
2512 --- a/arch/arm/include/uapi/asm/ptrace.h
2513 +++ b/arch/arm/include/uapi/asm/ptrace.h
2514 @@ -92,7 +92,7 @@
2515 * ARMv7 groups of PSR bits
2516 */
2517 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2518 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2519 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2520 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2521 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2522
2523 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2524 index a88671c..1cc895e 100644
2525 --- a/arch/arm/kernel/armksyms.c
2526 +++ b/arch/arm/kernel/armksyms.c
2527 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2528
2529 /* networking */
2530 EXPORT_SYMBOL(csum_partial);
2531 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2532 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2533 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2534 EXPORT_SYMBOL(__csum_ipv6_magic);
2535
2536 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2537 #ifdef CONFIG_MMU
2538 EXPORT_SYMBOL(copy_page);
2539
2540 -EXPORT_SYMBOL(__copy_from_user);
2541 -EXPORT_SYMBOL(__copy_to_user);
2542 -EXPORT_SYMBOL(__clear_user);
2543 +EXPORT_SYMBOL(___copy_from_user);
2544 +EXPORT_SYMBOL(___copy_to_user);
2545 +EXPORT_SYMBOL(___clear_user);
2546
2547 EXPORT_SYMBOL(__get_user_1);
2548 EXPORT_SYMBOL(__get_user_2);
2549 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2550 index 36276cd..9d7b13b 100644
2551 --- a/arch/arm/kernel/entry-armv.S
2552 +++ b/arch/arm/kernel/entry-armv.S
2553 @@ -47,6 +47,87 @@
2554 9997:
2555 .endm
2556
2557 + .macro pax_enter_kernel
2558 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2559 + @ make aligned space for saved DACR
2560 + sub sp, sp, #8
2561 + @ save regs
2562 + stmdb sp!, {r1, r2}
2563 + @ read DACR from cpu_domain into r1
2564 + mov r2, sp
2565 + @ assume 8K pages, since we have to split the immediate in two
2566 + bic r2, r2, #(0x1fc0)
2567 + bic r2, r2, #(0x3f)
2568 + ldr r1, [r2, #TI_CPU_DOMAIN]
2569 + @ store old DACR on stack
2570 + str r1, [sp, #8]
2571 +#ifdef CONFIG_PAX_KERNEXEC
2572 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2573 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2574 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2575 +#endif
2576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2577 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2578 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2579 +#endif
2580 + @ write r1 to current_thread_info()->cpu_domain
2581 + str r1, [r2, #TI_CPU_DOMAIN]
2582 + @ write r1 to DACR
2583 + mcr p15, 0, r1, c3, c0, 0
2584 + @ instruction sync
2585 + instr_sync
2586 + @ restore regs
2587 + ldmia sp!, {r1, r2}
2588 +#endif
2589 + .endm
2590 +
2591 + .macro pax_open_userland
2592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2593 + @ save regs
2594 + stmdb sp!, {r0, r1}
2595 + @ read DACR from cpu_domain into r1
2596 + mov r0, sp
2597 + @ assume 8K pages, since we have to split the immediate in two
2598 + bic r0, r0, #(0x1fc0)
2599 + bic r0, r0, #(0x3f)
2600 + ldr r1, [r0, #TI_CPU_DOMAIN]
2601 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2602 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2603 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2604 + @ write r1 to current_thread_info()->cpu_domain
2605 + str r1, [r0, #TI_CPU_DOMAIN]
2606 + @ write r1 to DACR
2607 + mcr p15, 0, r1, c3, c0, 0
2608 + @ instruction sync
2609 + instr_sync
2610 + @ restore regs
2611 + ldmia sp!, {r0, r1}
2612 +#endif
2613 + .endm
2614 +
2615 + .macro pax_close_userland
2616 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2617 + @ save regs
2618 + stmdb sp!, {r0, r1}
2619 + @ read DACR from cpu_domain into r1
2620 + mov r0, sp
2621 + @ assume 8K pages, since we have to split the immediate in two
2622 + bic r0, r0, #(0x1fc0)
2623 + bic r0, r0, #(0x3f)
2624 + ldr r1, [r0, #TI_CPU_DOMAIN]
2625 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2626 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2627 + @ write r1 to current_thread_info()->cpu_domain
2628 + str r1, [r0, #TI_CPU_DOMAIN]
2629 + @ write r1 to DACR
2630 + mcr p15, 0, r1, c3, c0, 0
2631 + @ instruction sync
2632 + instr_sync
2633 + @ restore regs
2634 + ldmia sp!, {r0, r1}
2635 +#endif
2636 + .endm
2637 +
2638 .macro pabt_helper
2639 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2640 #ifdef MULTI_PABORT
2641 @@ -89,11 +170,15 @@
2642 * Invalid mode handlers
2643 */
2644 .macro inv_entry, reason
2645 +
2646 + pax_enter_kernel
2647 +
2648 sub sp, sp, #S_FRAME_SIZE
2649 ARM( stmib sp, {r1 - lr} )
2650 THUMB( stmia sp, {r0 - r12} )
2651 THUMB( str sp, [sp, #S_SP] )
2652 THUMB( str lr, [sp, #S_LR] )
2653 +
2654 mov r1, #\reason
2655 .endm
2656
2657 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2658 .macro svc_entry, stack_hole=0
2659 UNWIND(.fnstart )
2660 UNWIND(.save {r0 - pc} )
2661 +
2662 + pax_enter_kernel
2663 +
2664 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2665 +
2666 #ifdef CONFIG_THUMB2_KERNEL
2667 SPFIX( str r0, [sp] ) @ temporarily saved
2668 SPFIX( mov r0, sp )
2669 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2670 ldmia r0, {r3 - r5}
2671 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2672 mov r6, #-1 @ "" "" "" ""
2673 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2674 + @ offset sp by 8 as done in pax_enter_kernel
2675 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2676 +#else
2677 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2678 +#endif
2679 SPFIX( addeq r2, r2, #4 )
2680 str r3, [sp, #-4]! @ save the "real" r0 copied
2681 @ from the exception stack
2682 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2683 .macro usr_entry
2684 UNWIND(.fnstart )
2685 UNWIND(.cantunwind ) @ don't unwind the user space
2686 +
2687 + pax_enter_kernel_user
2688 +
2689 sub sp, sp, #S_FRAME_SIZE
2690 ARM( stmib sp, {r1 - r12} )
2691 THUMB( stmia sp, {r0 - r12} )
2692 @@ -421,7 +518,9 @@ __und_usr:
2693 tst r3, #PSR_T_BIT @ Thumb mode?
2694 bne __und_usr_thumb
2695 sub r4, r2, #4 @ ARM instr at LR - 4
2696 + pax_open_userland
2697 1: ldrt r0, [r4]
2698 + pax_close_userland
2699 ARM_BE8(rev r0, r0) @ little endian instruction
2700
2701 @ r0 = 32-bit ARM instruction which caused the exception
2702 @@ -455,11 +554,15 @@ __und_usr_thumb:
2703 */
2704 .arch armv6t2
2705 #endif
2706 + pax_open_userland
2707 2: ldrht r5, [r4]
2708 + pax_close_userland
2709 ARM_BE8(rev16 r5, r5) @ little endian instruction
2710 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2711 blo __und_usr_fault_16 @ 16bit undefined instruction
2712 + pax_open_userland
2713 3: ldrht r0, [r2]
2714 + pax_close_userland
2715 ARM_BE8(rev16 r0, r0) @ little endian instruction
2716 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2717 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2718 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
2719 */
2720 .pushsection .fixup, "ax"
2721 .align 2
2722 -4: str r4, [sp, #S_PC] @ retry current instruction
2723 +4: pax_close_userland
2724 + str r4, [sp, #S_PC] @ retry current instruction
2725 ret r9
2726 .popsection
2727 .pushsection __ex_table,"a"
2728 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
2729 THUMB( str lr, [ip], #4 )
2730 ldr r4, [r2, #TI_TP_VALUE]
2731 ldr r5, [r2, #TI_TP_VALUE + 4]
2732 -#ifdef CONFIG_CPU_USE_DOMAINS
2733 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2734 ldr r6, [r2, #TI_CPU_DOMAIN]
2735 #endif
2736 switch_tls r1, r4, r5, r3, r7
2737 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
2738 ldr r8, =__stack_chk_guard
2739 ldr r7, [r7, #TSK_STACK_CANARY]
2740 #endif
2741 -#ifdef CONFIG_CPU_USE_DOMAINS
2742 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2743 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2744 #endif
2745 mov r5, r0
2746 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2747 index e52fe5a..1b0a924 100644
2748 --- a/arch/arm/kernel/entry-common.S
2749 +++ b/arch/arm/kernel/entry-common.S
2750 @@ -11,18 +11,46 @@
2751 #include <asm/assembler.h>
2752 #include <asm/unistd.h>
2753 #include <asm/ftrace.h>
2754 +#include <asm/domain.h>
2755 #include <asm/unwind.h>
2756
2757 +#include "entry-header.S"
2758 +
2759 #ifdef CONFIG_NEED_RET_TO_USER
2760 #include <mach/entry-macro.S>
2761 #else
2762 .macro arch_ret_to_user, tmp1, tmp2
2763 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2764 + @ save regs
2765 + stmdb sp!, {r1, r2}
2766 + @ read DACR from cpu_domain into r1
2767 + mov r2, sp
2768 + @ assume 8K pages, since we have to split the immediate in two
2769 + bic r2, r2, #(0x1fc0)
2770 + bic r2, r2, #(0x3f)
2771 + ldr r1, [r2, #TI_CPU_DOMAIN]
2772 +#ifdef CONFIG_PAX_KERNEXEC
2773 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2774 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2775 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2776 +#endif
2777 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2778 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2779 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2780 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2781 +#endif
2782 + @ write r1 to current_thread_info()->cpu_domain
2783 + str r1, [r2, #TI_CPU_DOMAIN]
2784 + @ write r1 to DACR
2785 + mcr p15, 0, r1, c3, c0, 0
2786 + @ instruction sync
2787 + instr_sync
2788 + @ restore regs
2789 + ldmia sp!, {r1, r2}
2790 +#endif
2791 .endm
2792 #endif
2793
2794 -#include "entry-header.S"
2795 -
2796 -
2797 .align 5
2798 /*
2799 * This is the fast syscall return path. We do as little as
2800 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2801 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2802 #endif
2803
2804 + /*
2805 + * do this here to avoid a performance hit of wrapping the code above
2806 + * that directly dereferences userland to parse the SWI instruction
2807 + */
2808 + pax_enter_kernel_user
2809 +
2810 adr tbl, sys_call_table @ load syscall table pointer
2811
2812 #if defined(CONFIG_OABI_COMPAT)
2813 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2814 index 2fdf867..6e909e4 100644
2815 --- a/arch/arm/kernel/entry-header.S
2816 +++ b/arch/arm/kernel/entry-header.S
2817 @@ -188,6 +188,60 @@
2818 msr cpsr_c, \rtemp @ switch back to the SVC mode
2819 .endm
2820
2821 + .macro pax_enter_kernel_user
2822 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2823 + @ save regs
2824 + stmdb sp!, {r0, r1}
2825 + @ read DACR from cpu_domain into r1
2826 + mov r0, sp
2827 + @ assume 8K pages, since we have to split the immediate in two
2828 + bic r0, r0, #(0x1fc0)
2829 + bic r0, r0, #(0x3f)
2830 + ldr r1, [r0, #TI_CPU_DOMAIN]
2831 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2832 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2833 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2834 +#endif
2835 +#ifdef CONFIG_PAX_KERNEXEC
2836 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2837 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2838 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2839 +#endif
2840 + @ write r1 to current_thread_info()->cpu_domain
2841 + str r1, [r0, #TI_CPU_DOMAIN]
2842 + @ write r1 to DACR
2843 + mcr p15, 0, r1, c3, c0, 0
2844 + @ instruction sync
2845 + instr_sync
2846 + @ restore regs
2847 + ldmia sp!, {r0, r1}
2848 +#endif
2849 + .endm
2850 +
2851 + .macro pax_exit_kernel
2852 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2853 + @ save regs
2854 + stmdb sp!, {r0, r1}
2855 + @ read old DACR from stack into r1
2856 + ldr r1, [sp, #(8 + S_SP)]
2857 + sub r1, r1, #8
2858 + ldr r1, [r1]
2859 +
2860 + @ write r1 to current_thread_info()->cpu_domain
2861 + mov r0, sp
2862 + @ assume 8K pages, since we have to split the immediate in two
2863 + bic r0, r0, #(0x1fc0)
2864 + bic r0, r0, #(0x3f)
2865 + str r1, [r0, #TI_CPU_DOMAIN]
2866 + @ write r1 to DACR
2867 + mcr p15, 0, r1, c3, c0, 0
2868 + @ instruction sync
2869 + instr_sync
2870 + @ restore regs
2871 + ldmia sp!, {r0, r1}
2872 +#endif
2873 + .endm
2874 +
2875 #ifndef CONFIG_THUMB2_KERNEL
2876 .macro svc_exit, rpsr, irq = 0
2877 .if \irq != 0
2878 @@ -207,6 +261,9 @@
2879 blne trace_hardirqs_off
2880 #endif
2881 .endif
2882 +
2883 + pax_exit_kernel
2884 +
2885 msr spsr_cxsf, \rpsr
2886 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2887 @ We must avoid clrex due to Cortex-A15 erratum #830321
2888 @@ -254,6 +311,9 @@
2889 blne trace_hardirqs_off
2890 #endif
2891 .endif
2892 +
2893 + pax_exit_kernel
2894 +
2895 ldr lr, [sp, #S_SP] @ top of the stack
2896 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2897
2898 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2899 index 918875d..cd5fa27 100644
2900 --- a/arch/arm/kernel/fiq.c
2901 +++ b/arch/arm/kernel/fiq.c
2902 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2903 void *base = vectors_page;
2904 unsigned offset = FIQ_OFFSET;
2905
2906 + pax_open_kernel();
2907 memcpy(base + offset, start, length);
2908 + pax_close_kernel();
2909 +
2910 if (!cache_is_vipt_nonaliasing())
2911 flush_icache_range((unsigned long)base + offset, offset +
2912 length);
2913 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2914 index 664eee8..f470938 100644
2915 --- a/arch/arm/kernel/head.S
2916 +++ b/arch/arm/kernel/head.S
2917 @@ -437,7 +437,7 @@ __enable_mmu:
2918 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2919 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2920 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2921 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2922 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2923 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2924 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2925 #endif
2926 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2927 index 6a4dffe..4a86a70 100644
2928 --- a/arch/arm/kernel/module.c
2929 +++ b/arch/arm/kernel/module.c
2930 @@ -38,12 +38,39 @@
2931 #endif
2932
2933 #ifdef CONFIG_MMU
2934 -void *module_alloc(unsigned long size)
2935 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2936 {
2937 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2938 + return NULL;
2939 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2940 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2941 + GFP_KERNEL, prot, NUMA_NO_NODE,
2942 __builtin_return_address(0));
2943 }
2944 +
2945 +void *module_alloc(unsigned long size)
2946 +{
2947 +
2948 +#ifdef CONFIG_PAX_KERNEXEC
2949 + return __module_alloc(size, PAGE_KERNEL);
2950 +#else
2951 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2952 +#endif
2953 +
2954 +}
2955 +
2956 +#ifdef CONFIG_PAX_KERNEXEC
2957 +void module_free_exec(struct module *mod, void *module_region)
2958 +{
2959 + module_free(mod, module_region);
2960 +}
2961 +EXPORT_SYMBOL(module_free_exec);
2962 +
2963 +void *module_alloc_exec(unsigned long size)
2964 +{
2965 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2966 +}
2967 +EXPORT_SYMBOL(module_alloc_exec);
2968 +#endif
2969 #endif
2970
2971 int
2972 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2973 index 07314af..c46655c 100644
2974 --- a/arch/arm/kernel/patch.c
2975 +++ b/arch/arm/kernel/patch.c
2976 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2977 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2978 int size;
2979
2980 + pax_open_kernel();
2981 if (thumb2 && __opcode_is_thumb16(insn)) {
2982 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2983 size = sizeof(u16);
2984 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2985 *(u32 *)addr = insn;
2986 size = sizeof(u32);
2987 }
2988 + pax_close_kernel();
2989
2990 flush_icache_range((uintptr_t)(addr),
2991 (uintptr_t)(addr) + size);
2992 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2993 index a35f6eb..7af43a0 100644
2994 --- a/arch/arm/kernel/process.c
2995 +++ b/arch/arm/kernel/process.c
2996 @@ -212,6 +212,7 @@ void machine_power_off(void)
2997
2998 if (pm_power_off)
2999 pm_power_off();
3000 + BUG();
3001 }
3002
3003 /*
3004 @@ -225,7 +226,7 @@ void machine_power_off(void)
3005 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3006 * to use. Implementing such co-ordination would be essentially impossible.
3007 */
3008 -void machine_restart(char *cmd)
3009 +__noreturn void machine_restart(char *cmd)
3010 {
3011 local_irq_disable();
3012 smp_send_stop();
3013 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3014
3015 show_regs_print_info(KERN_DEFAULT);
3016
3017 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3018 - print_symbol("LR is at %s\n", regs->ARM_lr);
3019 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3020 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3021 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3022 "sp : %08lx ip : %08lx fp : %08lx\n",
3023 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3024 @@ -427,12 +428,6 @@ unsigned long get_wchan(struct task_struct *p)
3025 return 0;
3026 }
3027
3028 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3029 -{
3030 - unsigned long range_end = mm->brk + 0x02000000;
3031 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3032 -}
3033 -
3034 #ifdef CONFIG_MMU
3035 #ifdef CONFIG_KUSER_HELPERS
3036 /*
3037 @@ -448,7 +443,7 @@ static struct vm_area_struct gate_vma = {
3038
3039 static int __init gate_vma_init(void)
3040 {
3041 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3042 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3043 return 0;
3044 }
3045 arch_initcall(gate_vma_init);
3046 @@ -474,41 +469,16 @@ int in_gate_area_no_mm(unsigned long addr)
3047
3048 const char *arch_vma_name(struct vm_area_struct *vma)
3049 {
3050 - return is_gate_vma(vma) ? "[vectors]" :
3051 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3052 - "[sigpage]" : NULL;
3053 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3054 }
3055
3056 -static struct page *signal_page;
3057 -extern struct page *get_signal_page(void);
3058 -
3059 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3060 {
3061 struct mm_struct *mm = current->mm;
3062 - unsigned long addr;
3063 - int ret;
3064 -
3065 - if (!signal_page)
3066 - signal_page = get_signal_page();
3067 - if (!signal_page)
3068 - return -ENOMEM;
3069
3070 down_write(&mm->mmap_sem);
3071 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3072 - if (IS_ERR_VALUE(addr)) {
3073 - ret = addr;
3074 - goto up_fail;
3075 - }
3076 -
3077 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3078 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3079 - &signal_page);
3080 -
3081 - if (ret == 0)
3082 - mm->context.sigpage = addr;
3083 -
3084 - up_fail:
3085 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3086 up_write(&mm->mmap_sem);
3087 - return ret;
3088 + return 0;
3089 }
3090 #endif
3091 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3092 index f73891b..cf3004e 100644
3093 --- a/arch/arm/kernel/psci.c
3094 +++ b/arch/arm/kernel/psci.c
3095 @@ -28,7 +28,7 @@
3096 #include <asm/psci.h>
3097 #include <asm/system_misc.h>
3098
3099 -struct psci_operations psci_ops;
3100 +struct psci_operations psci_ops __read_only;
3101
3102 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3103 typedef int (*psci_initcall_t)(const struct device_node *);
3104 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3105 index 0c27ed6..b67388e 100644
3106 --- a/arch/arm/kernel/ptrace.c
3107 +++ b/arch/arm/kernel/ptrace.c
3108 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3109 regs->ARM_ip = ip;
3110 }
3111
3112 +#ifdef CONFIG_GRKERNSEC_SETXID
3113 +extern void gr_delayed_cred_worker(void);
3114 +#endif
3115 +
3116 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3117 {
3118 current_thread_info()->syscall = scno;
3119
3120 +#ifdef CONFIG_GRKERNSEC_SETXID
3121 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3122 + gr_delayed_cred_worker();
3123 +#endif
3124 +
3125 /* Do the secure computing check first; failures should be fast. */
3126 if (secure_computing(scno) == -1)
3127 return -1;
3128 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3129 index 84db893d..bd8213a 100644
3130 --- a/arch/arm/kernel/setup.c
3131 +++ b/arch/arm/kernel/setup.c
3132 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3133 unsigned int elf_hwcap2 __read_mostly;
3134 EXPORT_SYMBOL(elf_hwcap2);
3135
3136 +pteval_t __supported_pte_mask __read_only;
3137 +pmdval_t __supported_pmd_mask __read_only;
3138
3139 #ifdef MULTI_CPU
3140 -struct processor processor __read_mostly;
3141 +struct processor processor __read_only;
3142 #endif
3143 #ifdef MULTI_TLB
3144 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3145 +struct cpu_tlb_fns cpu_tlb __read_only;
3146 #endif
3147 #ifdef MULTI_USER
3148 -struct cpu_user_fns cpu_user __read_mostly;
3149 +struct cpu_user_fns cpu_user __read_only;
3150 #endif
3151 #ifdef MULTI_CACHE
3152 -struct cpu_cache_fns cpu_cache __read_mostly;
3153 +struct cpu_cache_fns cpu_cache __read_only;
3154 #endif
3155 #ifdef CONFIG_OUTER_CACHE
3156 -struct outer_cache_fns outer_cache __read_mostly;
3157 +struct outer_cache_fns outer_cache __read_only;
3158 EXPORT_SYMBOL(outer_cache);
3159 #endif
3160
3161 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3162 asm("mrc p15, 0, %0, c0, c1, 4"
3163 : "=r" (mmfr0));
3164 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3165 - (mmfr0 & 0x000000f0) >= 0x00000030)
3166 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3167 cpu_arch = CPU_ARCH_ARMv7;
3168 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3169 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3170 + __supported_pte_mask |= L_PTE_PXN;
3171 + __supported_pmd_mask |= PMD_PXNTABLE;
3172 + }
3173 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3174 (mmfr0 & 0x000000f0) == 0x00000020)
3175 cpu_arch = CPU_ARCH_ARMv6;
3176 else
3177 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3178 index bd19834..e4d8c66 100644
3179 --- a/arch/arm/kernel/signal.c
3180 +++ b/arch/arm/kernel/signal.c
3181 @@ -24,8 +24,6 @@
3182
3183 extern const unsigned long sigreturn_codes[7];
3184
3185 -static unsigned long signal_return_offset;
3186 -
3187 #ifdef CONFIG_CRUNCH
3188 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3189 {
3190 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3191 * except when the MPU has protected the vectors
3192 * page from PL0
3193 */
3194 - retcode = mm->context.sigpage + signal_return_offset +
3195 - (idx << 2) + thumb;
3196 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3197 } else
3198 #endif
3199 {
3200 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3201 } while (thread_flags & _TIF_WORK_MASK);
3202 return 0;
3203 }
3204 -
3205 -struct page *get_signal_page(void)
3206 -{
3207 - unsigned long ptr;
3208 - unsigned offset;
3209 - struct page *page;
3210 - void *addr;
3211 -
3212 - page = alloc_pages(GFP_KERNEL, 0);
3213 -
3214 - if (!page)
3215 - return NULL;
3216 -
3217 - addr = page_address(page);
3218 -
3219 - /* Give the signal return code some randomness */
3220 - offset = 0x200 + (get_random_int() & 0x7fc);
3221 - signal_return_offset = offset;
3222 -
3223 - /*
3224 - * Copy signal return handlers into the vector page, and
3225 - * set sigreturn to be a pointer to these.
3226 - */
3227 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3228 -
3229 - ptr = (unsigned long)addr + offset;
3230 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3231 -
3232 - return page;
3233 -}
3234 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3235 index bbe22fc..d7737f5 100644
3236 --- a/arch/arm/kernel/smp.c
3237 +++ b/arch/arm/kernel/smp.c
3238 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3239
3240 static DECLARE_COMPLETION(cpu_running);
3241
3242 -static struct smp_operations smp_ops;
3243 +static struct smp_operations smp_ops __read_only;
3244
3245 void __init smp_set_ops(struct smp_operations *ops)
3246 {
3247 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3248 index 7a3be1d..b00c7de 100644
3249 --- a/arch/arm/kernel/tcm.c
3250 +++ b/arch/arm/kernel/tcm.c
3251 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3252 .virtual = ITCM_OFFSET,
3253 .pfn = __phys_to_pfn(ITCM_OFFSET),
3254 .length = 0,
3255 - .type = MT_MEMORY_RWX_ITCM,
3256 + .type = MT_MEMORY_RX_ITCM,
3257 }
3258 };
3259
3260 @@ -267,7 +267,9 @@ no_dtcm:
3261 start = &__sitcm_text;
3262 end = &__eitcm_text;
3263 ram = &__itcm_start;
3264 + pax_open_kernel();
3265 memcpy(start, ram, itcm_code_sz);
3266 + pax_close_kernel();
3267 pr_debug("CPU ITCM: copied code from %p - %p\n",
3268 start, end);
3269 itcm_present = true;
3270 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3271 index a964c9f..cf2a5b1 100644
3272 --- a/arch/arm/kernel/traps.c
3273 +++ b/arch/arm/kernel/traps.c
3274 @@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3275 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3276 {
3277 #ifdef CONFIG_KALLSYMS
3278 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3279 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3280 #else
3281 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3282 #endif
3283 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3284 static int die_owner = -1;
3285 static unsigned int die_nest_count;
3286
3287 +extern void gr_handle_kernel_exploit(void);
3288 +
3289 static unsigned long oops_begin(void)
3290 {
3291 int cpu;
3292 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3293 panic("Fatal exception in interrupt");
3294 if (panic_on_oops)
3295 panic("Fatal exception");
3296 +
3297 + gr_handle_kernel_exploit();
3298 +
3299 if (signr)
3300 do_exit(signr);
3301 }
3302 @@ -887,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3303 kuser_init(vectors_base);
3304
3305 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3306 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3307 +
3308 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3309 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3310 +#endif
3311 +
3312 #else /* ifndef CONFIG_CPU_V7M */
3313 /*
3314 * on V7-M there is no need to copy the vector table to a dedicated
3315 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3316 index 6f57cb9..645f8c4 100644
3317 --- a/arch/arm/kernel/vmlinux.lds.S
3318 +++ b/arch/arm/kernel/vmlinux.lds.S
3319 @@ -8,7 +8,11 @@
3320 #include <asm/thread_info.h>
3321 #include <asm/memory.h>
3322 #include <asm/page.h>
3323 -
3324 +
3325 +#ifdef CONFIG_PAX_KERNEXEC
3326 +#include <asm/pgtable.h>
3327 +#endif
3328 +
3329 #define PROC_INFO \
3330 . = ALIGN(4); \
3331 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3332 @@ -34,7 +38,7 @@
3333 #endif
3334
3335 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3336 - defined(CONFIG_GENERIC_BUG)
3337 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3338 #define ARM_EXIT_KEEP(x) x
3339 #define ARM_EXIT_DISCARD(x)
3340 #else
3341 @@ -90,6 +94,11 @@ SECTIONS
3342 _text = .;
3343 HEAD_TEXT
3344 }
3345 +
3346 +#ifdef CONFIG_PAX_KERNEXEC
3347 + . = ALIGN(1<<SECTION_SHIFT);
3348 +#endif
3349 +
3350 .text : { /* Real text segment */
3351 _stext = .; /* Text and read-only data */
3352 __exception_text_start = .;
3353 @@ -112,6 +121,8 @@ SECTIONS
3354 ARM_CPU_KEEP(PROC_INFO)
3355 }
3356
3357 + _etext = .; /* End of text section */
3358 +
3359 RO_DATA(PAGE_SIZE)
3360
3361 . = ALIGN(4);
3362 @@ -142,7 +153,9 @@ SECTIONS
3363
3364 NOTES
3365
3366 - _etext = .; /* End of text and rodata section */
3367 +#ifdef CONFIG_PAX_KERNEXEC
3368 + . = ALIGN(1<<SECTION_SHIFT);
3369 +#endif
3370
3371 #ifndef CONFIG_XIP_KERNEL
3372 . = ALIGN(PAGE_SIZE);
3373 @@ -220,6 +233,11 @@ SECTIONS
3374 . = PAGE_OFFSET + TEXT_OFFSET;
3375 #else
3376 __init_end = .;
3377 +
3378 +#ifdef CONFIG_PAX_KERNEXEC
3379 + . = ALIGN(1<<SECTION_SHIFT);
3380 +#endif
3381 +
3382 . = ALIGN(THREAD_SIZE);
3383 __data_loc = .;
3384 #endif
3385 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3386 index a99e0cd..ab56421d 100644
3387 --- a/arch/arm/kvm/arm.c
3388 +++ b/arch/arm/kvm/arm.c
3389 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3390 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3391
3392 /* The VMID used in the VTTBR */
3393 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3394 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3395 static u8 kvm_next_vmid;
3396 static DEFINE_SPINLOCK(kvm_vmid_lock);
3397
3398 @@ -372,7 +372,7 @@ void force_vm_exit(const cpumask_t *mask)
3399 */
3400 static bool need_new_vmid_gen(struct kvm *kvm)
3401 {
3402 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3403 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3404 }
3405
3406 /**
3407 @@ -405,7 +405,7 @@ static void update_vttbr(struct kvm *kvm)
3408
3409 /* First user of a new VMID generation? */
3410 if (unlikely(kvm_next_vmid == 0)) {
3411 - atomic64_inc(&kvm_vmid_gen);
3412 + atomic64_inc_unchecked(&kvm_vmid_gen);
3413 kvm_next_vmid = 1;
3414
3415 /*
3416 @@ -422,7 +422,7 @@ static void update_vttbr(struct kvm *kvm)
3417 kvm_call_hyp(__kvm_flush_vm_context);
3418 }
3419
3420 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3421 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3422 kvm->arch.vmid = kvm_next_vmid;
3423 kvm_next_vmid++;
3424
3425 @@ -997,7 +997,7 @@ static void check_kvm_target_cpu(void *ret)
3426 /**
3427 * Initialize Hyp-mode and memory mappings on all CPUs.
3428 */
3429 -int kvm_arch_init(void *opaque)
3430 +int kvm_arch_init(const void *opaque)
3431 {
3432 int err;
3433 int ret, cpu;
3434 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3435 index 14a0d98..7771a7d 100644
3436 --- a/arch/arm/lib/clear_user.S
3437 +++ b/arch/arm/lib/clear_user.S
3438 @@ -12,14 +12,14 @@
3439
3440 .text
3441
3442 -/* Prototype: int __clear_user(void *addr, size_t sz)
3443 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3444 * Purpose : clear some user memory
3445 * Params : addr - user memory address to clear
3446 * : sz - number of bytes to clear
3447 * Returns : number of bytes NOT cleared
3448 */
3449 ENTRY(__clear_user_std)
3450 -WEAK(__clear_user)
3451 +WEAK(___clear_user)
3452 stmfd sp!, {r1, lr}
3453 mov r2, #0
3454 cmp r1, #4
3455 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3456 USER( strnebt r2, [r0])
3457 mov r0, #0
3458 ldmfd sp!, {r1, pc}
3459 -ENDPROC(__clear_user)
3460 +ENDPROC(___clear_user)
3461 ENDPROC(__clear_user_std)
3462
3463 .pushsection .fixup,"ax"
3464 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3465 index 66a477a..bee61d3 100644
3466 --- a/arch/arm/lib/copy_from_user.S
3467 +++ b/arch/arm/lib/copy_from_user.S
3468 @@ -16,7 +16,7 @@
3469 /*
3470 * Prototype:
3471 *
3472 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3473 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3474 *
3475 * Purpose:
3476 *
3477 @@ -84,11 +84,11 @@
3478
3479 .text
3480
3481 -ENTRY(__copy_from_user)
3482 +ENTRY(___copy_from_user)
3483
3484 #include "copy_template.S"
3485
3486 -ENDPROC(__copy_from_user)
3487 +ENDPROC(___copy_from_user)
3488
3489 .pushsection .fixup,"ax"
3490 .align 0
3491 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3492 index 6ee2f67..d1cce76 100644
3493 --- a/arch/arm/lib/copy_page.S
3494 +++ b/arch/arm/lib/copy_page.S
3495 @@ -10,6 +10,7 @@
3496 * ASM optimised string functions
3497 */
3498 #include <linux/linkage.h>
3499 +#include <linux/const.h>
3500 #include <asm/assembler.h>
3501 #include <asm/asm-offsets.h>
3502 #include <asm/cache.h>
3503 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3504 index d066df6..df28194 100644
3505 --- a/arch/arm/lib/copy_to_user.S
3506 +++ b/arch/arm/lib/copy_to_user.S
3507 @@ -16,7 +16,7 @@
3508 /*
3509 * Prototype:
3510 *
3511 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3512 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3513 *
3514 * Purpose:
3515 *
3516 @@ -88,11 +88,11 @@
3517 .text
3518
3519 ENTRY(__copy_to_user_std)
3520 -WEAK(__copy_to_user)
3521 +WEAK(___copy_to_user)
3522
3523 #include "copy_template.S"
3524
3525 -ENDPROC(__copy_to_user)
3526 +ENDPROC(___copy_to_user)
3527 ENDPROC(__copy_to_user_std)
3528
3529 .pushsection .fixup,"ax"
3530 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3531 index 7d08b43..f7ca7ea 100644
3532 --- a/arch/arm/lib/csumpartialcopyuser.S
3533 +++ b/arch/arm/lib/csumpartialcopyuser.S
3534 @@ -57,8 +57,8 @@
3535 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3536 */
3537
3538 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3539 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3540 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3541 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3542
3543 #include "csumpartialcopygeneric.S"
3544
3545 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3546 index 312d43e..21d2322 100644
3547 --- a/arch/arm/lib/delay.c
3548 +++ b/arch/arm/lib/delay.c
3549 @@ -29,7 +29,7 @@
3550 /*
3551 * Default to the loop-based delay implementation.
3552 */
3553 -struct arm_delay_ops arm_delay_ops = {
3554 +struct arm_delay_ops arm_delay_ops __read_only = {
3555 .delay = __loop_delay,
3556 .const_udelay = __loop_const_udelay,
3557 .udelay = __loop_udelay,
3558 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3559 index 3e58d71..029817c 100644
3560 --- a/arch/arm/lib/uaccess_with_memcpy.c
3561 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3562 @@ -136,7 +136,7 @@ out:
3563 }
3564
3565 unsigned long
3566 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3567 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3568 {
3569 /*
3570 * This test is stubbed out of the main function above to keep
3571 @@ -190,7 +190,7 @@ out:
3572 return n;
3573 }
3574
3575 -unsigned long __clear_user(void __user *addr, unsigned long n)
3576 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3577 {
3578 /* See rational for this in __copy_to_user() above. */
3579 if (n < 64)
3580 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3581 index f7a07a5..258e1f7 100644
3582 --- a/arch/arm/mach-at91/setup.c
3583 +++ b/arch/arm/mach-at91/setup.c
3584 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3585
3586 desc->pfn = __phys_to_pfn(base);
3587 desc->length = length;
3588 - desc->type = MT_MEMORY_RWX_NONCACHED;
3589 + desc->type = MT_MEMORY_RW_NONCACHED;
3590
3591 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3592 base, length, desc->virtual);
3593 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3594 index 2bdc323..cf1c607 100644
3595 --- a/arch/arm/mach-mvebu/coherency.c
3596 +++ b/arch/arm/mach-mvebu/coherency.c
3597 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3598
3599 /*
3600 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3601 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3602 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3603 * is needed as a workaround for a deadlock issue between the PCIe
3604 * interface and the cache controller.
3605 */
3606 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3607 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3608
3609 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3610 - mtype = MT_UNCACHED;
3611 + mtype = MT_UNCACHED_RW;
3612
3613 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3614 }
3615 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3616 index aead77a..a2253fa 100644
3617 --- a/arch/arm/mach-omap2/board-n8x0.c
3618 +++ b/arch/arm/mach-omap2/board-n8x0.c
3619 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3620 }
3621 #endif
3622
3623 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3624 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3625 .late_init = n8x0_menelaus_late_init,
3626 };
3627
3628 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3629 index 2f97228..6ce10e1 100644
3630 --- a/arch/arm/mach-omap2/gpmc.c
3631 +++ b/arch/arm/mach-omap2/gpmc.c
3632 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3633 };
3634
3635 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3636 -static struct irq_chip gpmc_irq_chip;
3637 static int gpmc_irq_start;
3638
3639 static struct resource gpmc_mem_root;
3640 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3641
3642 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3643
3644 +static struct irq_chip gpmc_irq_chip = {
3645 + .name = "gpmc",
3646 + .irq_startup = gpmc_irq_noop_ret,
3647 + .irq_enable = gpmc_irq_enable,
3648 + .irq_disable = gpmc_irq_disable,
3649 + .irq_shutdown = gpmc_irq_noop,
3650 + .irq_ack = gpmc_irq_noop,
3651 + .irq_mask = gpmc_irq_noop,
3652 + .irq_unmask = gpmc_irq_noop,
3653 +
3654 +};
3655 +
3656 static int gpmc_setup_irq(void)
3657 {
3658 int i;
3659 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3660 return gpmc_irq_start;
3661 }
3662
3663 - gpmc_irq_chip.name = "gpmc";
3664 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3665 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3666 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3667 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3668 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3669 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3670 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3671 -
3672 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3673 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3674
3675 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3676 index 4001325..b14e2a0 100644
3677 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3678 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3679 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3680 int (*finish_suspend)(unsigned long cpu_state);
3681 void (*resume)(void);
3682 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3683 -};
3684 +} __no_const;
3685
3686 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3687 static struct powerdomain *mpuss_pd;
3688 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3689 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3690 {}
3691
3692 -struct cpu_pm_ops omap_pm_ops = {
3693 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3694 .finish_suspend = default_finish_suspend,
3695 .resume = dummy_cpu_resume,
3696 .scu_prepare = dummy_scu_prepare,
3697 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3698 index 37843a7..a98df13 100644
3699 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3700 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3701 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3702 return NOTIFY_OK;
3703 }
3704
3705 -static struct notifier_block __refdata irq_hotplug_notifier = {
3706 +static struct notifier_block irq_hotplug_notifier = {
3707 .notifier_call = irq_cpu_hotplug_notify,
3708 };
3709
3710 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3711 index d22c30d..23697a1 100644
3712 --- a/arch/arm/mach-omap2/omap_device.c
3713 +++ b/arch/arm/mach-omap2/omap_device.c
3714 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3715 struct platform_device __init *omap_device_build(const char *pdev_name,
3716 int pdev_id,
3717 struct omap_hwmod *oh,
3718 - void *pdata, int pdata_len)
3719 + const void *pdata, int pdata_len)
3720 {
3721 struct omap_hwmod *ohs[] = { oh };
3722
3723 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3724 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3725 int pdev_id,
3726 struct omap_hwmod **ohs,
3727 - int oh_cnt, void *pdata,
3728 + int oh_cnt, const void *pdata,
3729 int pdata_len)
3730 {
3731 int ret = -ENOMEM;
3732 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3733 index 78c02b3..c94109a 100644
3734 --- a/arch/arm/mach-omap2/omap_device.h
3735 +++ b/arch/arm/mach-omap2/omap_device.h
3736 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3737 /* Core code interface */
3738
3739 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3740 - struct omap_hwmod *oh, void *pdata,
3741 + struct omap_hwmod *oh, const void *pdata,
3742 int pdata_len);
3743
3744 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3745 struct omap_hwmod **oh, int oh_cnt,
3746 - void *pdata, int pdata_len);
3747 + const void *pdata, int pdata_len);
3748
3749 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3750 struct omap_hwmod **ohs, int oh_cnt);
3751 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3752 index 9e91a4e..357ed0d 100644
3753 --- a/arch/arm/mach-omap2/omap_hwmod.c
3754 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3755 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3756 int (*init_clkdm)(struct omap_hwmod *oh);
3757 void (*update_context_lost)(struct omap_hwmod *oh);
3758 int (*get_context_lost)(struct omap_hwmod *oh);
3759 -};
3760 +} __no_const;
3761
3762 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3763 -static struct omap_hwmod_soc_ops soc_ops;
3764 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3765
3766 /* omap_hwmod_list contains all registered struct omap_hwmods */
3767 static LIST_HEAD(omap_hwmod_list);
3768 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3769 index 95fee54..cfa9cf1 100644
3770 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3771 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3772 @@ -10,6 +10,7 @@
3773
3774 #include <linux/kernel.h>
3775 #include <linux/init.h>
3776 +#include <asm/pgtable.h>
3777
3778 #include "powerdomain.h"
3779
3780 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3781
3782 void __init am43xx_powerdomains_init(void)
3783 {
3784 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3785 + pax_open_kernel();
3786 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3787 + pax_close_kernel();
3788 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3789 pwrdm_register_pwrdms(powerdomains_am43xx);
3790 pwrdm_complete_init();
3791 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3792 index 97d6607..8429d14 100644
3793 --- a/arch/arm/mach-omap2/wd_timer.c
3794 +++ b/arch/arm/mach-omap2/wd_timer.c
3795 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3796 struct omap_hwmod *oh;
3797 char *oh_name = "wd_timer2";
3798 char *dev_name = "omap_wdt";
3799 - struct omap_wd_timer_platform_data pdata;
3800 + static struct omap_wd_timer_platform_data pdata = {
3801 + .read_reset_sources = prm_read_reset_sources
3802 + };
3803
3804 if (!cpu_class_is_omap2() || of_have_populated_dt())
3805 return 0;
3806 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3807 return -EINVAL;
3808 }
3809
3810 - pdata.read_reset_sources = prm_read_reset_sources;
3811 -
3812 pdev = omap_device_build(dev_name, id, oh, &pdata,
3813 sizeof(struct omap_wd_timer_platform_data));
3814 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3815 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3816 index b30bf5c..d0825bf 100644
3817 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3818 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3819 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3820 bool entered_lp2 = false;
3821
3822 if (tegra_pending_sgi())
3823 - ACCESS_ONCE(abort_flag) = true;
3824 + ACCESS_ONCE_RW(abort_flag) = true;
3825
3826 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3827
3828 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3829 index 2dea8b5..6499da2 100644
3830 --- a/arch/arm/mach-ux500/setup.h
3831 +++ b/arch/arm/mach-ux500/setup.h
3832 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3833 .type = MT_DEVICE, \
3834 }
3835
3836 -#define __MEM_DEV_DESC(x, sz) { \
3837 - .virtual = IO_ADDRESS(x), \
3838 - .pfn = __phys_to_pfn(x), \
3839 - .length = sz, \
3840 - .type = MT_MEMORY_RWX, \
3841 -}
3842 -
3843 extern struct smp_operations ux500_smp_ops;
3844 extern void ux500_cpu_die(unsigned int cpu);
3845
3846 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3847 index ae69809..2665202 100644
3848 --- a/arch/arm/mm/Kconfig
3849 +++ b/arch/arm/mm/Kconfig
3850 @@ -446,6 +446,7 @@ config CPU_32v5
3851
3852 config CPU_32v6
3853 bool
3854 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3855 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3856
3857 config CPU_32v6K
3858 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3859
3860 config CPU_USE_DOMAINS
3861 bool
3862 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3863 help
3864 This option enables or disables the use of domain switching
3865 via the set_fs() function.
3866 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3867 config KUSER_HELPERS
3868 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3869 default y
3870 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3871 help
3872 Warning: disabling this option may break user programs.
3873
3874 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3875 See Documentation/arm/kernel_user_helpers.txt for details.
3876
3877 However, the fixed address nature of these helpers can be used
3878 - by ROP (return orientated programming) authors when creating
3879 + by ROP (Return Oriented Programming) authors when creating
3880 exploits.
3881
3882 If all of the binaries and libraries which run on your platform
3883 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3884 index 83792f4..c25d36b 100644
3885 --- a/arch/arm/mm/alignment.c
3886 +++ b/arch/arm/mm/alignment.c
3887 @@ -216,10 +216,12 @@ union offset_union {
3888 #define __get16_unaligned_check(ins,val,addr) \
3889 do { \
3890 unsigned int err = 0, v, a = addr; \
3891 + pax_open_userland(); \
3892 __get8_unaligned_check(ins,v,a,err); \
3893 val = v << ((BE) ? 8 : 0); \
3894 __get8_unaligned_check(ins,v,a,err); \
3895 val |= v << ((BE) ? 0 : 8); \
3896 + pax_close_userland(); \
3897 if (err) \
3898 goto fault; \
3899 } while (0)
3900 @@ -233,6 +235,7 @@ union offset_union {
3901 #define __get32_unaligned_check(ins,val,addr) \
3902 do { \
3903 unsigned int err = 0, v, a = addr; \
3904 + pax_open_userland(); \
3905 __get8_unaligned_check(ins,v,a,err); \
3906 val = v << ((BE) ? 24 : 0); \
3907 __get8_unaligned_check(ins,v,a,err); \
3908 @@ -241,6 +244,7 @@ union offset_union {
3909 val |= v << ((BE) ? 8 : 16); \
3910 __get8_unaligned_check(ins,v,a,err); \
3911 val |= v << ((BE) ? 0 : 24); \
3912 + pax_close_userland(); \
3913 if (err) \
3914 goto fault; \
3915 } while (0)
3916 @@ -254,6 +258,7 @@ union offset_union {
3917 #define __put16_unaligned_check(ins,val,addr) \
3918 do { \
3919 unsigned int err = 0, v = val, a = addr; \
3920 + pax_open_userland(); \
3921 __asm__( FIRST_BYTE_16 \
3922 ARM( "1: "ins" %1, [%2], #1\n" ) \
3923 THUMB( "1: "ins" %1, [%2]\n" ) \
3924 @@ -273,6 +278,7 @@ union offset_union {
3925 " .popsection\n" \
3926 : "=r" (err), "=&r" (v), "=&r" (a) \
3927 : "0" (err), "1" (v), "2" (a)); \
3928 + pax_close_userland(); \
3929 if (err) \
3930 goto fault; \
3931 } while (0)
3932 @@ -286,6 +292,7 @@ union offset_union {
3933 #define __put32_unaligned_check(ins,val,addr) \
3934 do { \
3935 unsigned int err = 0, v = val, a = addr; \
3936 + pax_open_userland(); \
3937 __asm__( FIRST_BYTE_32 \
3938 ARM( "1: "ins" %1, [%2], #1\n" ) \
3939 THUMB( "1: "ins" %1, [%2]\n" ) \
3940 @@ -315,6 +322,7 @@ union offset_union {
3941 " .popsection\n" \
3942 : "=r" (err), "=&r" (v), "=&r" (a) \
3943 : "0" (err), "1" (v), "2" (a)); \
3944 + pax_close_userland(); \
3945 if (err) \
3946 goto fault; \
3947 } while (0)
3948 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3949 index 5f2c988..221412d 100644
3950 --- a/arch/arm/mm/cache-l2x0.c
3951 +++ b/arch/arm/mm/cache-l2x0.c
3952 @@ -41,7 +41,7 @@ struct l2c_init_data {
3953 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3954 void (*save)(void __iomem *);
3955 struct outer_cache_fns outer_cache;
3956 -};
3957 +} __do_const;
3958
3959 #define CACHE_LINE_SIZE 32
3960
3961 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3962 index 6eb97b3..ac509f6 100644
3963 --- a/arch/arm/mm/context.c
3964 +++ b/arch/arm/mm/context.c
3965 @@ -43,7 +43,7 @@
3966 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3967
3968 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3969 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3970 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3971 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3972
3973 static DEFINE_PER_CPU(atomic64_t, active_asids);
3974 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3975 {
3976 static u32 cur_idx = 1;
3977 u64 asid = atomic64_read(&mm->context.id);
3978 - u64 generation = atomic64_read(&asid_generation);
3979 + u64 generation = atomic64_read_unchecked(&asid_generation);
3980
3981 if (asid != 0 && is_reserved_asid(asid)) {
3982 /*
3983 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3984 */
3985 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3986 if (asid == NUM_USER_ASIDS) {
3987 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3988 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3989 &asid_generation);
3990 flush_context(cpu);
3991 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3992 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3993 cpu_set_reserved_ttbr0();
3994
3995 asid = atomic64_read(&mm->context.id);
3996 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3997 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3998 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3999 goto switch_mm_fastpath;
4000
4001 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4002 /* Check that our ASID belongs to the current generation. */
4003 asid = atomic64_read(&mm->context.id);
4004 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4005 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4006 asid = new_context(mm, cpu);
4007 atomic64_set(&mm->context.id, asid);
4008 }
4009 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4010 index eb8830a..5360ce7 100644
4011 --- a/arch/arm/mm/fault.c
4012 +++ b/arch/arm/mm/fault.c
4013 @@ -25,6 +25,7 @@
4014 #include <asm/system_misc.h>
4015 #include <asm/system_info.h>
4016 #include <asm/tlbflush.h>
4017 +#include <asm/sections.h>
4018
4019 #include "fault.h"
4020
4021 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4022 if (fixup_exception(regs))
4023 return;
4024
4025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4026 + if (addr < TASK_SIZE) {
4027 + if (current->signal->curr_ip)
4028 + 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),
4029 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4030 + else
4031 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4032 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4033 + }
4034 +#endif
4035 +
4036 +#ifdef CONFIG_PAX_KERNEXEC
4037 + if ((fsr & FSR_WRITE) &&
4038 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4039 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4040 + {
4041 + if (current->signal->curr_ip)
4042 + 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),
4043 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4044 + else
4045 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4046 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4047 + }
4048 +#endif
4049 +
4050 /*
4051 * No handler, we'll have to terminate things with extreme prejudice.
4052 */
4053 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4054 }
4055 #endif
4056
4057 +#ifdef CONFIG_PAX_PAGEEXEC
4058 + if (fsr & FSR_LNX_PF) {
4059 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4060 + do_group_exit(SIGKILL);
4061 + }
4062 +#endif
4063 +
4064 tsk->thread.address = addr;
4065 tsk->thread.error_code = fsr;
4066 tsk->thread.trap_no = 14;
4067 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4068 }
4069 #endif /* CONFIG_MMU */
4070
4071 +#ifdef CONFIG_PAX_PAGEEXEC
4072 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4073 +{
4074 + long i;
4075 +
4076 + printk(KERN_ERR "PAX: bytes at PC: ");
4077 + for (i = 0; i < 20; i++) {
4078 + unsigned char c;
4079 + if (get_user(c, (__force unsigned char __user *)pc+i))
4080 + printk(KERN_CONT "?? ");
4081 + else
4082 + printk(KERN_CONT "%02x ", c);
4083 + }
4084 + printk("\n");
4085 +
4086 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4087 + for (i = -1; i < 20; i++) {
4088 + unsigned long c;
4089 + if (get_user(c, (__force unsigned long __user *)sp+i))
4090 + printk(KERN_CONT "???????? ");
4091 + else
4092 + printk(KERN_CONT "%08lx ", c);
4093 + }
4094 + printk("\n");
4095 +}
4096 +#endif
4097 +
4098 /*
4099 * First Level Translation Fault Handler
4100 *
4101 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4102 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4103 struct siginfo info;
4104
4105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4106 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4107 + if (current->signal->curr_ip)
4108 + 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),
4109 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4110 + else
4111 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4112 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4113 + goto die;
4114 + }
4115 +#endif
4116 +
4117 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4118 return;
4119
4120 +die:
4121 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4122 inf->name, fsr, addr);
4123
4124 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4125 ifsr_info[nr].name = name;
4126 }
4127
4128 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4129 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4130 +
4131 asmlinkage void __exception
4132 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4133 {
4134 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4135 struct siginfo info;
4136 + unsigned long pc = instruction_pointer(regs);
4137 +
4138 + if (user_mode(regs)) {
4139 + unsigned long sigpage = current->mm->context.sigpage;
4140 +
4141 + if (sigpage <= pc && pc < sigpage + 7*4) {
4142 + if (pc < sigpage + 3*4)
4143 + sys_sigreturn(regs);
4144 + else
4145 + sys_rt_sigreturn(regs);
4146 + return;
4147 + }
4148 + if (pc == 0xffff0f60UL) {
4149 + /*
4150 + * PaX: __kuser_cmpxchg64 emulation
4151 + */
4152 + // TODO
4153 + //regs->ARM_pc = regs->ARM_lr;
4154 + //return;
4155 + }
4156 + if (pc == 0xffff0fa0UL) {
4157 + /*
4158 + * PaX: __kuser_memory_barrier emulation
4159 + */
4160 + // dmb(); implied by the exception
4161 + regs->ARM_pc = regs->ARM_lr;
4162 + return;
4163 + }
4164 + if (pc == 0xffff0fc0UL) {
4165 + /*
4166 + * PaX: __kuser_cmpxchg emulation
4167 + */
4168 + // TODO
4169 + //long new;
4170 + //int op;
4171 +
4172 + //op = FUTEX_OP_SET << 28;
4173 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4174 + //regs->ARM_r0 = old != new;
4175 + //regs->ARM_pc = regs->ARM_lr;
4176 + //return;
4177 + }
4178 + if (pc == 0xffff0fe0UL) {
4179 + /*
4180 + * PaX: __kuser_get_tls emulation
4181 + */
4182 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4183 + regs->ARM_pc = regs->ARM_lr;
4184 + return;
4185 + }
4186 + }
4187 +
4188 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4189 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4190 + if (current->signal->curr_ip)
4191 + 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),
4192 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4193 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4194 + else
4195 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4196 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4197 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4198 + goto die;
4199 + }
4200 +#endif
4201 +
4202 +#ifdef CONFIG_PAX_REFCOUNT
4203 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4204 + unsigned int bkpt;
4205 +
4206 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4207 + current->thread.error_code = ifsr;
4208 + current->thread.trap_no = 0;
4209 + pax_report_refcount_overflow(regs);
4210 + fixup_exception(regs);
4211 + return;
4212 + }
4213 + }
4214 +#endif
4215
4216 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4217 return;
4218
4219 +die:
4220 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4221 inf->name, ifsr, addr);
4222
4223 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4224 index cf08bdf..772656c 100644
4225 --- a/arch/arm/mm/fault.h
4226 +++ b/arch/arm/mm/fault.h
4227 @@ -3,6 +3,7 @@
4228
4229 /*
4230 * Fault status register encodings. We steal bit 31 for our own purposes.
4231 + * Set when the FSR value is from an instruction fault.
4232 */
4233 #define FSR_LNX_PF (1 << 31)
4234 #define FSR_WRITE (1 << 11)
4235 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4236 }
4237 #endif
4238
4239 +/* valid for LPAE and !LPAE */
4240 +static inline int is_xn_fault(unsigned int fsr)
4241 +{
4242 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4243 +}
4244 +
4245 +static inline int is_domain_fault(unsigned int fsr)
4246 +{
4247 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4248 +}
4249 +
4250 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4251 unsigned long search_exception_table(unsigned long addr);
4252
4253 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4254 index 659c75d..6f8c029 100644
4255 --- a/arch/arm/mm/init.c
4256 +++ b/arch/arm/mm/init.c
4257 @@ -31,6 +31,8 @@
4258 #include <asm/setup.h>
4259 #include <asm/tlb.h>
4260 #include <asm/fixmap.h>
4261 +#include <asm/system_info.h>
4262 +#include <asm/cp15.h>
4263
4264 #include <asm/mach/arch.h>
4265 #include <asm/mach/map.h>
4266 @@ -619,7 +621,46 @@ void free_initmem(void)
4267 {
4268 #ifdef CONFIG_HAVE_TCM
4269 extern char __tcm_start, __tcm_end;
4270 +#endif
4271
4272 +#ifdef CONFIG_PAX_KERNEXEC
4273 + unsigned long addr;
4274 + pgd_t *pgd;
4275 + pud_t *pud;
4276 + pmd_t *pmd;
4277 + int cpu_arch = cpu_architecture();
4278 + unsigned int cr = get_cr();
4279 +
4280 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4281 + /* make pages tables, etc before .text NX */
4282 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4283 + pgd = pgd_offset_k(addr);
4284 + pud = pud_offset(pgd, addr);
4285 + pmd = pmd_offset(pud, addr);
4286 + __section_update(pmd, addr, PMD_SECT_XN);
4287 + }
4288 + /* make init NX */
4289 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4290 + pgd = pgd_offset_k(addr);
4291 + pud = pud_offset(pgd, addr);
4292 + pmd = pmd_offset(pud, addr);
4293 + __section_update(pmd, addr, PMD_SECT_XN);
4294 + }
4295 + /* make kernel code/rodata RX */
4296 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4297 + pgd = pgd_offset_k(addr);
4298 + pud = pud_offset(pgd, addr);
4299 + pmd = pmd_offset(pud, addr);
4300 +#ifdef CONFIG_ARM_LPAE
4301 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4302 +#else
4303 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4304 +#endif
4305 + }
4306 + }
4307 +#endif
4308 +
4309 +#ifdef CONFIG_HAVE_TCM
4310 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4311 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4312 #endif
4313 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4314 index d1e5ad7..84dcbf2 100644
4315 --- a/arch/arm/mm/ioremap.c
4316 +++ b/arch/arm/mm/ioremap.c
4317 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4318 unsigned int mtype;
4319
4320 if (cached)
4321 - mtype = MT_MEMORY_RWX;
4322 + mtype = MT_MEMORY_RX;
4323 else
4324 - mtype = MT_MEMORY_RWX_NONCACHED;
4325 + mtype = MT_MEMORY_RX_NONCACHED;
4326
4327 return __arm_ioremap_caller(phys_addr, size, mtype,
4328 __builtin_return_address(0));
4329 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4330 index 5e85ed3..b10a7ed 100644
4331 --- a/arch/arm/mm/mmap.c
4332 +++ b/arch/arm/mm/mmap.c
4333 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4334 struct vm_area_struct *vma;
4335 int do_align = 0;
4336 int aliasing = cache_is_vipt_aliasing();
4337 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4338 struct vm_unmapped_area_info info;
4339
4340 /*
4341 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4342 if (len > TASK_SIZE)
4343 return -ENOMEM;
4344
4345 +#ifdef CONFIG_PAX_RANDMMAP
4346 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4347 +#endif
4348 +
4349 if (addr) {
4350 if (do_align)
4351 addr = COLOUR_ALIGN(addr, pgoff);
4352 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4353 addr = PAGE_ALIGN(addr);
4354
4355 vma = find_vma(mm, addr);
4356 - if (TASK_SIZE - len >= addr &&
4357 - (!vma || addr + len <= vma->vm_start))
4358 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4359 return addr;
4360 }
4361
4362 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4363 info.high_limit = TASK_SIZE;
4364 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4365 info.align_offset = pgoff << PAGE_SHIFT;
4366 + info.threadstack_offset = offset;
4367 return vm_unmapped_area(&info);
4368 }
4369
4370 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4371 unsigned long addr = addr0;
4372 int do_align = 0;
4373 int aliasing = cache_is_vipt_aliasing();
4374 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4375 struct vm_unmapped_area_info info;
4376
4377 /*
4378 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4379 return addr;
4380 }
4381
4382 +#ifdef CONFIG_PAX_RANDMMAP
4383 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4384 +#endif
4385 +
4386 /* requesting a specific address */
4387 if (addr) {
4388 if (do_align)
4389 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4390 else
4391 addr = PAGE_ALIGN(addr);
4392 vma = find_vma(mm, addr);
4393 - if (TASK_SIZE - len >= addr &&
4394 - (!vma || addr + len <= vma->vm_start))
4395 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4396 return addr;
4397 }
4398
4399 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4400 info.high_limit = mm->mmap_base;
4401 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4402 info.align_offset = pgoff << PAGE_SHIFT;
4403 + info.threadstack_offset = offset;
4404 addr = vm_unmapped_area(&info);
4405
4406 /*
4407 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4408 {
4409 unsigned long random_factor = 0UL;
4410
4411 +#ifdef CONFIG_PAX_RANDMMAP
4412 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4413 +#endif
4414 +
4415 /* 8 bits of randomness in 20 address space bits */
4416 if ((current->flags & PF_RANDOMIZE) &&
4417 !(current->personality & ADDR_NO_RANDOMIZE))
4418 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4419
4420 if (mmap_is_legacy()) {
4421 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4422 +
4423 +#ifdef CONFIG_PAX_RANDMMAP
4424 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4425 + mm->mmap_base += mm->delta_mmap;
4426 +#endif
4427 +
4428 mm->get_unmapped_area = arch_get_unmapped_area;
4429 } else {
4430 mm->mmap_base = mmap_base(random_factor);
4431 +
4432 +#ifdef CONFIG_PAX_RANDMMAP
4433 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4434 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4435 +#endif
4436 +
4437 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4438 }
4439 }
4440 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4441 index 8348ed6..b73a807 100644
4442 --- a/arch/arm/mm/mmu.c
4443 +++ b/arch/arm/mm/mmu.c
4444 @@ -40,6 +40,22 @@
4445 #include "mm.h"
4446 #include "tcm.h"
4447
4448 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4449 +void modify_domain(unsigned int dom, unsigned int type)
4450 +{
4451 + struct thread_info *thread = current_thread_info();
4452 + unsigned int domain = thread->cpu_domain;
4453 + /*
4454 + * DOMAIN_MANAGER might be defined to some other value,
4455 + * use the arch-defined constant
4456 + */
4457 + domain &= ~domain_val(dom, 3);
4458 + thread->cpu_domain = domain | domain_val(dom, type);
4459 + set_domain(thread->cpu_domain);
4460 +}
4461 +EXPORT_SYMBOL(modify_domain);
4462 +#endif
4463 +
4464 /*
4465 * empty_zero_page is a special page that is used for
4466 * zero-initialized data and COW.
4467 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4468 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4469 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4470
4471 -static struct mem_type mem_types[] = {
4472 +#ifdef CONFIG_PAX_KERNEXEC
4473 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4474 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4475 +#else
4476 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4477 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4478 +#endif
4479 +
4480 +static struct mem_type mem_types[] __read_only = {
4481 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4482 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4483 L_PTE_SHARED,
4484 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4485 .prot_sect = PROT_SECT_DEVICE,
4486 .domain = DOMAIN_IO,
4487 },
4488 - [MT_UNCACHED] = {
4489 + [MT_UNCACHED_RW] = {
4490 .prot_pte = PROT_PTE_DEVICE,
4491 .prot_l1 = PMD_TYPE_TABLE,
4492 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4493 .domain = DOMAIN_IO,
4494 },
4495 - [MT_CACHECLEAN] = {
4496 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4497 + [MT_CACHECLEAN_RO] = {
4498 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4499 .domain = DOMAIN_KERNEL,
4500 },
4501 #ifndef CONFIG_ARM_LPAE
4502 - [MT_MINICLEAN] = {
4503 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4504 + [MT_MINICLEAN_RO] = {
4505 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4506 .domain = DOMAIN_KERNEL,
4507 },
4508 #endif
4509 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4510 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4511 L_PTE_RDONLY,
4512 .prot_l1 = PMD_TYPE_TABLE,
4513 - .domain = DOMAIN_USER,
4514 + .domain = DOMAIN_VECTORS,
4515 },
4516 [MT_HIGH_VECTORS] = {
4517 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4518 L_PTE_USER | L_PTE_RDONLY,
4519 .prot_l1 = PMD_TYPE_TABLE,
4520 - .domain = DOMAIN_USER,
4521 + .domain = DOMAIN_VECTORS,
4522 },
4523 - [MT_MEMORY_RWX] = {
4524 + [__MT_MEMORY_RWX] = {
4525 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4526 .prot_l1 = PMD_TYPE_TABLE,
4527 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4528 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4529 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4530 .domain = DOMAIN_KERNEL,
4531 },
4532 - [MT_ROM] = {
4533 - .prot_sect = PMD_TYPE_SECT,
4534 + [MT_MEMORY_RX] = {
4535 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4536 + .prot_l1 = PMD_TYPE_TABLE,
4537 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4538 + .domain = DOMAIN_KERNEL,
4539 + },
4540 + [MT_ROM_RX] = {
4541 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4542 .domain = DOMAIN_KERNEL,
4543 },
4544 - [MT_MEMORY_RWX_NONCACHED] = {
4545 + [MT_MEMORY_RW_NONCACHED] = {
4546 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4547 L_PTE_MT_BUFFERABLE,
4548 .prot_l1 = PMD_TYPE_TABLE,
4549 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4550 .domain = DOMAIN_KERNEL,
4551 },
4552 + [MT_MEMORY_RX_NONCACHED] = {
4553 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4554 + L_PTE_MT_BUFFERABLE,
4555 + .prot_l1 = PMD_TYPE_TABLE,
4556 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4557 + .domain = DOMAIN_KERNEL,
4558 + },
4559 [MT_MEMORY_RW_DTCM] = {
4560 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4561 L_PTE_XN,
4562 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4563 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4564 .domain = DOMAIN_KERNEL,
4565 },
4566 - [MT_MEMORY_RWX_ITCM] = {
4567 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4568 + [MT_MEMORY_RX_ITCM] = {
4569 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4570 .prot_l1 = PMD_TYPE_TABLE,
4571 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4572 .domain = DOMAIN_KERNEL,
4573 },
4574 [MT_MEMORY_RW_SO] = {
4575 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4576 * Mark cache clean areas and XIP ROM read only
4577 * from SVC mode and no access from userspace.
4578 */
4579 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4580 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4581 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4582 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4583 +#ifdef CONFIG_PAX_KERNEXEC
4584 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4585 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4586 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4587 +#endif
4588 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4589 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4590 #endif
4591
4592 /*
4593 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4594 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4595 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4596 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4597 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4598 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4599 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4600 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4601 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4602 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4603 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4604 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4605 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4606 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4607 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4608 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4609 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4610 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4611 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4612 }
4613 }
4614
4615 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4616 if (cpu_arch >= CPU_ARCH_ARMv6) {
4617 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4618 /* Non-cacheable Normal is XCB = 001 */
4619 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4620 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4621 + PMD_SECT_BUFFERED;
4622 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4623 PMD_SECT_BUFFERED;
4624 } else {
4625 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4626 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4627 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4628 + PMD_SECT_TEX(1);
4629 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4630 PMD_SECT_TEX(1);
4631 }
4632 } else {
4633 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4634 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4635 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4636 }
4637
4638 #ifdef CONFIG_ARM_LPAE
4639 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4640 vecs_pgprot |= PTE_EXT_AF;
4641 #endif
4642
4643 + user_pgprot |= __supported_pte_mask;
4644 +
4645 for (i = 0; i < 16; i++) {
4646 pteval_t v = pgprot_val(protection_map[i]);
4647 protection_map[i] = __pgprot(v | user_pgprot);
4648 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4649
4650 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4651 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4652 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4653 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4654 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4655 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4656 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4657 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4658 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4659 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4660 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4661 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4662 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4663 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4664 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4665 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4666
4667 switch (cp->pmd) {
4668 case PMD_SECT_WT:
4669 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4670 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4671 break;
4672 case PMD_SECT_WB:
4673 case PMD_SECT_WBWA:
4674 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4675 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4676 break;
4677 }
4678 pr_info("Memory policy: %sData cache %s\n",
4679 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4680 return;
4681 }
4682
4683 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4684 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4685 md->virtual >= PAGE_OFFSET &&
4686 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4687 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4688 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4689 * called function. This means you can't use any function or debugging
4690 * method which may touch any device, otherwise the kernel _will_ crash.
4691 */
4692 +
4693 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4694 +
4695 static void __init devicemaps_init(const struct machine_desc *mdesc)
4696 {
4697 struct map_desc map;
4698 unsigned long addr;
4699 - void *vectors;
4700
4701 - /*
4702 - * Allocate the vector page early.
4703 - */
4704 - vectors = early_alloc(PAGE_SIZE * 2);
4705 -
4706 - early_trap_init(vectors);
4707 + early_trap_init(&vectors);
4708
4709 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4710 pmd_clear(pmd_off_k(addr));
4711 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4712 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4713 map.virtual = MODULES_VADDR;
4714 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4715 - map.type = MT_ROM;
4716 + map.type = MT_ROM_RX;
4717 create_mapping(&map);
4718 #endif
4719
4720 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4721 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4722 map.virtual = FLUSH_BASE;
4723 map.length = SZ_1M;
4724 - map.type = MT_CACHECLEAN;
4725 + map.type = MT_CACHECLEAN_RO;
4726 create_mapping(&map);
4727 #endif
4728 #ifdef FLUSH_BASE_MINICACHE
4729 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4730 map.virtual = FLUSH_BASE_MINICACHE;
4731 map.length = SZ_1M;
4732 - map.type = MT_MINICLEAN;
4733 + map.type = MT_MINICLEAN_RO;
4734 create_mapping(&map);
4735 #endif
4736
4737 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4738 * location (0xffff0000). If we aren't using high-vectors, also
4739 * create a mapping at the low-vectors virtual address.
4740 */
4741 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4742 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4743 map.virtual = 0xffff0000;
4744 map.length = PAGE_SIZE;
4745 #ifdef CONFIG_KUSER_HELPERS
4746 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4747 static void __init map_lowmem(void)
4748 {
4749 struct memblock_region *reg;
4750 +#ifndef CONFIG_PAX_KERNEXEC
4751 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4752 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4753 +#endif
4754
4755 /* Map all the lowmem memory banks. */
4756 for_each_memblock(memory, reg) {
4757 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4758 if (start >= end)
4759 break;
4760
4761 +#ifdef CONFIG_PAX_KERNEXEC
4762 + map.pfn = __phys_to_pfn(start);
4763 + map.virtual = __phys_to_virt(start);
4764 + map.length = end - start;
4765 +
4766 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4767 + struct map_desc kernel;
4768 + struct map_desc initmap;
4769 +
4770 + /* when freeing initmem we will make this RW */
4771 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4772 + initmap.virtual = (unsigned long)__init_begin;
4773 + initmap.length = _sdata - __init_begin;
4774 + initmap.type = __MT_MEMORY_RWX;
4775 + create_mapping(&initmap);
4776 +
4777 + /* when freeing initmem we will make this RX */
4778 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4779 + kernel.virtual = (unsigned long)_stext;
4780 + kernel.length = __init_begin - _stext;
4781 + kernel.type = __MT_MEMORY_RWX;
4782 + create_mapping(&kernel);
4783 +
4784 + if (map.virtual < (unsigned long)_stext) {
4785 + map.length = (unsigned long)_stext - map.virtual;
4786 + map.type = __MT_MEMORY_RWX;
4787 + create_mapping(&map);
4788 + }
4789 +
4790 + map.pfn = __phys_to_pfn(__pa(_sdata));
4791 + map.virtual = (unsigned long)_sdata;
4792 + map.length = end - __pa(_sdata);
4793 + }
4794 +
4795 + map.type = MT_MEMORY_RW;
4796 + create_mapping(&map);
4797 +#else
4798 if (end < kernel_x_start || start >= kernel_x_end) {
4799 map.pfn = __phys_to_pfn(start);
4800 map.virtual = __phys_to_virt(start);
4801 map.length = end - start;
4802 - map.type = MT_MEMORY_RWX;
4803 + map.type = __MT_MEMORY_RWX;
4804
4805 create_mapping(&map);
4806 } else {
4807 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4808 map.pfn = __phys_to_pfn(kernel_x_start);
4809 map.virtual = __phys_to_virt(kernel_x_start);
4810 map.length = kernel_x_end - kernel_x_start;
4811 - map.type = MT_MEMORY_RWX;
4812 + map.type = __MT_MEMORY_RWX;
4813
4814 create_mapping(&map);
4815
4816 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4817 create_mapping(&map);
4818 }
4819 }
4820 +#endif
4821 }
4822 }
4823
4824 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4825 index a37b989..5c9ae75 100644
4826 --- a/arch/arm/net/bpf_jit_32.c
4827 +++ b/arch/arm/net/bpf_jit_32.c
4828 @@ -71,7 +71,11 @@ struct jit_ctx {
4829 #endif
4830 };
4831
4832 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4833 +int bpf_jit_enable __read_only;
4834 +#else
4835 int bpf_jit_enable __read_mostly;
4836 +#endif
4837
4838 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4839 {
4840 @@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4841 {
4842 if (fp->jited)
4843 module_free(NULL, fp->bpf_func);
4844 - kfree(fp);
4845 +
4846 + bpf_prog_unlock_free(fp);
4847 }
4848 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4849 index 5b217f4..c23f40e 100644
4850 --- a/arch/arm/plat-iop/setup.c
4851 +++ b/arch/arm/plat-iop/setup.c
4852 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4853 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4854 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4855 .length = IOP3XX_PERIPHERAL_SIZE,
4856 - .type = MT_UNCACHED,
4857 + .type = MT_UNCACHED_RW,
4858 },
4859 };
4860
4861 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4862 index a5bc92d..0bb4730 100644
4863 --- a/arch/arm/plat-omap/sram.c
4864 +++ b/arch/arm/plat-omap/sram.c
4865 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4866 * Looks like we need to preserve some bootloader code at the
4867 * beginning of SRAM for jumping to flash for reboot to work...
4868 */
4869 + pax_open_kernel();
4870 memset_io(omap_sram_base + omap_sram_skip, 0,
4871 omap_sram_size - omap_sram_skip);
4872 + pax_close_kernel();
4873 }
4874 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4875 index ce6d763..cfea917 100644
4876 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4877 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4878 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4879 int (*started)(unsigned ch);
4880 int (*flush)(unsigned ch);
4881 int (*stop)(unsigned ch);
4882 -};
4883 +} __no_const;
4884
4885 extern void *samsung_dmadev_get_ops(void);
4886 extern void *s3c_dma_get_ops(void);
4887 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4888 index 6389d60..b5d3bdd 100644
4889 --- a/arch/arm64/include/asm/barrier.h
4890 +++ b/arch/arm64/include/asm/barrier.h
4891 @@ -41,7 +41,7 @@
4892 do { \
4893 compiletime_assert_atomic_type(*p); \
4894 barrier(); \
4895 - ACCESS_ONCE(*p) = (v); \
4896 + ACCESS_ONCE_RW(*p) = (v); \
4897 } while (0)
4898
4899 #define smp_load_acquire(p) \
4900 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4901 index 3bf8f4e..5dd5491 100644
4902 --- a/arch/arm64/include/asm/uaccess.h
4903 +++ b/arch/arm64/include/asm/uaccess.h
4904 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4905 flag; \
4906 })
4907
4908 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4909 #define access_ok(type, addr, size) __range_ok(addr, size)
4910 #define user_addr_max get_fs
4911
4912 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4913 index c3a58a1..78fbf54 100644
4914 --- a/arch/avr32/include/asm/cache.h
4915 +++ b/arch/avr32/include/asm/cache.h
4916 @@ -1,8 +1,10 @@
4917 #ifndef __ASM_AVR32_CACHE_H
4918 #define __ASM_AVR32_CACHE_H
4919
4920 +#include <linux/const.h>
4921 +
4922 #define L1_CACHE_SHIFT 5
4923 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4924 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4925
4926 /*
4927 * Memory returned by kmalloc() may be used for DMA, so we must make
4928 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4929 index d232888..87c8df1 100644
4930 --- a/arch/avr32/include/asm/elf.h
4931 +++ b/arch/avr32/include/asm/elf.h
4932 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4933 the loader. We need to make sure that it is out of the way of the program
4934 that it will "exec", and that there is sufficient room for the brk. */
4935
4936 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4937 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4938
4939 +#ifdef CONFIG_PAX_ASLR
4940 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4941 +
4942 +#define PAX_DELTA_MMAP_LEN 15
4943 +#define PAX_DELTA_STACK_LEN 15
4944 +#endif
4945
4946 /* This yields a mask that user programs can use to figure out what
4947 instruction set this CPU supports. This could be done in user space,
4948 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4949 index 479330b..53717a8 100644
4950 --- a/arch/avr32/include/asm/kmap_types.h
4951 +++ b/arch/avr32/include/asm/kmap_types.h
4952 @@ -2,9 +2,9 @@
4953 #define __ASM_AVR32_KMAP_TYPES_H
4954
4955 #ifdef CONFIG_DEBUG_HIGHMEM
4956 -# define KM_TYPE_NR 29
4957 +# define KM_TYPE_NR 30
4958 #else
4959 -# define KM_TYPE_NR 14
4960 +# define KM_TYPE_NR 15
4961 #endif
4962
4963 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4964 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4965 index 0eca933..eb78c7b 100644
4966 --- a/arch/avr32/mm/fault.c
4967 +++ b/arch/avr32/mm/fault.c
4968 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4969
4970 int exception_trace = 1;
4971
4972 +#ifdef CONFIG_PAX_PAGEEXEC
4973 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4974 +{
4975 + unsigned long i;
4976 +
4977 + printk(KERN_ERR "PAX: bytes at PC: ");
4978 + for (i = 0; i < 20; i++) {
4979 + unsigned char c;
4980 + if (get_user(c, (unsigned char *)pc+i))
4981 + printk(KERN_CONT "???????? ");
4982 + else
4983 + printk(KERN_CONT "%02x ", c);
4984 + }
4985 + printk("\n");
4986 +}
4987 +#endif
4988 +
4989 /*
4990 * This routine handles page faults. It determines the address and the
4991 * problem, and then passes it off to one of the appropriate routines.
4992 @@ -176,6 +193,16 @@ bad_area:
4993 up_read(&mm->mmap_sem);
4994
4995 if (user_mode(regs)) {
4996 +
4997 +#ifdef CONFIG_PAX_PAGEEXEC
4998 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4999 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5000 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5001 + do_group_exit(SIGKILL);
5002 + }
5003 + }
5004 +#endif
5005 +
5006 if (exception_trace && printk_ratelimit())
5007 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5008 "sp %08lx ecr %lu\n",
5009 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5010 index 568885a..f8008df 100644
5011 --- a/arch/blackfin/include/asm/cache.h
5012 +++ b/arch/blackfin/include/asm/cache.h
5013 @@ -7,6 +7,7 @@
5014 #ifndef __ARCH_BLACKFIN_CACHE_H
5015 #define __ARCH_BLACKFIN_CACHE_H
5016
5017 +#include <linux/const.h>
5018 #include <linux/linkage.h> /* for asmlinkage */
5019
5020 /*
5021 @@ -14,7 +15,7 @@
5022 * Blackfin loads 32 bytes for cache
5023 */
5024 #define L1_CACHE_SHIFT 5
5025 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5026 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5027 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5028
5029 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5030 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5031 index aea2718..3639a60 100644
5032 --- a/arch/cris/include/arch-v10/arch/cache.h
5033 +++ b/arch/cris/include/arch-v10/arch/cache.h
5034 @@ -1,8 +1,9 @@
5035 #ifndef _ASM_ARCH_CACHE_H
5036 #define _ASM_ARCH_CACHE_H
5037
5038 +#include <linux/const.h>
5039 /* Etrax 100LX have 32-byte cache-lines. */
5040 -#define L1_CACHE_BYTES 32
5041 #define L1_CACHE_SHIFT 5
5042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5043
5044 #endif /* _ASM_ARCH_CACHE_H */
5045 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5046 index 7caf25d..ee65ac5 100644
5047 --- a/arch/cris/include/arch-v32/arch/cache.h
5048 +++ b/arch/cris/include/arch-v32/arch/cache.h
5049 @@ -1,11 +1,12 @@
5050 #ifndef _ASM_CRIS_ARCH_CACHE_H
5051 #define _ASM_CRIS_ARCH_CACHE_H
5052
5053 +#include <linux/const.h>
5054 #include <arch/hwregs/dma.h>
5055
5056 /* A cache-line is 32 bytes. */
5057 -#define L1_CACHE_BYTES 32
5058 #define L1_CACHE_SHIFT 5
5059 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5060
5061 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5062
5063 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5064 index f6c3a16..cd422a4 100644
5065 --- a/arch/frv/include/asm/atomic.h
5066 +++ b/arch/frv/include/asm/atomic.h
5067 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5068 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5069 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5070
5071 +#define atomic64_read_unchecked(v) atomic64_read(v)
5072 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5073 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5074 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5075 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5076 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5077 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5078 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5079 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5080 +
5081 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5082 {
5083 int c, old;
5084 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5085 index 2797163..c2a401d 100644
5086 --- a/arch/frv/include/asm/cache.h
5087 +++ b/arch/frv/include/asm/cache.h
5088 @@ -12,10 +12,11 @@
5089 #ifndef __ASM_CACHE_H
5090 #define __ASM_CACHE_H
5091
5092 +#include <linux/const.h>
5093
5094 /* bytes per L1 cache line */
5095 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5096 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5097 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5098
5099 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5100 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5101 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5102 index 43901f2..0d8b865 100644
5103 --- a/arch/frv/include/asm/kmap_types.h
5104 +++ b/arch/frv/include/asm/kmap_types.h
5105 @@ -2,6 +2,6 @@
5106 #ifndef _ASM_KMAP_TYPES_H
5107 #define _ASM_KMAP_TYPES_H
5108
5109 -#define KM_TYPE_NR 17
5110 +#define KM_TYPE_NR 18
5111
5112 #endif
5113 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5114 index 836f147..4cf23f5 100644
5115 --- a/arch/frv/mm/elf-fdpic.c
5116 +++ b/arch/frv/mm/elf-fdpic.c
5117 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5118 {
5119 struct vm_area_struct *vma;
5120 struct vm_unmapped_area_info info;
5121 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5122
5123 if (len > TASK_SIZE)
5124 return -ENOMEM;
5125 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5126 if (addr) {
5127 addr = PAGE_ALIGN(addr);
5128 vma = find_vma(current->mm, addr);
5129 - if (TASK_SIZE - len >= addr &&
5130 - (!vma || addr + len <= vma->vm_start))
5131 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5132 goto success;
5133 }
5134
5135 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5136 info.high_limit = (current->mm->start_stack - 0x00200000);
5137 info.align_mask = 0;
5138 info.align_offset = 0;
5139 + info.threadstack_offset = offset;
5140 addr = vm_unmapped_area(&info);
5141 if (!(addr & ~PAGE_MASK))
5142 goto success;
5143 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5144 index 2635117..fa223cb 100644
5145 --- a/arch/hexagon/include/asm/cache.h
5146 +++ b/arch/hexagon/include/asm/cache.h
5147 @@ -21,9 +21,11 @@
5148 #ifndef __ASM_CACHE_H
5149 #define __ASM_CACHE_H
5150
5151 +#include <linux/const.h>
5152 +
5153 /* Bytes per L1 cache line */
5154 -#define L1_CACHE_SHIFT (5)
5155 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5156 +#define L1_CACHE_SHIFT 5
5157 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5158
5159 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5160 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5161 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5162 index c84c88b..2a6e1ba 100644
5163 --- a/arch/ia64/Kconfig
5164 +++ b/arch/ia64/Kconfig
5165 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5166 config KEXEC
5167 bool "kexec system call"
5168 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5169 + depends on !GRKERNSEC_KMEM
5170 help
5171 kexec is a system call that implements the ability to shutdown your
5172 current kernel, and to start another kernel. It is like a reboot
5173 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5174 index 5441b14..039a446 100644
5175 --- a/arch/ia64/Makefile
5176 +++ b/arch/ia64/Makefile
5177 @@ -99,5 +99,6 @@ endef
5178 archprepare: make_nr_irqs_h FORCE
5179 PHONY += make_nr_irqs_h FORCE
5180
5181 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5182 make_nr_irqs_h: FORCE
5183 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5184 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5185 index 0f8bf48..40ea950 100644
5186 --- a/arch/ia64/include/asm/atomic.h
5187 +++ b/arch/ia64/include/asm/atomic.h
5188 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5189 #define atomic64_inc(v) atomic64_add(1, (v))
5190 #define atomic64_dec(v) atomic64_sub(1, (v))
5191
5192 +#define atomic64_read_unchecked(v) atomic64_read(v)
5193 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5194 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5195 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5196 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5197 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5198 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5199 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5200 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5201 +
5202 #endif /* _ASM_IA64_ATOMIC_H */
5203 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5204 index a48957c..e097b56 100644
5205 --- a/arch/ia64/include/asm/barrier.h
5206 +++ b/arch/ia64/include/asm/barrier.h
5207 @@ -67,7 +67,7 @@
5208 do { \
5209 compiletime_assert_atomic_type(*p); \
5210 barrier(); \
5211 - ACCESS_ONCE(*p) = (v); \
5212 + ACCESS_ONCE_RW(*p) = (v); \
5213 } while (0)
5214
5215 #define smp_load_acquire(p) \
5216 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5217 index 988254a..e1ee885 100644
5218 --- a/arch/ia64/include/asm/cache.h
5219 +++ b/arch/ia64/include/asm/cache.h
5220 @@ -1,6 +1,7 @@
5221 #ifndef _ASM_IA64_CACHE_H
5222 #define _ASM_IA64_CACHE_H
5223
5224 +#include <linux/const.h>
5225
5226 /*
5227 * Copyright (C) 1998-2000 Hewlett-Packard Co
5228 @@ -9,7 +10,7 @@
5229
5230 /* Bytes per L1 (data) cache line. */
5231 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5232 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5233 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5234
5235 #ifdef CONFIG_SMP
5236 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5237 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5238 index 5a83c5c..4d7f553 100644
5239 --- a/arch/ia64/include/asm/elf.h
5240 +++ b/arch/ia64/include/asm/elf.h
5241 @@ -42,6 +42,13 @@
5242 */
5243 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5244
5245 +#ifdef CONFIG_PAX_ASLR
5246 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5247 +
5248 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5249 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5250 +#endif
5251 +
5252 #define PT_IA_64_UNWIND 0x70000001
5253
5254 /* IA-64 relocations: */
5255 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5256 index 5767cdf..7462574 100644
5257 --- a/arch/ia64/include/asm/pgalloc.h
5258 +++ b/arch/ia64/include/asm/pgalloc.h
5259 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5260 pgd_val(*pgd_entry) = __pa(pud);
5261 }
5262
5263 +static inline void
5264 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5265 +{
5266 + pgd_populate(mm, pgd_entry, pud);
5267 +}
5268 +
5269 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5270 {
5271 return quicklist_alloc(0, GFP_KERNEL, NULL);
5272 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5273 pud_val(*pud_entry) = __pa(pmd);
5274 }
5275
5276 +static inline void
5277 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5278 +{
5279 + pud_populate(mm, pud_entry, pmd);
5280 +}
5281 +
5282 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5283 {
5284 return quicklist_alloc(0, GFP_KERNEL, NULL);
5285 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5286 index 7935115..c0eca6a 100644
5287 --- a/arch/ia64/include/asm/pgtable.h
5288 +++ b/arch/ia64/include/asm/pgtable.h
5289 @@ -12,7 +12,7 @@
5290 * David Mosberger-Tang <davidm@hpl.hp.com>
5291 */
5292
5293 -
5294 +#include <linux/const.h>
5295 #include <asm/mman.h>
5296 #include <asm/page.h>
5297 #include <asm/processor.h>
5298 @@ -142,6 +142,17 @@
5299 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5300 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5301 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5302 +
5303 +#ifdef CONFIG_PAX_PAGEEXEC
5304 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5305 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5306 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5307 +#else
5308 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5309 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5310 +# define PAGE_COPY_NOEXEC PAGE_COPY
5311 +#endif
5312 +
5313 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5314 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5315 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5316 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5317 index 45698cd..e8e2dbc 100644
5318 --- a/arch/ia64/include/asm/spinlock.h
5319 +++ b/arch/ia64/include/asm/spinlock.h
5320 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5321 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5322
5323 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5324 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5325 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5326 }
5327
5328 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5329 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5330 index 449c8c0..3d4b1e9 100644
5331 --- a/arch/ia64/include/asm/uaccess.h
5332 +++ b/arch/ia64/include/asm/uaccess.h
5333 @@ -70,6 +70,7 @@
5334 && ((segment).seg == KERNEL_DS.seg \
5335 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5336 })
5337 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5338 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5339
5340 /*
5341 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5342 static inline unsigned long
5343 __copy_to_user (void __user *to, const void *from, unsigned long count)
5344 {
5345 + if (count > INT_MAX)
5346 + return count;
5347 +
5348 + if (!__builtin_constant_p(count))
5349 + check_object_size(from, count, true);
5350 +
5351 return __copy_user(to, (__force void __user *) from, count);
5352 }
5353
5354 static inline unsigned long
5355 __copy_from_user (void *to, const void __user *from, unsigned long count)
5356 {
5357 + if (count > INT_MAX)
5358 + return count;
5359 +
5360 + if (!__builtin_constant_p(count))
5361 + check_object_size(to, count, false);
5362 +
5363 return __copy_user((__force void __user *) to, from, count);
5364 }
5365
5366 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5367 ({ \
5368 void __user *__cu_to = (to); \
5369 const void *__cu_from = (from); \
5370 - long __cu_len = (n); \
5371 + unsigned long __cu_len = (n); \
5372 \
5373 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5374 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5375 + if (!__builtin_constant_p(n)) \
5376 + check_object_size(__cu_from, __cu_len, true); \
5377 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5378 + } \
5379 __cu_len; \
5380 })
5381
5382 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5383 ({ \
5384 void *__cu_to = (to); \
5385 const void __user *__cu_from = (from); \
5386 - long __cu_len = (n); \
5387 + unsigned long __cu_len = (n); \
5388 \
5389 __chk_user_ptr(__cu_from); \
5390 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5391 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5392 + if (!__builtin_constant_p(n)) \
5393 + check_object_size(__cu_to, __cu_len, false); \
5394 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5395 + } \
5396 __cu_len; \
5397 })
5398
5399 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5400 index 24603be..948052d 100644
5401 --- a/arch/ia64/kernel/module.c
5402 +++ b/arch/ia64/kernel/module.c
5403 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5404 void
5405 module_free (struct module *mod, void *module_region)
5406 {
5407 - if (mod && mod->arch.init_unw_table &&
5408 - module_region == mod->module_init) {
5409 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5410 unw_remove_unwind_table(mod->arch.init_unw_table);
5411 mod->arch.init_unw_table = NULL;
5412 }
5413 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5414 }
5415
5416 static inline int
5417 +in_init_rx (const struct module *mod, uint64_t addr)
5418 +{
5419 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5420 +}
5421 +
5422 +static inline int
5423 +in_init_rw (const struct module *mod, uint64_t addr)
5424 +{
5425 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5426 +}
5427 +
5428 +static inline int
5429 in_init (const struct module *mod, uint64_t addr)
5430 {
5431 - return addr - (uint64_t) mod->module_init < mod->init_size;
5432 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5433 +}
5434 +
5435 +static inline int
5436 +in_core_rx (const struct module *mod, uint64_t addr)
5437 +{
5438 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5439 +}
5440 +
5441 +static inline int
5442 +in_core_rw (const struct module *mod, uint64_t addr)
5443 +{
5444 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5445 }
5446
5447 static inline int
5448 in_core (const struct module *mod, uint64_t addr)
5449 {
5450 - return addr - (uint64_t) mod->module_core < mod->core_size;
5451 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5452 }
5453
5454 static inline int
5455 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5456 break;
5457
5458 case RV_BDREL:
5459 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5460 + if (in_init_rx(mod, val))
5461 + val -= (uint64_t) mod->module_init_rx;
5462 + else if (in_init_rw(mod, val))
5463 + val -= (uint64_t) mod->module_init_rw;
5464 + else if (in_core_rx(mod, val))
5465 + val -= (uint64_t) mod->module_core_rx;
5466 + else if (in_core_rw(mod, val))
5467 + val -= (uint64_t) mod->module_core_rw;
5468 break;
5469
5470 case RV_LTV:
5471 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5472 * addresses have been selected...
5473 */
5474 uint64_t gp;
5475 - if (mod->core_size > MAX_LTOFF)
5476 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5477 /*
5478 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5479 * at the end of the module.
5480 */
5481 - gp = mod->core_size - MAX_LTOFF / 2;
5482 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5483 else
5484 - gp = mod->core_size / 2;
5485 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5486 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5487 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5488 mod->arch.gp = gp;
5489 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5490 }
5491 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5492 index c39c3cd..3c77738 100644
5493 --- a/arch/ia64/kernel/palinfo.c
5494 +++ b/arch/ia64/kernel/palinfo.c
5495 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5496 return NOTIFY_OK;
5497 }
5498
5499 -static struct notifier_block __refdata palinfo_cpu_notifier =
5500 +static struct notifier_block palinfo_cpu_notifier =
5501 {
5502 .notifier_call = palinfo_cpu_callback,
5503 .priority = 0,
5504 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5505 index 41e33f8..65180b2a 100644
5506 --- a/arch/ia64/kernel/sys_ia64.c
5507 +++ b/arch/ia64/kernel/sys_ia64.c
5508 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5509 unsigned long align_mask = 0;
5510 struct mm_struct *mm = current->mm;
5511 struct vm_unmapped_area_info info;
5512 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5513
5514 if (len > RGN_MAP_LIMIT)
5515 return -ENOMEM;
5516 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5517 if (REGION_NUMBER(addr) == RGN_HPAGE)
5518 addr = 0;
5519 #endif
5520 +
5521 +#ifdef CONFIG_PAX_RANDMMAP
5522 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5523 + addr = mm->free_area_cache;
5524 + else
5525 +#endif
5526 +
5527 if (!addr)
5528 addr = TASK_UNMAPPED_BASE;
5529
5530 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5531 info.high_limit = TASK_SIZE;
5532 info.align_mask = align_mask;
5533 info.align_offset = 0;
5534 + info.threadstack_offset = offset;
5535 return vm_unmapped_area(&info);
5536 }
5537
5538 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5539 index 84f8a52..7c76178 100644
5540 --- a/arch/ia64/kernel/vmlinux.lds.S
5541 +++ b/arch/ia64/kernel/vmlinux.lds.S
5542 @@ -192,7 +192,7 @@ SECTIONS {
5543 /* Per-cpu data: */
5544 . = ALIGN(PERCPU_PAGE_SIZE);
5545 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5546 - __phys_per_cpu_start = __per_cpu_load;
5547 + __phys_per_cpu_start = per_cpu_load;
5548 /*
5549 * ensure percpu data fits
5550 * into percpu page size
5551 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5552 index 7225dad..2a7c8256 100644
5553 --- a/arch/ia64/mm/fault.c
5554 +++ b/arch/ia64/mm/fault.c
5555 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5556 return pte_present(pte);
5557 }
5558
5559 +#ifdef CONFIG_PAX_PAGEEXEC
5560 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5561 +{
5562 + unsigned long i;
5563 +
5564 + printk(KERN_ERR "PAX: bytes at PC: ");
5565 + for (i = 0; i < 8; i++) {
5566 + unsigned int c;
5567 + if (get_user(c, (unsigned int *)pc+i))
5568 + printk(KERN_CONT "???????? ");
5569 + else
5570 + printk(KERN_CONT "%08x ", c);
5571 + }
5572 + printk("\n");
5573 +}
5574 +#endif
5575 +
5576 # define VM_READ_BIT 0
5577 # define VM_WRITE_BIT 1
5578 # define VM_EXEC_BIT 2
5579 @@ -151,8 +168,21 @@ retry:
5580 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5581 goto bad_area;
5582
5583 - if ((vma->vm_flags & mask) != mask)
5584 + if ((vma->vm_flags & mask) != mask) {
5585 +
5586 +#ifdef CONFIG_PAX_PAGEEXEC
5587 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5588 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5589 + goto bad_area;
5590 +
5591 + up_read(&mm->mmap_sem);
5592 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5593 + do_group_exit(SIGKILL);
5594 + }
5595 +#endif
5596 +
5597 goto bad_area;
5598 + }
5599
5600 /*
5601 * If for any reason at all we couldn't handle the fault, make
5602 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5603 index 76069c1..c2aa816 100644
5604 --- a/arch/ia64/mm/hugetlbpage.c
5605 +++ b/arch/ia64/mm/hugetlbpage.c
5606 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5607 unsigned long pgoff, unsigned long flags)
5608 {
5609 struct vm_unmapped_area_info info;
5610 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5611
5612 if (len > RGN_MAP_LIMIT)
5613 return -ENOMEM;
5614 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5615 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5616 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5617 info.align_offset = 0;
5618 + info.threadstack_offset = offset;
5619 return vm_unmapped_area(&info);
5620 }
5621
5622 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5623 index 6b33457..88b5124 100644
5624 --- a/arch/ia64/mm/init.c
5625 +++ b/arch/ia64/mm/init.c
5626 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5627 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5628 vma->vm_end = vma->vm_start + PAGE_SIZE;
5629 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5630 +
5631 +#ifdef CONFIG_PAX_PAGEEXEC
5632 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5633 + vma->vm_flags &= ~VM_EXEC;
5634 +
5635 +#ifdef CONFIG_PAX_MPROTECT
5636 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5637 + vma->vm_flags &= ~VM_MAYEXEC;
5638 +#endif
5639 +
5640 + }
5641 +#endif
5642 +
5643 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5644 down_write(&current->mm->mmap_sem);
5645 if (insert_vm_struct(current->mm, vma)) {
5646 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5647 gate_vma.vm_start = FIXADDR_USER_START;
5648 gate_vma.vm_end = FIXADDR_USER_END;
5649 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5650 - gate_vma.vm_page_prot = __P101;
5651 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5652
5653 return 0;
5654 }
5655 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5656 index 40b3ee9..8c2c112 100644
5657 --- a/arch/m32r/include/asm/cache.h
5658 +++ b/arch/m32r/include/asm/cache.h
5659 @@ -1,8 +1,10 @@
5660 #ifndef _ASM_M32R_CACHE_H
5661 #define _ASM_M32R_CACHE_H
5662
5663 +#include <linux/const.h>
5664 +
5665 /* L1 cache line size */
5666 #define L1_CACHE_SHIFT 4
5667 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5668 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5669
5670 #endif /* _ASM_M32R_CACHE_H */
5671 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5672 index 82abd15..d95ae5d 100644
5673 --- a/arch/m32r/lib/usercopy.c
5674 +++ b/arch/m32r/lib/usercopy.c
5675 @@ -14,6 +14,9 @@
5676 unsigned long
5677 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5678 {
5679 + if ((long)n < 0)
5680 + return n;
5681 +
5682 prefetch(from);
5683 if (access_ok(VERIFY_WRITE, to, n))
5684 __copy_user(to,from,n);
5685 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5686 unsigned long
5687 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5688 {
5689 + if ((long)n < 0)
5690 + return n;
5691 +
5692 prefetchw(to);
5693 if (access_ok(VERIFY_READ, from, n))
5694 __copy_user_zeroing(to,from,n);
5695 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5696 index 0395c51..5f26031 100644
5697 --- a/arch/m68k/include/asm/cache.h
5698 +++ b/arch/m68k/include/asm/cache.h
5699 @@ -4,9 +4,11 @@
5700 #ifndef __ARCH_M68K_CACHE_H
5701 #define __ARCH_M68K_CACHE_H
5702
5703 +#include <linux/const.h>
5704 +
5705 /* bytes per L1 cache line */
5706 #define L1_CACHE_SHIFT 4
5707 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5708 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5709
5710 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5711
5712 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5713 index c7591e8..ecef036 100644
5714 --- a/arch/metag/include/asm/barrier.h
5715 +++ b/arch/metag/include/asm/barrier.h
5716 @@ -89,7 +89,7 @@ static inline void fence(void)
5717 do { \
5718 compiletime_assert_atomic_type(*p); \
5719 smp_mb(); \
5720 - ACCESS_ONCE(*p) = (v); \
5721 + ACCESS_ONCE_RW(*p) = (v); \
5722 } while (0)
5723
5724 #define smp_load_acquire(p) \
5725 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5726 index 3c32075..ae0ae75 100644
5727 --- a/arch/metag/mm/hugetlbpage.c
5728 +++ b/arch/metag/mm/hugetlbpage.c
5729 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5730 info.high_limit = TASK_SIZE;
5731 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5732 info.align_offset = 0;
5733 + info.threadstack_offset = 0;
5734 return vm_unmapped_area(&info);
5735 }
5736
5737 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5738 index 4efe96a..60e8699 100644
5739 --- a/arch/microblaze/include/asm/cache.h
5740 +++ b/arch/microblaze/include/asm/cache.h
5741 @@ -13,11 +13,12 @@
5742 #ifndef _ASM_MICROBLAZE_CACHE_H
5743 #define _ASM_MICROBLAZE_CACHE_H
5744
5745 +#include <linux/const.h>
5746 #include <asm/registers.h>
5747
5748 #define L1_CACHE_SHIFT 5
5749 /* word-granular cache in microblaze */
5750 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5751 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5752
5753 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5754
5755 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5756 index 574c430..470200d 100644
5757 --- a/arch/mips/Kconfig
5758 +++ b/arch/mips/Kconfig
5759 @@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5760
5761 config KEXEC
5762 bool "Kexec system call"
5763 + depends on !GRKERNSEC_KMEM
5764 help
5765 kexec is a system call that implements the ability to shutdown your
5766 current kernel, and to start another kernel. It is like a reboot
5767 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5768 index 02f2444..506969c 100644
5769 --- a/arch/mips/cavium-octeon/dma-octeon.c
5770 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5771 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5772 if (dma_release_from_coherent(dev, order, vaddr))
5773 return;
5774
5775 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5776 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5777 }
5778
5779 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5780 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5781 index 37b2bef..02122b8 100644
5782 --- a/arch/mips/include/asm/atomic.h
5783 +++ b/arch/mips/include/asm/atomic.h
5784 @@ -21,15 +21,39 @@
5785 #include <asm/cmpxchg.h>
5786 #include <asm/war.h>
5787
5788 +#ifdef CONFIG_GENERIC_ATOMIC64
5789 +#include <asm-generic/atomic64.h>
5790 +#endif
5791 +
5792 #define ATOMIC_INIT(i) { (i) }
5793
5794 +#ifdef CONFIG_64BIT
5795 +#define _ASM_EXTABLE(from, to) \
5796 +" .section __ex_table,\"a\"\n" \
5797 +" .dword " #from ", " #to"\n" \
5798 +" .previous\n"
5799 +#else
5800 +#define _ASM_EXTABLE(from, to) \
5801 +" .section __ex_table,\"a\"\n" \
5802 +" .word " #from ", " #to"\n" \
5803 +" .previous\n"
5804 +#endif
5805 +
5806 /*
5807 * atomic_read - read atomic variable
5808 * @v: pointer of type atomic_t
5809 *
5810 * Atomically reads the value of @v.
5811 */
5812 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5813 +static inline int atomic_read(const atomic_t *v)
5814 +{
5815 + return (*(volatile const int *) &v->counter);
5816 +}
5817 +
5818 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5819 +{
5820 + return (*(volatile const int *) &v->counter);
5821 +}
5822
5823 /*
5824 * atomic_set - set atomic variable
5825 @@ -38,7 +62,15 @@
5826 *
5827 * Atomically sets the value of @v to @i.
5828 */
5829 -#define atomic_set(v, i) ((v)->counter = (i))
5830 +static inline void atomic_set(atomic_t *v, int i)
5831 +{
5832 + v->counter = i;
5833 +}
5834 +
5835 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5836 +{
5837 + v->counter = i;
5838 +}
5839
5840 /*
5841 * atomic_add - add integer to atomic variable
5842 @@ -47,7 +79,67 @@
5843 *
5844 * Atomically adds @i to @v.
5845 */
5846 -static __inline__ void atomic_add(int i, atomic_t * v)
5847 +static __inline__ void atomic_add(int i, atomic_t *v)
5848 +{
5849 + int temp;
5850 +
5851 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5852 + __asm__ __volatile__(
5853 + " .set mips3 \n"
5854 + "1: ll %0, %1 # atomic_add \n"
5855 +#ifdef CONFIG_PAX_REFCOUNT
5856 + /* Exception on overflow. */
5857 + "2: add %0, %2 \n"
5858 +#else
5859 + " addu %0, %2 \n"
5860 +#endif
5861 + " sc %0, %1 \n"
5862 + " beqzl %0, 1b \n"
5863 +#ifdef CONFIG_PAX_REFCOUNT
5864 + "3: \n"
5865 + _ASM_EXTABLE(2b, 3b)
5866 +#endif
5867 + " .set mips0 \n"
5868 + : "=&r" (temp), "+m" (v->counter)
5869 + : "Ir" (i));
5870 + } else if (kernel_uses_llsc) {
5871 + __asm__ __volatile__(
5872 + " .set mips3 \n"
5873 + "1: ll %0, %1 # atomic_add \n"
5874 +#ifdef CONFIG_PAX_REFCOUNT
5875 + /* Exception on overflow. */
5876 + "2: add %0, %2 \n"
5877 +#else
5878 + " addu %0, %2 \n"
5879 +#endif
5880 + " sc %0, %1 \n"
5881 + " beqz %0, 1b \n"
5882 +#ifdef CONFIG_PAX_REFCOUNT
5883 + "3: \n"
5884 + _ASM_EXTABLE(2b, 3b)
5885 +#endif
5886 + " .set mips0 \n"
5887 + : "=&r" (temp), "+m" (v->counter)
5888 + : "Ir" (i));
5889 + } else {
5890 + unsigned long flags;
5891 +
5892 + raw_local_irq_save(flags);
5893 + __asm__ __volatile__(
5894 +#ifdef CONFIG_PAX_REFCOUNT
5895 + /* Exception on overflow. */
5896 + "1: add %0, %1 \n"
5897 + "2: \n"
5898 + _ASM_EXTABLE(1b, 2b)
5899 +#else
5900 + " addu %0, %1 \n"
5901 +#endif
5902 + : "+r" (v->counter) : "Ir" (i));
5903 + raw_local_irq_restore(flags);
5904 + }
5905 +}
5906 +
5907 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5908 {
5909 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5910 int temp;
5911 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5912 *
5913 * Atomically subtracts @i from @v.
5914 */
5915 -static __inline__ void atomic_sub(int i, atomic_t * v)
5916 +static __inline__ void atomic_sub(int i, atomic_t *v)
5917 +{
5918 + int temp;
5919 +
5920 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5921 + __asm__ __volatile__(
5922 + " .set mips3 \n"
5923 + "1: ll %0, %1 # atomic64_sub \n"
5924 +#ifdef CONFIG_PAX_REFCOUNT
5925 + /* Exception on overflow. */
5926 + "2: sub %0, %2 \n"
5927 +#else
5928 + " subu %0, %2 \n"
5929 +#endif
5930 + " sc %0, %1 \n"
5931 + " beqzl %0, 1b \n"
5932 +#ifdef CONFIG_PAX_REFCOUNT
5933 + "3: \n"
5934 + _ASM_EXTABLE(2b, 3b)
5935 +#endif
5936 + " .set mips0 \n"
5937 + : "=&r" (temp), "+m" (v->counter)
5938 + : "Ir" (i));
5939 + } else if (kernel_uses_llsc) {
5940 + __asm__ __volatile__(
5941 + " .set mips3 \n"
5942 + "1: ll %0, %1 # atomic64_sub \n"
5943 +#ifdef CONFIG_PAX_REFCOUNT
5944 + /* Exception on overflow. */
5945 + "2: sub %0, %2 \n"
5946 +#else
5947 + " subu %0, %2 \n"
5948 +#endif
5949 + " sc %0, %1 \n"
5950 + " beqz %0, 1b \n"
5951 +#ifdef CONFIG_PAX_REFCOUNT
5952 + "3: \n"
5953 + _ASM_EXTABLE(2b, 3b)
5954 +#endif
5955 + " .set mips0 \n"
5956 + : "=&r" (temp), "+m" (v->counter)
5957 + : "Ir" (i));
5958 + } else {
5959 + unsigned long flags;
5960 +
5961 + raw_local_irq_save(flags);
5962 + __asm__ __volatile__(
5963 +#ifdef CONFIG_PAX_REFCOUNT
5964 + /* Exception on overflow. */
5965 + "1: sub %0, %1 \n"
5966 + "2: \n"
5967 + _ASM_EXTABLE(1b, 2b)
5968 +#else
5969 + " subu %0, %1 \n"
5970 +#endif
5971 + : "+r" (v->counter) : "Ir" (i));
5972 + raw_local_irq_restore(flags);
5973 + }
5974 +}
5975 +
5976 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5977 {
5978 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5979 int temp;
5980 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5981 /*
5982 * Same as above, but return the result value
5983 */
5984 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5985 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5986 +{
5987 + int result;
5988 + int temp;
5989 +
5990 + smp_mb__before_llsc();
5991 +
5992 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5993 + __asm__ __volatile__(
5994 + " .set mips3 \n"
5995 + "1: ll %1, %2 # atomic_add_return \n"
5996 +#ifdef CONFIG_PAX_REFCOUNT
5997 + "2: add %0, %1, %3 \n"
5998 +#else
5999 + " addu %0, %1, %3 \n"
6000 +#endif
6001 + " sc %0, %2 \n"
6002 + " beqzl %0, 1b \n"
6003 +#ifdef CONFIG_PAX_REFCOUNT
6004 + " b 4f \n"
6005 + " .set noreorder \n"
6006 + "3: b 5f \n"
6007 + " move %0, %1 \n"
6008 + " .set reorder \n"
6009 + _ASM_EXTABLE(2b, 3b)
6010 +#endif
6011 + "4: addu %0, %1, %3 \n"
6012 +#ifdef CONFIG_PAX_REFCOUNT
6013 + "5: \n"
6014 +#endif
6015 + " .set mips0 \n"
6016 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6017 + : "Ir" (i));
6018 + } else if (kernel_uses_llsc) {
6019 + __asm__ __volatile__(
6020 + " .set mips3 \n"
6021 + "1: ll %1, %2 # atomic_add_return \n"
6022 +#ifdef CONFIG_PAX_REFCOUNT
6023 + "2: add %0, %1, %3 \n"
6024 +#else
6025 + " addu %0, %1, %3 \n"
6026 +#endif
6027 + " sc %0, %2 \n"
6028 + " bnez %0, 4f \n"
6029 + " b 1b \n"
6030 +#ifdef CONFIG_PAX_REFCOUNT
6031 + " .set noreorder \n"
6032 + "3: b 5f \n"
6033 + " move %0, %1 \n"
6034 + " .set reorder \n"
6035 + _ASM_EXTABLE(2b, 3b)
6036 +#endif
6037 + "4: addu %0, %1, %3 \n"
6038 +#ifdef CONFIG_PAX_REFCOUNT
6039 + "5: \n"
6040 +#endif
6041 + " .set mips0 \n"
6042 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6043 + : "Ir" (i));
6044 + } else {
6045 + unsigned long flags;
6046 +
6047 + raw_local_irq_save(flags);
6048 + __asm__ __volatile__(
6049 + " lw %0, %1 \n"
6050 +#ifdef CONFIG_PAX_REFCOUNT
6051 + /* Exception on overflow. */
6052 + "1: add %0, %2 \n"
6053 +#else
6054 + " addu %0, %2 \n"
6055 +#endif
6056 + " sw %0, %1 \n"
6057 +#ifdef CONFIG_PAX_REFCOUNT
6058 + /* Note: Dest reg is not modified on overflow */
6059 + "2: \n"
6060 + _ASM_EXTABLE(1b, 2b)
6061 +#endif
6062 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6063 + raw_local_irq_restore(flags);
6064 + }
6065 +
6066 + smp_llsc_mb();
6067 +
6068 + return result;
6069 +}
6070 +
6071 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6072 {
6073 int result;
6074
6075 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6076 return result;
6077 }
6078
6079 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6080 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6081 +{
6082 + int result;
6083 + int temp;
6084 +
6085 + smp_mb__before_llsc();
6086 +
6087 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6088 + __asm__ __volatile__(
6089 + " .set mips3 \n"
6090 + "1: ll %1, %2 # atomic_sub_return \n"
6091 +#ifdef CONFIG_PAX_REFCOUNT
6092 + "2: sub %0, %1, %3 \n"
6093 +#else
6094 + " subu %0, %1, %3 \n"
6095 +#endif
6096 + " sc %0, %2 \n"
6097 + " beqzl %0, 1b \n"
6098 +#ifdef CONFIG_PAX_REFCOUNT
6099 + " b 4f \n"
6100 + " .set noreorder \n"
6101 + "3: b 5f \n"
6102 + " move %0, %1 \n"
6103 + " .set reorder \n"
6104 + _ASM_EXTABLE(2b, 3b)
6105 +#endif
6106 + "4: subu %0, %1, %3 \n"
6107 +#ifdef CONFIG_PAX_REFCOUNT
6108 + "5: \n"
6109 +#endif
6110 + " .set mips0 \n"
6111 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6112 + : "Ir" (i), "m" (v->counter)
6113 + : "memory");
6114 + } else if (kernel_uses_llsc) {
6115 + __asm__ __volatile__(
6116 + " .set mips3 \n"
6117 + "1: ll %1, %2 # atomic_sub_return \n"
6118 +#ifdef CONFIG_PAX_REFCOUNT
6119 + "2: sub %0, %1, %3 \n"
6120 +#else
6121 + " subu %0, %1, %3 \n"
6122 +#endif
6123 + " sc %0, %2 \n"
6124 + " bnez %0, 4f \n"
6125 + " b 1b \n"
6126 +#ifdef CONFIG_PAX_REFCOUNT
6127 + " .set noreorder \n"
6128 + "3: b 5f \n"
6129 + " move %0, %1 \n"
6130 + " .set reorder \n"
6131 + _ASM_EXTABLE(2b, 3b)
6132 +#endif
6133 + "4: subu %0, %1, %3 \n"
6134 +#ifdef CONFIG_PAX_REFCOUNT
6135 + "5: \n"
6136 +#endif
6137 + " .set mips0 \n"
6138 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6139 + : "Ir" (i));
6140 + } else {
6141 + unsigned long flags;
6142 +
6143 + raw_local_irq_save(flags);
6144 + __asm__ __volatile__(
6145 + " lw %0, %1 \n"
6146 +#ifdef CONFIG_PAX_REFCOUNT
6147 + /* Exception on overflow. */
6148 + "1: sub %0, %2 \n"
6149 +#else
6150 + " subu %0, %2 \n"
6151 +#endif
6152 + " sw %0, %1 \n"
6153 +#ifdef CONFIG_PAX_REFCOUNT
6154 + /* Note: Dest reg is not modified on overflow */
6155 + "2: \n"
6156 + _ASM_EXTABLE(1b, 2b)
6157 +#endif
6158 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6159 + raw_local_irq_restore(flags);
6160 + }
6161 +
6162 + smp_llsc_mb();
6163 +
6164 + return result;
6165 +}
6166 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6167 {
6168 int result;
6169
6170 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6171 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6172 * The function returns the old value of @v minus @i.
6173 */
6174 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6175 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6176 {
6177 int result;
6178
6179 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6180 return result;
6181 }
6182
6183 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6184 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6185 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6186 +{
6187 + return cmpxchg(&v->counter, old, new);
6188 +}
6189 +
6190 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6191 + int new)
6192 +{
6193 + return cmpxchg(&(v->counter), old, new);
6194 +}
6195 +
6196 +static inline int atomic_xchg(atomic_t *v, int new)
6197 +{
6198 + return xchg(&v->counter, new);
6199 +}
6200 +
6201 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6202 +{
6203 + return xchg(&(v->counter), new);
6204 +}
6205
6206 /**
6207 * __atomic_add_unless - add unless the number is a given value
6208 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6209
6210 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6211 #define atomic_inc_return(v) atomic_add_return(1, (v))
6212 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6213 +{
6214 + return atomic_add_return_unchecked(1, v);
6215 +}
6216
6217 /*
6218 * atomic_sub_and_test - subtract value from variable and test result
6219 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6220 * other cases.
6221 */
6222 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6223 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6224 +{
6225 + return atomic_add_return_unchecked(1, v) == 0;
6226 +}
6227
6228 /*
6229 * atomic_dec_and_test - decrement by 1 and test
6230 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6231 * Atomically increments @v by 1.
6232 */
6233 #define atomic_inc(v) atomic_add(1, (v))
6234 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6235 +{
6236 + atomic_add_unchecked(1, v);
6237 +}
6238
6239 /*
6240 * atomic_dec - decrement and test
6241 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6242 * Atomically decrements @v by 1.
6243 */
6244 #define atomic_dec(v) atomic_sub(1, (v))
6245 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6246 +{
6247 + atomic_sub_unchecked(1, v);
6248 +}
6249
6250 /*
6251 * atomic_add_negative - add and test if negative
6252 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6253 * @v: pointer of type atomic64_t
6254 *
6255 */
6256 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6257 +static inline long atomic64_read(const atomic64_t *v)
6258 +{
6259 + return (*(volatile const long *) &v->counter);
6260 +}
6261 +
6262 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6263 +{
6264 + return (*(volatile const long *) &v->counter);
6265 +}
6266
6267 /*
6268 * atomic64_set - set atomic variable
6269 * @v: pointer of type atomic64_t
6270 * @i: required value
6271 */
6272 -#define atomic64_set(v, i) ((v)->counter = (i))
6273 +static inline void atomic64_set(atomic64_t *v, long i)
6274 +{
6275 + v->counter = i;
6276 +}
6277 +
6278 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6279 +{
6280 + v->counter = i;
6281 +}
6282
6283 /*
6284 * atomic64_add - add integer to atomic variable
6285 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6286 *
6287 * Atomically adds @i to @v.
6288 */
6289 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6290 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6291 +{
6292 + long temp;
6293 +
6294 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6295 + __asm__ __volatile__(
6296 + " .set mips3 \n"
6297 + "1: lld %0, %1 # atomic64_add \n"
6298 +#ifdef CONFIG_PAX_REFCOUNT
6299 + /* Exception on overflow. */
6300 + "2: dadd %0, %2 \n"
6301 +#else
6302 + " daddu %0, %2 \n"
6303 +#endif
6304 + " scd %0, %1 \n"
6305 + " beqzl %0, 1b \n"
6306 +#ifdef CONFIG_PAX_REFCOUNT
6307 + "3: \n"
6308 + _ASM_EXTABLE(2b, 3b)
6309 +#endif
6310 + " .set mips0 \n"
6311 + : "=&r" (temp), "+m" (v->counter)
6312 + : "Ir" (i));
6313 + } else if (kernel_uses_llsc) {
6314 + __asm__ __volatile__(
6315 + " .set mips3 \n"
6316 + "1: lld %0, %1 # atomic64_add \n"
6317 +#ifdef CONFIG_PAX_REFCOUNT
6318 + /* Exception on overflow. */
6319 + "2: dadd %0, %2 \n"
6320 +#else
6321 + " daddu %0, %2 \n"
6322 +#endif
6323 + " scd %0, %1 \n"
6324 + " beqz %0, 1b \n"
6325 +#ifdef CONFIG_PAX_REFCOUNT
6326 + "3: \n"
6327 + _ASM_EXTABLE(2b, 3b)
6328 +#endif
6329 + " .set mips0 \n"
6330 + : "=&r" (temp), "+m" (v->counter)
6331 + : "Ir" (i));
6332 + } else {
6333 + unsigned long flags;
6334 +
6335 + raw_local_irq_save(flags);
6336 + __asm__ __volatile__(
6337 +#ifdef CONFIG_PAX_REFCOUNT
6338 + /* Exception on overflow. */
6339 + "1: dadd %0, %1 \n"
6340 + "2: \n"
6341 + _ASM_EXTABLE(1b, 2b)
6342 +#else
6343 + " daddu %0, %1 \n"
6344 +#endif
6345 + : "+r" (v->counter) : "Ir" (i));
6346 + raw_local_irq_restore(flags);
6347 + }
6348 +}
6349 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6350 {
6351 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6352 long temp;
6353 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6354 *
6355 * Atomically subtracts @i from @v.
6356 */
6357 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6358 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6359 +{
6360 + long temp;
6361 +
6362 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6363 + __asm__ __volatile__(
6364 + " .set mips3 \n"
6365 + "1: lld %0, %1 # atomic64_sub \n"
6366 +#ifdef CONFIG_PAX_REFCOUNT
6367 + /* Exception on overflow. */
6368 + "2: dsub %0, %2 \n"
6369 +#else
6370 + " dsubu %0, %2 \n"
6371 +#endif
6372 + " scd %0, %1 \n"
6373 + " beqzl %0, 1b \n"
6374 +#ifdef CONFIG_PAX_REFCOUNT
6375 + "3: \n"
6376 + _ASM_EXTABLE(2b, 3b)
6377 +#endif
6378 + " .set mips0 \n"
6379 + : "=&r" (temp), "+m" (v->counter)
6380 + : "Ir" (i));
6381 + } else if (kernel_uses_llsc) {
6382 + __asm__ __volatile__(
6383 + " .set mips3 \n"
6384 + "1: lld %0, %1 # atomic64_sub \n"
6385 +#ifdef CONFIG_PAX_REFCOUNT
6386 + /* Exception on overflow. */
6387 + "2: dsub %0, %2 \n"
6388 +#else
6389 + " dsubu %0, %2 \n"
6390 +#endif
6391 + " scd %0, %1 \n"
6392 + " beqz %0, 1b \n"
6393 +#ifdef CONFIG_PAX_REFCOUNT
6394 + "3: \n"
6395 + _ASM_EXTABLE(2b, 3b)
6396 +#endif
6397 + " .set mips0 \n"
6398 + : "=&r" (temp), "+m" (v->counter)
6399 + : "Ir" (i));
6400 + } else {
6401 + unsigned long flags;
6402 +
6403 + raw_local_irq_save(flags);
6404 + __asm__ __volatile__(
6405 +#ifdef CONFIG_PAX_REFCOUNT
6406 + /* Exception on overflow. */
6407 + "1: dsub %0, %1 \n"
6408 + "2: \n"
6409 + _ASM_EXTABLE(1b, 2b)
6410 +#else
6411 + " dsubu %0, %1 \n"
6412 +#endif
6413 + : "+r" (v->counter) : "Ir" (i));
6414 + raw_local_irq_restore(flags);
6415 + }
6416 +}
6417 +
6418 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6419 {
6420 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6421 long temp;
6422 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6423 /*
6424 * Same as above, but return the result value
6425 */
6426 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6427 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6428 +{
6429 + long result;
6430 + long temp;
6431 +
6432 + smp_mb__before_llsc();
6433 +
6434 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6435 + __asm__ __volatile__(
6436 + " .set mips3 \n"
6437 + "1: lld %1, %2 # atomic64_add_return \n"
6438 +#ifdef CONFIG_PAX_REFCOUNT
6439 + "2: dadd %0, %1, %3 \n"
6440 +#else
6441 + " daddu %0, %1, %3 \n"
6442 +#endif
6443 + " scd %0, %2 \n"
6444 + " beqzl %0, 1b \n"
6445 +#ifdef CONFIG_PAX_REFCOUNT
6446 + " b 4f \n"
6447 + " .set noreorder \n"
6448 + "3: b 5f \n"
6449 + " move %0, %1 \n"
6450 + " .set reorder \n"
6451 + _ASM_EXTABLE(2b, 3b)
6452 +#endif
6453 + "4: daddu %0, %1, %3 \n"
6454 +#ifdef CONFIG_PAX_REFCOUNT
6455 + "5: \n"
6456 +#endif
6457 + " .set mips0 \n"
6458 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6459 + : "Ir" (i));
6460 + } else if (kernel_uses_llsc) {
6461 + __asm__ __volatile__(
6462 + " .set mips3 \n"
6463 + "1: lld %1, %2 # atomic64_add_return \n"
6464 +#ifdef CONFIG_PAX_REFCOUNT
6465 + "2: dadd %0, %1, %3 \n"
6466 +#else
6467 + " daddu %0, %1, %3 \n"
6468 +#endif
6469 + " scd %0, %2 \n"
6470 + " bnez %0, 4f \n"
6471 + " b 1b \n"
6472 +#ifdef CONFIG_PAX_REFCOUNT
6473 + " .set noreorder \n"
6474 + "3: b 5f \n"
6475 + " move %0, %1 \n"
6476 + " .set reorder \n"
6477 + _ASM_EXTABLE(2b, 3b)
6478 +#endif
6479 + "4: daddu %0, %1, %3 \n"
6480 +#ifdef CONFIG_PAX_REFCOUNT
6481 + "5: \n"
6482 +#endif
6483 + " .set mips0 \n"
6484 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6485 + : "Ir" (i), "m" (v->counter)
6486 + : "memory");
6487 + } else {
6488 + unsigned long flags;
6489 +
6490 + raw_local_irq_save(flags);
6491 + __asm__ __volatile__(
6492 + " ld %0, %1 \n"
6493 +#ifdef CONFIG_PAX_REFCOUNT
6494 + /* Exception on overflow. */
6495 + "1: dadd %0, %2 \n"
6496 +#else
6497 + " daddu %0, %2 \n"
6498 +#endif
6499 + " sd %0, %1 \n"
6500 +#ifdef CONFIG_PAX_REFCOUNT
6501 + /* Note: Dest reg is not modified on overflow */
6502 + "2: \n"
6503 + _ASM_EXTABLE(1b, 2b)
6504 +#endif
6505 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6506 + raw_local_irq_restore(flags);
6507 + }
6508 +
6509 + smp_llsc_mb();
6510 +
6511 + return result;
6512 +}
6513 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6514 {
6515 long result;
6516
6517 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6518 return result;
6519 }
6520
6521 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6522 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6523 +{
6524 + long result;
6525 + long temp;
6526 +
6527 + smp_mb__before_llsc();
6528 +
6529 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6530 + long temp;
6531 +
6532 + __asm__ __volatile__(
6533 + " .set mips3 \n"
6534 + "1: lld %1, %2 # atomic64_sub_return \n"
6535 +#ifdef CONFIG_PAX_REFCOUNT
6536 + "2: dsub %0, %1, %3 \n"
6537 +#else
6538 + " dsubu %0, %1, %3 \n"
6539 +#endif
6540 + " scd %0, %2 \n"
6541 + " beqzl %0, 1b \n"
6542 +#ifdef CONFIG_PAX_REFCOUNT
6543 + " b 4f \n"
6544 + " .set noreorder \n"
6545 + "3: b 5f \n"
6546 + " move %0, %1 \n"
6547 + " .set reorder \n"
6548 + _ASM_EXTABLE(2b, 3b)
6549 +#endif
6550 + "4: dsubu %0, %1, %3 \n"
6551 +#ifdef CONFIG_PAX_REFCOUNT
6552 + "5: \n"
6553 +#endif
6554 + " .set mips0 \n"
6555 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6556 + : "Ir" (i), "m" (v->counter)
6557 + : "memory");
6558 + } else if (kernel_uses_llsc) {
6559 + __asm__ __volatile__(
6560 + " .set mips3 \n"
6561 + "1: lld %1, %2 # atomic64_sub_return \n"
6562 +#ifdef CONFIG_PAX_REFCOUNT
6563 + "2: dsub %0, %1, %3 \n"
6564 +#else
6565 + " dsubu %0, %1, %3 \n"
6566 +#endif
6567 + " scd %0, %2 \n"
6568 + " bnez %0, 4f \n"
6569 + " b 1b \n"
6570 +#ifdef CONFIG_PAX_REFCOUNT
6571 + " .set noreorder \n"
6572 + "3: b 5f \n"
6573 + " move %0, %1 \n"
6574 + " .set reorder \n"
6575 + _ASM_EXTABLE(2b, 3b)
6576 +#endif
6577 + "4: dsubu %0, %1, %3 \n"
6578 +#ifdef CONFIG_PAX_REFCOUNT
6579 + "5: \n"
6580 +#endif
6581 + " .set mips0 \n"
6582 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6583 + : "Ir" (i), "m" (v->counter)
6584 + : "memory");
6585 + } else {
6586 + unsigned long flags;
6587 +
6588 + raw_local_irq_save(flags);
6589 + __asm__ __volatile__(
6590 + " ld %0, %1 \n"
6591 +#ifdef CONFIG_PAX_REFCOUNT
6592 + /* Exception on overflow. */
6593 + "1: dsub %0, %2 \n"
6594 +#else
6595 + " dsubu %0, %2 \n"
6596 +#endif
6597 + " sd %0, %1 \n"
6598 +#ifdef CONFIG_PAX_REFCOUNT
6599 + /* Note: Dest reg is not modified on overflow */
6600 + "2: \n"
6601 + _ASM_EXTABLE(1b, 2b)
6602 +#endif
6603 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6604 + raw_local_irq_restore(flags);
6605 + }
6606 +
6607 + smp_llsc_mb();
6608 +
6609 + return result;
6610 +}
6611 +
6612 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6613 {
6614 long result;
6615
6616 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6617 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6618 * The function returns the old value of @v minus @i.
6619 */
6620 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6621 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6622 {
6623 long result;
6624
6625 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6626 return result;
6627 }
6628
6629 -#define atomic64_cmpxchg(v, o, n) \
6630 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6631 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6632 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6633 +{
6634 + return cmpxchg(&v->counter, old, new);
6635 +}
6636 +
6637 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6638 + long new)
6639 +{
6640 + return cmpxchg(&(v->counter), old, new);
6641 +}
6642 +
6643 +static inline long atomic64_xchg(atomic64_t *v, long new)
6644 +{
6645 + return xchg(&v->counter, new);
6646 +}
6647 +
6648 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6649 +{
6650 + return xchg(&(v->counter), new);
6651 +}
6652
6653 /**
6654 * atomic64_add_unless - add unless the number is a given value
6655 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6656
6657 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6658 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6659 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6660
6661 /*
6662 * atomic64_sub_and_test - subtract value from variable and test result
6663 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6664 * other cases.
6665 */
6666 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6667 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6668
6669 /*
6670 * atomic64_dec_and_test - decrement by 1 and test
6671 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6672 * Atomically increments @v by 1.
6673 */
6674 #define atomic64_inc(v) atomic64_add(1, (v))
6675 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6676
6677 /*
6678 * atomic64_dec - decrement and test
6679 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6680 * Atomically decrements @v by 1.
6681 */
6682 #define atomic64_dec(v) atomic64_sub(1, (v))
6683 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6684
6685 /*
6686 * atomic64_add_negative - add and test if negative
6687 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6688 index d0101dd..266982c 100644
6689 --- a/arch/mips/include/asm/barrier.h
6690 +++ b/arch/mips/include/asm/barrier.h
6691 @@ -184,7 +184,7 @@
6692 do { \
6693 compiletime_assert_atomic_type(*p); \
6694 smp_mb(); \
6695 - ACCESS_ONCE(*p) = (v); \
6696 + ACCESS_ONCE_RW(*p) = (v); \
6697 } while (0)
6698
6699 #define smp_load_acquire(p) \
6700 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6701 index b4db69f..8f3b093 100644
6702 --- a/arch/mips/include/asm/cache.h
6703 +++ b/arch/mips/include/asm/cache.h
6704 @@ -9,10 +9,11 @@
6705 #ifndef _ASM_CACHE_H
6706 #define _ASM_CACHE_H
6707
6708 +#include <linux/const.h>
6709 #include <kmalloc.h>
6710
6711 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6712 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6713 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6714
6715 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6716 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6717 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6718 index 1d38fe0..9beabc9 100644
6719 --- a/arch/mips/include/asm/elf.h
6720 +++ b/arch/mips/include/asm/elf.h
6721 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6722 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6723 #endif
6724
6725 +#ifdef CONFIG_PAX_ASLR
6726 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6727 +
6728 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6729 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6730 +#endif
6731 +
6732 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6733 struct linux_binprm;
6734 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6735 int uses_interp);
6736
6737 -struct mm_struct;
6738 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6739 -#define arch_randomize_brk arch_randomize_brk
6740 -
6741 #endif /* _ASM_ELF_H */
6742 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6743 index c1f6afa..38cc6e9 100644
6744 --- a/arch/mips/include/asm/exec.h
6745 +++ b/arch/mips/include/asm/exec.h
6746 @@ -12,6 +12,6 @@
6747 #ifndef _ASM_EXEC_H
6748 #define _ASM_EXEC_H
6749
6750 -extern unsigned long arch_align_stack(unsigned long sp);
6751 +#define arch_align_stack(x) ((x) & ~0xfUL)
6752
6753 #endif /* _ASM_EXEC_H */
6754 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6755 index 9e8ef59..1139d6b 100644
6756 --- a/arch/mips/include/asm/hw_irq.h
6757 +++ b/arch/mips/include/asm/hw_irq.h
6758 @@ -10,7 +10,7 @@
6759
6760 #include <linux/atomic.h>
6761
6762 -extern atomic_t irq_err_count;
6763 +extern atomic_unchecked_t irq_err_count;
6764
6765 /*
6766 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6767 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6768 index 46dfc3c..a16b13a 100644
6769 --- a/arch/mips/include/asm/local.h
6770 +++ b/arch/mips/include/asm/local.h
6771 @@ -12,15 +12,25 @@ typedef struct
6772 atomic_long_t a;
6773 } local_t;
6774
6775 +typedef struct {
6776 + atomic_long_unchecked_t a;
6777 +} local_unchecked_t;
6778 +
6779 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6780
6781 #define local_read(l) atomic_long_read(&(l)->a)
6782 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6783 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6784 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6785
6786 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6787 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6788 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6789 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6790 #define local_inc(l) atomic_long_inc(&(l)->a)
6791 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6792 #define local_dec(l) atomic_long_dec(&(l)->a)
6793 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6794
6795 /*
6796 * Same as above, but return the result value
6797 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6798 return result;
6799 }
6800
6801 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6802 +{
6803 + unsigned long result;
6804 +
6805 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6806 + unsigned long temp;
6807 +
6808 + __asm__ __volatile__(
6809 + " .set mips3 \n"
6810 + "1:" __LL "%1, %2 # local_add_return \n"
6811 + " addu %0, %1, %3 \n"
6812 + __SC "%0, %2 \n"
6813 + " beqzl %0, 1b \n"
6814 + " addu %0, %1, %3 \n"
6815 + " .set mips0 \n"
6816 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6817 + : "Ir" (i), "m" (l->a.counter)
6818 + : "memory");
6819 + } else if (kernel_uses_llsc) {
6820 + unsigned long temp;
6821 +
6822 + __asm__ __volatile__(
6823 + " .set mips3 \n"
6824 + "1:" __LL "%1, %2 # local_add_return \n"
6825 + " addu %0, %1, %3 \n"
6826 + __SC "%0, %2 \n"
6827 + " beqz %0, 1b \n"
6828 + " addu %0, %1, %3 \n"
6829 + " .set mips0 \n"
6830 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6831 + : "Ir" (i), "m" (l->a.counter)
6832 + : "memory");
6833 + } else {
6834 + unsigned long flags;
6835 +
6836 + local_irq_save(flags);
6837 + result = l->a.counter;
6838 + result += i;
6839 + l->a.counter = result;
6840 + local_irq_restore(flags);
6841 + }
6842 +
6843 + return result;
6844 +}
6845 +
6846 static __inline__ long local_sub_return(long i, local_t * l)
6847 {
6848 unsigned long result;
6849 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6850
6851 #define local_cmpxchg(l, o, n) \
6852 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6853 +#define local_cmpxchg_unchecked(l, o, n) \
6854 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6855 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6856
6857 /**
6858 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6859 index 3be8180..c4798d5 100644
6860 --- a/arch/mips/include/asm/page.h
6861 +++ b/arch/mips/include/asm/page.h
6862 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6863 #ifdef CONFIG_CPU_MIPS32
6864 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6865 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6866 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6867 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6868 #else
6869 typedef struct { unsigned long long pte; } pte_t;
6870 #define pte_val(x) ((x).pte)
6871 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6872 index b336037..5b874cc 100644
6873 --- a/arch/mips/include/asm/pgalloc.h
6874 +++ b/arch/mips/include/asm/pgalloc.h
6875 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6876 {
6877 set_pud(pud, __pud((unsigned long)pmd));
6878 }
6879 +
6880 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6881 +{
6882 + pud_populate(mm, pud, pmd);
6883 +}
6884 #endif
6885
6886 /*
6887 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6888 index df49a30..c0d3dd6 100644
6889 --- a/arch/mips/include/asm/pgtable.h
6890 +++ b/arch/mips/include/asm/pgtable.h
6891 @@ -20,6 +20,9 @@
6892 #include <asm/io.h>
6893 #include <asm/pgtable-bits.h>
6894
6895 +#define ktla_ktva(addr) (addr)
6896 +#define ktva_ktla(addr) (addr)
6897 +
6898 struct mm_struct;
6899 struct vm_area_struct;
6900
6901 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6902 index 7de8658..c109224 100644
6903 --- a/arch/mips/include/asm/thread_info.h
6904 +++ b/arch/mips/include/asm/thread_info.h
6905 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6906 #define TIF_SECCOMP 4 /* secure computing */
6907 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6908 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6909 +/* li takes a 32bit immediate */
6910 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6911 +
6912 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6913 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6914 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6915 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6916 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6917 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6918 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6919 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6920
6921 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6922 _TIF_SYSCALL_AUDIT | \
6923 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6924 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6925 + _TIF_GRSEC_SETXID)
6926
6927 /* work to do in syscall_trace_leave() */
6928 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6929 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6930 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6931
6932 /* work to do on interrupt/exception return */
6933 #define _TIF_WORK_MASK \
6934 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6935 /* work to do on any return to u-space */
6936 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6937 _TIF_WORK_SYSCALL_EXIT | \
6938 - _TIF_SYSCALL_TRACEPOINT)
6939 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6940
6941 /*
6942 * We stash processor id into a COP0 register to retrieve it fast
6943 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6944 index a109510..94ee3f6 100644
6945 --- a/arch/mips/include/asm/uaccess.h
6946 +++ b/arch/mips/include/asm/uaccess.h
6947 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6948 __ok == 0; \
6949 })
6950
6951 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6952 #define access_ok(type, addr, size) \
6953 likely(__access_ok((addr), (size), __access_mask))
6954
6955 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6956 index 1188e00..41cf144 100644
6957 --- a/arch/mips/kernel/binfmt_elfn32.c
6958 +++ b/arch/mips/kernel/binfmt_elfn32.c
6959 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6960 #undef ELF_ET_DYN_BASE
6961 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6962
6963 +#ifdef CONFIG_PAX_ASLR
6964 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6965 +
6966 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6967 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6968 +#endif
6969 +
6970 #include <asm/processor.h>
6971 #include <linux/module.h>
6972 #include <linux/elfcore.h>
6973 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6974 index 9287678..f870e47 100644
6975 --- a/arch/mips/kernel/binfmt_elfo32.c
6976 +++ b/arch/mips/kernel/binfmt_elfo32.c
6977 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6978 #undef ELF_ET_DYN_BASE
6979 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6980
6981 +#ifdef CONFIG_PAX_ASLR
6982 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6983 +
6984 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6985 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6986 +#endif
6987 +
6988 #include <asm/processor.h>
6989
6990 #include <linux/module.h>
6991 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6992 index 50b3648..c2f3cec 100644
6993 --- a/arch/mips/kernel/i8259.c
6994 +++ b/arch/mips/kernel/i8259.c
6995 @@ -201,7 +201,7 @@ spurious_8259A_irq:
6996 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6997 spurious_irq_mask |= irqmask;
6998 }
6999 - atomic_inc(&irq_err_count);
7000 + atomic_inc_unchecked(&irq_err_count);
7001 /*
7002 * Theoretically we do not have to handle this IRQ,
7003 * but in Linux this does not cause problems and is
7004 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7005 index 44a1f79..2bd6aa3 100644
7006 --- a/arch/mips/kernel/irq-gt641xx.c
7007 +++ b/arch/mips/kernel/irq-gt641xx.c
7008 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7009 }
7010 }
7011
7012 - atomic_inc(&irq_err_count);
7013 + atomic_inc_unchecked(&irq_err_count);
7014 }
7015
7016 void __init gt641xx_irq_init(void)
7017 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7018 index d2bfbc2..a8eacd2 100644
7019 --- a/arch/mips/kernel/irq.c
7020 +++ b/arch/mips/kernel/irq.c
7021 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7022 printk("unexpected IRQ # %d\n", irq);
7023 }
7024
7025 -atomic_t irq_err_count;
7026 +atomic_unchecked_t irq_err_count;
7027
7028 int arch_show_interrupts(struct seq_file *p, int prec)
7029 {
7030 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7031 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7032 return 0;
7033 }
7034
7035 asmlinkage void spurious_interrupt(void)
7036 {
7037 - atomic_inc(&irq_err_count);
7038 + atomic_inc_unchecked(&irq_err_count);
7039 }
7040
7041 void __init init_IRQ(void)
7042 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7043 #endif
7044 }
7045
7046 +
7047 #ifdef DEBUG_STACKOVERFLOW
7048 +extern void gr_handle_kernel_exploit(void);
7049 +
7050 static inline void check_stack_overflow(void)
7051 {
7052 unsigned long sp;
7053 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7054 printk("do_IRQ: stack overflow: %ld\n",
7055 sp - sizeof(struct thread_info));
7056 dump_stack();
7057 + gr_handle_kernel_exploit();
7058 }
7059 }
7060 #else
7061 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7062 index 0614717..002fa43 100644
7063 --- a/arch/mips/kernel/pm-cps.c
7064 +++ b/arch/mips/kernel/pm-cps.c
7065 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7066 nc_core_ready_count = nc_addr;
7067
7068 /* Ensure ready_count is zero-initialised before the assembly runs */
7069 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7070 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7071 coupled_barrier(&per_cpu(pm_barrier, core), online);
7072
7073 /* Run the generated entry code */
7074 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7075 index 636b074..8fbb91f 100644
7076 --- a/arch/mips/kernel/process.c
7077 +++ b/arch/mips/kernel/process.c
7078 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7079 out:
7080 return pc;
7081 }
7082 -
7083 -/*
7084 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7085 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7086 - */
7087 -unsigned long arch_align_stack(unsigned long sp)
7088 -{
7089 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7090 - sp -= get_random_int() & ~PAGE_MASK;
7091 -
7092 - return sp & ALMASK;
7093 -}
7094 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7095 index 645b3c4..909c75a 100644
7096 --- a/arch/mips/kernel/ptrace.c
7097 +++ b/arch/mips/kernel/ptrace.c
7098 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7099 return ret;
7100 }
7101
7102 +#ifdef CONFIG_GRKERNSEC_SETXID
7103 +extern void gr_delayed_cred_worker(void);
7104 +#endif
7105 +
7106 /*
7107 * Notification of system call entry/exit
7108 * - triggered by current->work.syscall_trace
7109 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7110 tracehook_report_syscall_entry(regs))
7111 ret = -1;
7112
7113 +#ifdef CONFIG_GRKERNSEC_SETXID
7114 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7115 + gr_delayed_cred_worker();
7116 +#endif
7117 +
7118 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7119 trace_sys_enter(regs, regs->regs[2]);
7120
7121 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7122 index 07fc524..b9d7f28 100644
7123 --- a/arch/mips/kernel/reset.c
7124 +++ b/arch/mips/kernel/reset.c
7125 @@ -13,6 +13,7 @@
7126 #include <linux/reboot.h>
7127
7128 #include <asm/reboot.h>
7129 +#include <asm/bug.h>
7130
7131 /*
7132 * Urgs ... Too many MIPS machines to handle this in a generic way.
7133 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7134 {
7135 if (_machine_restart)
7136 _machine_restart(command);
7137 + BUG();
7138 }
7139
7140 void machine_halt(void)
7141 {
7142 if (_machine_halt)
7143 _machine_halt();
7144 + BUG();
7145 }
7146
7147 void machine_power_off(void)
7148 {
7149 if (pm_power_off)
7150 pm_power_off();
7151 + BUG();
7152 }
7153 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7154 index 2242bdd..b284048 100644
7155 --- a/arch/mips/kernel/sync-r4k.c
7156 +++ b/arch/mips/kernel/sync-r4k.c
7157 @@ -18,8 +18,8 @@
7158 #include <asm/mipsregs.h>
7159
7160 static atomic_t count_start_flag = ATOMIC_INIT(0);
7161 -static atomic_t count_count_start = ATOMIC_INIT(0);
7162 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7163 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7164 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7165 static atomic_t count_reference = ATOMIC_INIT(0);
7166
7167 #define COUNTON 100
7168 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7169
7170 for (i = 0; i < NR_LOOPS; i++) {
7171 /* slaves loop on '!= 2' */
7172 - while (atomic_read(&count_count_start) != 1)
7173 + while (atomic_read_unchecked(&count_count_start) != 1)
7174 mb();
7175 - atomic_set(&count_count_stop, 0);
7176 + atomic_set_unchecked(&count_count_stop, 0);
7177 smp_wmb();
7178
7179 /* this lets the slaves write their count register */
7180 - atomic_inc(&count_count_start);
7181 + atomic_inc_unchecked(&count_count_start);
7182
7183 /*
7184 * Everyone initialises count in the last loop:
7185 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7186 /*
7187 * Wait for all slaves to leave the synchronization point:
7188 */
7189 - while (atomic_read(&count_count_stop) != 1)
7190 + while (atomic_read_unchecked(&count_count_stop) != 1)
7191 mb();
7192 - atomic_set(&count_count_start, 0);
7193 + atomic_set_unchecked(&count_count_start, 0);
7194 smp_wmb();
7195 - atomic_inc(&count_count_stop);
7196 + atomic_inc_unchecked(&count_count_stop);
7197 }
7198 /* Arrange for an interrupt in a short while */
7199 write_c0_compare(read_c0_count() + COUNTON);
7200 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7201 initcount = atomic_read(&count_reference);
7202
7203 for (i = 0; i < NR_LOOPS; i++) {
7204 - atomic_inc(&count_count_start);
7205 - while (atomic_read(&count_count_start) != 2)
7206 + atomic_inc_unchecked(&count_count_start);
7207 + while (atomic_read_unchecked(&count_count_start) != 2)
7208 mb();
7209
7210 /*
7211 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7212 if (i == NR_LOOPS-1)
7213 write_c0_count(initcount);
7214
7215 - atomic_inc(&count_count_stop);
7216 - while (atomic_read(&count_count_stop) != 2)
7217 + atomic_inc_unchecked(&count_count_stop);
7218 + while (atomic_read_unchecked(&count_count_stop) != 2)
7219 mb();
7220 }
7221 /* Arrange for an interrupt in a short while */
7222 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7223 index 22b19c2..c5cc8c4 100644
7224 --- a/arch/mips/kernel/traps.c
7225 +++ b/arch/mips/kernel/traps.c
7226 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7227 siginfo_t info;
7228
7229 prev_state = exception_enter();
7230 - die_if_kernel("Integer overflow", regs);
7231 + if (unlikely(!user_mode(regs))) {
7232 +
7233 +#ifdef CONFIG_PAX_REFCOUNT
7234 + if (fixup_exception(regs)) {
7235 + pax_report_refcount_overflow(regs);
7236 + exception_exit(prev_state);
7237 + return;
7238 + }
7239 +#endif
7240 +
7241 + die("Integer overflow", regs);
7242 + }
7243
7244 info.si_code = FPE_INTOVF;
7245 info.si_signo = SIGFPE;
7246 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7247 index cd71141..e02c4df 100644
7248 --- a/arch/mips/kvm/mips.c
7249 +++ b/arch/mips/kvm/mips.c
7250 @@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7251 return r;
7252 }
7253
7254 -int kvm_arch_init(void *opaque)
7255 +int kvm_arch_init(const void *opaque)
7256 {
7257 if (kvm_mips_callbacks) {
7258 kvm_err("kvm: module already exists\n");
7259 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7260 index becc42b..9e43d4b 100644
7261 --- a/arch/mips/mm/fault.c
7262 +++ b/arch/mips/mm/fault.c
7263 @@ -28,6 +28,23 @@
7264 #include <asm/highmem.h> /* For VMALLOC_END */
7265 #include <linux/kdebug.h>
7266
7267 +#ifdef CONFIG_PAX_PAGEEXEC
7268 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7269 +{
7270 + unsigned long i;
7271 +
7272 + printk(KERN_ERR "PAX: bytes at PC: ");
7273 + for (i = 0; i < 5; i++) {
7274 + unsigned int c;
7275 + if (get_user(c, (unsigned int *)pc+i))
7276 + printk(KERN_CONT "???????? ");
7277 + else
7278 + printk(KERN_CONT "%08x ", c);
7279 + }
7280 + printk("\n");
7281 +}
7282 +#endif
7283 +
7284 /*
7285 * This routine handles page faults. It determines the address,
7286 * and the problem, and then passes it off to one of the appropriate
7287 @@ -199,6 +216,14 @@ bad_area:
7288 bad_area_nosemaphore:
7289 /* User mode accesses just cause a SIGSEGV */
7290 if (user_mode(regs)) {
7291 +
7292 +#ifdef CONFIG_PAX_PAGEEXEC
7293 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7294 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7295 + do_group_exit(SIGKILL);
7296 + }
7297 +#endif
7298 +
7299 tsk->thread.cp0_badvaddr = address;
7300 tsk->thread.error_code = write;
7301 #if 0
7302 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7303 index f1baadd..5472dca 100644
7304 --- a/arch/mips/mm/mmap.c
7305 +++ b/arch/mips/mm/mmap.c
7306 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7307 struct vm_area_struct *vma;
7308 unsigned long addr = addr0;
7309 int do_color_align;
7310 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7311 struct vm_unmapped_area_info info;
7312
7313 if (unlikely(len > TASK_SIZE))
7314 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7315 do_color_align = 1;
7316
7317 /* requesting a specific address */
7318 +
7319 +#ifdef CONFIG_PAX_RANDMMAP
7320 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7321 +#endif
7322 +
7323 if (addr) {
7324 if (do_color_align)
7325 addr = COLOUR_ALIGN(addr, pgoff);
7326 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7327 addr = PAGE_ALIGN(addr);
7328
7329 vma = find_vma(mm, addr);
7330 - if (TASK_SIZE - len >= addr &&
7331 - (!vma || addr + len <= vma->vm_start))
7332 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7333 return addr;
7334 }
7335
7336 info.length = len;
7337 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7338 info.align_offset = pgoff << PAGE_SHIFT;
7339 + info.threadstack_offset = offset;
7340
7341 if (dir == DOWN) {
7342 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7343 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7344 {
7345 unsigned long random_factor = 0UL;
7346
7347 +#ifdef CONFIG_PAX_RANDMMAP
7348 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7349 +#endif
7350 +
7351 if (current->flags & PF_RANDOMIZE) {
7352 random_factor = get_random_int();
7353 random_factor = random_factor << PAGE_SHIFT;
7354 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7355
7356 if (mmap_is_legacy()) {
7357 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7358 +
7359 +#ifdef CONFIG_PAX_RANDMMAP
7360 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7361 + mm->mmap_base += mm->delta_mmap;
7362 +#endif
7363 +
7364 mm->get_unmapped_area = arch_get_unmapped_area;
7365 } else {
7366 mm->mmap_base = mmap_base(random_factor);
7367 +
7368 +#ifdef CONFIG_PAX_RANDMMAP
7369 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7370 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7371 +#endif
7372 +
7373 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7374 }
7375 }
7376
7377 -static inline unsigned long brk_rnd(void)
7378 -{
7379 - unsigned long rnd = get_random_int();
7380 -
7381 - rnd = rnd << PAGE_SHIFT;
7382 - /* 8MB for 32bit, 256MB for 64bit */
7383 - if (TASK_IS_32BIT_ADDR)
7384 - rnd = rnd & 0x7ffffful;
7385 - else
7386 - rnd = rnd & 0xffffffful;
7387 -
7388 - return rnd;
7389 -}
7390 -
7391 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7392 -{
7393 - unsigned long base = mm->brk;
7394 - unsigned long ret;
7395 -
7396 - ret = PAGE_ALIGN(base + brk_rnd());
7397 -
7398 - if (ret < mm->brk)
7399 - return mm->brk;
7400 -
7401 - return ret;
7402 -}
7403 -
7404 int __virt_addr_valid(const volatile void *kaddr)
7405 {
7406 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7407 diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7408 index 9f7ecbd..6e370fc 100644
7409 --- a/arch/mips/net/bpf_jit.c
7410 +++ b/arch/mips/net/bpf_jit.c
7411 @@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7412 {
7413 if (fp->jited)
7414 module_free(NULL, fp->bpf_func);
7415 - kfree(fp);
7416 +
7417 + bpf_prog_unlock_free(fp);
7418 }
7419 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7420 index 59cccd9..f39ac2f 100644
7421 --- a/arch/mips/pci/pci-octeon.c
7422 +++ b/arch/mips/pci/pci-octeon.c
7423 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7424
7425
7426 static struct pci_ops octeon_pci_ops = {
7427 - octeon_read_config,
7428 - octeon_write_config,
7429 + .read = octeon_read_config,
7430 + .write = octeon_write_config,
7431 };
7432
7433 static struct resource octeon_pci_mem_resource = {
7434 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7435 index 5e36c33..eb4a17b 100644
7436 --- a/arch/mips/pci/pcie-octeon.c
7437 +++ b/arch/mips/pci/pcie-octeon.c
7438 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7439 }
7440
7441 static struct pci_ops octeon_pcie0_ops = {
7442 - octeon_pcie0_read_config,
7443 - octeon_pcie0_write_config,
7444 + .read = octeon_pcie0_read_config,
7445 + .write = octeon_pcie0_write_config,
7446 };
7447
7448 static struct resource octeon_pcie0_mem_resource = {
7449 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7450 };
7451
7452 static struct pci_ops octeon_pcie1_ops = {
7453 - octeon_pcie1_read_config,
7454 - octeon_pcie1_write_config,
7455 + .read = octeon_pcie1_read_config,
7456 + .write = octeon_pcie1_write_config,
7457 };
7458
7459 static struct resource octeon_pcie1_mem_resource = {
7460 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7461 };
7462
7463 static struct pci_ops octeon_dummy_ops = {
7464 - octeon_dummy_read_config,
7465 - octeon_dummy_write_config,
7466 + .read = octeon_dummy_read_config,
7467 + .write = octeon_dummy_write_config,
7468 };
7469
7470 static struct resource octeon_dummy_mem_resource = {
7471 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7472 index a2358b4..7cead4f 100644
7473 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7474 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7475 @@ -187,9 +187,9 @@ void
7476 cont_nmi_dump(void)
7477 {
7478 #ifndef REAL_NMI_SIGNAL
7479 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7480 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7481
7482 - atomic_inc(&nmied_cpus);
7483 + atomic_inc_unchecked(&nmied_cpus);
7484 #endif
7485 /*
7486 * Only allow 1 cpu to proceed
7487 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7488 udelay(10000);
7489 }
7490 #else
7491 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7492 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7493 #endif
7494
7495 /*
7496 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7497 index a046b30..6799527 100644
7498 --- a/arch/mips/sni/rm200.c
7499 +++ b/arch/mips/sni/rm200.c
7500 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7501 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7502 spurious_irq_mask |= irqmask;
7503 }
7504 - atomic_inc(&irq_err_count);
7505 + atomic_inc_unchecked(&irq_err_count);
7506 /*
7507 * Theoretically we do not have to handle this IRQ,
7508 * but in Linux this does not cause problems and is
7509 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7510 index 41e873b..34d33a7 100644
7511 --- a/arch/mips/vr41xx/common/icu.c
7512 +++ b/arch/mips/vr41xx/common/icu.c
7513 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7514
7515 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7516
7517 - atomic_inc(&irq_err_count);
7518 + atomic_inc_unchecked(&irq_err_count);
7519
7520 return -1;
7521 }
7522 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7523 index ae0e4ee..e8f0692 100644
7524 --- a/arch/mips/vr41xx/common/irq.c
7525 +++ b/arch/mips/vr41xx/common/irq.c
7526 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7527 irq_cascade_t *cascade;
7528
7529 if (irq >= NR_IRQS) {
7530 - atomic_inc(&irq_err_count);
7531 + atomic_inc_unchecked(&irq_err_count);
7532 return;
7533 }
7534
7535 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7536 ret = cascade->get_irq(irq);
7537 irq = ret;
7538 if (ret < 0)
7539 - atomic_inc(&irq_err_count);
7540 + atomic_inc_unchecked(&irq_err_count);
7541 else
7542 irq_dispatch(irq);
7543 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7544 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7545 index 967d144..db12197 100644
7546 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7547 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7548 @@ -11,12 +11,14 @@
7549 #ifndef _ASM_PROC_CACHE_H
7550 #define _ASM_PROC_CACHE_H
7551
7552 +#include <linux/const.h>
7553 +
7554 /* L1 cache */
7555
7556 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7557 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7558 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7559 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7560 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7561 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7562
7563 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7564 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7565 index bcb5df2..84fabd2 100644
7566 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7567 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7568 @@ -16,13 +16,15 @@
7569 #ifndef _ASM_PROC_CACHE_H
7570 #define _ASM_PROC_CACHE_H
7571
7572 +#include <linux/const.h>
7573 +
7574 /*
7575 * L1 cache
7576 */
7577 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7578 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7579 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7580 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7581 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7582 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7583
7584 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7585 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7586 index 4ce7a01..449202a 100644
7587 --- a/arch/openrisc/include/asm/cache.h
7588 +++ b/arch/openrisc/include/asm/cache.h
7589 @@ -19,11 +19,13 @@
7590 #ifndef __ASM_OPENRISC_CACHE_H
7591 #define __ASM_OPENRISC_CACHE_H
7592
7593 +#include <linux/const.h>
7594 +
7595 /* FIXME: How can we replace these with values from the CPU...
7596 * they shouldn't be hard-coded!
7597 */
7598
7599 -#define L1_CACHE_BYTES 16
7600 #define L1_CACHE_SHIFT 4
7601 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7602
7603 #endif /* __ASM_OPENRISC_CACHE_H */
7604 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7605 index 0be2db2..1b0f26d 100644
7606 --- a/arch/parisc/include/asm/atomic.h
7607 +++ b/arch/parisc/include/asm/atomic.h
7608 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7609 return dec;
7610 }
7611
7612 +#define atomic64_read_unchecked(v) atomic64_read(v)
7613 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7614 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7615 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7616 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7617 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7618 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7619 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7620 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7621 +
7622 #endif /* !CONFIG_64BIT */
7623
7624
7625 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7626 index 47f11c7..3420df2 100644
7627 --- a/arch/parisc/include/asm/cache.h
7628 +++ b/arch/parisc/include/asm/cache.h
7629 @@ -5,6 +5,7 @@
7630 #ifndef __ARCH_PARISC_CACHE_H
7631 #define __ARCH_PARISC_CACHE_H
7632
7633 +#include <linux/const.h>
7634
7635 /*
7636 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7637 @@ -15,13 +16,13 @@
7638 * just ruin performance.
7639 */
7640 #ifdef CONFIG_PA20
7641 -#define L1_CACHE_BYTES 64
7642 #define L1_CACHE_SHIFT 6
7643 #else
7644 -#define L1_CACHE_BYTES 32
7645 #define L1_CACHE_SHIFT 5
7646 #endif
7647
7648 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7649 +
7650 #ifndef __ASSEMBLY__
7651
7652 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7653 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7654 index 3391d06..c23a2cc 100644
7655 --- a/arch/parisc/include/asm/elf.h
7656 +++ b/arch/parisc/include/asm/elf.h
7657 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7658
7659 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7660
7661 +#ifdef CONFIG_PAX_ASLR
7662 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7663 +
7664 +#define PAX_DELTA_MMAP_LEN 16
7665 +#define PAX_DELTA_STACK_LEN 16
7666 +#endif
7667 +
7668 /* This yields a mask that user programs can use to figure out what
7669 instruction set this CPU supports. This could be done in user space,
7670 but it's not easy, and we've already done it here. */
7671 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7672 index f213f5b..0af3e8e 100644
7673 --- a/arch/parisc/include/asm/pgalloc.h
7674 +++ b/arch/parisc/include/asm/pgalloc.h
7675 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7676 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7677 }
7678
7679 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7680 +{
7681 + pgd_populate(mm, pgd, pmd);
7682 +}
7683 +
7684 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7685 {
7686 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7687 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7688 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7689 #define pmd_free(mm, x) do { } while (0)
7690 #define pgd_populate(mm, pmd, pte) BUG()
7691 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7692
7693 #endif
7694
7695 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7696 index 22b89d1..ce34230 100644
7697 --- a/arch/parisc/include/asm/pgtable.h
7698 +++ b/arch/parisc/include/asm/pgtable.h
7699 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7700 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7701 #define PAGE_COPY PAGE_EXECREAD
7702 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7703 +
7704 +#ifdef CONFIG_PAX_PAGEEXEC
7705 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7706 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7707 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7708 +#else
7709 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7710 +# define PAGE_COPY_NOEXEC PAGE_COPY
7711 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7712 +#endif
7713 +
7714 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7715 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7716 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7717 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7718 index 4006964..fcb3cc2 100644
7719 --- a/arch/parisc/include/asm/uaccess.h
7720 +++ b/arch/parisc/include/asm/uaccess.h
7721 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7722 const void __user *from,
7723 unsigned long n)
7724 {
7725 - int sz = __compiletime_object_size(to);
7726 + size_t sz = __compiletime_object_size(to);
7727 int ret = -EFAULT;
7728
7729 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7730 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7731 ret = __copy_from_user(to, from, n);
7732 else
7733 copy_from_user_overflow();
7734 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7735 index 50dfafc..b9fc230 100644
7736 --- a/arch/parisc/kernel/module.c
7737 +++ b/arch/parisc/kernel/module.c
7738 @@ -98,16 +98,38 @@
7739
7740 /* three functions to determine where in the module core
7741 * or init pieces the location is */
7742 +static inline int in_init_rx(struct module *me, void *loc)
7743 +{
7744 + return (loc >= me->module_init_rx &&
7745 + loc < (me->module_init_rx + me->init_size_rx));
7746 +}
7747 +
7748 +static inline int in_init_rw(struct module *me, void *loc)
7749 +{
7750 + return (loc >= me->module_init_rw &&
7751 + loc < (me->module_init_rw + me->init_size_rw));
7752 +}
7753 +
7754 static inline int in_init(struct module *me, void *loc)
7755 {
7756 - return (loc >= me->module_init &&
7757 - loc <= (me->module_init + me->init_size));
7758 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7759 +}
7760 +
7761 +static inline int in_core_rx(struct module *me, void *loc)
7762 +{
7763 + return (loc >= me->module_core_rx &&
7764 + loc < (me->module_core_rx + me->core_size_rx));
7765 +}
7766 +
7767 +static inline int in_core_rw(struct module *me, void *loc)
7768 +{
7769 + return (loc >= me->module_core_rw &&
7770 + loc < (me->module_core_rw + me->core_size_rw));
7771 }
7772
7773 static inline int in_core(struct module *me, void *loc)
7774 {
7775 - return (loc >= me->module_core &&
7776 - loc <= (me->module_core + me->core_size));
7777 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7778 }
7779
7780 static inline int in_local(struct module *me, void *loc)
7781 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7782 }
7783
7784 /* align things a bit */
7785 - me->core_size = ALIGN(me->core_size, 16);
7786 - me->arch.got_offset = me->core_size;
7787 - me->core_size += gots * sizeof(struct got_entry);
7788 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7789 + me->arch.got_offset = me->core_size_rw;
7790 + me->core_size_rw += gots * sizeof(struct got_entry);
7791
7792 - me->core_size = ALIGN(me->core_size, 16);
7793 - me->arch.fdesc_offset = me->core_size;
7794 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7795 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7796 + me->arch.fdesc_offset = me->core_size_rw;
7797 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7798
7799 me->arch.got_max = gots;
7800 me->arch.fdesc_max = fdescs;
7801 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7802
7803 BUG_ON(value == 0);
7804
7805 - got = me->module_core + me->arch.got_offset;
7806 + got = me->module_core_rw + me->arch.got_offset;
7807 for (i = 0; got[i].addr; i++)
7808 if (got[i].addr == value)
7809 goto out;
7810 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7811 #ifdef CONFIG_64BIT
7812 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7813 {
7814 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7815 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7816
7817 if (!value) {
7818 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7819 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7820
7821 /* Create new one */
7822 fdesc->addr = value;
7823 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7824 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7825 return (Elf_Addr)fdesc;
7826 }
7827 #endif /* CONFIG_64BIT */
7828 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7829
7830 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7831 end = table + sechdrs[me->arch.unwind_section].sh_size;
7832 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7833 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7834
7835 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7836 me->arch.unwind_section, table, end, gp);
7837 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7838 index e1ffea2..46ed66e 100644
7839 --- a/arch/parisc/kernel/sys_parisc.c
7840 +++ b/arch/parisc/kernel/sys_parisc.c
7841 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7842 unsigned long task_size = TASK_SIZE;
7843 int do_color_align, last_mmap;
7844 struct vm_unmapped_area_info info;
7845 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7846
7847 if (len > task_size)
7848 return -ENOMEM;
7849 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7850 goto found_addr;
7851 }
7852
7853 +#ifdef CONFIG_PAX_RANDMMAP
7854 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7855 +#endif
7856 +
7857 if (addr) {
7858 if (do_color_align && last_mmap)
7859 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7860 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7861 info.high_limit = mmap_upper_limit();
7862 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7863 info.align_offset = shared_align_offset(last_mmap, pgoff);
7864 + info.threadstack_offset = offset;
7865 addr = vm_unmapped_area(&info);
7866
7867 found_addr:
7868 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7869 unsigned long addr = addr0;
7870 int do_color_align, last_mmap;
7871 struct vm_unmapped_area_info info;
7872 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7873
7874 #ifdef CONFIG_64BIT
7875 /* This should only ever run for 32-bit processes. */
7876 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7877 }
7878
7879 /* requesting a specific address */
7880 +#ifdef CONFIG_PAX_RANDMMAP
7881 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7882 +#endif
7883 +
7884 if (addr) {
7885 if (do_color_align && last_mmap)
7886 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7887 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7888 info.high_limit = mm->mmap_base;
7889 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7890 info.align_offset = shared_align_offset(last_mmap, pgoff);
7891 + info.threadstack_offset = offset;
7892 addr = vm_unmapped_area(&info);
7893 if (!(addr & ~PAGE_MASK))
7894 goto found_addr;
7895 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7896 mm->mmap_legacy_base = mmap_legacy_base();
7897 mm->mmap_base = mmap_upper_limit();
7898
7899 +#ifdef CONFIG_PAX_RANDMMAP
7900 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7901 + mm->mmap_legacy_base += mm->delta_mmap;
7902 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7903 + }
7904 +#endif
7905 +
7906 if (mmap_is_legacy()) {
7907 mm->mmap_base = mm->mmap_legacy_base;
7908 mm->get_unmapped_area = arch_get_unmapped_area;
7909 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7910 index 47ee620..1107387 100644
7911 --- a/arch/parisc/kernel/traps.c
7912 +++ b/arch/parisc/kernel/traps.c
7913 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7914
7915 down_read(&current->mm->mmap_sem);
7916 vma = find_vma(current->mm,regs->iaoq[0]);
7917 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7918 - && (vma->vm_flags & VM_EXEC)) {
7919 -
7920 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7921 fault_address = regs->iaoq[0];
7922 fault_space = regs->iasq[0];
7923
7924 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7925 index 3ca9c11..d163ef7 100644
7926 --- a/arch/parisc/mm/fault.c
7927 +++ b/arch/parisc/mm/fault.c
7928 @@ -15,6 +15,7 @@
7929 #include <linux/sched.h>
7930 #include <linux/interrupt.h>
7931 #include <linux/module.h>
7932 +#include <linux/unistd.h>
7933
7934 #include <asm/uaccess.h>
7935 #include <asm/traps.h>
7936 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7937 static unsigned long
7938 parisc_acctyp(unsigned long code, unsigned int inst)
7939 {
7940 - if (code == 6 || code == 16)
7941 + if (code == 6 || code == 7 || code == 16)
7942 return VM_EXEC;
7943
7944 switch (inst & 0xf0000000) {
7945 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7946 }
7947 #endif
7948
7949 +#ifdef CONFIG_PAX_PAGEEXEC
7950 +/*
7951 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7952 + *
7953 + * returns 1 when task should be killed
7954 + * 2 when rt_sigreturn trampoline was detected
7955 + * 3 when unpatched PLT trampoline was detected
7956 + */
7957 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7958 +{
7959 +
7960 +#ifdef CONFIG_PAX_EMUPLT
7961 + int err;
7962 +
7963 + do { /* PaX: unpatched PLT emulation */
7964 + unsigned int bl, depwi;
7965 +
7966 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7967 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7968 +
7969 + if (err)
7970 + break;
7971 +
7972 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7973 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7974 +
7975 + err = get_user(ldw, (unsigned int *)addr);
7976 + err |= get_user(bv, (unsigned int *)(addr+4));
7977 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7978 +
7979 + if (err)
7980 + break;
7981 +
7982 + if (ldw == 0x0E801096U &&
7983 + bv == 0xEAC0C000U &&
7984 + ldw2 == 0x0E881095U)
7985 + {
7986 + unsigned int resolver, map;
7987 +
7988 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7989 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7990 + if (err)
7991 + break;
7992 +
7993 + regs->gr[20] = instruction_pointer(regs)+8;
7994 + regs->gr[21] = map;
7995 + regs->gr[22] = resolver;
7996 + regs->iaoq[0] = resolver | 3UL;
7997 + regs->iaoq[1] = regs->iaoq[0] + 4;
7998 + return 3;
7999 + }
8000 + }
8001 + } while (0);
8002 +#endif
8003 +
8004 +#ifdef CONFIG_PAX_EMUTRAMP
8005 +
8006 +#ifndef CONFIG_PAX_EMUSIGRT
8007 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8008 + return 1;
8009 +#endif
8010 +
8011 + do { /* PaX: rt_sigreturn emulation */
8012 + unsigned int ldi1, ldi2, bel, nop;
8013 +
8014 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8015 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8016 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8017 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8018 +
8019 + if (err)
8020 + break;
8021 +
8022 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8023 + ldi2 == 0x3414015AU &&
8024 + bel == 0xE4008200U &&
8025 + nop == 0x08000240U)
8026 + {
8027 + regs->gr[25] = (ldi1 & 2) >> 1;
8028 + regs->gr[20] = __NR_rt_sigreturn;
8029 + regs->gr[31] = regs->iaoq[1] + 16;
8030 + regs->sr[0] = regs->iasq[1];
8031 + regs->iaoq[0] = 0x100UL;
8032 + regs->iaoq[1] = regs->iaoq[0] + 4;
8033 + regs->iasq[0] = regs->sr[2];
8034 + regs->iasq[1] = regs->sr[2];
8035 + return 2;
8036 + }
8037 + } while (0);
8038 +#endif
8039 +
8040 + return 1;
8041 +}
8042 +
8043 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8044 +{
8045 + unsigned long i;
8046 +
8047 + printk(KERN_ERR "PAX: bytes at PC: ");
8048 + for (i = 0; i < 5; i++) {
8049 + unsigned int c;
8050 + if (get_user(c, (unsigned int *)pc+i))
8051 + printk(KERN_CONT "???????? ");
8052 + else
8053 + printk(KERN_CONT "%08x ", c);
8054 + }
8055 + printk("\n");
8056 +}
8057 +#endif
8058 +
8059 int fixup_exception(struct pt_regs *regs)
8060 {
8061 const struct exception_table_entry *fix;
8062 @@ -234,8 +345,33 @@ retry:
8063
8064 good_area:
8065
8066 - if ((vma->vm_flags & acc_type) != acc_type)
8067 + if ((vma->vm_flags & acc_type) != acc_type) {
8068 +
8069 +#ifdef CONFIG_PAX_PAGEEXEC
8070 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8071 + (address & ~3UL) == instruction_pointer(regs))
8072 + {
8073 + up_read(&mm->mmap_sem);
8074 + switch (pax_handle_fetch_fault(regs)) {
8075 +
8076 +#ifdef CONFIG_PAX_EMUPLT
8077 + case 3:
8078 + return;
8079 +#endif
8080 +
8081 +#ifdef CONFIG_PAX_EMUTRAMP
8082 + case 2:
8083 + return;
8084 +#endif
8085 +
8086 + }
8087 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8088 + do_group_exit(SIGKILL);
8089 + }
8090 +#endif
8091 +
8092 goto bad_area;
8093 + }
8094
8095 /*
8096 * If for any reason at all we couldn't handle the fault, make
8097 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8098 index 4bc7b62..107e0b2 100644
8099 --- a/arch/powerpc/Kconfig
8100 +++ b/arch/powerpc/Kconfig
8101 @@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8102 config KEXEC
8103 bool "kexec system call"
8104 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8105 + depends on !GRKERNSEC_KMEM
8106 help
8107 kexec is a system call that implements the ability to shutdown your
8108 current kernel, and to start another kernel. It is like a reboot
8109 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8110 index 28992d0..c797b20 100644
8111 --- a/arch/powerpc/include/asm/atomic.h
8112 +++ b/arch/powerpc/include/asm/atomic.h
8113 @@ -519,6 +519,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8114 return t1;
8115 }
8116
8117 +#define atomic64_read_unchecked(v) atomic64_read(v)
8118 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8119 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8120 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8121 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8122 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8123 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8124 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8125 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8126 +
8127 #endif /* __powerpc64__ */
8128
8129 #endif /* __KERNEL__ */
8130 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8131 index bab79a1..4a3eabc 100644
8132 --- a/arch/powerpc/include/asm/barrier.h
8133 +++ b/arch/powerpc/include/asm/barrier.h
8134 @@ -73,7 +73,7 @@
8135 do { \
8136 compiletime_assert_atomic_type(*p); \
8137 __lwsync(); \
8138 - ACCESS_ONCE(*p) = (v); \
8139 + ACCESS_ONCE_RW(*p) = (v); \
8140 } while (0)
8141
8142 #define smp_load_acquire(p) \
8143 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8144 index 34a05a1..a1f2c67 100644
8145 --- a/arch/powerpc/include/asm/cache.h
8146 +++ b/arch/powerpc/include/asm/cache.h
8147 @@ -4,6 +4,7 @@
8148 #ifdef __KERNEL__
8149
8150 #include <asm/reg.h>
8151 +#include <linux/const.h>
8152
8153 /* bytes per L1 cache line */
8154 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8155 @@ -23,7 +24,7 @@
8156 #define L1_CACHE_SHIFT 7
8157 #endif
8158
8159 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8160 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8161
8162 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8163
8164 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8165 index 888d8f3..66f581c 100644
8166 --- a/arch/powerpc/include/asm/elf.h
8167 +++ b/arch/powerpc/include/asm/elf.h
8168 @@ -28,8 +28,19 @@
8169 the loader. We need to make sure that it is out of the way of the program
8170 that it will "exec", and that there is sufficient room for the brk. */
8171
8172 -extern unsigned long randomize_et_dyn(unsigned long base);
8173 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8174 +#define ELF_ET_DYN_BASE (0x20000000)
8175 +
8176 +#ifdef CONFIG_PAX_ASLR
8177 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8178 +
8179 +#ifdef __powerpc64__
8180 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8181 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8182 +#else
8183 +#define PAX_DELTA_MMAP_LEN 15
8184 +#define PAX_DELTA_STACK_LEN 15
8185 +#endif
8186 +#endif
8187
8188 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8189
8190 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8191 (0x7ff >> (PAGE_SHIFT - 12)) : \
8192 (0x3ffff >> (PAGE_SHIFT - 12)))
8193
8194 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8195 -#define arch_randomize_brk arch_randomize_brk
8196 -
8197 -
8198 #ifdef CONFIG_SPU_BASE
8199 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8200 #define NT_SPU 1
8201 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8202 index 8196e9c..d83a9f3 100644
8203 --- a/arch/powerpc/include/asm/exec.h
8204 +++ b/arch/powerpc/include/asm/exec.h
8205 @@ -4,6 +4,6 @@
8206 #ifndef _ASM_POWERPC_EXEC_H
8207 #define _ASM_POWERPC_EXEC_H
8208
8209 -extern unsigned long arch_align_stack(unsigned long sp);
8210 +#define arch_align_stack(x) ((x) & ~0xfUL)
8211
8212 #endif /* _ASM_POWERPC_EXEC_H */
8213 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8214 index 5acabbd..7ea14fa 100644
8215 --- a/arch/powerpc/include/asm/kmap_types.h
8216 +++ b/arch/powerpc/include/asm/kmap_types.h
8217 @@ -10,7 +10,7 @@
8218 * 2 of the License, or (at your option) any later version.
8219 */
8220
8221 -#define KM_TYPE_NR 16
8222 +#define KM_TYPE_NR 17
8223
8224 #endif /* __KERNEL__ */
8225 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8226 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8227 index b8da913..60b608a 100644
8228 --- a/arch/powerpc/include/asm/local.h
8229 +++ b/arch/powerpc/include/asm/local.h
8230 @@ -9,15 +9,26 @@ typedef struct
8231 atomic_long_t a;
8232 } local_t;
8233
8234 +typedef struct
8235 +{
8236 + atomic_long_unchecked_t a;
8237 +} local_unchecked_t;
8238 +
8239 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8240
8241 #define local_read(l) atomic_long_read(&(l)->a)
8242 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8243 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8244 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8245
8246 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8247 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8248 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8249 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8250 #define local_inc(l) atomic_long_inc(&(l)->a)
8251 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8252 #define local_dec(l) atomic_long_dec(&(l)->a)
8253 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8254
8255 static __inline__ long local_add_return(long a, local_t *l)
8256 {
8257 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8258
8259 return t;
8260 }
8261 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8262
8263 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8264
8265 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8266
8267 return t;
8268 }
8269 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8270
8271 static __inline__ long local_inc_return(local_t *l)
8272 {
8273 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8274
8275 #define local_cmpxchg(l, o, n) \
8276 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8277 +#define local_cmpxchg_unchecked(l, o, n) \
8278 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8279 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8280
8281 /**
8282 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8283 index 8565c25..2865190 100644
8284 --- a/arch/powerpc/include/asm/mman.h
8285 +++ b/arch/powerpc/include/asm/mman.h
8286 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8287 }
8288 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8289
8290 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8291 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8292 {
8293 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8294 }
8295 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8296 index 26fe1ae..987ffc5 100644
8297 --- a/arch/powerpc/include/asm/page.h
8298 +++ b/arch/powerpc/include/asm/page.h
8299 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8300 * and needs to be executable. This means the whole heap ends
8301 * up being executable.
8302 */
8303 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8304 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8305 +#define VM_DATA_DEFAULT_FLAGS32 \
8306 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8307 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8308
8309 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8310 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8311 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8312 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8313 #endif
8314
8315 +#define ktla_ktva(addr) (addr)
8316 +#define ktva_ktla(addr) (addr)
8317 +
8318 #ifndef CONFIG_PPC_BOOK3S_64
8319 /*
8320 * Use the top bit of the higher-level page table entries to indicate whether
8321 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8322 index 88693ce..ac6f9ab 100644
8323 --- a/arch/powerpc/include/asm/page_64.h
8324 +++ b/arch/powerpc/include/asm/page_64.h
8325 @@ -153,15 +153,18 @@ do { \
8326 * stack by default, so in the absence of a PT_GNU_STACK program header
8327 * we turn execute permission off.
8328 */
8329 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8330 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8331 +#define VM_STACK_DEFAULT_FLAGS32 \
8332 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8333 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8334
8335 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8336 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8337
8338 +#ifndef CONFIG_PAX_PAGEEXEC
8339 #define VM_STACK_DEFAULT_FLAGS \
8340 (is_32bit_task() ? \
8341 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8342 +#endif
8343
8344 #include <asm-generic/getorder.h>
8345
8346 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8347 index 4b0be20..c15a27d 100644
8348 --- a/arch/powerpc/include/asm/pgalloc-64.h
8349 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8350 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8351 #ifndef CONFIG_PPC_64K_PAGES
8352
8353 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8354 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8355
8356 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8357 {
8358 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8359 pud_set(pud, (unsigned long)pmd);
8360 }
8361
8362 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8363 +{
8364 + pud_populate(mm, pud, pmd);
8365 +}
8366 +
8367 #define pmd_populate(mm, pmd, pte_page) \
8368 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8369 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8370 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8371 #endif
8372
8373 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8374 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8375
8376 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8377 pte_t *pte)
8378 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8379 index d98c1ec..9f61569 100644
8380 --- a/arch/powerpc/include/asm/pgtable.h
8381 +++ b/arch/powerpc/include/asm/pgtable.h
8382 @@ -2,6 +2,7 @@
8383 #define _ASM_POWERPC_PGTABLE_H
8384 #ifdef __KERNEL__
8385
8386 +#include <linux/const.h>
8387 #ifndef __ASSEMBLY__
8388 #include <linux/mmdebug.h>
8389 #include <asm/processor.h> /* For TASK_SIZE */
8390 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8391 index 4aad413..85d86bf 100644
8392 --- a/arch/powerpc/include/asm/pte-hash32.h
8393 +++ b/arch/powerpc/include/asm/pte-hash32.h
8394 @@ -21,6 +21,7 @@
8395 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8396 #define _PAGE_USER 0x004 /* usermode access allowed */
8397 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8398 +#define _PAGE_EXEC _PAGE_GUARDED
8399 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8400 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8401 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8402 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8403 index 0c05059..7e056e4 100644
8404 --- a/arch/powerpc/include/asm/reg.h
8405 +++ b/arch/powerpc/include/asm/reg.h
8406 @@ -251,6 +251,7 @@
8407 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8408 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8409 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8410 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8411 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8412 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8413 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8414 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8415 index 5a6614a..d89995d1 100644
8416 --- a/arch/powerpc/include/asm/smp.h
8417 +++ b/arch/powerpc/include/asm/smp.h
8418 @@ -51,7 +51,7 @@ struct smp_ops_t {
8419 int (*cpu_disable)(void);
8420 void (*cpu_die)(unsigned int nr);
8421 int (*cpu_bootable)(unsigned int nr);
8422 -};
8423 +} __no_const;
8424
8425 extern void smp_send_debugger_break(void);
8426 extern void start_secondary_resume(void);
8427 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8428 index b034ecd..af7e31f 100644
8429 --- a/arch/powerpc/include/asm/thread_info.h
8430 +++ b/arch/powerpc/include/asm/thread_info.h
8431 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8432 #if defined(CONFIG_PPC64)
8433 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8434 #endif
8435 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8436 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8437
8438 /* as above, but as bit values */
8439 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8440 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8441 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8442 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8443 #define _TIF_NOHZ (1<<TIF_NOHZ)
8444 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8445 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8446 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8447 - _TIF_NOHZ)
8448 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8449
8450 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8451 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8452 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8453 index 9485b43..3bd3c16 100644
8454 --- a/arch/powerpc/include/asm/uaccess.h
8455 +++ b/arch/powerpc/include/asm/uaccess.h
8456 @@ -58,6 +58,7 @@
8457
8458 #endif
8459
8460 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8461 #define access_ok(type, addr, size) \
8462 (__chk_user_ptr(addr), \
8463 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8464 @@ -318,52 +319,6 @@ do { \
8465 extern unsigned long __copy_tofrom_user(void __user *to,
8466 const void __user *from, unsigned long size);
8467
8468 -#ifndef __powerpc64__
8469 -
8470 -static inline unsigned long copy_from_user(void *to,
8471 - const void __user *from, unsigned long n)
8472 -{
8473 - unsigned long over;
8474 -
8475 - if (access_ok(VERIFY_READ, from, n))
8476 - return __copy_tofrom_user((__force void __user *)to, from, n);
8477 - if ((unsigned long)from < TASK_SIZE) {
8478 - over = (unsigned long)from + n - TASK_SIZE;
8479 - return __copy_tofrom_user((__force void __user *)to, from,
8480 - n - over) + over;
8481 - }
8482 - return n;
8483 -}
8484 -
8485 -static inline unsigned long copy_to_user(void __user *to,
8486 - const void *from, unsigned long n)
8487 -{
8488 - unsigned long over;
8489 -
8490 - if (access_ok(VERIFY_WRITE, to, n))
8491 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8492 - if ((unsigned long)to < TASK_SIZE) {
8493 - over = (unsigned long)to + n - TASK_SIZE;
8494 - return __copy_tofrom_user(to, (__force void __user *)from,
8495 - n - over) + over;
8496 - }
8497 - return n;
8498 -}
8499 -
8500 -#else /* __powerpc64__ */
8501 -
8502 -#define __copy_in_user(to, from, size) \
8503 - __copy_tofrom_user((to), (from), (size))
8504 -
8505 -extern unsigned long copy_from_user(void *to, const void __user *from,
8506 - unsigned long n);
8507 -extern unsigned long copy_to_user(void __user *to, const void *from,
8508 - unsigned long n);
8509 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8510 - unsigned long n);
8511 -
8512 -#endif /* __powerpc64__ */
8513 -
8514 static inline unsigned long __copy_from_user_inatomic(void *to,
8515 const void __user *from, unsigned long n)
8516 {
8517 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8518 if (ret == 0)
8519 return 0;
8520 }
8521 +
8522 + if (!__builtin_constant_p(n))
8523 + check_object_size(to, n, false);
8524 +
8525 return __copy_tofrom_user((__force void __user *)to, from, n);
8526 }
8527
8528 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8529 if (ret == 0)
8530 return 0;
8531 }
8532 +
8533 + if (!__builtin_constant_p(n))
8534 + check_object_size(from, n, true);
8535 +
8536 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8537 }
8538
8539 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8540 return __copy_to_user_inatomic(to, from, size);
8541 }
8542
8543 +#ifndef __powerpc64__
8544 +
8545 +static inline unsigned long __must_check copy_from_user(void *to,
8546 + const void __user *from, unsigned long n)
8547 +{
8548 + unsigned long over;
8549 +
8550 + if ((long)n < 0)
8551 + return n;
8552 +
8553 + if (access_ok(VERIFY_READ, from, n)) {
8554 + if (!__builtin_constant_p(n))
8555 + check_object_size(to, n, false);
8556 + return __copy_tofrom_user((__force void __user *)to, from, n);
8557 + }
8558 + if ((unsigned long)from < TASK_SIZE) {
8559 + over = (unsigned long)from + n - TASK_SIZE;
8560 + if (!__builtin_constant_p(n - over))
8561 + check_object_size(to, n - over, false);
8562 + return __copy_tofrom_user((__force void __user *)to, from,
8563 + n - over) + over;
8564 + }
8565 + return n;
8566 +}
8567 +
8568 +static inline unsigned long __must_check copy_to_user(void __user *to,
8569 + const void *from, unsigned long n)
8570 +{
8571 + unsigned long over;
8572 +
8573 + if ((long)n < 0)
8574 + return n;
8575 +
8576 + if (access_ok(VERIFY_WRITE, to, n)) {
8577 + if (!__builtin_constant_p(n))
8578 + check_object_size(from, n, true);
8579 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8580 + }
8581 + if ((unsigned long)to < TASK_SIZE) {
8582 + over = (unsigned long)to + n - TASK_SIZE;
8583 + if (!__builtin_constant_p(n))
8584 + check_object_size(from, n - over, true);
8585 + return __copy_tofrom_user(to, (__force void __user *)from,
8586 + n - over) + over;
8587 + }
8588 + return n;
8589 +}
8590 +
8591 +#else /* __powerpc64__ */
8592 +
8593 +#define __copy_in_user(to, from, size) \
8594 + __copy_tofrom_user((to), (from), (size))
8595 +
8596 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8597 +{
8598 + if ((long)n < 0 || n > INT_MAX)
8599 + return n;
8600 +
8601 + if (!__builtin_constant_p(n))
8602 + check_object_size(to, n, false);
8603 +
8604 + if (likely(access_ok(VERIFY_READ, from, n)))
8605 + n = __copy_from_user(to, from, n);
8606 + else
8607 + memset(to, 0, n);
8608 + return n;
8609 +}
8610 +
8611 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8612 +{
8613 + if ((long)n < 0 || n > INT_MAX)
8614 + return n;
8615 +
8616 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8617 + if (!__builtin_constant_p(n))
8618 + check_object_size(from, n, true);
8619 + n = __copy_to_user(to, from, n);
8620 + }
8621 + return n;
8622 +}
8623 +
8624 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8625 + unsigned long n);
8626 +
8627 +#endif /* __powerpc64__ */
8628 +
8629 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8630
8631 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8632 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8633 index 670c312..60c2b52 100644
8634 --- a/arch/powerpc/kernel/Makefile
8635 +++ b/arch/powerpc/kernel/Makefile
8636 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8637 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8638 endif
8639
8640 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8641 +
8642 obj-y := cputable.o ptrace.o syscalls.o \
8643 irq.o align.o signal_32.o pmc.o vdso.o \
8644 process.o systbl.o idle.o \
8645 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8646 index bb9cac6..5181202 100644
8647 --- a/arch/powerpc/kernel/exceptions-64e.S
8648 +++ b/arch/powerpc/kernel/exceptions-64e.S
8649 @@ -1010,6 +1010,7 @@ storage_fault_common:
8650 std r14,_DAR(r1)
8651 std r15,_DSISR(r1)
8652 addi r3,r1,STACK_FRAME_OVERHEAD
8653 + bl save_nvgprs
8654 mr r4,r14
8655 mr r5,r15
8656 ld r14,PACA_EXGEN+EX_R14(r13)
8657 @@ -1018,8 +1019,7 @@ storage_fault_common:
8658 cmpdi r3,0
8659 bne- 1f
8660 b ret_from_except_lite
8661 -1: bl save_nvgprs
8662 - mr r5,r3
8663 +1: mr r5,r3
8664 addi r3,r1,STACK_FRAME_OVERHEAD
8665 ld r4,_DAR(r1)
8666 bl bad_page_fault
8667 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8668 index 050f79a..f385bfe 100644
8669 --- a/arch/powerpc/kernel/exceptions-64s.S
8670 +++ b/arch/powerpc/kernel/exceptions-64s.S
8671 @@ -1593,10 +1593,10 @@ handle_page_fault:
8672 11: ld r4,_DAR(r1)
8673 ld r5,_DSISR(r1)
8674 addi r3,r1,STACK_FRAME_OVERHEAD
8675 + bl save_nvgprs
8676 bl do_page_fault
8677 cmpdi r3,0
8678 beq+ 12f
8679 - bl save_nvgprs
8680 mr r5,r3
8681 addi r3,r1,STACK_FRAME_OVERHEAD
8682 lwz r4,_DAR(r1)
8683 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8684 index 4c5891d..a5d88bb 100644
8685 --- a/arch/powerpc/kernel/irq.c
8686 +++ b/arch/powerpc/kernel/irq.c
8687 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8688 }
8689 #endif
8690
8691 +extern void gr_handle_kernel_exploit(void);
8692 +
8693 static inline void check_stack_overflow(void)
8694 {
8695 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8696 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8697 printk("do_IRQ: stack overflow: %ld\n",
8698 sp - sizeof(struct thread_info));
8699 dump_stack();
8700 + gr_handle_kernel_exploit();
8701 }
8702 #endif
8703 }
8704 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8705 index 6cff040..74ac5d1b 100644
8706 --- a/arch/powerpc/kernel/module_32.c
8707 +++ b/arch/powerpc/kernel/module_32.c
8708 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8709 me->arch.core_plt_section = i;
8710 }
8711 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8712 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8713 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8714 return -ENOEXEC;
8715 }
8716
8717 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8718
8719 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8720 /* Init, or core PLT? */
8721 - if (location >= mod->module_core
8722 - && location < mod->module_core + mod->core_size)
8723 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8724 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8725 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8726 - else
8727 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8728 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8729 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8730 + else {
8731 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8732 + return ~0UL;
8733 + }
8734
8735 /* Find this entry, or if that fails, the next avail. entry */
8736 while (entry->jump[0]) {
8737 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8738 }
8739 #ifdef CONFIG_DYNAMIC_FTRACE
8740 module->arch.tramp =
8741 - do_plt_call(module->module_core,
8742 + do_plt_call(module->module_core_rx,
8743 (unsigned long)ftrace_caller,
8744 sechdrs, module);
8745 #endif
8746 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8747 index bf44ae9..6d2ce71 100644
8748 --- a/arch/powerpc/kernel/process.c
8749 +++ b/arch/powerpc/kernel/process.c
8750 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
8751 * Lookup NIP late so we have the best change of getting the
8752 * above info out without failing
8753 */
8754 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8755 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8756 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8757 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8758 #endif
8759 show_stack(current, (unsigned long *) regs->gpr[1]);
8760 if (!user_mode(regs))
8761 @@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8762 newsp = stack[0];
8763 ip = stack[STACK_FRAME_LR_SAVE];
8764 if (!firstframe || ip != lr) {
8765 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8766 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8767 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8768 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8769 - printk(" (%pS)",
8770 + printk(" (%pA)",
8771 (void *)current->ret_stack[curr_frame].ret);
8772 curr_frame--;
8773 }
8774 @@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8775 struct pt_regs *regs = (struct pt_regs *)
8776 (sp + STACK_FRAME_OVERHEAD);
8777 lr = regs->link;
8778 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8779 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8780 regs->trap, (void *)regs->nip, (void *)lr);
8781 firstframe = 1;
8782 }
8783 @@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
8784 mtspr(SPRN_CTRLT, ctrl);
8785 }
8786 #endif /* CONFIG_PPC64 */
8787 -
8788 -unsigned long arch_align_stack(unsigned long sp)
8789 -{
8790 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8791 - sp -= get_random_int() & ~PAGE_MASK;
8792 - return sp & ~0xf;
8793 -}
8794 -
8795 -static inline unsigned long brk_rnd(void)
8796 -{
8797 - unsigned long rnd = 0;
8798 -
8799 - /* 8MB for 32bit, 1GB for 64bit */
8800 - if (is_32bit_task())
8801 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8802 - else
8803 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8804 -
8805 - return rnd << PAGE_SHIFT;
8806 -}
8807 -
8808 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8809 -{
8810 - unsigned long base = mm->brk;
8811 - unsigned long ret;
8812 -
8813 -#ifdef CONFIG_PPC_STD_MMU_64
8814 - /*
8815 - * If we are using 1TB segments and we are allowed to randomise
8816 - * the heap, we can put it above 1TB so it is backed by a 1TB
8817 - * segment. Otherwise the heap will be in the bottom 1TB
8818 - * which always uses 256MB segments and this may result in a
8819 - * performance penalty.
8820 - */
8821 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8822 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8823 -#endif
8824 -
8825 - ret = PAGE_ALIGN(base + brk_rnd());
8826 -
8827 - if (ret < mm->brk)
8828 - return mm->brk;
8829 -
8830 - return ret;
8831 -}
8832 -
8833 -unsigned long randomize_et_dyn(unsigned long base)
8834 -{
8835 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8836 -
8837 - if (ret < base)
8838 - return base;
8839 -
8840 - return ret;
8841 -}
8842 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8843 index 2e3d2bf..35df241 100644
8844 --- a/arch/powerpc/kernel/ptrace.c
8845 +++ b/arch/powerpc/kernel/ptrace.c
8846 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8847 return ret;
8848 }
8849
8850 +#ifdef CONFIG_GRKERNSEC_SETXID
8851 +extern void gr_delayed_cred_worker(void);
8852 +#endif
8853 +
8854 /*
8855 * We must return the syscall number to actually look up in the table.
8856 * This can be -1L to skip running any syscall at all.
8857 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8858
8859 secure_computing_strict(regs->gpr[0]);
8860
8861 +#ifdef CONFIG_GRKERNSEC_SETXID
8862 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8863 + gr_delayed_cred_worker();
8864 +#endif
8865 +
8866 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8867 tracehook_report_syscall_entry(regs))
8868 /*
8869 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8870 {
8871 int step;
8872
8873 +#ifdef CONFIG_GRKERNSEC_SETXID
8874 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8875 + gr_delayed_cred_worker();
8876 +#endif
8877 +
8878 audit_syscall_exit(regs);
8879
8880 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8881 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8882 index b171001..4ac7ac5 100644
8883 --- a/arch/powerpc/kernel/signal_32.c
8884 +++ b/arch/powerpc/kernel/signal_32.c
8885 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
8886 /* Save user registers on the stack */
8887 frame = &rt_sf->uc.uc_mcontext;
8888 addr = frame;
8889 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8890 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8891 sigret = 0;
8892 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8893 } else {
8894 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8895 index 2cb0c94..c0c0bc9 100644
8896 --- a/arch/powerpc/kernel/signal_64.c
8897 +++ b/arch/powerpc/kernel/signal_64.c
8898 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
8899 current->thread.fp_state.fpscr = 0;
8900
8901 /* Set up to return from userspace. */
8902 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8903 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8904 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8905 } else {
8906 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8907 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8908 index 0dc43f9..7893068 100644
8909 --- a/arch/powerpc/kernel/traps.c
8910 +++ b/arch/powerpc/kernel/traps.c
8911 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8912 return flags;
8913 }
8914
8915 +extern void gr_handle_kernel_exploit(void);
8916 +
8917 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8918 int signr)
8919 {
8920 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8921 panic("Fatal exception in interrupt");
8922 if (panic_on_oops)
8923 panic("Fatal exception");
8924 +
8925 + gr_handle_kernel_exploit();
8926 +
8927 do_exit(signr);
8928 }
8929
8930 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8931 index f174351..5722009 100644
8932 --- a/arch/powerpc/kernel/vdso.c
8933 +++ b/arch/powerpc/kernel/vdso.c
8934 @@ -35,6 +35,7 @@
8935 #include <asm/vdso.h>
8936 #include <asm/vdso_datapage.h>
8937 #include <asm/setup.h>
8938 +#include <asm/mman.h>
8939
8940 #undef DEBUG
8941
8942 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8943 vdso_base = VDSO32_MBASE;
8944 #endif
8945
8946 - current->mm->context.vdso_base = 0;
8947 + current->mm->context.vdso_base = ~0UL;
8948
8949 /* vDSO has a problem and was disabled, just don't "enable" it for the
8950 * process
8951 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8952 vdso_base = get_unmapped_area(NULL, vdso_base,
8953 (vdso_pages << PAGE_SHIFT) +
8954 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8955 - 0, 0);
8956 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8957 if (IS_ERR_VALUE(vdso_base)) {
8958 rc = vdso_base;
8959 goto fail_mmapsem;
8960 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8961 index 4c79284..0e462c3 100644
8962 --- a/arch/powerpc/kvm/powerpc.c
8963 +++ b/arch/powerpc/kvm/powerpc.c
8964 @@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8965 }
8966 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8967
8968 -int kvm_arch_init(void *opaque)
8969 +int kvm_arch_init(const void *opaque)
8970 {
8971 return 0;
8972 }
8973 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8974 index 5eea6f3..5d10396 100644
8975 --- a/arch/powerpc/lib/usercopy_64.c
8976 +++ b/arch/powerpc/lib/usercopy_64.c
8977 @@ -9,22 +9,6 @@
8978 #include <linux/module.h>
8979 #include <asm/uaccess.h>
8980
8981 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8982 -{
8983 - if (likely(access_ok(VERIFY_READ, from, n)))
8984 - n = __copy_from_user(to, from, n);
8985 - else
8986 - memset(to, 0, n);
8987 - return n;
8988 -}
8989 -
8990 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8991 -{
8992 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8993 - n = __copy_to_user(to, from, n);
8994 - return n;
8995 -}
8996 -
8997 unsigned long copy_in_user(void __user *to, const void __user *from,
8998 unsigned long n)
8999 {
9000 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9001 return n;
9002 }
9003
9004 -EXPORT_SYMBOL(copy_from_user);
9005 -EXPORT_SYMBOL(copy_to_user);
9006 EXPORT_SYMBOL(copy_in_user);
9007
9008 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9009 index 51ab9e7..7d3c78b 100644
9010 --- a/arch/powerpc/mm/fault.c
9011 +++ b/arch/powerpc/mm/fault.c
9012 @@ -33,6 +33,10 @@
9013 #include <linux/magic.h>
9014 #include <linux/ratelimit.h>
9015 #include <linux/context_tracking.h>
9016 +#include <linux/slab.h>
9017 +#include <linux/pagemap.h>
9018 +#include <linux/compiler.h>
9019 +#include <linux/unistd.h>
9020
9021 #include <asm/firmware.h>
9022 #include <asm/page.h>
9023 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9024 }
9025 #endif
9026
9027 +#ifdef CONFIG_PAX_PAGEEXEC
9028 +/*
9029 + * PaX: decide what to do with offenders (regs->nip = fault address)
9030 + *
9031 + * returns 1 when task should be killed
9032 + */
9033 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9034 +{
9035 + return 1;
9036 +}
9037 +
9038 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9039 +{
9040 + unsigned long i;
9041 +
9042 + printk(KERN_ERR "PAX: bytes at PC: ");
9043 + for (i = 0; i < 5; i++) {
9044 + unsigned int c;
9045 + if (get_user(c, (unsigned int __user *)pc+i))
9046 + printk(KERN_CONT "???????? ");
9047 + else
9048 + printk(KERN_CONT "%08x ", c);
9049 + }
9050 + printk("\n");
9051 +}
9052 +#endif
9053 +
9054 /*
9055 * Check whether the instruction at regs->nip is a store using
9056 * an update addressing form which will update r1.
9057 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9058 * indicate errors in DSISR but can validly be set in SRR1.
9059 */
9060 if (trap == 0x400)
9061 - error_code &= 0x48200000;
9062 + error_code &= 0x58200000;
9063 else
9064 is_write = error_code & DSISR_ISSTORE;
9065 #else
9066 @@ -378,7 +409,7 @@ good_area:
9067 * "undefined". Of those that can be set, this is the only
9068 * one which seems bad.
9069 */
9070 - if (error_code & 0x10000000)
9071 + if (error_code & DSISR_GUARDED)
9072 /* Guarded storage error. */
9073 goto bad_area;
9074 #endif /* CONFIG_8xx */
9075 @@ -393,7 +424,7 @@ good_area:
9076 * processors use the same I/D cache coherency mechanism
9077 * as embedded.
9078 */
9079 - if (error_code & DSISR_PROTFAULT)
9080 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9081 goto bad_area;
9082 #endif /* CONFIG_PPC_STD_MMU */
9083
9084 @@ -483,6 +514,23 @@ bad_area:
9085 bad_area_nosemaphore:
9086 /* User mode accesses cause a SIGSEGV */
9087 if (user_mode(regs)) {
9088 +
9089 +#ifdef CONFIG_PAX_PAGEEXEC
9090 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9091 +#ifdef CONFIG_PPC_STD_MMU
9092 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9093 +#else
9094 + if (is_exec && regs->nip == address) {
9095 +#endif
9096 + switch (pax_handle_fetch_fault(regs)) {
9097 + }
9098 +
9099 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9100 + do_group_exit(SIGKILL);
9101 + }
9102 + }
9103 +#endif
9104 +
9105 _exception(SIGSEGV, regs, code, address);
9106 goto bail;
9107 }
9108 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9109 index cb8bdbe..cde4bc7 100644
9110 --- a/arch/powerpc/mm/mmap.c
9111 +++ b/arch/powerpc/mm/mmap.c
9112 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9113 return sysctl_legacy_va_layout;
9114 }
9115
9116 -static unsigned long mmap_rnd(void)
9117 +static unsigned long mmap_rnd(struct mm_struct *mm)
9118 {
9119 unsigned long rnd = 0;
9120
9121 +#ifdef CONFIG_PAX_RANDMMAP
9122 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9123 +#endif
9124 +
9125 if (current->flags & PF_RANDOMIZE) {
9126 /* 8MB for 32bit, 1GB for 64bit */
9127 if (is_32bit_task())
9128 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9129 return rnd << PAGE_SHIFT;
9130 }
9131
9132 -static inline unsigned long mmap_base(void)
9133 +static inline unsigned long mmap_base(struct mm_struct *mm)
9134 {
9135 unsigned long gap = rlimit(RLIMIT_STACK);
9136
9137 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9138 else if (gap > MAX_GAP)
9139 gap = MAX_GAP;
9140
9141 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9142 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9143 }
9144
9145 /*
9146 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9147 */
9148 if (mmap_is_legacy()) {
9149 mm->mmap_base = TASK_UNMAPPED_BASE;
9150 +
9151 +#ifdef CONFIG_PAX_RANDMMAP
9152 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9153 + mm->mmap_base += mm->delta_mmap;
9154 +#endif
9155 +
9156 mm->get_unmapped_area = arch_get_unmapped_area;
9157 } else {
9158 - mm->mmap_base = mmap_base();
9159 + mm->mmap_base = mmap_base(mm);
9160 +
9161 +#ifdef CONFIG_PAX_RANDMMAP
9162 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9163 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9164 +#endif
9165 +
9166 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9167 }
9168 }
9169 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9170 index b0c75cc..ef7fb93 100644
9171 --- a/arch/powerpc/mm/slice.c
9172 +++ b/arch/powerpc/mm/slice.c
9173 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9174 if ((mm->task_size - len) < addr)
9175 return 0;
9176 vma = find_vma(mm, addr);
9177 - return (!vma || (addr + len) <= vma->vm_start);
9178 + return check_heap_stack_gap(vma, addr, len, 0);
9179 }
9180
9181 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9182 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9183 info.align_offset = 0;
9184
9185 addr = TASK_UNMAPPED_BASE;
9186 +
9187 +#ifdef CONFIG_PAX_RANDMMAP
9188 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9189 + addr += mm->delta_mmap;
9190 +#endif
9191 +
9192 while (addr < TASK_SIZE) {
9193 info.low_limit = addr;
9194 if (!slice_scan_available(addr, available, 1, &addr))
9195 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9196 if (fixed && addr > (mm->task_size - len))
9197 return -ENOMEM;
9198
9199 +#ifdef CONFIG_PAX_RANDMMAP
9200 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9201 + addr = 0;
9202 +#endif
9203 +
9204 /* If hint, make sure it matches our alignment restrictions */
9205 if (!fixed && addr) {
9206 addr = _ALIGN_UP(addr, 1ul << pshift);
9207 diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
9208 index 3afa6f4..40c53ff 100644
9209 --- a/arch/powerpc/net/bpf_jit_comp.c
9210 +++ b/arch/powerpc/net/bpf_jit_comp.c
9211 @@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
9212 {
9213 if (fp->jited)
9214 module_free(NULL, fp->bpf_func);
9215 - kfree(fp);
9216 +
9217 + bpf_prog_unlock_free(fp);
9218 }
9219 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9220 index 4278acf..67fd0e6 100644
9221 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9222 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9223 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9224 }
9225
9226 static struct pci_ops scc_pciex_pci_ops = {
9227 - scc_pciex_read_config,
9228 - scc_pciex_write_config,
9229 + .read = scc_pciex_read_config,
9230 + .write = scc_pciex_write_config,
9231 };
9232
9233 static void pciex_clear_intr_all(unsigned int __iomem *base)
9234 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9235 index d966bbe..372124a 100644
9236 --- a/arch/powerpc/platforms/cell/spufs/file.c
9237 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9238 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9239 return VM_FAULT_NOPAGE;
9240 }
9241
9242 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9243 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9244 unsigned long address,
9245 - void *buf, int len, int write)
9246 + void *buf, size_t len, int write)
9247 {
9248 struct spu_context *ctx = vma->vm_file->private_data;
9249 unsigned long offset = address - vma->vm_start;
9250 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9251 index fa934fe..c296056 100644
9252 --- a/arch/s390/include/asm/atomic.h
9253 +++ b/arch/s390/include/asm/atomic.h
9254 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9255 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9256 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9257
9258 +#define atomic64_read_unchecked(v) atomic64_read(v)
9259 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9260 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9261 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9262 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9263 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9264 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9265 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9266 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9267 +
9268 #endif /* __ARCH_S390_ATOMIC__ */
9269 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9270 index 19ff956..8d39cb1 100644
9271 --- a/arch/s390/include/asm/barrier.h
9272 +++ b/arch/s390/include/asm/barrier.h
9273 @@ -37,7 +37,7 @@
9274 do { \
9275 compiletime_assert_atomic_type(*p); \
9276 barrier(); \
9277 - ACCESS_ONCE(*p) = (v); \
9278 + ACCESS_ONCE_RW(*p) = (v); \
9279 } while (0)
9280
9281 #define smp_load_acquire(p) \
9282 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9283 index 4d7ccac..d03d0ad 100644
9284 --- a/arch/s390/include/asm/cache.h
9285 +++ b/arch/s390/include/asm/cache.h
9286 @@ -9,8 +9,10 @@
9287 #ifndef __ARCH_S390_CACHE_H
9288 #define __ARCH_S390_CACHE_H
9289
9290 -#define L1_CACHE_BYTES 256
9291 +#include <linux/const.h>
9292 +
9293 #define L1_CACHE_SHIFT 8
9294 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9295 #define NET_SKB_PAD 32
9296
9297 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9298 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9299 index 78f4f87..598ce39 100644
9300 --- a/arch/s390/include/asm/elf.h
9301 +++ b/arch/s390/include/asm/elf.h
9302 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9303 the loader. We need to make sure that it is out of the way of the program
9304 that it will "exec", and that there is sufficient room for the brk. */
9305
9306 -extern unsigned long randomize_et_dyn(unsigned long base);
9307 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9308 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9309 +
9310 +#ifdef CONFIG_PAX_ASLR
9311 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9312 +
9313 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9314 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9315 +#endif
9316
9317 /* This yields a mask that user programs can use to figure out what
9318 instruction set this CPU supports. */
9319 @@ -222,9 +228,6 @@ struct linux_binprm;
9320 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9321 int arch_setup_additional_pages(struct linux_binprm *, int);
9322
9323 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9324 -#define arch_randomize_brk arch_randomize_brk
9325 -
9326 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9327
9328 #endif
9329 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9330 index c4a93d6..4d2a9b4 100644
9331 --- a/arch/s390/include/asm/exec.h
9332 +++ b/arch/s390/include/asm/exec.h
9333 @@ -7,6 +7,6 @@
9334 #ifndef __ASM_EXEC_H
9335 #define __ASM_EXEC_H
9336
9337 -extern unsigned long arch_align_stack(unsigned long sp);
9338 +#define arch_align_stack(x) ((x) & ~0xfUL)
9339
9340 #endif /* __ASM_EXEC_H */
9341 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9342 index cd4c68e..6764641 100644
9343 --- a/arch/s390/include/asm/uaccess.h
9344 +++ b/arch/s390/include/asm/uaccess.h
9345 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9346 __range_ok((unsigned long)(addr), (size)); \
9347 })
9348
9349 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9350 #define access_ok(type, addr, size) __access_ok(addr, size)
9351
9352 /*
9353 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9354 copy_to_user(void __user *to, const void *from, unsigned long n)
9355 {
9356 might_fault();
9357 +
9358 + if ((long)n < 0)
9359 + return n;
9360 +
9361 return __copy_to_user(to, from, n);
9362 }
9363
9364 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9365 static inline unsigned long __must_check
9366 copy_from_user(void *to, const void __user *from, unsigned long n)
9367 {
9368 - unsigned int sz = __compiletime_object_size(to);
9369 + size_t sz = __compiletime_object_size(to);
9370
9371 might_fault();
9372 - if (unlikely(sz != -1 && sz < n)) {
9373 +
9374 + if ((long)n < 0)
9375 + return n;
9376 +
9377 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9378 copy_from_user_overflow();
9379 return n;
9380 }
9381 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9382 index b89b591..fd9609d 100644
9383 --- a/arch/s390/kernel/module.c
9384 +++ b/arch/s390/kernel/module.c
9385 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9386
9387 /* Increase core size by size of got & plt and set start
9388 offsets for got and plt. */
9389 - me->core_size = ALIGN(me->core_size, 4);
9390 - me->arch.got_offset = me->core_size;
9391 - me->core_size += me->arch.got_size;
9392 - me->arch.plt_offset = me->core_size;
9393 - me->core_size += me->arch.plt_size;
9394 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9395 + me->arch.got_offset = me->core_size_rw;
9396 + me->core_size_rw += me->arch.got_size;
9397 + me->arch.plt_offset = me->core_size_rx;
9398 + me->core_size_rx += me->arch.plt_size;
9399 return 0;
9400 }
9401
9402 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9403 if (info->got_initialized == 0) {
9404 Elf_Addr *gotent;
9405
9406 - gotent = me->module_core + me->arch.got_offset +
9407 + gotent = me->module_core_rw + me->arch.got_offset +
9408 info->got_offset;
9409 *gotent = val;
9410 info->got_initialized = 1;
9411 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9412 rc = apply_rela_bits(loc, val, 0, 64, 0);
9413 else if (r_type == R_390_GOTENT ||
9414 r_type == R_390_GOTPLTENT) {
9415 - val += (Elf_Addr) me->module_core - loc;
9416 + val += (Elf_Addr) me->module_core_rw - loc;
9417 rc = apply_rela_bits(loc, val, 1, 32, 1);
9418 }
9419 break;
9420 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9421 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9422 if (info->plt_initialized == 0) {
9423 unsigned int *ip;
9424 - ip = me->module_core + me->arch.plt_offset +
9425 + ip = me->module_core_rx + me->arch.plt_offset +
9426 info->plt_offset;
9427 #ifndef CONFIG_64BIT
9428 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9429 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9430 val - loc + 0xffffUL < 0x1ffffeUL) ||
9431 (r_type == R_390_PLT32DBL &&
9432 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9433 - val = (Elf_Addr) me->module_core +
9434 + val = (Elf_Addr) me->module_core_rx +
9435 me->arch.plt_offset +
9436 info->plt_offset;
9437 val += rela->r_addend - loc;
9438 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9439 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9440 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9441 val = val + rela->r_addend -
9442 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9443 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9444 if (r_type == R_390_GOTOFF16)
9445 rc = apply_rela_bits(loc, val, 0, 16, 0);
9446 else if (r_type == R_390_GOTOFF32)
9447 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9448 break;
9449 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9450 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9451 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9452 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9453 rela->r_addend - loc;
9454 if (r_type == R_390_GOTPC)
9455 rc = apply_rela_bits(loc, val, 1, 32, 0);
9456 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9457 index 93b9ca4..4ea1454 100644
9458 --- a/arch/s390/kernel/process.c
9459 +++ b/arch/s390/kernel/process.c
9460 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9461 }
9462 return 0;
9463 }
9464 -
9465 -unsigned long arch_align_stack(unsigned long sp)
9466 -{
9467 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9468 - sp -= get_random_int() & ~PAGE_MASK;
9469 - return sp & ~0xf;
9470 -}
9471 -
9472 -static inline unsigned long brk_rnd(void)
9473 -{
9474 - /* 8MB for 32bit, 1GB for 64bit */
9475 - if (is_32bit_task())
9476 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9477 - else
9478 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9479 -}
9480 -
9481 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9482 -{
9483 - unsigned long ret;
9484 -
9485 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9486 - return (ret > mm->brk) ? ret : mm->brk;
9487 -}
9488 -
9489 -unsigned long randomize_et_dyn(unsigned long base)
9490 -{
9491 - unsigned long ret;
9492 -
9493 - if (!(current->flags & PF_RANDOMIZE))
9494 - return base;
9495 - ret = PAGE_ALIGN(base + brk_rnd());
9496 - return (ret > base) ? ret : base;
9497 -}
9498 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9499 index 9b436c2..54fbf0a 100644
9500 --- a/arch/s390/mm/mmap.c
9501 +++ b/arch/s390/mm/mmap.c
9502 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9503 */
9504 if (mmap_is_legacy()) {
9505 mm->mmap_base = mmap_base_legacy();
9506 +
9507 +#ifdef CONFIG_PAX_RANDMMAP
9508 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9509 + mm->mmap_base += mm->delta_mmap;
9510 +#endif
9511 +
9512 mm->get_unmapped_area = arch_get_unmapped_area;
9513 } else {
9514 mm->mmap_base = mmap_base();
9515 +
9516 +#ifdef CONFIG_PAX_RANDMMAP
9517 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9518 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9519 +#endif
9520 +
9521 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9522 }
9523 }
9524 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9525 */
9526 if (mmap_is_legacy()) {
9527 mm->mmap_base = mmap_base_legacy();
9528 +
9529 +#ifdef CONFIG_PAX_RANDMMAP
9530 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9531 + mm->mmap_base += mm->delta_mmap;
9532 +#endif
9533 +
9534 mm->get_unmapped_area = s390_get_unmapped_area;
9535 } else {
9536 mm->mmap_base = mmap_base();
9537 +
9538 +#ifdef CONFIG_PAX_RANDMMAP
9539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9540 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9541 +#endif
9542 +
9543 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9544 }
9545 }
9546 diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
9547 index 61e45b7..f2833c5 100644
9548 --- a/arch/s390/net/bpf_jit_comp.c
9549 +++ b/arch/s390/net/bpf_jit_comp.c
9550 @@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
9551 module_free(NULL, header);
9552
9553 free_filter:
9554 - kfree(fp);
9555 + bpf_prog_unlock_free(fp);
9556 }
9557 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9558 index ae3d59f..f65f075 100644
9559 --- a/arch/score/include/asm/cache.h
9560 +++ b/arch/score/include/asm/cache.h
9561 @@ -1,7 +1,9 @@
9562 #ifndef _ASM_SCORE_CACHE_H
9563 #define _ASM_SCORE_CACHE_H
9564
9565 +#include <linux/const.h>
9566 +
9567 #define L1_CACHE_SHIFT 4
9568 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9569 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9570
9571 #endif /* _ASM_SCORE_CACHE_H */
9572 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9573 index f9f3cd5..58ff438 100644
9574 --- a/arch/score/include/asm/exec.h
9575 +++ b/arch/score/include/asm/exec.h
9576 @@ -1,6 +1,6 @@
9577 #ifndef _ASM_SCORE_EXEC_H
9578 #define _ASM_SCORE_EXEC_H
9579
9580 -extern unsigned long arch_align_stack(unsigned long sp);
9581 +#define arch_align_stack(x) (x)
9582
9583 #endif /* _ASM_SCORE_EXEC_H */
9584 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9585 index a1519ad3..e8ac1ff 100644
9586 --- a/arch/score/kernel/process.c
9587 +++ b/arch/score/kernel/process.c
9588 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9589
9590 return task_pt_regs(task)->cp0_epc;
9591 }
9592 -
9593 -unsigned long arch_align_stack(unsigned long sp)
9594 -{
9595 - return sp;
9596 -}
9597 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9598 index ef9e555..331bd29 100644
9599 --- a/arch/sh/include/asm/cache.h
9600 +++ b/arch/sh/include/asm/cache.h
9601 @@ -9,10 +9,11 @@
9602 #define __ASM_SH_CACHE_H
9603 #ifdef __KERNEL__
9604
9605 +#include <linux/const.h>
9606 #include <linux/init.h>
9607 #include <cpu/cache.h>
9608
9609 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9610 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9611
9612 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9613
9614 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9615 index 6777177..cb5e44f 100644
9616 --- a/arch/sh/mm/mmap.c
9617 +++ b/arch/sh/mm/mmap.c
9618 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9619 struct mm_struct *mm = current->mm;
9620 struct vm_area_struct *vma;
9621 int do_colour_align;
9622 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9623 struct vm_unmapped_area_info info;
9624
9625 if (flags & MAP_FIXED) {
9626 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9627 if (filp || (flags & MAP_SHARED))
9628 do_colour_align = 1;
9629
9630 +#ifdef CONFIG_PAX_RANDMMAP
9631 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9632 +#endif
9633 +
9634 if (addr) {
9635 if (do_colour_align)
9636 addr = COLOUR_ALIGN(addr, pgoff);
9637 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9638 addr = PAGE_ALIGN(addr);
9639
9640 vma = find_vma(mm, addr);
9641 - if (TASK_SIZE - len >= addr &&
9642 - (!vma || addr + len <= vma->vm_start))
9643 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9644 return addr;
9645 }
9646
9647 info.flags = 0;
9648 info.length = len;
9649 - info.low_limit = TASK_UNMAPPED_BASE;
9650 + info.low_limit = mm->mmap_base;
9651 info.high_limit = TASK_SIZE;
9652 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9653 info.align_offset = pgoff << PAGE_SHIFT;
9654 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9655 struct mm_struct *mm = current->mm;
9656 unsigned long addr = addr0;
9657 int do_colour_align;
9658 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9659 struct vm_unmapped_area_info info;
9660
9661 if (flags & MAP_FIXED) {
9662 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9663 if (filp || (flags & MAP_SHARED))
9664 do_colour_align = 1;
9665
9666 +#ifdef CONFIG_PAX_RANDMMAP
9667 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9668 +#endif
9669 +
9670 /* requesting a specific address */
9671 if (addr) {
9672 if (do_colour_align)
9673 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9674 addr = PAGE_ALIGN(addr);
9675
9676 vma = find_vma(mm, addr);
9677 - if (TASK_SIZE - len >= addr &&
9678 - (!vma || addr + len <= vma->vm_start))
9679 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9680 return addr;
9681 }
9682
9683 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9684 VM_BUG_ON(addr != -ENOMEM);
9685 info.flags = 0;
9686 info.low_limit = TASK_UNMAPPED_BASE;
9687 +
9688 +#ifdef CONFIG_PAX_RANDMMAP
9689 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9690 + info.low_limit += mm->delta_mmap;
9691 +#endif
9692 +
9693 info.high_limit = TASK_SIZE;
9694 addr = vm_unmapped_area(&info);
9695 }
9696 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9697 index bb894c8..8141d5c 100644
9698 --- a/arch/sparc/include/asm/atomic_64.h
9699 +++ b/arch/sparc/include/asm/atomic_64.h
9700 @@ -15,18 +15,40 @@
9701 #define ATOMIC64_INIT(i) { (i) }
9702
9703 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9704 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9705 +{
9706 + return v->counter;
9707 +}
9708 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9709 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9710 +{
9711 + return v->counter;
9712 +}
9713
9714 #define atomic_set(v, i) (((v)->counter) = i)
9715 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9716 +{
9717 + v->counter = i;
9718 +}
9719 #define atomic64_set(v, i) (((v)->counter) = i)
9720 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9721 +{
9722 + v->counter = i;
9723 +}
9724
9725 void atomic_add(int, atomic_t *);
9726 +void atomic_add_unchecked(int, atomic_unchecked_t *);
9727 void atomic64_add(long, atomic64_t *);
9728 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9729 void atomic_sub(int, atomic_t *);
9730 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
9731 void atomic64_sub(long, atomic64_t *);
9732 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9733
9734 int atomic_add_ret(int, atomic_t *);
9735 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9736 long atomic64_add_ret(long, atomic64_t *);
9737 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9738 int atomic_sub_ret(int, atomic_t *);
9739 long atomic64_sub_ret(long, atomic64_t *);
9740
9741 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
9742 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9743
9744 #define atomic_inc_return(v) atomic_add_ret(1, v)
9745 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9746 +{
9747 + return atomic_add_ret_unchecked(1, v);
9748 +}
9749 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9750 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9751 +{
9752 + return atomic64_add_ret_unchecked(1, v);
9753 +}
9754
9755 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9756 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9757
9758 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9759 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9760 +{
9761 + return atomic_add_ret_unchecked(i, v);
9762 +}
9763 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9764 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9765 +{
9766 + return atomic64_add_ret_unchecked(i, v);
9767 +}
9768
9769 /*
9770 * atomic_inc_and_test - increment and test
9771 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
9772 * other cases.
9773 */
9774 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9775 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9776 +{
9777 + return atomic_inc_return_unchecked(v) == 0;
9778 +}
9779 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9780
9781 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9782 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
9783 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9784
9785 #define atomic_inc(v) atomic_add(1, v)
9786 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9787 +{
9788 + atomic_add_unchecked(1, v);
9789 +}
9790 #define atomic64_inc(v) atomic64_add(1, v)
9791 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9792 +{
9793 + atomic64_add_unchecked(1, v);
9794 +}
9795
9796 #define atomic_dec(v) atomic_sub(1, v)
9797 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9798 +{
9799 + atomic_sub_unchecked(1, v);
9800 +}
9801 #define atomic64_dec(v) atomic64_sub(1, v)
9802 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9803 +{
9804 + atomic64_sub_unchecked(1, v);
9805 +}
9806
9807 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9808 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9809
9810 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9811 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9812 +{
9813 + return cmpxchg(&v->counter, old, new);
9814 +}
9815 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9816 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9817 +{
9818 + return xchg(&v->counter, new);
9819 +}
9820
9821 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9822 {
9823 - int c, old;
9824 + int c, old, new;
9825 c = atomic_read(v);
9826 for (;;) {
9827 - if (unlikely(c == (u)))
9828 + if (unlikely(c == u))
9829 break;
9830 - old = atomic_cmpxchg((v), c, c + (a));
9831 +
9832 + asm volatile("addcc %2, %0, %0\n"
9833 +
9834 +#ifdef CONFIG_PAX_REFCOUNT
9835 + "tvs %%icc, 6\n"
9836 +#endif
9837 +
9838 + : "=r" (new)
9839 + : "0" (c), "ir" (a)
9840 + : "cc");
9841 +
9842 + old = atomic_cmpxchg(v, c, new);
9843 if (likely(old == c))
9844 break;
9845 c = old;
9846 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9847 #define atomic64_cmpxchg(v, o, n) \
9848 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9849 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9850 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9851 +{
9852 + return xchg(&v->counter, new);
9853 +}
9854
9855 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9856 {
9857 - long c, old;
9858 + long c, old, new;
9859 c = atomic64_read(v);
9860 for (;;) {
9861 - if (unlikely(c == (u)))
9862 + if (unlikely(c == u))
9863 break;
9864 - old = atomic64_cmpxchg((v), c, c + (a));
9865 +
9866 + asm volatile("addcc %2, %0, %0\n"
9867 +
9868 +#ifdef CONFIG_PAX_REFCOUNT
9869 + "tvs %%xcc, 6\n"
9870 +#endif
9871 +
9872 + : "=r" (new)
9873 + : "0" (c), "ir" (a)
9874 + : "cc");
9875 +
9876 + old = atomic64_cmpxchg(v, c, new);
9877 if (likely(old == c))
9878 break;
9879 c = old;
9880 }
9881 - return c != (u);
9882 + return c != u;
9883 }
9884
9885 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9886 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9887 index 305dcc3..7835030 100644
9888 --- a/arch/sparc/include/asm/barrier_64.h
9889 +++ b/arch/sparc/include/asm/barrier_64.h
9890 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9891 do { \
9892 compiletime_assert_atomic_type(*p); \
9893 barrier(); \
9894 - ACCESS_ONCE(*p) = (v); \
9895 + ACCESS_ONCE_RW(*p) = (v); \
9896 } while (0)
9897
9898 #define smp_load_acquire(p) \
9899 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9900 index 5bb6991..5c2132e 100644
9901 --- a/arch/sparc/include/asm/cache.h
9902 +++ b/arch/sparc/include/asm/cache.h
9903 @@ -7,10 +7,12 @@
9904 #ifndef _SPARC_CACHE_H
9905 #define _SPARC_CACHE_H
9906
9907 +#include <linux/const.h>
9908 +
9909 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9910
9911 #define L1_CACHE_SHIFT 5
9912 -#define L1_CACHE_BYTES 32
9913 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9914
9915 #ifdef CONFIG_SPARC32
9916 #define SMP_CACHE_BYTES_SHIFT 5
9917 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9918 index a24e41f..47677ff 100644
9919 --- a/arch/sparc/include/asm/elf_32.h
9920 +++ b/arch/sparc/include/asm/elf_32.h
9921 @@ -114,6 +114,13 @@ typedef struct {
9922
9923 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9924
9925 +#ifdef CONFIG_PAX_ASLR
9926 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9927 +
9928 +#define PAX_DELTA_MMAP_LEN 16
9929 +#define PAX_DELTA_STACK_LEN 16
9930 +#endif
9931 +
9932 /* This yields a mask that user programs can use to figure out what
9933 instruction set this cpu supports. This can NOT be done in userspace
9934 on Sparc. */
9935 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9936 index 370ca1e..d4f4a98 100644
9937 --- a/arch/sparc/include/asm/elf_64.h
9938 +++ b/arch/sparc/include/asm/elf_64.h
9939 @@ -189,6 +189,13 @@ typedef struct {
9940 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9941 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9942
9943 +#ifdef CONFIG_PAX_ASLR
9944 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9945 +
9946 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9947 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9948 +#endif
9949 +
9950 extern unsigned long sparc64_elf_hwcap;
9951 #define ELF_HWCAP sparc64_elf_hwcap
9952
9953 diff --git a/arch/sparc/include/asm/oplib_64.h b/arch/sparc/include/asm/oplib_64.h
9954 index f346824..2e3a4ad 100644
9955 --- a/arch/sparc/include/asm/oplib_64.h
9956 +++ b/arch/sparc/include/asm/oplib_64.h
9957 @@ -62,7 +62,8 @@ struct linux_mem_p1275 {
9958 /* You must call prom_init() before using any of the library services,
9959 * preferably as early as possible. Pass it the romvec pointer.
9960 */
9961 -void prom_init(void *cif_handler, void *cif_stack);
9962 +void prom_init(void *cif_handler);
9963 +void prom_init_report(void);
9964
9965 /* Boot argument acquisition, returns the boot command line string. */
9966 char *prom_getbootargs(void);
9967 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9968 index a3890da..f6a408e 100644
9969 --- a/arch/sparc/include/asm/pgalloc_32.h
9970 +++ b/arch/sparc/include/asm/pgalloc_32.h
9971 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9972 }
9973
9974 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9975 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9976
9977 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9978 unsigned long address)
9979 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9980 index 39a7ac4..2c9b586 100644
9981 --- a/arch/sparc/include/asm/pgalloc_64.h
9982 +++ b/arch/sparc/include/asm/pgalloc_64.h
9983 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9984 }
9985
9986 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9987 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9988
9989 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9990 {
9991 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9992 index 59ba6f6..4518128 100644
9993 --- a/arch/sparc/include/asm/pgtable.h
9994 +++ b/arch/sparc/include/asm/pgtable.h
9995 @@ -5,4 +5,8 @@
9996 #else
9997 #include <asm/pgtable_32.h>
9998 #endif
9999 +
10000 +#define ktla_ktva(addr) (addr)
10001 +#define ktva_ktla(addr) (addr)
10002 +
10003 #endif
10004 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10005 index b9b91ae..950b91e 100644
10006 --- a/arch/sparc/include/asm/pgtable_32.h
10007 +++ b/arch/sparc/include/asm/pgtable_32.h
10008 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10009 #define PAGE_SHARED SRMMU_PAGE_SHARED
10010 #define PAGE_COPY SRMMU_PAGE_COPY
10011 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10012 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10013 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10014 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10015 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10016
10017 /* Top-level page directory - dummy used by init-mm.
10018 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10019
10020 /* xwr */
10021 #define __P000 PAGE_NONE
10022 -#define __P001 PAGE_READONLY
10023 -#define __P010 PAGE_COPY
10024 -#define __P011 PAGE_COPY
10025 +#define __P001 PAGE_READONLY_NOEXEC
10026 +#define __P010 PAGE_COPY_NOEXEC
10027 +#define __P011 PAGE_COPY_NOEXEC
10028 #define __P100 PAGE_READONLY
10029 #define __P101 PAGE_READONLY
10030 #define __P110 PAGE_COPY
10031 #define __P111 PAGE_COPY
10032
10033 #define __S000 PAGE_NONE
10034 -#define __S001 PAGE_READONLY
10035 -#define __S010 PAGE_SHARED
10036 -#define __S011 PAGE_SHARED
10037 +#define __S001 PAGE_READONLY_NOEXEC
10038 +#define __S010 PAGE_SHARED_NOEXEC
10039 +#define __S011 PAGE_SHARED_NOEXEC
10040 #define __S100 PAGE_READONLY
10041 #define __S101 PAGE_READONLY
10042 #define __S110 PAGE_SHARED
10043 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10044 index 79da178..c2eede8 100644
10045 --- a/arch/sparc/include/asm/pgtsrmmu.h
10046 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10047 @@ -115,6 +115,11 @@
10048 SRMMU_EXEC | SRMMU_REF)
10049 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10050 SRMMU_EXEC | SRMMU_REF)
10051 +
10052 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10053 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10054 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10055 +
10056 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10057 SRMMU_DIRTY | SRMMU_REF)
10058
10059 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10060 index f5fffd8..4272fe8 100644
10061 --- a/arch/sparc/include/asm/setup.h
10062 +++ b/arch/sparc/include/asm/setup.h
10063 @@ -48,13 +48,15 @@ unsigned long safe_compute_effective_address(struct pt_regs *, unsigned int);
10064 #endif
10065
10066 #ifdef CONFIG_SPARC64
10067 +void __init start_early_boot(void);
10068 +
10069 /* unaligned_64.c */
10070 int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10071 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10072
10073 /* init_64.c */
10074 -extern atomic_t dcpage_flushes;
10075 -extern atomic_t dcpage_flushes_xcall;
10076 +extern atomic_unchecked_t dcpage_flushes;
10077 +extern atomic_unchecked_t dcpage_flushes_xcall;
10078
10079 extern int sysctl_tsb_ratio;
10080 #endif
10081 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10082 index 9689176..63c18ea 100644
10083 --- a/arch/sparc/include/asm/spinlock_64.h
10084 +++ b/arch/sparc/include/asm/spinlock_64.h
10085 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10086
10087 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10088
10089 -static void inline arch_read_lock(arch_rwlock_t *lock)
10090 +static inline void arch_read_lock(arch_rwlock_t *lock)
10091 {
10092 unsigned long tmp1, tmp2;
10093
10094 __asm__ __volatile__ (
10095 "1: ldsw [%2], %0\n"
10096 " brlz,pn %0, 2f\n"
10097 -"4: add %0, 1, %1\n"
10098 +"4: addcc %0, 1, %1\n"
10099 +
10100 +#ifdef CONFIG_PAX_REFCOUNT
10101 +" tvs %%icc, 6\n"
10102 +#endif
10103 +
10104 " cas [%2], %0, %1\n"
10105 " cmp %0, %1\n"
10106 " bne,pn %%icc, 1b\n"
10107 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10108 " .previous"
10109 : "=&r" (tmp1), "=&r" (tmp2)
10110 : "r" (lock)
10111 - : "memory");
10112 + : "memory", "cc");
10113 }
10114
10115 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10116 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10117 {
10118 int tmp1, tmp2;
10119
10120 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10121 "1: ldsw [%2], %0\n"
10122 " brlz,a,pn %0, 2f\n"
10123 " mov 0, %0\n"
10124 -" add %0, 1, %1\n"
10125 +" addcc %0, 1, %1\n"
10126 +
10127 +#ifdef CONFIG_PAX_REFCOUNT
10128 +" tvs %%icc, 6\n"
10129 +#endif
10130 +
10131 " cas [%2], %0, %1\n"
10132 " cmp %0, %1\n"
10133 " bne,pn %%icc, 1b\n"
10134 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10135 return tmp1;
10136 }
10137
10138 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10139 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10140 {
10141 unsigned long tmp1, tmp2;
10142
10143 __asm__ __volatile__(
10144 "1: lduw [%2], %0\n"
10145 -" sub %0, 1, %1\n"
10146 +" subcc %0, 1, %1\n"
10147 +
10148 +#ifdef CONFIG_PAX_REFCOUNT
10149 +" tvs %%icc, 6\n"
10150 +#endif
10151 +
10152 " cas [%2], %0, %1\n"
10153 " cmp %0, %1\n"
10154 " bne,pn %%xcc, 1b\n"
10155 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10156 : "memory");
10157 }
10158
10159 -static void inline arch_write_lock(arch_rwlock_t *lock)
10160 +static inline void arch_write_lock(arch_rwlock_t *lock)
10161 {
10162 unsigned long mask, tmp1, tmp2;
10163
10164 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10165 : "memory");
10166 }
10167
10168 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10169 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10170 {
10171 __asm__ __volatile__(
10172 " stw %%g0, [%0]"
10173 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10174 : "memory");
10175 }
10176
10177 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10178 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10179 {
10180 unsigned long mask, tmp1, tmp2, result;
10181
10182 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10183 index 96efa7a..16858bf 100644
10184 --- a/arch/sparc/include/asm/thread_info_32.h
10185 +++ b/arch/sparc/include/asm/thread_info_32.h
10186 @@ -49,6 +49,8 @@ struct thread_info {
10187 unsigned long w_saved;
10188
10189 struct restart_block restart_block;
10190 +
10191 + unsigned long lowest_stack;
10192 };
10193
10194 /*
10195 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10196 index a5f01ac..a8811dd 100644
10197 --- a/arch/sparc/include/asm/thread_info_64.h
10198 +++ b/arch/sparc/include/asm/thread_info_64.h
10199 @@ -63,7 +63,10 @@ struct thread_info {
10200 struct pt_regs *kern_una_regs;
10201 unsigned int kern_una_insn;
10202
10203 - unsigned long fpregs[0] __attribute__ ((aligned(64)));
10204 + unsigned long lowest_stack;
10205 +
10206 + unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10207 + __attribute__ ((aligned(64)));
10208 };
10209
10210 #endif /* !(__ASSEMBLY__) */
10211 @@ -188,12 +191,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10212 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10213 /* flag bit 4 is available */
10214 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10215 -/* flag bit 6 is available */
10216 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10217 #define TIF_32BIT 7 /* 32-bit binary */
10218 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10219 #define TIF_SECCOMP 9 /* secure computing */
10220 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10221 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10222 +
10223 /* NOTE: Thread flags >= 12 should be ones we have no interest
10224 * in using in assembly, else we can't use the mask as
10225 * an immediate value in instructions such as andcc.
10226 @@ -213,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10227 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10228 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10229 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10230 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10231
10232 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10233 _TIF_DO_NOTIFY_RESUME_MASK | \
10234 _TIF_NEED_RESCHED)
10235 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10236
10237 +#define _TIF_WORK_SYSCALL \
10238 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10239 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10240 +
10241 +
10242 /*
10243 * Thread-synchronous status.
10244 *
10245 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10246 index bd56c28..4b63d83 100644
10247 --- a/arch/sparc/include/asm/uaccess.h
10248 +++ b/arch/sparc/include/asm/uaccess.h
10249 @@ -1,5 +1,6 @@
10250 #ifndef ___ASM_SPARC_UACCESS_H
10251 #define ___ASM_SPARC_UACCESS_H
10252 +
10253 #if defined(__sparc__) && defined(__arch64__)
10254 #include <asm/uaccess_64.h>
10255 #else
10256 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10257 index 9634d08..f55fe4f 100644
10258 --- a/arch/sparc/include/asm/uaccess_32.h
10259 +++ b/arch/sparc/include/asm/uaccess_32.h
10260 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10261
10262 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10263 {
10264 - if (n && __access_ok((unsigned long) to, n))
10265 + if ((long)n < 0)
10266 + return n;
10267 +
10268 + if (n && __access_ok((unsigned long) to, n)) {
10269 + if (!__builtin_constant_p(n))
10270 + check_object_size(from, n, true);
10271 return __copy_user(to, (__force void __user *) from, n);
10272 - else
10273 + } else
10274 return n;
10275 }
10276
10277 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10278 {
10279 + if ((long)n < 0)
10280 + return n;
10281 +
10282 + if (!__builtin_constant_p(n))
10283 + check_object_size(from, n, true);
10284 +
10285 return __copy_user(to, (__force void __user *) from, n);
10286 }
10287
10288 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10289 {
10290 - if (n && __access_ok((unsigned long) from, n))
10291 + if ((long)n < 0)
10292 + return n;
10293 +
10294 + if (n && __access_ok((unsigned long) from, n)) {
10295 + if (!__builtin_constant_p(n))
10296 + check_object_size(to, n, false);
10297 return __copy_user((__force void __user *) to, from, n);
10298 - else
10299 + } else
10300 return n;
10301 }
10302
10303 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10304 {
10305 + if ((long)n < 0)
10306 + return n;
10307 +
10308 return __copy_user((__force void __user *) to, from, n);
10309 }
10310
10311 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10312 index c990a5e..f17b9c1 100644
10313 --- a/arch/sparc/include/asm/uaccess_64.h
10314 +++ b/arch/sparc/include/asm/uaccess_64.h
10315 @@ -10,6 +10,7 @@
10316 #include <linux/compiler.h>
10317 #include <linux/string.h>
10318 #include <linux/thread_info.h>
10319 +#include <linux/kernel.h>
10320 #include <asm/asi.h>
10321 #include <asm/spitfire.h>
10322 #include <asm-generic/uaccess-unaligned.h>
10323 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10324 static inline unsigned long __must_check
10325 copy_from_user(void *to, const void __user *from, unsigned long size)
10326 {
10327 - unsigned long ret = ___copy_from_user(to, from, size);
10328 + unsigned long ret;
10329
10330 + if ((long)size < 0 || size > INT_MAX)
10331 + return size;
10332 +
10333 + if (!__builtin_constant_p(size))
10334 + check_object_size(to, size, false);
10335 +
10336 + ret = ___copy_from_user(to, from, size);
10337 if (unlikely(ret))
10338 ret = copy_from_user_fixup(to, from, size);
10339
10340 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10341 static inline unsigned long __must_check
10342 copy_to_user(void __user *to, const void *from, unsigned long size)
10343 {
10344 - unsigned long ret = ___copy_to_user(to, from, size);
10345 + unsigned long ret;
10346
10347 + if ((long)size < 0 || size > INT_MAX)
10348 + return size;
10349 +
10350 + if (!__builtin_constant_p(size))
10351 + check_object_size(from, size, true);
10352 +
10353 + ret = ___copy_to_user(to, from, size);
10354 if (unlikely(ret))
10355 ret = copy_to_user_fixup(to, from, size);
10356 return ret;
10357 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10358 index 7cf9c6e..6206648 100644
10359 --- a/arch/sparc/kernel/Makefile
10360 +++ b/arch/sparc/kernel/Makefile
10361 @@ -4,7 +4,7 @@
10362 #
10363
10364 asflags-y := -ansi
10365 -ccflags-y := -Werror
10366 +#ccflags-y := -Werror
10367
10368 extra-y := head_$(BITS).o
10369
10370 diff --git a/arch/sparc/kernel/entry.h b/arch/sparc/kernel/entry.h
10371 index ebaba61..88d322b 100644
10372 --- a/arch/sparc/kernel/entry.h
10373 +++ b/arch/sparc/kernel/entry.h
10374 @@ -65,13 +65,10 @@ struct pause_patch_entry {
10375 extern struct pause_patch_entry __pause_3insn_patch,
10376 __pause_3insn_patch_end;
10377
10378 -void __init per_cpu_patch(void);
10379 void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *,
10380 struct sun4v_1insn_patch_entry *);
10381 void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *,
10382 struct sun4v_2insn_patch_entry *);
10383 -void __init sun4v_patch(void);
10384 -void __init boot_cpu_id_too_large(int cpu);
10385 extern unsigned int dcache_parity_tl1_occurred;
10386 extern unsigned int icache_parity_tl1_occurred;
10387
10388 diff --git a/arch/sparc/kernel/head_64.S b/arch/sparc/kernel/head_64.S
10389 index 452f04fe..fbea0ac 100644
10390 --- a/arch/sparc/kernel/head_64.S
10391 +++ b/arch/sparc/kernel/head_64.S
10392 @@ -660,14 +660,12 @@ tlb_fixup_done:
10393 sethi %hi(init_thread_union), %g6
10394 or %g6, %lo(init_thread_union), %g6
10395 ldx [%g6 + TI_TASK], %g4
10396 - mov %sp, %l6
10397
10398 wr %g0, ASI_P, %asi
10399 mov 1, %g1
10400 sllx %g1, THREAD_SHIFT, %g1
10401 sub %g1, (STACKFRAME_SZ + STACK_BIAS), %g1
10402 add %g6, %g1, %sp
10403 - mov 0, %fp
10404
10405 /* Set per-cpu pointer initially to zero, this makes
10406 * the boot-cpu use the in-kernel-image per-cpu areas
10407 @@ -694,44 +692,14 @@ tlb_fixup_done:
10408 nop
10409 #endif
10410
10411 - mov %l6, %o1 ! OpenPROM stack
10412 call prom_init
10413 mov %l7, %o0 ! OpenPROM cif handler
10414
10415 - /* Initialize current_thread_info()->cpu as early as possible.
10416 - * In order to do that accurately we have to patch up the get_cpuid()
10417 - * assembler sequences. And that, in turn, requires that we know
10418 - * if we are on a Starfire box or not. While we're here, patch up
10419 - * the sun4v sequences as well.
10420 + /* To create a one-register-window buffer between the kernel's
10421 + * initial stack and the last stack frame we use from the firmware,
10422 + * do the rest of the boot from a C helper function.
10423 */
10424 - call check_if_starfire
10425 - nop
10426 - call per_cpu_patch
10427 - nop
10428 - call sun4v_patch
10429 - nop
10430 -
10431 -#ifdef CONFIG_SMP
10432 - call hard_smp_processor_id
10433 - nop
10434 - cmp %o0, NR_CPUS
10435 - blu,pt %xcc, 1f
10436 - nop
10437 - call boot_cpu_id_too_large
10438 - nop
10439 - /* Not reached... */
10440 -
10441 -1:
10442 -#else
10443 - mov 0, %o0
10444 -#endif
10445 - sth %o0, [%g6 + TI_CPU]
10446 -
10447 - call prom_init_report
10448 - nop
10449 -
10450 - /* Off we go.... */
10451 - call start_kernel
10452 + call start_early_boot
10453 nop
10454 /* Not reached... */
10455
10456 diff --git a/arch/sparc/kernel/hvtramp.S b/arch/sparc/kernel/hvtramp.S
10457 index b7ddcdd..cdbfec2 100644
10458 --- a/arch/sparc/kernel/hvtramp.S
10459 +++ b/arch/sparc/kernel/hvtramp.S
10460 @@ -109,7 +109,6 @@ hv_cpu_startup:
10461 sllx %g5, THREAD_SHIFT, %g5
10462 sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
10463 add %g6, %g5, %sp
10464 - mov 0, %fp
10465
10466 call init_irqwork_curcpu
10467 nop
10468 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10469 index 50e7b62..79fae35 100644
10470 --- a/arch/sparc/kernel/process_32.c
10471 +++ b/arch/sparc/kernel/process_32.c
10472 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10473
10474 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10475 r->psr, r->pc, r->npc, r->y, print_tainted());
10476 - printk("PC: <%pS>\n", (void *) r->pc);
10477 + printk("PC: <%pA>\n", (void *) r->pc);
10478 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10479 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10480 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10481 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10482 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10483 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10484 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10485 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10486
10487 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10488 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10489 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10490 rw = (struct reg_window32 *) fp;
10491 pc = rw->ins[7];
10492 printk("[%08lx : ", pc);
10493 - printk("%pS ] ", (void *) pc);
10494 + printk("%pA ] ", (void *) pc);
10495 fp = rw->ins[6];
10496 } while (++count < 16);
10497 printk("\n");
10498 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10499 index 0be7bf9..2b1cba8 100644
10500 --- a/arch/sparc/kernel/process_64.c
10501 +++ b/arch/sparc/kernel/process_64.c
10502 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10503 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10504 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10505 if (regs->tstate & TSTATE_PRIV)
10506 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10507 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10508 }
10509
10510 void show_regs(struct pt_regs *regs)
10511 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10512
10513 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10514 regs->tpc, regs->tnpc, regs->y, print_tainted());
10515 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10516 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10517 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10518 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10519 regs->u_regs[3]);
10520 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10521 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10522 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10523 regs->u_regs[15]);
10524 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10525 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10526 show_regwindow(regs);
10527 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10528 }
10529 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10530 ((tp && tp->task) ? tp->task->pid : -1));
10531
10532 if (gp->tstate & TSTATE_PRIV) {
10533 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10534 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10535 (void *) gp->tpc,
10536 (void *) gp->o7,
10537 (void *) gp->i7,
10538 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10539 index 79cc0d1..ec62734 100644
10540 --- a/arch/sparc/kernel/prom_common.c
10541 +++ b/arch/sparc/kernel/prom_common.c
10542 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10543
10544 unsigned int prom_early_allocated __initdata;
10545
10546 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10547 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10548 .nextprop = prom_common_nextprop,
10549 .getproplen = prom_getproplen,
10550 .getproperty = prom_getproperty,
10551 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10552 index c13c9f2..d572c34 100644
10553 --- a/arch/sparc/kernel/ptrace_64.c
10554 +++ b/arch/sparc/kernel/ptrace_64.c
10555 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10556 return ret;
10557 }
10558
10559 +#ifdef CONFIG_GRKERNSEC_SETXID
10560 +extern void gr_delayed_cred_worker(void);
10561 +#endif
10562 +
10563 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10564 {
10565 int ret = 0;
10566 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10567 if (test_thread_flag(TIF_NOHZ))
10568 user_exit();
10569
10570 +#ifdef CONFIG_GRKERNSEC_SETXID
10571 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10572 + gr_delayed_cred_worker();
10573 +#endif
10574 +
10575 if (test_thread_flag(TIF_SYSCALL_TRACE))
10576 ret = tracehook_report_syscall_entry(regs);
10577
10578 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10579 if (test_thread_flag(TIF_NOHZ))
10580 user_exit();
10581
10582 +#ifdef CONFIG_GRKERNSEC_SETXID
10583 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10584 + gr_delayed_cred_worker();
10585 +#endif
10586 +
10587 audit_syscall_exit(regs);
10588
10589 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10590 diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
10591 index 3fdb455..949f773 100644
10592 --- a/arch/sparc/kernel/setup_64.c
10593 +++ b/arch/sparc/kernel/setup_64.c
10594 @@ -30,6 +30,7 @@
10595 #include <linux/cpu.h>
10596 #include <linux/initrd.h>
10597 #include <linux/module.h>
10598 +#include <linux/start_kernel.h>
10599
10600 #include <asm/io.h>
10601 #include <asm/processor.h>
10602 @@ -174,7 +175,7 @@ char reboot_command[COMMAND_LINE_SIZE];
10603
10604 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
10605
10606 -void __init per_cpu_patch(void)
10607 +static void __init per_cpu_patch(void)
10608 {
10609 struct cpuid_patch_entry *p;
10610 unsigned long ver;
10611 @@ -266,7 +267,7 @@ void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *start,
10612 }
10613 }
10614
10615 -void __init sun4v_patch(void)
10616 +static void __init sun4v_patch(void)
10617 {
10618 extern void sun4v_hvapi_init(void);
10619
10620 @@ -335,14 +336,25 @@ static void __init pause_patch(void)
10621 }
10622 }
10623
10624 -#ifdef CONFIG_SMP
10625 -void __init boot_cpu_id_too_large(int cpu)
10626 +void __init start_early_boot(void)
10627 {
10628 - prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
10629 - cpu, NR_CPUS);
10630 - prom_halt();
10631 + int cpu;
10632 +
10633 + check_if_starfire();
10634 + per_cpu_patch();
10635 + sun4v_patch();
10636 +
10637 + cpu = hard_smp_processor_id();
10638 + if (cpu >= NR_CPUS) {
10639 + prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
10640 + cpu, NR_CPUS);
10641 + prom_halt();
10642 + }
10643 + current_thread_info()->cpu = cpu;
10644 +
10645 + prom_init_report();
10646 + start_kernel();
10647 }
10648 -#endif
10649
10650 /* On Ultra, we support all of the v8 capabilities. */
10651 unsigned long sparc64_elf_hwcap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
10652 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10653 index f7ba875..b65677e 100644
10654 --- a/arch/sparc/kernel/smp_64.c
10655 +++ b/arch/sparc/kernel/smp_64.c
10656 @@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10657 return;
10658
10659 #ifdef CONFIG_DEBUG_DCFLUSH
10660 - atomic_inc(&dcpage_flushes);
10661 + atomic_inc_unchecked(&dcpage_flushes);
10662 #endif
10663
10664 this_cpu = get_cpu();
10665 @@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10666 xcall_deliver(data0, __pa(pg_addr),
10667 (u64) pg_addr, cpumask_of(cpu));
10668 #ifdef CONFIG_DEBUG_DCFLUSH
10669 - atomic_inc(&dcpage_flushes_xcall);
10670 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10671 #endif
10672 }
10673 }
10674 @@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10675 preempt_disable();
10676
10677 #ifdef CONFIG_DEBUG_DCFLUSH
10678 - atomic_inc(&dcpage_flushes);
10679 + atomic_inc_unchecked(&dcpage_flushes);
10680 #endif
10681 data0 = 0;
10682 pg_addr = page_address(page);
10683 @@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10684 xcall_deliver(data0, __pa(pg_addr),
10685 (u64) pg_addr, cpu_online_mask);
10686 #ifdef CONFIG_DEBUG_DCFLUSH
10687 - atomic_inc(&dcpage_flushes_xcall);
10688 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10689 #endif
10690 }
10691 __local_flush_dcache_page(page);
10692 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10693 index 646988d..b88905f 100644
10694 --- a/arch/sparc/kernel/sys_sparc_32.c
10695 +++ b/arch/sparc/kernel/sys_sparc_32.c
10696 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10697 if (len > TASK_SIZE - PAGE_SIZE)
10698 return -ENOMEM;
10699 if (!addr)
10700 - addr = TASK_UNMAPPED_BASE;
10701 + addr = current->mm->mmap_base;
10702
10703 info.flags = 0;
10704 info.length = len;
10705 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10706 index c85403d..6af95c9 100644
10707 --- a/arch/sparc/kernel/sys_sparc_64.c
10708 +++ b/arch/sparc/kernel/sys_sparc_64.c
10709 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10710 struct vm_area_struct * vma;
10711 unsigned long task_size = TASK_SIZE;
10712 int do_color_align;
10713 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10714 struct vm_unmapped_area_info info;
10715
10716 if (flags & MAP_FIXED) {
10717 /* We do not accept a shared mapping if it would violate
10718 * cache aliasing constraints.
10719 */
10720 - if ((flags & MAP_SHARED) &&
10721 + if ((filp || (flags & MAP_SHARED)) &&
10722 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10723 return -EINVAL;
10724 return addr;
10725 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10726 if (filp || (flags & MAP_SHARED))
10727 do_color_align = 1;
10728
10729 +#ifdef CONFIG_PAX_RANDMMAP
10730 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10731 +#endif
10732 +
10733 if (addr) {
10734 if (do_color_align)
10735 addr = COLOR_ALIGN(addr, pgoff);
10736 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10737 addr = PAGE_ALIGN(addr);
10738
10739 vma = find_vma(mm, addr);
10740 - if (task_size - len >= addr &&
10741 - (!vma || addr + len <= vma->vm_start))
10742 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10743 return addr;
10744 }
10745
10746 info.flags = 0;
10747 info.length = len;
10748 - info.low_limit = TASK_UNMAPPED_BASE;
10749 + info.low_limit = mm->mmap_base;
10750 info.high_limit = min(task_size, VA_EXCLUDE_START);
10751 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10752 info.align_offset = pgoff << PAGE_SHIFT;
10753 + info.threadstack_offset = offset;
10754 addr = vm_unmapped_area(&info);
10755
10756 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10757 VM_BUG_ON(addr != -ENOMEM);
10758 info.low_limit = VA_EXCLUDE_END;
10759 +
10760 +#ifdef CONFIG_PAX_RANDMMAP
10761 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10762 + info.low_limit += mm->delta_mmap;
10763 +#endif
10764 +
10765 info.high_limit = task_size;
10766 addr = vm_unmapped_area(&info);
10767 }
10768 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10769 unsigned long task_size = STACK_TOP32;
10770 unsigned long addr = addr0;
10771 int do_color_align;
10772 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10773 struct vm_unmapped_area_info info;
10774
10775 /* This should only ever run for 32-bit processes. */
10776 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10777 /* We do not accept a shared mapping if it would violate
10778 * cache aliasing constraints.
10779 */
10780 - if ((flags & MAP_SHARED) &&
10781 + if ((filp || (flags & MAP_SHARED)) &&
10782 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10783 return -EINVAL;
10784 return addr;
10785 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10786 if (filp || (flags & MAP_SHARED))
10787 do_color_align = 1;
10788
10789 +#ifdef CONFIG_PAX_RANDMMAP
10790 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10791 +#endif
10792 +
10793 /* requesting a specific address */
10794 if (addr) {
10795 if (do_color_align)
10796 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10797 addr = PAGE_ALIGN(addr);
10798
10799 vma = find_vma(mm, addr);
10800 - if (task_size - len >= addr &&
10801 - (!vma || addr + len <= vma->vm_start))
10802 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10803 return addr;
10804 }
10805
10806 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10807 info.high_limit = mm->mmap_base;
10808 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10809 info.align_offset = pgoff << PAGE_SHIFT;
10810 + info.threadstack_offset = offset;
10811 addr = vm_unmapped_area(&info);
10812
10813 /*
10814 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10815 VM_BUG_ON(addr != -ENOMEM);
10816 info.flags = 0;
10817 info.low_limit = TASK_UNMAPPED_BASE;
10818 +
10819 +#ifdef CONFIG_PAX_RANDMMAP
10820 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10821 + info.low_limit += mm->delta_mmap;
10822 +#endif
10823 +
10824 info.high_limit = STACK_TOP32;
10825 addr = vm_unmapped_area(&info);
10826 }
10827 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10828 EXPORT_SYMBOL(get_fb_unmapped_area);
10829
10830 /* Essentially the same as PowerPC. */
10831 -static unsigned long mmap_rnd(void)
10832 +static unsigned long mmap_rnd(struct mm_struct *mm)
10833 {
10834 unsigned long rnd = 0UL;
10835
10836 +#ifdef CONFIG_PAX_RANDMMAP
10837 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10838 +#endif
10839 +
10840 if (current->flags & PF_RANDOMIZE) {
10841 unsigned long val = get_random_int();
10842 if (test_thread_flag(TIF_32BIT))
10843 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10844
10845 void arch_pick_mmap_layout(struct mm_struct *mm)
10846 {
10847 - unsigned long random_factor = mmap_rnd();
10848 + unsigned long random_factor = mmap_rnd(mm);
10849 unsigned long gap;
10850
10851 /*
10852 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10853 gap == RLIM_INFINITY ||
10854 sysctl_legacy_va_layout) {
10855 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10856 +
10857 +#ifdef CONFIG_PAX_RANDMMAP
10858 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10859 + mm->mmap_base += mm->delta_mmap;
10860 +#endif
10861 +
10862 mm->get_unmapped_area = arch_get_unmapped_area;
10863 } else {
10864 /* We know it's 32-bit */
10865 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10866 gap = (task_size / 6 * 5);
10867
10868 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10869 +
10870 +#ifdef CONFIG_PAX_RANDMMAP
10871 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10872 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10873 +#endif
10874 +
10875 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10876 }
10877 }
10878 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10879 index 33a17e7..d87fb1f 100644
10880 --- a/arch/sparc/kernel/syscalls.S
10881 +++ b/arch/sparc/kernel/syscalls.S
10882 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10883 #endif
10884 .align 32
10885 1: ldx [%g6 + TI_FLAGS], %l5
10886 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10887 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10888 be,pt %icc, rtrap
10889 nop
10890 call syscall_trace_leave
10891 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10892
10893 srl %i3, 0, %o3 ! IEU0
10894 srl %i2, 0, %o2 ! IEU0 Group
10895 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10896 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10897 bne,pn %icc, linux_syscall_trace32 ! CTI
10898 mov %i0, %l5 ! IEU1
10899 5: call %l7 ! CTI Group brk forced
10900 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10901
10902 mov %i3, %o3 ! IEU1
10903 mov %i4, %o4 ! IEU0 Group
10904 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10905 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10906 bne,pn %icc, linux_syscall_trace ! CTI Group
10907 mov %i0, %l5 ! IEU0
10908 2: call %l7 ! CTI Group brk forced
10909 @@ -223,7 +223,7 @@ ret_sys_call:
10910
10911 cmp %o0, -ERESTART_RESTARTBLOCK
10912 bgeu,pn %xcc, 1f
10913 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10914 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10915 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10916
10917 2:
10918 diff --git a/arch/sparc/kernel/trampoline_64.S b/arch/sparc/kernel/trampoline_64.S
10919 index 737f8cb..88ede1d 100644
10920 --- a/arch/sparc/kernel/trampoline_64.S
10921 +++ b/arch/sparc/kernel/trampoline_64.S
10922 @@ -109,10 +109,13 @@ startup_continue:
10923 brnz,pn %g1, 1b
10924 nop
10925
10926 - sethi %hi(p1275buf), %g2
10927 - or %g2, %lo(p1275buf), %g2
10928 - ldx [%g2 + 0x10], %l2
10929 - add %l2, -(192 + 128), %sp
10930 + /* Get onto temporary stack which will be in the locked
10931 + * kernel image.
10932 + */
10933 + sethi %hi(tramp_stack), %g1
10934 + or %g1, %lo(tramp_stack), %g1
10935 + add %g1, TRAMP_STACK_SIZE, %g1
10936 + sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
10937 flushw
10938
10939 /* Setup the loop variables:
10940 @@ -394,7 +397,6 @@ after_lock_tlb:
10941 sllx %g5, THREAD_SHIFT, %g5
10942 sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
10943 add %g6, %g5, %sp
10944 - mov 0, %fp
10945
10946 rdpr %pstate, %o1
10947 or %o1, PSTATE_IE, %o1
10948 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10949 index 6fd386c5..6907d81 100644
10950 --- a/arch/sparc/kernel/traps_32.c
10951 +++ b/arch/sparc/kernel/traps_32.c
10952 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10953 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10954 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10955
10956 +extern void gr_handle_kernel_exploit(void);
10957 +
10958 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10959 {
10960 static int die_counter;
10961 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10962 count++ < 30 &&
10963 (((unsigned long) rw) >= PAGE_OFFSET) &&
10964 !(((unsigned long) rw) & 0x7)) {
10965 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10966 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10967 (void *) rw->ins[7]);
10968 rw = (struct reg_window32 *)rw->ins[6];
10969 }
10970 }
10971 printk("Instruction DUMP:");
10972 instruction_dump ((unsigned long *) regs->pc);
10973 - if(regs->psr & PSR_PS)
10974 + if(regs->psr & PSR_PS) {
10975 + gr_handle_kernel_exploit();
10976 do_exit(SIGKILL);
10977 + }
10978 do_exit(SIGSEGV);
10979 }
10980
10981 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10982 index fb6640e..2daada8 100644
10983 --- a/arch/sparc/kernel/traps_64.c
10984 +++ b/arch/sparc/kernel/traps_64.c
10985 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10986 i + 1,
10987 p->trapstack[i].tstate, p->trapstack[i].tpc,
10988 p->trapstack[i].tnpc, p->trapstack[i].tt);
10989 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10990 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10991 }
10992 }
10993
10994 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10995
10996 lvl -= 0x100;
10997 if (regs->tstate & TSTATE_PRIV) {
10998 +
10999 +#ifdef CONFIG_PAX_REFCOUNT
11000 + if (lvl == 6)
11001 + pax_report_refcount_overflow(regs);
11002 +#endif
11003 +
11004 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11005 die_if_kernel(buffer, regs);
11006 }
11007 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11008 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11009 {
11010 char buffer[32];
11011 -
11012 +
11013 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11014 0, lvl, SIGTRAP) == NOTIFY_STOP)
11015 return;
11016
11017 +#ifdef CONFIG_PAX_REFCOUNT
11018 + if (lvl == 6)
11019 + pax_report_refcount_overflow(regs);
11020 +#endif
11021 +
11022 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11023
11024 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11025 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11026 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11027 printk("%s" "ERROR(%d): ",
11028 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11029 - printk("TPC<%pS>\n", (void *) regs->tpc);
11030 + printk("TPC<%pA>\n", (void *) regs->tpc);
11031 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11032 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11033 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11034 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11035 smp_processor_id(),
11036 (type & 0x1) ? 'I' : 'D',
11037 regs->tpc);
11038 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11039 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11040 panic("Irrecoverable Cheetah+ parity error.");
11041 }
11042
11043 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11044 smp_processor_id(),
11045 (type & 0x1) ? 'I' : 'D',
11046 regs->tpc);
11047 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11048 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11049 }
11050
11051 struct sun4v_error_entry {
11052 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11053 /*0x38*/u64 reserved_5;
11054 };
11055
11056 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11057 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11058 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11059 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11060
11061 static const char *sun4v_err_type_to_str(u8 type)
11062 {
11063 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11064 }
11065
11066 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11067 - int cpu, const char *pfx, atomic_t *ocnt)
11068 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11069 {
11070 u64 *raw_ptr = (u64 *) ent;
11071 u32 attrs;
11072 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11073
11074 show_regs(regs);
11075
11076 - if ((cnt = atomic_read(ocnt)) != 0) {
11077 - atomic_set(ocnt, 0);
11078 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11079 + atomic_set_unchecked(ocnt, 0);
11080 wmb();
11081 printk("%s: Queue overflowed %d times.\n",
11082 pfx, cnt);
11083 @@ -2048,7 +2059,7 @@ out:
11084 */
11085 void sun4v_resum_overflow(struct pt_regs *regs)
11086 {
11087 - atomic_inc(&sun4v_resum_oflow_cnt);
11088 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11089 }
11090
11091 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11092 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11093 /* XXX Actually even this can make not that much sense. Perhaps
11094 * XXX we should just pull the plug and panic directly from here?
11095 */
11096 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11097 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11098 }
11099
11100 unsigned long sun4v_err_itlb_vaddr;
11101 @@ -2116,9 +2127,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11102
11103 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11104 regs->tpc, tl);
11105 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11106 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11107 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11108 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11109 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11110 (void *) regs->u_regs[UREG_I7]);
11111 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11112 "pte[%lx] error[%lx]\n",
11113 @@ -2140,9 +2151,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11114
11115 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11116 regs->tpc, tl);
11117 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11118 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11119 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11120 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11121 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11122 (void *) regs->u_regs[UREG_I7]);
11123 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11124 "pte[%lx] error[%lx]\n",
11125 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11126 fp = (unsigned long)sf->fp + STACK_BIAS;
11127 }
11128
11129 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11130 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11131 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11132 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11133 int index = tsk->curr_ret_stack;
11134 if (tsk->ret_stack && index >= graph) {
11135 pc = tsk->ret_stack[index - graph].ret;
11136 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11137 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11138 graph++;
11139 }
11140 }
11141 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11142 return (struct reg_window *) (fp + STACK_BIAS);
11143 }
11144
11145 +extern void gr_handle_kernel_exploit(void);
11146 +
11147 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11148 {
11149 static int die_counter;
11150 @@ -2411,7 +2424,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11151 while (rw &&
11152 count++ < 30 &&
11153 kstack_valid(tp, (unsigned long) rw)) {
11154 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11155 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11156 (void *) rw->ins[7]);
11157
11158 rw = kernel_stack_up(rw);
11159 @@ -2424,8 +2437,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11160 }
11161 user_instruction_dump ((unsigned int __user *) regs->tpc);
11162 }
11163 - if (regs->tstate & TSTATE_PRIV)
11164 + if (regs->tstate & TSTATE_PRIV) {
11165 + gr_handle_kernel_exploit();
11166 do_exit(SIGKILL);
11167 + }
11168 do_exit(SIGSEGV);
11169 }
11170 EXPORT_SYMBOL(die_if_kernel);
11171 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11172 index 62098a8..547ab2c 100644
11173 --- a/arch/sparc/kernel/unaligned_64.c
11174 +++ b/arch/sparc/kernel/unaligned_64.c
11175 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11176 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11177
11178 if (__ratelimit(&ratelimit)) {
11179 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11180 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11181 regs->tpc, (void *) regs->tpc);
11182 }
11183 }
11184 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11185 index 3269b02..64f5231 100644
11186 --- a/arch/sparc/lib/Makefile
11187 +++ b/arch/sparc/lib/Makefile
11188 @@ -2,7 +2,7 @@
11189 #
11190
11191 asflags-y := -ansi -DST_DIV0=0x02
11192 -ccflags-y := -Werror
11193 +#ccflags-y := -Werror
11194
11195 lib-$(CONFIG_SPARC32) += ashrdi3.o
11196 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11197 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11198 index 85c233d..68500e0 100644
11199 --- a/arch/sparc/lib/atomic_64.S
11200 +++ b/arch/sparc/lib/atomic_64.S
11201 @@ -17,7 +17,12 @@
11202 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11203 BACKOFF_SETUP(%o2)
11204 1: lduw [%o1], %g1
11205 - add %g1, %o0, %g7
11206 + addcc %g1, %o0, %g7
11207 +
11208 +#ifdef CONFIG_PAX_REFCOUNT
11209 + tvs %icc, 6
11210 +#endif
11211 +
11212 cas [%o1], %g1, %g7
11213 cmp %g1, %g7
11214 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11215 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11216 2: BACKOFF_SPIN(%o2, %o3, 1b)
11217 ENDPROC(atomic_add)
11218
11219 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11220 + BACKOFF_SETUP(%o2)
11221 +1: lduw [%o1], %g1
11222 + add %g1, %o0, %g7
11223 + cas [%o1], %g1, %g7
11224 + cmp %g1, %g7
11225 + bne,pn %icc, 2f
11226 + nop
11227 + retl
11228 + nop
11229 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11230 +ENDPROC(atomic_add_unchecked)
11231 +
11232 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11233 BACKOFF_SETUP(%o2)
11234 1: lduw [%o1], %g1
11235 - sub %g1, %o0, %g7
11236 + subcc %g1, %o0, %g7
11237 +
11238 +#ifdef CONFIG_PAX_REFCOUNT
11239 + tvs %icc, 6
11240 +#endif
11241 +
11242 cas [%o1], %g1, %g7
11243 cmp %g1, %g7
11244 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11245 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11246 2: BACKOFF_SPIN(%o2, %o3, 1b)
11247 ENDPROC(atomic_sub)
11248
11249 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11250 + BACKOFF_SETUP(%o2)
11251 +1: lduw [%o1], %g1
11252 + sub %g1, %o0, %g7
11253 + cas [%o1], %g1, %g7
11254 + cmp %g1, %g7
11255 + bne,pn %icc, 2f
11256 + nop
11257 + retl
11258 + nop
11259 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11260 +ENDPROC(atomic_sub_unchecked)
11261 +
11262 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11263 BACKOFF_SETUP(%o2)
11264 1: lduw [%o1], %g1
11265 - add %g1, %o0, %g7
11266 + addcc %g1, %o0, %g7
11267 +
11268 +#ifdef CONFIG_PAX_REFCOUNT
11269 + tvs %icc, 6
11270 +#endif
11271 +
11272 cas [%o1], %g1, %g7
11273 cmp %g1, %g7
11274 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11275 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11276 2: BACKOFF_SPIN(%o2, %o3, 1b)
11277 ENDPROC(atomic_add_ret)
11278
11279 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11280 + BACKOFF_SETUP(%o2)
11281 +1: lduw [%o1], %g1
11282 + addcc %g1, %o0, %g7
11283 + cas [%o1], %g1, %g7
11284 + cmp %g1, %g7
11285 + bne,pn %icc, 2f
11286 + add %g7, %o0, %g7
11287 + sra %g7, 0, %o0
11288 + retl
11289 + nop
11290 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11291 +ENDPROC(atomic_add_ret_unchecked)
11292 +
11293 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11294 BACKOFF_SETUP(%o2)
11295 1: lduw [%o1], %g1
11296 - sub %g1, %o0, %g7
11297 + subcc %g1, %o0, %g7
11298 +
11299 +#ifdef CONFIG_PAX_REFCOUNT
11300 + tvs %icc, 6
11301 +#endif
11302 +
11303 cas [%o1], %g1, %g7
11304 cmp %g1, %g7
11305 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11306 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11307 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11308 BACKOFF_SETUP(%o2)
11309 1: ldx [%o1], %g1
11310 - add %g1, %o0, %g7
11311 + addcc %g1, %o0, %g7
11312 +
11313 +#ifdef CONFIG_PAX_REFCOUNT
11314 + tvs %xcc, 6
11315 +#endif
11316 +
11317 casx [%o1], %g1, %g7
11318 cmp %g1, %g7
11319 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11320 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11321 2: BACKOFF_SPIN(%o2, %o3, 1b)
11322 ENDPROC(atomic64_add)
11323
11324 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11325 + BACKOFF_SETUP(%o2)
11326 +1: ldx [%o1], %g1
11327 + addcc %g1, %o0, %g7
11328 + casx [%o1], %g1, %g7
11329 + cmp %g1, %g7
11330 + bne,pn %xcc, 2f
11331 + nop
11332 + retl
11333 + nop
11334 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11335 +ENDPROC(atomic64_add_unchecked)
11336 +
11337 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11338 BACKOFF_SETUP(%o2)
11339 1: ldx [%o1], %g1
11340 - sub %g1, %o0, %g7
11341 + subcc %g1, %o0, %g7
11342 +
11343 +#ifdef CONFIG_PAX_REFCOUNT
11344 + tvs %xcc, 6
11345 +#endif
11346 +
11347 casx [%o1], %g1, %g7
11348 cmp %g1, %g7
11349 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11350 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11351 2: BACKOFF_SPIN(%o2, %o3, 1b)
11352 ENDPROC(atomic64_sub)
11353
11354 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11355 + BACKOFF_SETUP(%o2)
11356 +1: ldx [%o1], %g1
11357 + subcc %g1, %o0, %g7
11358 + casx [%o1], %g1, %g7
11359 + cmp %g1, %g7
11360 + bne,pn %xcc, 2f
11361 + nop
11362 + retl
11363 + nop
11364 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11365 +ENDPROC(atomic64_sub_unchecked)
11366 +
11367 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11368 BACKOFF_SETUP(%o2)
11369 1: ldx [%o1], %g1
11370 - add %g1, %o0, %g7
11371 + addcc %g1, %o0, %g7
11372 +
11373 +#ifdef CONFIG_PAX_REFCOUNT
11374 + tvs %xcc, 6
11375 +#endif
11376 +
11377 casx [%o1], %g1, %g7
11378 cmp %g1, %g7
11379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11380 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11381 2: BACKOFF_SPIN(%o2, %o3, 1b)
11382 ENDPROC(atomic64_add_ret)
11383
11384 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11385 + BACKOFF_SETUP(%o2)
11386 +1: ldx [%o1], %g1
11387 + addcc %g1, %o0, %g7
11388 + casx [%o1], %g1, %g7
11389 + cmp %g1, %g7
11390 + bne,pn %xcc, 2f
11391 + add %g7, %o0, %g7
11392 + mov %g7, %o0
11393 + retl
11394 + nop
11395 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11396 +ENDPROC(atomic64_add_ret_unchecked)
11397 +
11398 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11399 BACKOFF_SETUP(%o2)
11400 1: ldx [%o1], %g1
11401 - sub %g1, %o0, %g7
11402 + subcc %g1, %o0, %g7
11403 +
11404 +#ifdef CONFIG_PAX_REFCOUNT
11405 + tvs %xcc, 6
11406 +#endif
11407 +
11408 casx [%o1], %g1, %g7
11409 cmp %g1, %g7
11410 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11411 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11412 index 323335b..ed85ea2 100644
11413 --- a/arch/sparc/lib/ksyms.c
11414 +++ b/arch/sparc/lib/ksyms.c
11415 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11416
11417 /* Atomic counter implementation. */
11418 EXPORT_SYMBOL(atomic_add);
11419 +EXPORT_SYMBOL(atomic_add_unchecked);
11420 EXPORT_SYMBOL(atomic_add_ret);
11421 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11422 EXPORT_SYMBOL(atomic_sub);
11423 +EXPORT_SYMBOL(atomic_sub_unchecked);
11424 EXPORT_SYMBOL(atomic_sub_ret);
11425 EXPORT_SYMBOL(atomic64_add);
11426 +EXPORT_SYMBOL(atomic64_add_unchecked);
11427 EXPORT_SYMBOL(atomic64_add_ret);
11428 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11429 EXPORT_SYMBOL(atomic64_sub);
11430 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11431 EXPORT_SYMBOL(atomic64_sub_ret);
11432 EXPORT_SYMBOL(atomic64_dec_if_positive);
11433
11434 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11435 index 30c3ecc..736f015 100644
11436 --- a/arch/sparc/mm/Makefile
11437 +++ b/arch/sparc/mm/Makefile
11438 @@ -2,7 +2,7 @@
11439 #
11440
11441 asflags-y := -ansi
11442 -ccflags-y := -Werror
11443 +#ccflags-y := -Werror
11444
11445 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11446 obj-y += fault_$(BITS).o
11447 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11448 index 908e8c1..1524793 100644
11449 --- a/arch/sparc/mm/fault_32.c
11450 +++ b/arch/sparc/mm/fault_32.c
11451 @@ -21,6 +21,9 @@
11452 #include <linux/perf_event.h>
11453 #include <linux/interrupt.h>
11454 #include <linux/kdebug.h>
11455 +#include <linux/slab.h>
11456 +#include <linux/pagemap.h>
11457 +#include <linux/compiler.h>
11458
11459 #include <asm/page.h>
11460 #include <asm/pgtable.h>
11461 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11462 return safe_compute_effective_address(regs, insn);
11463 }
11464
11465 +#ifdef CONFIG_PAX_PAGEEXEC
11466 +#ifdef CONFIG_PAX_DLRESOLVE
11467 +static void pax_emuplt_close(struct vm_area_struct *vma)
11468 +{
11469 + vma->vm_mm->call_dl_resolve = 0UL;
11470 +}
11471 +
11472 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11473 +{
11474 + unsigned int *kaddr;
11475 +
11476 + vmf->page = alloc_page(GFP_HIGHUSER);
11477 + if (!vmf->page)
11478 + return VM_FAULT_OOM;
11479 +
11480 + kaddr = kmap(vmf->page);
11481 + memset(kaddr, 0, PAGE_SIZE);
11482 + kaddr[0] = 0x9DE3BFA8U; /* save */
11483 + flush_dcache_page(vmf->page);
11484 + kunmap(vmf->page);
11485 + return VM_FAULT_MAJOR;
11486 +}
11487 +
11488 +static const struct vm_operations_struct pax_vm_ops = {
11489 + .close = pax_emuplt_close,
11490 + .fault = pax_emuplt_fault
11491 +};
11492 +
11493 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11494 +{
11495 + int ret;
11496 +
11497 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11498 + vma->vm_mm = current->mm;
11499 + vma->vm_start = addr;
11500 + vma->vm_end = addr + PAGE_SIZE;
11501 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11502 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11503 + vma->vm_ops = &pax_vm_ops;
11504 +
11505 + ret = insert_vm_struct(current->mm, vma);
11506 + if (ret)
11507 + return ret;
11508 +
11509 + ++current->mm->total_vm;
11510 + return 0;
11511 +}
11512 +#endif
11513 +
11514 +/*
11515 + * PaX: decide what to do with offenders (regs->pc = fault address)
11516 + *
11517 + * returns 1 when task should be killed
11518 + * 2 when patched PLT trampoline was detected
11519 + * 3 when unpatched PLT trampoline was detected
11520 + */
11521 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11522 +{
11523 +
11524 +#ifdef CONFIG_PAX_EMUPLT
11525 + int err;
11526 +
11527 + do { /* PaX: patched PLT emulation #1 */
11528 + unsigned int sethi1, sethi2, jmpl;
11529 +
11530 + err = get_user(sethi1, (unsigned int *)regs->pc);
11531 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11532 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11533 +
11534 + if (err)
11535 + break;
11536 +
11537 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11538 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11539 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11540 + {
11541 + unsigned int addr;
11542 +
11543 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11544 + addr = regs->u_regs[UREG_G1];
11545 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11546 + regs->pc = addr;
11547 + regs->npc = addr+4;
11548 + return 2;
11549 + }
11550 + } while (0);
11551 +
11552 + do { /* PaX: patched PLT emulation #2 */
11553 + unsigned int ba;
11554 +
11555 + err = get_user(ba, (unsigned int *)regs->pc);
11556 +
11557 + if (err)
11558 + break;
11559 +
11560 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11561 + unsigned int addr;
11562 +
11563 + if ((ba & 0xFFC00000U) == 0x30800000U)
11564 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11565 + else
11566 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11567 + regs->pc = addr;
11568 + regs->npc = addr+4;
11569 + return 2;
11570 + }
11571 + } while (0);
11572 +
11573 + do { /* PaX: patched PLT emulation #3 */
11574 + unsigned int sethi, bajmpl, nop;
11575 +
11576 + err = get_user(sethi, (unsigned int *)regs->pc);
11577 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11578 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11579 +
11580 + if (err)
11581 + break;
11582 +
11583 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11584 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11585 + nop == 0x01000000U)
11586 + {
11587 + unsigned int addr;
11588 +
11589 + addr = (sethi & 0x003FFFFFU) << 10;
11590 + regs->u_regs[UREG_G1] = addr;
11591 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11592 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11593 + else
11594 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11595 + regs->pc = addr;
11596 + regs->npc = addr+4;
11597 + return 2;
11598 + }
11599 + } while (0);
11600 +
11601 + do { /* PaX: unpatched PLT emulation step 1 */
11602 + unsigned int sethi, ba, nop;
11603 +
11604 + err = get_user(sethi, (unsigned int *)regs->pc);
11605 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11606 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11607 +
11608 + if (err)
11609 + break;
11610 +
11611 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11612 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11613 + nop == 0x01000000U)
11614 + {
11615 + unsigned int addr, save, call;
11616 +
11617 + if ((ba & 0xFFC00000U) == 0x30800000U)
11618 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11619 + else
11620 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11621 +
11622 + err = get_user(save, (unsigned int *)addr);
11623 + err |= get_user(call, (unsigned int *)(addr+4));
11624 + err |= get_user(nop, (unsigned int *)(addr+8));
11625 + if (err)
11626 + break;
11627 +
11628 +#ifdef CONFIG_PAX_DLRESOLVE
11629 + if (save == 0x9DE3BFA8U &&
11630 + (call & 0xC0000000U) == 0x40000000U &&
11631 + nop == 0x01000000U)
11632 + {
11633 + struct vm_area_struct *vma;
11634 + unsigned long call_dl_resolve;
11635 +
11636 + down_read(&current->mm->mmap_sem);
11637 + call_dl_resolve = current->mm->call_dl_resolve;
11638 + up_read(&current->mm->mmap_sem);
11639 + if (likely(call_dl_resolve))
11640 + goto emulate;
11641 +
11642 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11643 +
11644 + down_write(&current->mm->mmap_sem);
11645 + if (current->mm->call_dl_resolve) {
11646 + call_dl_resolve = current->mm->call_dl_resolve;
11647 + up_write(&current->mm->mmap_sem);
11648 + if (vma)
11649 + kmem_cache_free(vm_area_cachep, vma);
11650 + goto emulate;
11651 + }
11652 +
11653 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11654 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11655 + up_write(&current->mm->mmap_sem);
11656 + if (vma)
11657 + kmem_cache_free(vm_area_cachep, vma);
11658 + return 1;
11659 + }
11660 +
11661 + if (pax_insert_vma(vma, call_dl_resolve)) {
11662 + up_write(&current->mm->mmap_sem);
11663 + kmem_cache_free(vm_area_cachep, vma);
11664 + return 1;
11665 + }
11666 +
11667 + current->mm->call_dl_resolve = call_dl_resolve;
11668 + up_write(&current->mm->mmap_sem);
11669 +
11670 +emulate:
11671 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11672 + regs->pc = call_dl_resolve;
11673 + regs->npc = addr+4;
11674 + return 3;
11675 + }
11676 +#endif
11677 +
11678 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11679 + if ((save & 0xFFC00000U) == 0x05000000U &&
11680 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11681 + nop == 0x01000000U)
11682 + {
11683 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11684 + regs->u_regs[UREG_G2] = addr + 4;
11685 + addr = (save & 0x003FFFFFU) << 10;
11686 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11687 + regs->pc = addr;
11688 + regs->npc = addr+4;
11689 + return 3;
11690 + }
11691 + }
11692 + } while (0);
11693 +
11694 + do { /* PaX: unpatched PLT emulation step 2 */
11695 + unsigned int save, call, nop;
11696 +
11697 + err = get_user(save, (unsigned int *)(regs->pc-4));
11698 + err |= get_user(call, (unsigned int *)regs->pc);
11699 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11700 + if (err)
11701 + break;
11702 +
11703 + if (save == 0x9DE3BFA8U &&
11704 + (call & 0xC0000000U) == 0x40000000U &&
11705 + nop == 0x01000000U)
11706 + {
11707 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11708 +
11709 + regs->u_regs[UREG_RETPC] = regs->pc;
11710 + regs->pc = dl_resolve;
11711 + regs->npc = dl_resolve+4;
11712 + return 3;
11713 + }
11714 + } while (0);
11715 +#endif
11716 +
11717 + return 1;
11718 +}
11719 +
11720 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11721 +{
11722 + unsigned long i;
11723 +
11724 + printk(KERN_ERR "PAX: bytes at PC: ");
11725 + for (i = 0; i < 8; i++) {
11726 + unsigned int c;
11727 + if (get_user(c, (unsigned int *)pc+i))
11728 + printk(KERN_CONT "???????? ");
11729 + else
11730 + printk(KERN_CONT "%08x ", c);
11731 + }
11732 + printk("\n");
11733 +}
11734 +#endif
11735 +
11736 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11737 int text_fault)
11738 {
11739 @@ -226,6 +500,24 @@ good_area:
11740 if (!(vma->vm_flags & VM_WRITE))
11741 goto bad_area;
11742 } else {
11743 +
11744 +#ifdef CONFIG_PAX_PAGEEXEC
11745 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11746 + up_read(&mm->mmap_sem);
11747 + switch (pax_handle_fetch_fault(regs)) {
11748 +
11749 +#ifdef CONFIG_PAX_EMUPLT
11750 + case 2:
11751 + case 3:
11752 + return;
11753 +#endif
11754 +
11755 + }
11756 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11757 + do_group_exit(SIGKILL);
11758 + }
11759 +#endif
11760 +
11761 /* Allow reads even for write-only mappings */
11762 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11763 goto bad_area;
11764 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11765 index 587cd05..fbdf17a 100644
11766 --- a/arch/sparc/mm/fault_64.c
11767 +++ b/arch/sparc/mm/fault_64.c
11768 @@ -22,6 +22,9 @@
11769 #include <linux/kdebug.h>
11770 #include <linux/percpu.h>
11771 #include <linux/context_tracking.h>
11772 +#include <linux/slab.h>
11773 +#include <linux/pagemap.h>
11774 +#include <linux/compiler.h>
11775
11776 #include <asm/page.h>
11777 #include <asm/pgtable.h>
11778 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11779 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11780 regs->tpc);
11781 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11782 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11783 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11784 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11785 dump_stack();
11786 unhandled_fault(regs->tpc, current, regs);
11787 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11788 show_regs(regs);
11789 }
11790
11791 +#ifdef CONFIG_PAX_PAGEEXEC
11792 +#ifdef CONFIG_PAX_DLRESOLVE
11793 +static void pax_emuplt_close(struct vm_area_struct *vma)
11794 +{
11795 + vma->vm_mm->call_dl_resolve = 0UL;
11796 +}
11797 +
11798 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11799 +{
11800 + unsigned int *kaddr;
11801 +
11802 + vmf->page = alloc_page(GFP_HIGHUSER);
11803 + if (!vmf->page)
11804 + return VM_FAULT_OOM;
11805 +
11806 + kaddr = kmap(vmf->page);
11807 + memset(kaddr, 0, PAGE_SIZE);
11808 + kaddr[0] = 0x9DE3BFA8U; /* save */
11809 + flush_dcache_page(vmf->page);
11810 + kunmap(vmf->page);
11811 + return VM_FAULT_MAJOR;
11812 +}
11813 +
11814 +static const struct vm_operations_struct pax_vm_ops = {
11815 + .close = pax_emuplt_close,
11816 + .fault = pax_emuplt_fault
11817 +};
11818 +
11819 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11820 +{
11821 + int ret;
11822 +
11823 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11824 + vma->vm_mm = current->mm;
11825 + vma->vm_start = addr;
11826 + vma->vm_end = addr + PAGE_SIZE;
11827 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11828 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11829 + vma->vm_ops = &pax_vm_ops;
11830 +
11831 + ret = insert_vm_struct(current->mm, vma);
11832 + if (ret)
11833 + return ret;
11834 +
11835 + ++current->mm->total_vm;
11836 + return 0;
11837 +}
11838 +#endif
11839 +
11840 +/*
11841 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11842 + *
11843 + * returns 1 when task should be killed
11844 + * 2 when patched PLT trampoline was detected
11845 + * 3 when unpatched PLT trampoline was detected
11846 + */
11847 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11848 +{
11849 +
11850 +#ifdef CONFIG_PAX_EMUPLT
11851 + int err;
11852 +
11853 + do { /* PaX: patched PLT emulation #1 */
11854 + unsigned int sethi1, sethi2, jmpl;
11855 +
11856 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11857 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11858 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11859 +
11860 + if (err)
11861 + break;
11862 +
11863 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11864 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11865 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11866 + {
11867 + unsigned long addr;
11868 +
11869 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11870 + addr = regs->u_regs[UREG_G1];
11871 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11872 +
11873 + if (test_thread_flag(TIF_32BIT))
11874 + addr &= 0xFFFFFFFFUL;
11875 +
11876 + regs->tpc = addr;
11877 + regs->tnpc = addr+4;
11878 + return 2;
11879 + }
11880 + } while (0);
11881 +
11882 + do { /* PaX: patched PLT emulation #2 */
11883 + unsigned int ba;
11884 +
11885 + err = get_user(ba, (unsigned int *)regs->tpc);
11886 +
11887 + if (err)
11888 + break;
11889 +
11890 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11891 + unsigned long addr;
11892 +
11893 + if ((ba & 0xFFC00000U) == 0x30800000U)
11894 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11895 + else
11896 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11897 +
11898 + if (test_thread_flag(TIF_32BIT))
11899 + addr &= 0xFFFFFFFFUL;
11900 +
11901 + regs->tpc = addr;
11902 + regs->tnpc = addr+4;
11903 + return 2;
11904 + }
11905 + } while (0);
11906 +
11907 + do { /* PaX: patched PLT emulation #3 */
11908 + unsigned int sethi, bajmpl, nop;
11909 +
11910 + err = get_user(sethi, (unsigned int *)regs->tpc);
11911 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11912 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11913 +
11914 + if (err)
11915 + break;
11916 +
11917 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11918 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11919 + nop == 0x01000000U)
11920 + {
11921 + unsigned long addr;
11922 +
11923 + addr = (sethi & 0x003FFFFFU) << 10;
11924 + regs->u_regs[UREG_G1] = addr;
11925 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11926 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11927 + else
11928 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11929 +
11930 + if (test_thread_flag(TIF_32BIT))
11931 + addr &= 0xFFFFFFFFUL;
11932 +
11933 + regs->tpc = addr;
11934 + regs->tnpc = addr+4;
11935 + return 2;
11936 + }
11937 + } while (0);
11938 +
11939 + do { /* PaX: patched PLT emulation #4 */
11940 + unsigned int sethi, mov1, call, mov2;
11941 +
11942 + err = get_user(sethi, (unsigned int *)regs->tpc);
11943 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11944 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11945 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11946 +
11947 + if (err)
11948 + break;
11949 +
11950 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11951 + mov1 == 0x8210000FU &&
11952 + (call & 0xC0000000U) == 0x40000000U &&
11953 + mov2 == 0x9E100001U)
11954 + {
11955 + unsigned long addr;
11956 +
11957 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11958 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11959 +
11960 + if (test_thread_flag(TIF_32BIT))
11961 + addr &= 0xFFFFFFFFUL;
11962 +
11963 + regs->tpc = addr;
11964 + regs->tnpc = addr+4;
11965 + return 2;
11966 + }
11967 + } while (0);
11968 +
11969 + do { /* PaX: patched PLT emulation #5 */
11970 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11971 +
11972 + err = get_user(sethi, (unsigned int *)regs->tpc);
11973 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11974 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11975 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11976 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11977 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11978 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11979 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11980 +
11981 + if (err)
11982 + break;
11983 +
11984 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11985 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11986 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11987 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11988 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11989 + sllx == 0x83287020U &&
11990 + jmpl == 0x81C04005U &&
11991 + nop == 0x01000000U)
11992 + {
11993 + unsigned long addr;
11994 +
11995 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11996 + regs->u_regs[UREG_G1] <<= 32;
11997 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11998 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11999 + regs->tpc = addr;
12000 + regs->tnpc = addr+4;
12001 + return 2;
12002 + }
12003 + } while (0);
12004 +
12005 + do { /* PaX: patched PLT emulation #6 */
12006 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12007 +
12008 + err = get_user(sethi, (unsigned int *)regs->tpc);
12009 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12010 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12011 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12012 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12013 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12014 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12015 +
12016 + if (err)
12017 + break;
12018 +
12019 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12020 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12021 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12022 + sllx == 0x83287020U &&
12023 + (or & 0xFFFFE000U) == 0x8A116000U &&
12024 + jmpl == 0x81C04005U &&
12025 + nop == 0x01000000U)
12026 + {
12027 + unsigned long addr;
12028 +
12029 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12030 + regs->u_regs[UREG_G1] <<= 32;
12031 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12032 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12033 + regs->tpc = addr;
12034 + regs->tnpc = addr+4;
12035 + return 2;
12036 + }
12037 + } while (0);
12038 +
12039 + do { /* PaX: unpatched PLT emulation step 1 */
12040 + unsigned int sethi, ba, nop;
12041 +
12042 + err = get_user(sethi, (unsigned int *)regs->tpc);
12043 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12044 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12045 +
12046 + if (err)
12047 + break;
12048 +
12049 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12050 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12051 + nop == 0x01000000U)
12052 + {
12053 + unsigned long addr;
12054 + unsigned int save, call;
12055 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12056 +
12057 + if ((ba & 0xFFC00000U) == 0x30800000U)
12058 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12059 + else
12060 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12061 +
12062 + if (test_thread_flag(TIF_32BIT))
12063 + addr &= 0xFFFFFFFFUL;
12064 +
12065 + err = get_user(save, (unsigned int *)addr);
12066 + err |= get_user(call, (unsigned int *)(addr+4));
12067 + err |= get_user(nop, (unsigned int *)(addr+8));
12068 + if (err)
12069 + break;
12070 +
12071 +#ifdef CONFIG_PAX_DLRESOLVE
12072 + if (save == 0x9DE3BFA8U &&
12073 + (call & 0xC0000000U) == 0x40000000U &&
12074 + nop == 0x01000000U)
12075 + {
12076 + struct vm_area_struct *vma;
12077 + unsigned long call_dl_resolve;
12078 +
12079 + down_read(&current->mm->mmap_sem);
12080 + call_dl_resolve = current->mm->call_dl_resolve;
12081 + up_read(&current->mm->mmap_sem);
12082 + if (likely(call_dl_resolve))
12083 + goto emulate;
12084 +
12085 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12086 +
12087 + down_write(&current->mm->mmap_sem);
12088 + if (current->mm->call_dl_resolve) {
12089 + call_dl_resolve = current->mm->call_dl_resolve;
12090 + up_write(&current->mm->mmap_sem);
12091 + if (vma)
12092 + kmem_cache_free(vm_area_cachep, vma);
12093 + goto emulate;
12094 + }
12095 +
12096 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12097 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12098 + up_write(&current->mm->mmap_sem);
12099 + if (vma)
12100 + kmem_cache_free(vm_area_cachep, vma);
12101 + return 1;
12102 + }
12103 +
12104 + if (pax_insert_vma(vma, call_dl_resolve)) {
12105 + up_write(&current->mm->mmap_sem);
12106 + kmem_cache_free(vm_area_cachep, vma);
12107 + return 1;
12108 + }
12109 +
12110 + current->mm->call_dl_resolve = call_dl_resolve;
12111 + up_write(&current->mm->mmap_sem);
12112 +
12113 +emulate:
12114 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12115 + regs->tpc = call_dl_resolve;
12116 + regs->tnpc = addr+4;
12117 + return 3;
12118 + }
12119 +#endif
12120 +
12121 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12122 + if ((save & 0xFFC00000U) == 0x05000000U &&
12123 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12124 + nop == 0x01000000U)
12125 + {
12126 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12127 + regs->u_regs[UREG_G2] = addr + 4;
12128 + addr = (save & 0x003FFFFFU) << 10;
12129 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12130 +
12131 + if (test_thread_flag(TIF_32BIT))
12132 + addr &= 0xFFFFFFFFUL;
12133 +
12134 + regs->tpc = addr;
12135 + regs->tnpc = addr+4;
12136 + return 3;
12137 + }
12138 +
12139 + /* PaX: 64-bit PLT stub */
12140 + err = get_user(sethi1, (unsigned int *)addr);
12141 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12142 + err |= get_user(or1, (unsigned int *)(addr+8));
12143 + err |= get_user(or2, (unsigned int *)(addr+12));
12144 + err |= get_user(sllx, (unsigned int *)(addr+16));
12145 + err |= get_user(add, (unsigned int *)(addr+20));
12146 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12147 + err |= get_user(nop, (unsigned int *)(addr+28));
12148 + if (err)
12149 + break;
12150 +
12151 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12152 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12153 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12154 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12155 + sllx == 0x89293020U &&
12156 + add == 0x8A010005U &&
12157 + jmpl == 0x89C14000U &&
12158 + nop == 0x01000000U)
12159 + {
12160 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12161 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12162 + regs->u_regs[UREG_G4] <<= 32;
12163 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12164 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12165 + regs->u_regs[UREG_G4] = addr + 24;
12166 + addr = regs->u_regs[UREG_G5];
12167 + regs->tpc = addr;
12168 + regs->tnpc = addr+4;
12169 + return 3;
12170 + }
12171 + }
12172 + } while (0);
12173 +
12174 +#ifdef CONFIG_PAX_DLRESOLVE
12175 + do { /* PaX: unpatched PLT emulation step 2 */
12176 + unsigned int save, call, nop;
12177 +
12178 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12179 + err |= get_user(call, (unsigned int *)regs->tpc);
12180 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12181 + if (err)
12182 + break;
12183 +
12184 + if (save == 0x9DE3BFA8U &&
12185 + (call & 0xC0000000U) == 0x40000000U &&
12186 + nop == 0x01000000U)
12187 + {
12188 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12189 +
12190 + if (test_thread_flag(TIF_32BIT))
12191 + dl_resolve &= 0xFFFFFFFFUL;
12192 +
12193 + regs->u_regs[UREG_RETPC] = regs->tpc;
12194 + regs->tpc = dl_resolve;
12195 + regs->tnpc = dl_resolve+4;
12196 + return 3;
12197 + }
12198 + } while (0);
12199 +#endif
12200 +
12201 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12202 + unsigned int sethi, ba, nop;
12203 +
12204 + err = get_user(sethi, (unsigned int *)regs->tpc);
12205 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12206 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12207 +
12208 + if (err)
12209 + break;
12210 +
12211 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12212 + (ba & 0xFFF00000U) == 0x30600000U &&
12213 + nop == 0x01000000U)
12214 + {
12215 + unsigned long addr;
12216 +
12217 + addr = (sethi & 0x003FFFFFU) << 10;
12218 + regs->u_regs[UREG_G1] = addr;
12219 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12220 +
12221 + if (test_thread_flag(TIF_32BIT))
12222 + addr &= 0xFFFFFFFFUL;
12223 +
12224 + regs->tpc = addr;
12225 + regs->tnpc = addr+4;
12226 + return 2;
12227 + }
12228 + } while (0);
12229 +
12230 +#endif
12231 +
12232 + return 1;
12233 +}
12234 +
12235 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12236 +{
12237 + unsigned long i;
12238 +
12239 + printk(KERN_ERR "PAX: bytes at PC: ");
12240 + for (i = 0; i < 8; i++) {
12241 + unsigned int c;
12242 + if (get_user(c, (unsigned int *)pc+i))
12243 + printk(KERN_CONT "???????? ");
12244 + else
12245 + printk(KERN_CONT "%08x ", c);
12246 + }
12247 + printk("\n");
12248 +}
12249 +#endif
12250 +
12251 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12252 {
12253 enum ctx_state prev_state = exception_enter();
12254 @@ -350,6 +813,29 @@ retry:
12255 if (!vma)
12256 goto bad_area;
12257
12258 +#ifdef CONFIG_PAX_PAGEEXEC
12259 + /* PaX: detect ITLB misses on non-exec pages */
12260 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12261 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12262 + {
12263 + if (address != regs->tpc)
12264 + goto good_area;
12265 +
12266 + up_read(&mm->mmap_sem);
12267 + switch (pax_handle_fetch_fault(regs)) {
12268 +
12269 +#ifdef CONFIG_PAX_EMUPLT
12270 + case 2:
12271 + case 3:
12272 + return;
12273 +#endif
12274 +
12275 + }
12276 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12277 + do_group_exit(SIGKILL);
12278 + }
12279 +#endif
12280 +
12281 /* Pure DTLB misses do not tell us whether the fault causing
12282 * load/store/atomic was a write or not, it only says that there
12283 * was no match. So in such a case we (carefully) read the
12284 diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12285 index 1aed043..ae6ce38 100644
12286 --- a/arch/sparc/mm/gup.c
12287 +++ b/arch/sparc/mm/gup.c
12288 @@ -160,6 +160,36 @@ static int gup_pud_range(pgd_t pgd, unsigned long addr, unsigned long end,
12289 return 1;
12290 }
12291
12292 +int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
12293 + struct page **pages)
12294 +{
12295 + struct mm_struct *mm = current->mm;
12296 + unsigned long addr, len, end;
12297 + unsigned long next, flags;
12298 + pgd_t *pgdp;
12299 + int nr = 0;
12300 +
12301 + start &= PAGE_MASK;
12302 + addr = start;
12303 + len = (unsigned long) nr_pages << PAGE_SHIFT;
12304 + end = start + len;
12305 +
12306 + local_irq_save(flags);
12307 + pgdp = pgd_offset(mm, addr);
12308 + do {
12309 + pgd_t pgd = *pgdp;
12310 +
12311 + next = pgd_addr_end(addr, end);
12312 + if (pgd_none(pgd))
12313 + break;
12314 + if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
12315 + break;
12316 + } while (pgdp++, addr = next, addr != end);
12317 + local_irq_restore(flags);
12318 +
12319 + return nr;
12320 +}
12321 +
12322 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
12323 struct page **pages)
12324 {
12325 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12326 index d329537..2c3746a 100644
12327 --- a/arch/sparc/mm/hugetlbpage.c
12328 +++ b/arch/sparc/mm/hugetlbpage.c
12329 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12330 unsigned long addr,
12331 unsigned long len,
12332 unsigned long pgoff,
12333 - unsigned long flags)
12334 + unsigned long flags,
12335 + unsigned long offset)
12336 {
12337 + struct mm_struct *mm = current->mm;
12338 unsigned long task_size = TASK_SIZE;
12339 struct vm_unmapped_area_info info;
12340
12341 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12342
12343 info.flags = 0;
12344 info.length = len;
12345 - info.low_limit = TASK_UNMAPPED_BASE;
12346 + info.low_limit = mm->mmap_base;
12347 info.high_limit = min(task_size, VA_EXCLUDE_START);
12348 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12349 info.align_offset = 0;
12350 + info.threadstack_offset = offset;
12351 addr = vm_unmapped_area(&info);
12352
12353 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12354 VM_BUG_ON(addr != -ENOMEM);
12355 info.low_limit = VA_EXCLUDE_END;
12356 +
12357 +#ifdef CONFIG_PAX_RANDMMAP
12358 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12359 + info.low_limit += mm->delta_mmap;
12360 +#endif
12361 +
12362 info.high_limit = task_size;
12363 addr = vm_unmapped_area(&info);
12364 }
12365 @@ -55,7 +64,8 @@ static unsigned long
12366 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12367 const unsigned long len,
12368 const unsigned long pgoff,
12369 - const unsigned long flags)
12370 + const unsigned long flags,
12371 + const unsigned long offset)
12372 {
12373 struct mm_struct *mm = current->mm;
12374 unsigned long addr = addr0;
12375 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12376 info.high_limit = mm->mmap_base;
12377 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12378 info.align_offset = 0;
12379 + info.threadstack_offset = offset;
12380 addr = vm_unmapped_area(&info);
12381
12382 /*
12383 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12384 VM_BUG_ON(addr != -ENOMEM);
12385 info.flags = 0;
12386 info.low_limit = TASK_UNMAPPED_BASE;
12387 +
12388 +#ifdef CONFIG_PAX_RANDMMAP
12389 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12390 + info.low_limit += mm->delta_mmap;
12391 +#endif
12392 +
12393 info.high_limit = STACK_TOP32;
12394 addr = vm_unmapped_area(&info);
12395 }
12396 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12397 struct mm_struct *mm = current->mm;
12398 struct vm_area_struct *vma;
12399 unsigned long task_size = TASK_SIZE;
12400 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12401
12402 if (test_thread_flag(TIF_32BIT))
12403 task_size = STACK_TOP32;
12404 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12405 return addr;
12406 }
12407
12408 +#ifdef CONFIG_PAX_RANDMMAP
12409 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12410 +#endif
12411 +
12412 if (addr) {
12413 addr = ALIGN(addr, HPAGE_SIZE);
12414 vma = find_vma(mm, addr);
12415 - if (task_size - len >= addr &&
12416 - (!vma || addr + len <= vma->vm_start))
12417 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12418 return addr;
12419 }
12420 if (mm->get_unmapped_area == arch_get_unmapped_area)
12421 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12422 - pgoff, flags);
12423 + pgoff, flags, offset);
12424 else
12425 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12426 - pgoff, flags);
12427 + pgoff, flags, offset);
12428 }
12429
12430 pte_t *huge_pte_alloc(struct mm_struct *mm,
12431 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12432 index 98ac8e8..ba7dd39 100644
12433 --- a/arch/sparc/mm/init_64.c
12434 +++ b/arch/sparc/mm/init_64.c
12435 @@ -190,9 +190,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12436 int num_kernel_image_mappings;
12437
12438 #ifdef CONFIG_DEBUG_DCFLUSH
12439 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12440 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12441 #ifdef CONFIG_SMP
12442 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12443 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12444 #endif
12445 #endif
12446
12447 @@ -200,7 +200,7 @@ inline void flush_dcache_page_impl(struct page *page)
12448 {
12449 BUG_ON(tlb_type == hypervisor);
12450 #ifdef CONFIG_DEBUG_DCFLUSH
12451 - atomic_inc(&dcpage_flushes);
12452 + atomic_inc_unchecked(&dcpage_flushes);
12453 #endif
12454
12455 #ifdef DCACHE_ALIASING_POSSIBLE
12456 @@ -472,10 +472,10 @@ void mmu_info(struct seq_file *m)
12457
12458 #ifdef CONFIG_DEBUG_DCFLUSH
12459 seq_printf(m, "DCPageFlushes\t: %d\n",
12460 - atomic_read(&dcpage_flushes));
12461 + atomic_read_unchecked(&dcpage_flushes));
12462 #ifdef CONFIG_SMP
12463 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12464 - atomic_read(&dcpage_flushes_xcall));
12465 + atomic_read_unchecked(&dcpage_flushes_xcall));
12466 #endif /* CONFIG_SMP */
12467 #endif /* CONFIG_DEBUG_DCFLUSH */
12468 }
12469 diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
12470 index ece4af0..f04b862 100644
12471 --- a/arch/sparc/net/bpf_jit_comp.c
12472 +++ b/arch/sparc/net/bpf_jit_comp.c
12473 @@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
12474 {
12475 if (fp->jited)
12476 module_free(NULL, fp->bpf_func);
12477 - kfree(fp);
12478 +
12479 + bpf_prog_unlock_free(fp);
12480 }
12481 diff --git a/arch/sparc/prom/cif.S b/arch/sparc/prom/cif.S
12482 index 9c86b4b..8050f38 100644
12483 --- a/arch/sparc/prom/cif.S
12484 +++ b/arch/sparc/prom/cif.S
12485 @@ -11,11 +11,10 @@
12486 .text
12487 .globl prom_cif_direct
12488 prom_cif_direct:
12489 + save %sp, -192, %sp
12490 sethi %hi(p1275buf), %o1
12491 or %o1, %lo(p1275buf), %o1
12492 - ldx [%o1 + 0x0010], %o2 ! prom_cif_stack
12493 - save %o2, -192, %sp
12494 - ldx [%i1 + 0x0008], %l2 ! prom_cif_handler
12495 + ldx [%o1 + 0x0008], %l2 ! prom_cif_handler
12496 mov %g4, %l0
12497 mov %g5, %l1
12498 mov %g6, %l3
12499 diff --git a/arch/sparc/prom/init_64.c b/arch/sparc/prom/init_64.c
12500 index d95db75..110b0d7 100644
12501 --- a/arch/sparc/prom/init_64.c
12502 +++ b/arch/sparc/prom/init_64.c
12503 @@ -26,13 +26,13 @@ phandle prom_chosen_node;
12504 * It gets passed the pointer to the PROM vector.
12505 */
12506
12507 -extern void prom_cif_init(void *, void *);
12508 +extern void prom_cif_init(void *);
12509
12510 -void __init prom_init(void *cif_handler, void *cif_stack)
12511 +void __init prom_init(void *cif_handler)
12512 {
12513 phandle node;
12514
12515 - prom_cif_init(cif_handler, cif_stack);
12516 + prom_cif_init(cif_handler);
12517
12518 prom_chosen_node = prom_finddevice(prom_chosen_path);
12519 if (!prom_chosen_node || (s32)prom_chosen_node == -1)
12520 diff --git a/arch/sparc/prom/p1275.c b/arch/sparc/prom/p1275.c
12521 index e58b817..c27c30e4 100644
12522 --- a/arch/sparc/prom/p1275.c
12523 +++ b/arch/sparc/prom/p1275.c
12524 @@ -19,7 +19,6 @@
12525 struct {
12526 long prom_callback; /* 0x00 */
12527 void (*prom_cif_handler)(long *); /* 0x08 */
12528 - unsigned long prom_cif_stack; /* 0x10 */
12529 } p1275buf;
12530
12531 extern void prom_world(int);
12532 @@ -51,5 +50,4 @@ void p1275_cmd_direct(unsigned long *args)
12533 void prom_cif_init(void *cif_handler, void *cif_stack)
12534 {
12535 p1275buf.prom_cif_handler = (void (*)(long *))cif_handler;
12536 - p1275buf.prom_cif_stack = (unsigned long)cif_stack;
12537 }
12538 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12539 index 7fcd492..1311074 100644
12540 --- a/arch/tile/Kconfig
12541 +++ b/arch/tile/Kconfig
12542 @@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
12543
12544 config KEXEC
12545 bool "kexec system call"
12546 + depends on !GRKERNSEC_KMEM
12547 ---help---
12548 kexec is a system call that implements the ability to shutdown your
12549 current kernel, and to start another kernel. It is like a reboot
12550 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12551 index 7b11c5f..755a026 100644
12552 --- a/arch/tile/include/asm/atomic_64.h
12553 +++ b/arch/tile/include/asm/atomic_64.h
12554 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12555
12556 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12557
12558 +#define atomic64_read_unchecked(v) atomic64_read(v)
12559 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12560 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12561 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12562 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12563 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12564 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12565 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12566 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12567 +
12568 /* Define this to indicate that cmpxchg is an efficient operation. */
12569 #define __HAVE_ARCH_CMPXCHG
12570
12571 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12572 index 6160761..00cac88 100644
12573 --- a/arch/tile/include/asm/cache.h
12574 +++ b/arch/tile/include/asm/cache.h
12575 @@ -15,11 +15,12 @@
12576 #ifndef _ASM_TILE_CACHE_H
12577 #define _ASM_TILE_CACHE_H
12578
12579 +#include <linux/const.h>
12580 #include <arch/chip.h>
12581
12582 /* bytes per L1 data cache line */
12583 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12584 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12585 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12586
12587 /* bytes per L2 cache line */
12588 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12589 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12590 index b6cde32..c0cb736 100644
12591 --- a/arch/tile/include/asm/uaccess.h
12592 +++ b/arch/tile/include/asm/uaccess.h
12593 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12594 const void __user *from,
12595 unsigned long n)
12596 {
12597 - int sz = __compiletime_object_size(to);
12598 + size_t sz = __compiletime_object_size(to);
12599
12600 - if (likely(sz == -1 || sz >= n))
12601 + if (likely(sz == (size_t)-1 || sz >= n))
12602 n = _copy_from_user(to, from, n);
12603 else
12604 copy_from_user_overflow();
12605 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12606 index e514899..f8743c4 100644
12607 --- a/arch/tile/mm/hugetlbpage.c
12608 +++ b/arch/tile/mm/hugetlbpage.c
12609 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12610 info.high_limit = TASK_SIZE;
12611 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12612 info.align_offset = 0;
12613 + info.threadstack_offset = 0;
12614 return vm_unmapped_area(&info);
12615 }
12616
12617 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12618 info.high_limit = current->mm->mmap_base;
12619 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12620 info.align_offset = 0;
12621 + info.threadstack_offset = 0;
12622 addr = vm_unmapped_area(&info);
12623
12624 /*
12625 diff --git a/arch/um/Makefile b/arch/um/Makefile
12626 index e4b1a96..16162f8 100644
12627 --- a/arch/um/Makefile
12628 +++ b/arch/um/Makefile
12629 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12630 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12631 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12632
12633 +ifdef CONSTIFY_PLUGIN
12634 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12635 +endif
12636 +
12637 #This will adjust *FLAGS accordingly to the platform.
12638 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12639
12640 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12641 index 19e1bdd..3665b77 100644
12642 --- a/arch/um/include/asm/cache.h
12643 +++ b/arch/um/include/asm/cache.h
12644 @@ -1,6 +1,7 @@
12645 #ifndef __UM_CACHE_H
12646 #define __UM_CACHE_H
12647
12648 +#include <linux/const.h>
12649
12650 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12651 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12652 @@ -12,6 +13,6 @@
12653 # define L1_CACHE_SHIFT 5
12654 #endif
12655
12656 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12657 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12658
12659 #endif
12660 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12661 index 2e0a6b1..a64d0f5 100644
12662 --- a/arch/um/include/asm/kmap_types.h
12663 +++ b/arch/um/include/asm/kmap_types.h
12664 @@ -8,6 +8,6 @@
12665
12666 /* No more #include "asm/arch/kmap_types.h" ! */
12667
12668 -#define KM_TYPE_NR 14
12669 +#define KM_TYPE_NR 15
12670
12671 #endif
12672 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12673 index 71c5d13..4c7b9f1 100644
12674 --- a/arch/um/include/asm/page.h
12675 +++ b/arch/um/include/asm/page.h
12676 @@ -14,6 +14,9 @@
12677 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12678 #define PAGE_MASK (~(PAGE_SIZE-1))
12679
12680 +#define ktla_ktva(addr) (addr)
12681 +#define ktva_ktla(addr) (addr)
12682 +
12683 #ifndef __ASSEMBLY__
12684
12685 struct page;
12686 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12687 index 0032f92..cd151e0 100644
12688 --- a/arch/um/include/asm/pgtable-3level.h
12689 +++ b/arch/um/include/asm/pgtable-3level.h
12690 @@ -58,6 +58,7 @@
12691 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12692 #define pud_populate(mm, pud, pmd) \
12693 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12694 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12695
12696 #ifdef CONFIG_64BIT
12697 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12698 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12699 index f17bca8..48adb87 100644
12700 --- a/arch/um/kernel/process.c
12701 +++ b/arch/um/kernel/process.c
12702 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12703 return 2;
12704 }
12705
12706 -/*
12707 - * Only x86 and x86_64 have an arch_align_stack().
12708 - * All other arches have "#define arch_align_stack(x) (x)"
12709 - * in their asm/exec.h
12710 - * As this is included in UML from asm-um/system-generic.h,
12711 - * we can use it to behave as the subarch does.
12712 - */
12713 -#ifndef arch_align_stack
12714 -unsigned long arch_align_stack(unsigned long sp)
12715 -{
12716 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12717 - sp -= get_random_int() % 8192;
12718 - return sp & ~0xf;
12719 -}
12720 -#endif
12721 -
12722 unsigned long get_wchan(struct task_struct *p)
12723 {
12724 unsigned long stack_page, sp, ip;
12725 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12726 index ad8f795..2c7eec6 100644
12727 --- a/arch/unicore32/include/asm/cache.h
12728 +++ b/arch/unicore32/include/asm/cache.h
12729 @@ -12,8 +12,10 @@
12730 #ifndef __UNICORE_CACHE_H__
12731 #define __UNICORE_CACHE_H__
12732
12733 -#define L1_CACHE_SHIFT (5)
12734 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12735 +#include <linux/const.h>
12736 +
12737 +#define L1_CACHE_SHIFT 5
12738 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12739
12740 /*
12741 * Memory returned by kmalloc() may be used for DMA, so we must make
12742 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12743 index 3632743..630a8bb 100644
12744 --- a/arch/x86/Kconfig
12745 +++ b/arch/x86/Kconfig
12746 @@ -130,7 +130,7 @@ config X86
12747 select RTC_LIB
12748 select HAVE_DEBUG_STACKOVERFLOW
12749 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12750 - select HAVE_CC_STACKPROTECTOR
12751 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12752 select GENERIC_CPU_AUTOPROBE
12753 select HAVE_ARCH_AUDITSYSCALL
12754 select ARCH_SUPPORTS_ATOMIC_RMW
12755 @@ -258,7 +258,7 @@ config X86_HT
12756
12757 config X86_32_LAZY_GS
12758 def_bool y
12759 - depends on X86_32 && !CC_STACKPROTECTOR
12760 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12761
12762 config ARCH_HWEIGHT_CFLAGS
12763 string
12764 @@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
12765
12766 menuconfig HYPERVISOR_GUEST
12767 bool "Linux guest support"
12768 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12769 ---help---
12770 Say Y here to enable options for running Linux under various hyper-
12771 visors. This option enables basic hypervisor detection and platform
12772 @@ -1083,6 +1084,7 @@ choice
12773
12774 config NOHIGHMEM
12775 bool "off"
12776 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12777 ---help---
12778 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12779 However, the address space of 32-bit x86 processors is only 4
12780 @@ -1119,6 +1121,7 @@ config NOHIGHMEM
12781
12782 config HIGHMEM4G
12783 bool "4GB"
12784 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12785 ---help---
12786 Select this if you have a 32-bit processor and between 1 and 4
12787 gigabytes of physical RAM.
12788 @@ -1171,7 +1174,7 @@ config PAGE_OFFSET
12789 hex
12790 default 0xB0000000 if VMSPLIT_3G_OPT
12791 default 0x80000000 if VMSPLIT_2G
12792 - default 0x78000000 if VMSPLIT_2G_OPT
12793 + default 0x70000000 if VMSPLIT_2G_OPT
12794 default 0x40000000 if VMSPLIT_1G
12795 default 0xC0000000
12796 depends on X86_32
12797 @@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
12798
12799 config KEXEC
12800 bool "kexec system call"
12801 + depends on !GRKERNSEC_KMEM
12802 ---help---
12803 kexec is a system call that implements the ability to shutdown your
12804 current kernel, and to start another kernel. It is like a reboot
12805 @@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
12806
12807 config PHYSICAL_ALIGN
12808 hex "Alignment value to which kernel should be aligned"
12809 - default "0x200000"
12810 + default "0x1000000"
12811 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12812 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12813 range 0x2000 0x1000000 if X86_32
12814 range 0x200000 0x1000000 if X86_64
12815 ---help---
12816 @@ -1854,6 +1860,7 @@ config COMPAT_VDSO
12817 def_bool n
12818 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12819 depends on X86_32 || IA32_EMULATION
12820 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12821 ---help---
12822 Certain buggy versions of glibc will crash if they are
12823 presented with a 32-bit vDSO that is not mapped at the address
12824 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12825 index 6983314..54ad7e8 100644
12826 --- a/arch/x86/Kconfig.cpu
12827 +++ b/arch/x86/Kconfig.cpu
12828 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12829
12830 config X86_F00F_BUG
12831 def_bool y
12832 - depends on M586MMX || M586TSC || M586 || M486
12833 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12834
12835 config X86_INVD_BUG
12836 def_bool y
12837 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12838
12839 config X86_ALIGNMENT_16
12840 def_bool y
12841 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12842 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12843
12844 config X86_INTEL_USERCOPY
12845 def_bool y
12846 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12847 # generates cmov.
12848 config X86_CMOV
12849 def_bool y
12850 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12851 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12852
12853 config X86_MINIMUM_CPU_FAMILY
12854 int
12855 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12856 index 61bd2ad..50b625d 100644
12857 --- a/arch/x86/Kconfig.debug
12858 +++ b/arch/x86/Kconfig.debug
12859 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12860 config DEBUG_RODATA
12861 bool "Write protect kernel read-only data structures"
12862 default y
12863 - depends on DEBUG_KERNEL
12864 + depends on DEBUG_KERNEL && BROKEN
12865 ---help---
12866 Mark the kernel read-only data as write-protected in the pagetables,
12867 in order to catch accidental (and incorrect) writes to such const
12868 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12869
12870 config DEBUG_SET_MODULE_RONX
12871 bool "Set loadable kernel module data as NX and text as RO"
12872 - depends on MODULES
12873 + depends on MODULES && BROKEN
12874 ---help---
12875 This option helps catch unintended modifications to loadable
12876 kernel module's text and read-only data. It also prevents execution
12877 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12878 index 60087ca..9d9500e 100644
12879 --- a/arch/x86/Makefile
12880 +++ b/arch/x86/Makefile
12881 @@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
12882 # CPU-specific tuning. Anything which can be shared with UML should go here.
12883 include $(srctree)/arch/x86/Makefile_32.cpu
12884 KBUILD_CFLAGS += $(cflags-y)
12885 -
12886 - # temporary until string.h is fixed
12887 - KBUILD_CFLAGS += -ffreestanding
12888 else
12889 BITS := 64
12890 UTS_MACHINE := x86_64
12891 @@ -111,6 +108,9 @@ else
12892 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12893 endif
12894
12895 +# temporary until string.h is fixed
12896 +KBUILD_CFLAGS += -ffreestanding
12897 +
12898 # Make sure compiler does not have buggy stack-protector support.
12899 ifdef CONFIG_CC_STACKPROTECTOR
12900 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12901 @@ -184,6 +184,7 @@ archheaders:
12902 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12903
12904 archprepare:
12905 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12906 ifeq ($(CONFIG_KEXEC_FILE),y)
12907 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12908 endif
12909 @@ -274,3 +275,9 @@ define archhelp
12910 echo ' FDINITRD=file initrd for the booted kernel'
12911 echo ' kvmconfig - Enable additional options for guest kernel support'
12912 endef
12913 +
12914 +define OLD_LD
12915 +
12916 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12917 +*** Please upgrade your binutils to 2.18 or newer
12918 +endef
12919 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12920 index dbe8dd2..2f0a98f 100644
12921 --- a/arch/x86/boot/Makefile
12922 +++ b/arch/x86/boot/Makefile
12923 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12924 # ---------------------------------------------------------------------------
12925
12926 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12927 +ifdef CONSTIFY_PLUGIN
12928 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12929 +endif
12930 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12931 GCOV_PROFILE := n
12932
12933 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12934 index 878e4b9..20537ab 100644
12935 --- a/arch/x86/boot/bitops.h
12936 +++ b/arch/x86/boot/bitops.h
12937 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12938 u8 v;
12939 const u32 *p = (const u32 *)addr;
12940
12941 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12942 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12943 return v;
12944 }
12945
12946 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12947
12948 static inline void set_bit(int nr, void *addr)
12949 {
12950 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12951 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12952 }
12953
12954 #endif /* BOOT_BITOPS_H */
12955 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12956 index bd49ec6..94c7f58 100644
12957 --- a/arch/x86/boot/boot.h
12958 +++ b/arch/x86/boot/boot.h
12959 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12960 static inline u16 ds(void)
12961 {
12962 u16 seg;
12963 - asm("movw %%ds,%0" : "=rm" (seg));
12964 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12965 return seg;
12966 }
12967
12968 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12969 index 0fcd913..3bb5c42 100644
12970 --- a/arch/x86/boot/compressed/Makefile
12971 +++ b/arch/x86/boot/compressed/Makefile
12972 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12973 KBUILD_CFLAGS += -mno-mmx -mno-sse
12974 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12975 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12976 +ifdef CONSTIFY_PLUGIN
12977 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12978 +endif
12979
12980 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12981 GCOV_PROFILE := n
12982 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12983 index a53440e..c3dbf1e 100644
12984 --- a/arch/x86/boot/compressed/efi_stub_32.S
12985 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12986 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12987 * parameter 2, ..., param n. To make things easy, we save the return
12988 * address of efi_call_phys in a global variable.
12989 */
12990 - popl %ecx
12991 - movl %ecx, saved_return_addr(%edx)
12992 - /* get the function pointer into ECX*/
12993 - popl %ecx
12994 - movl %ecx, efi_rt_function_ptr(%edx)
12995 + popl saved_return_addr(%edx)
12996 + popl efi_rt_function_ptr(%edx)
12997
12998 /*
12999 * 3. Call the physical function.
13000 */
13001 - call *%ecx
13002 + call *efi_rt_function_ptr(%edx)
13003
13004 /*
13005 * 4. Balance the stack. And because EAX contain the return value,
13006 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13007 1: popl %edx
13008 subl $1b, %edx
13009
13010 - movl efi_rt_function_ptr(%edx), %ecx
13011 - pushl %ecx
13012 + pushl efi_rt_function_ptr(%edx)
13013
13014 /*
13015 * 10. Push the saved return address onto the stack and return.
13016 */
13017 - movl saved_return_addr(%edx), %ecx
13018 - pushl %ecx
13019 - ret
13020 + jmpl *saved_return_addr(%edx)
13021 ENDPROC(efi_call_phys)
13022 .previous
13023
13024 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13025 index cbed140..5f2ca57 100644
13026 --- a/arch/x86/boot/compressed/head_32.S
13027 +++ b/arch/x86/boot/compressed/head_32.S
13028 @@ -140,10 +140,10 @@ preferred_addr:
13029 addl %eax, %ebx
13030 notl %eax
13031 andl %eax, %ebx
13032 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13033 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13034 jge 1f
13035 #endif
13036 - movl $LOAD_PHYSICAL_ADDR, %ebx
13037 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13038 1:
13039
13040 /* Target address to relocate to for decompression */
13041 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13042 index 2884e0c..904a2f7 100644
13043 --- a/arch/x86/boot/compressed/head_64.S
13044 +++ b/arch/x86/boot/compressed/head_64.S
13045 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13046 addl %eax, %ebx
13047 notl %eax
13048 andl %eax, %ebx
13049 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13050 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13051 jge 1f
13052 #endif
13053 - movl $LOAD_PHYSICAL_ADDR, %ebx
13054 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13055 1:
13056
13057 /* Target address to relocate to for decompression */
13058 @@ -322,10 +322,10 @@ preferred_addr:
13059 addq %rax, %rbp
13060 notq %rax
13061 andq %rax, %rbp
13062 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13063 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13064 jge 1f
13065 #endif
13066 - movq $LOAD_PHYSICAL_ADDR, %rbp
13067 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13068 1:
13069
13070 /* Target address to relocate to for decompression */
13071 @@ -431,8 +431,8 @@ gdt:
13072 .long gdt
13073 .word 0
13074 .quad 0x0000000000000000 /* NULL descriptor */
13075 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13076 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13077 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13078 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13079 .quad 0x0080890000000000 /* TS descriptor */
13080 .quad 0x0000000000000000 /* TS continued */
13081 gdt_end:
13082 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13083 index 57ab74d..7c52182 100644
13084 --- a/arch/x86/boot/compressed/misc.c
13085 +++ b/arch/x86/boot/compressed/misc.c
13086 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13087 * Calculate the delta between where vmlinux was linked to load
13088 * and where it was actually loaded.
13089 */
13090 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13091 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13092 if (!delta) {
13093 debug_putstr("No relocation needed... ");
13094 return;
13095 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13096 Elf32_Ehdr ehdr;
13097 Elf32_Phdr *phdrs, *phdr;
13098 #endif
13099 - void *dest;
13100 + void *dest, *prev;
13101 int i;
13102
13103 memcpy(&ehdr, output, sizeof(ehdr));
13104 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13105 case PT_LOAD:
13106 #ifdef CONFIG_RELOCATABLE
13107 dest = output;
13108 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13109 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13110 #else
13111 dest = (void *)(phdr->p_paddr);
13112 #endif
13113 memcpy(dest,
13114 output + phdr->p_offset,
13115 phdr->p_filesz);
13116 + if (i)
13117 + memset(prev, 0xff, dest - prev);
13118 + prev = dest + phdr->p_filesz;
13119 break;
13120 default: /* Ignore other PT_* */ break;
13121 }
13122 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13123 error("Destination address too large");
13124 #endif
13125 #ifndef CONFIG_RELOCATABLE
13126 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13127 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13128 error("Wrong destination address");
13129 #endif
13130
13131 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13132 index 1fd7d57..0f7d096 100644
13133 --- a/arch/x86/boot/cpucheck.c
13134 +++ b/arch/x86/boot/cpucheck.c
13135 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13136 u32 ecx = MSR_K7_HWCR;
13137 u32 eax, edx;
13138
13139 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13140 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13141 eax &= ~(1 << 15);
13142 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13143 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13144
13145 get_cpuflags(); /* Make sure it really did something */
13146 err = check_cpuflags();
13147 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13148 u32 ecx = MSR_VIA_FCR;
13149 u32 eax, edx;
13150
13151 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13152 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13153 eax |= (1<<1)|(1<<7);
13154 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13155 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13156
13157 set_bit(X86_FEATURE_CX8, cpu.flags);
13158 err = check_cpuflags();
13159 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13160 u32 eax, edx;
13161 u32 level = 1;
13162
13163 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13164 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13165 - asm("cpuid"
13166 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13167 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13168 + asm volatile("cpuid"
13169 : "+a" (level), "=d" (cpu.flags[0])
13170 : : "ecx", "ebx");
13171 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13172 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13173
13174 err = check_cpuflags();
13175 } else if (err == 0x01 &&
13176 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13177 index 16ef025..91e033b 100644
13178 --- a/arch/x86/boot/header.S
13179 +++ b/arch/x86/boot/header.S
13180 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13181 # single linked list of
13182 # struct setup_data
13183
13184 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13185 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13186
13187 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13188 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13189 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13190 +#else
13191 #define VO_INIT_SIZE (VO__end - VO__text)
13192 +#endif
13193 #if ZO_INIT_SIZE > VO_INIT_SIZE
13194 #define INIT_SIZE ZO_INIT_SIZE
13195 #else
13196 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13197 index db75d07..8e6d0af 100644
13198 --- a/arch/x86/boot/memory.c
13199 +++ b/arch/x86/boot/memory.c
13200 @@ -19,7 +19,7 @@
13201
13202 static int detect_memory_e820(void)
13203 {
13204 - int count = 0;
13205 + unsigned int count = 0;
13206 struct biosregs ireg, oreg;
13207 struct e820entry *desc = boot_params.e820_map;
13208 static struct e820entry buf; /* static so it is zeroed */
13209 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13210 index ba3e100..6501b8f 100644
13211 --- a/arch/x86/boot/video-vesa.c
13212 +++ b/arch/x86/boot/video-vesa.c
13213 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13214
13215 boot_params.screen_info.vesapm_seg = oreg.es;
13216 boot_params.screen_info.vesapm_off = oreg.di;
13217 + boot_params.screen_info.vesapm_size = oreg.cx;
13218 }
13219
13220 /*
13221 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13222 index 43eda28..5ab5fdb 100644
13223 --- a/arch/x86/boot/video.c
13224 +++ b/arch/x86/boot/video.c
13225 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13226 static unsigned int get_entry(void)
13227 {
13228 char entry_buf[4];
13229 - int i, len = 0;
13230 + unsigned int i, len = 0;
13231 int key;
13232 unsigned int v;
13233
13234 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13235 index 9105655..41779c1 100644
13236 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13237 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13238 @@ -8,6 +8,8 @@
13239 * including this sentence is retained in full.
13240 */
13241
13242 +#include <asm/alternative-asm.h>
13243 +
13244 .extern crypto_ft_tab
13245 .extern crypto_it_tab
13246 .extern crypto_fl_tab
13247 @@ -70,6 +72,8 @@
13248 je B192; \
13249 leaq 32(r9),r9;
13250
13251 +#define ret pax_force_retaddr; ret
13252 +
13253 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13254 movq r1,r2; \
13255 movq r3,r4; \
13256 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13257 index 477e9d7..c92c7d8 100644
13258 --- a/arch/x86/crypto/aesni-intel_asm.S
13259 +++ b/arch/x86/crypto/aesni-intel_asm.S
13260 @@ -31,6 +31,7 @@
13261
13262 #include <linux/linkage.h>
13263 #include <asm/inst.h>
13264 +#include <asm/alternative-asm.h>
13265
13266 #ifdef __x86_64__
13267 .data
13268 @@ -205,7 +206,7 @@ enc: .octa 0x2
13269 * num_initial_blocks = b mod 4
13270 * encrypt the initial num_initial_blocks blocks and apply ghash on
13271 * the ciphertext
13272 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13273 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13274 * are clobbered
13275 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13276 */
13277 @@ -214,8 +215,8 @@ enc: .octa 0x2
13278 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13279 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13280 mov arg7, %r10 # %r10 = AAD
13281 - mov arg8, %r12 # %r12 = aadLen
13282 - mov %r12, %r11
13283 + mov arg8, %r15 # %r15 = aadLen
13284 + mov %r15, %r11
13285 pxor %xmm\i, %xmm\i
13286 _get_AAD_loop\num_initial_blocks\operation:
13287 movd (%r10), \TMP1
13288 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13289 psrldq $4, %xmm\i
13290 pxor \TMP1, %xmm\i
13291 add $4, %r10
13292 - sub $4, %r12
13293 + sub $4, %r15
13294 jne _get_AAD_loop\num_initial_blocks\operation
13295 cmp $16, %r11
13296 je _get_AAD_loop2_done\num_initial_blocks\operation
13297 - mov $16, %r12
13298 + mov $16, %r15
13299 _get_AAD_loop2\num_initial_blocks\operation:
13300 psrldq $4, %xmm\i
13301 - sub $4, %r12
13302 - cmp %r11, %r12
13303 + sub $4, %r15
13304 + cmp %r11, %r15
13305 jne _get_AAD_loop2\num_initial_blocks\operation
13306 _get_AAD_loop2_done\num_initial_blocks\operation:
13307 movdqa SHUF_MASK(%rip), %xmm14
13308 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13309 * num_initial_blocks = b mod 4
13310 * encrypt the initial num_initial_blocks blocks and apply ghash on
13311 * the ciphertext
13312 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13313 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13314 * are clobbered
13315 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13316 */
13317 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13318 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13319 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13320 mov arg7, %r10 # %r10 = AAD
13321 - mov arg8, %r12 # %r12 = aadLen
13322 - mov %r12, %r11
13323 + mov arg8, %r15 # %r15 = aadLen
13324 + mov %r15, %r11
13325 pxor %xmm\i, %xmm\i
13326 _get_AAD_loop\num_initial_blocks\operation:
13327 movd (%r10), \TMP1
13328 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13329 psrldq $4, %xmm\i
13330 pxor \TMP1, %xmm\i
13331 add $4, %r10
13332 - sub $4, %r12
13333 + sub $4, %r15
13334 jne _get_AAD_loop\num_initial_blocks\operation
13335 cmp $16, %r11
13336 je _get_AAD_loop2_done\num_initial_blocks\operation
13337 - mov $16, %r12
13338 + mov $16, %r15
13339 _get_AAD_loop2\num_initial_blocks\operation:
13340 psrldq $4, %xmm\i
13341 - sub $4, %r12
13342 - cmp %r11, %r12
13343 + sub $4, %r15
13344 + cmp %r11, %r15
13345 jne _get_AAD_loop2\num_initial_blocks\operation
13346 _get_AAD_loop2_done\num_initial_blocks\operation:
13347 movdqa SHUF_MASK(%rip), %xmm14
13348 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13349 *
13350 *****************************************************************************/
13351 ENTRY(aesni_gcm_dec)
13352 - push %r12
13353 + push %r15
13354 push %r13
13355 push %r14
13356 mov %rsp, %r14
13357 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13358 */
13359 sub $VARIABLE_OFFSET, %rsp
13360 and $~63, %rsp # align rsp to 64 bytes
13361 - mov %arg6, %r12
13362 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13363 + mov %arg6, %r15
13364 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13365 movdqa SHUF_MASK(%rip), %xmm2
13366 PSHUFB_XMM %xmm2, %xmm13
13367
13368 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13369 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13370 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13371 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13372 - mov %r13, %r12
13373 - and $(3<<4), %r12
13374 + mov %r13, %r15
13375 + and $(3<<4), %r15
13376 jz _initial_num_blocks_is_0_decrypt
13377 - cmp $(2<<4), %r12
13378 + cmp $(2<<4), %r15
13379 jb _initial_num_blocks_is_1_decrypt
13380 je _initial_num_blocks_is_2_decrypt
13381 _initial_num_blocks_is_3_decrypt:
13382 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13383 sub $16, %r11
13384 add %r13, %r11
13385 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13386 - lea SHIFT_MASK+16(%rip), %r12
13387 - sub %r13, %r12
13388 + lea SHIFT_MASK+16(%rip), %r15
13389 + sub %r13, %r15
13390 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13391 # (%r13 is the number of bytes in plaintext mod 16)
13392 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13393 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13394 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13395
13396 movdqa %xmm1, %xmm2
13397 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13398 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13399 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13400 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13401 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13402 pand %xmm1, %xmm2
13403 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13404 sub $1, %r13
13405 jne _less_than_8_bytes_left_decrypt
13406 _multiple_of_16_bytes_decrypt:
13407 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13408 - shl $3, %r12 # convert into number of bits
13409 - movd %r12d, %xmm15 # len(A) in %xmm15
13410 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13411 + shl $3, %r15 # convert into number of bits
13412 + movd %r15d, %xmm15 # len(A) in %xmm15
13413 shl $3, %arg4 # len(C) in bits (*128)
13414 MOVQ_R64_XMM %arg4, %xmm1
13415 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13416 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13417 mov %r14, %rsp
13418 pop %r14
13419 pop %r13
13420 - pop %r12
13421 + pop %r15
13422 + pax_force_retaddr
13423 ret
13424 ENDPROC(aesni_gcm_dec)
13425
13426 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13427 * poly = x^128 + x^127 + x^126 + x^121 + 1
13428 ***************************************************************************/
13429 ENTRY(aesni_gcm_enc)
13430 - push %r12
13431 + push %r15
13432 push %r13
13433 push %r14
13434 mov %rsp, %r14
13435 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13436 #
13437 sub $VARIABLE_OFFSET, %rsp
13438 and $~63, %rsp
13439 - mov %arg6, %r12
13440 - movdqu (%r12), %xmm13
13441 + mov %arg6, %r15
13442 + movdqu (%r15), %xmm13
13443 movdqa SHUF_MASK(%rip), %xmm2
13444 PSHUFB_XMM %xmm2, %xmm13
13445
13446 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13447 movdqa %xmm13, HashKey(%rsp)
13448 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13449 and $-16, %r13
13450 - mov %r13, %r12
13451 + mov %r13, %r15
13452
13453 # Encrypt first few blocks
13454
13455 - and $(3<<4), %r12
13456 + and $(3<<4), %r15
13457 jz _initial_num_blocks_is_0_encrypt
13458 - cmp $(2<<4), %r12
13459 + cmp $(2<<4), %r15
13460 jb _initial_num_blocks_is_1_encrypt
13461 je _initial_num_blocks_is_2_encrypt
13462 _initial_num_blocks_is_3_encrypt:
13463 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13464 sub $16, %r11
13465 add %r13, %r11
13466 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13467 - lea SHIFT_MASK+16(%rip), %r12
13468 - sub %r13, %r12
13469 + lea SHIFT_MASK+16(%rip), %r15
13470 + sub %r13, %r15
13471 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13472 # (%r13 is the number of bytes in plaintext mod 16)
13473 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13474 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13475 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13476 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13477 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13478 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13479 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13480 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13481 movdqa SHUF_MASK(%rip), %xmm10
13482 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13483 sub $1, %r13
13484 jne _less_than_8_bytes_left_encrypt
13485 _multiple_of_16_bytes_encrypt:
13486 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13487 - shl $3, %r12
13488 - movd %r12d, %xmm15 # len(A) in %xmm15
13489 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13490 + shl $3, %r15
13491 + movd %r15d, %xmm15 # len(A) in %xmm15
13492 shl $3, %arg4 # len(C) in bits (*128)
13493 MOVQ_R64_XMM %arg4, %xmm1
13494 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13495 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13496 mov %r14, %rsp
13497 pop %r14
13498 pop %r13
13499 - pop %r12
13500 + pop %r15
13501 + pax_force_retaddr
13502 ret
13503 ENDPROC(aesni_gcm_enc)
13504
13505 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13506 pxor %xmm1, %xmm0
13507 movaps %xmm0, (TKEYP)
13508 add $0x10, TKEYP
13509 + pax_force_retaddr
13510 ret
13511 ENDPROC(_key_expansion_128)
13512 ENDPROC(_key_expansion_256a)
13513 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13514 shufps $0b01001110, %xmm2, %xmm1
13515 movaps %xmm1, 0x10(TKEYP)
13516 add $0x20, TKEYP
13517 + pax_force_retaddr
13518 ret
13519 ENDPROC(_key_expansion_192a)
13520
13521 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13522
13523 movaps %xmm0, (TKEYP)
13524 add $0x10, TKEYP
13525 + pax_force_retaddr
13526 ret
13527 ENDPROC(_key_expansion_192b)
13528
13529 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13530 pxor %xmm1, %xmm2
13531 movaps %xmm2, (TKEYP)
13532 add $0x10, TKEYP
13533 + pax_force_retaddr
13534 ret
13535 ENDPROC(_key_expansion_256b)
13536
13537 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13538 #ifndef __x86_64__
13539 popl KEYP
13540 #endif
13541 + pax_force_retaddr
13542 ret
13543 ENDPROC(aesni_set_key)
13544
13545 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13546 popl KLEN
13547 popl KEYP
13548 #endif
13549 + pax_force_retaddr
13550 ret
13551 ENDPROC(aesni_enc)
13552
13553 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13554 AESENC KEY STATE
13555 movaps 0x70(TKEYP), KEY
13556 AESENCLAST KEY STATE
13557 + pax_force_retaddr
13558 ret
13559 ENDPROC(_aesni_enc1)
13560
13561 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13562 AESENCLAST KEY STATE2
13563 AESENCLAST KEY STATE3
13564 AESENCLAST KEY STATE4
13565 + pax_force_retaddr
13566 ret
13567 ENDPROC(_aesni_enc4)
13568
13569 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13570 popl KLEN
13571 popl KEYP
13572 #endif
13573 + pax_force_retaddr
13574 ret
13575 ENDPROC(aesni_dec)
13576
13577 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13578 AESDEC KEY STATE
13579 movaps 0x70(TKEYP), KEY
13580 AESDECLAST KEY STATE
13581 + pax_force_retaddr
13582 ret
13583 ENDPROC(_aesni_dec1)
13584
13585 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13586 AESDECLAST KEY STATE2
13587 AESDECLAST KEY STATE3
13588 AESDECLAST KEY STATE4
13589 + pax_force_retaddr
13590 ret
13591 ENDPROC(_aesni_dec4)
13592
13593 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13594 popl KEYP
13595 popl LEN
13596 #endif
13597 + pax_force_retaddr
13598 ret
13599 ENDPROC(aesni_ecb_enc)
13600
13601 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13602 popl KEYP
13603 popl LEN
13604 #endif
13605 + pax_force_retaddr
13606 ret
13607 ENDPROC(aesni_ecb_dec)
13608
13609 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13610 popl LEN
13611 popl IVP
13612 #endif
13613 + pax_force_retaddr
13614 ret
13615 ENDPROC(aesni_cbc_enc)
13616
13617 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13618 popl LEN
13619 popl IVP
13620 #endif
13621 + pax_force_retaddr
13622 ret
13623 ENDPROC(aesni_cbc_dec)
13624
13625 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13626 mov $1, TCTR_LOW
13627 MOVQ_R64_XMM TCTR_LOW INC
13628 MOVQ_R64_XMM CTR TCTR_LOW
13629 + pax_force_retaddr
13630 ret
13631 ENDPROC(_aesni_inc_init)
13632
13633 @@ -2579,6 +2598,7 @@ _aesni_inc:
13634 .Linc_low:
13635 movaps CTR, IV
13636 PSHUFB_XMM BSWAP_MASK IV
13637 + pax_force_retaddr
13638 ret
13639 ENDPROC(_aesni_inc)
13640
13641 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13642 .Lctr_enc_ret:
13643 movups IV, (IVP)
13644 .Lctr_enc_just_ret:
13645 + pax_force_retaddr
13646 ret
13647 ENDPROC(aesni_ctr_enc)
13648
13649 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13650 pxor INC, STATE4
13651 movdqu STATE4, 0x70(OUTP)
13652
13653 + pax_force_retaddr
13654 ret
13655 ENDPROC(aesni_xts_crypt8)
13656
13657 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13658 index 246c670..466e2d6 100644
13659 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13660 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13661 @@ -21,6 +21,7 @@
13662 */
13663
13664 #include <linux/linkage.h>
13665 +#include <asm/alternative-asm.h>
13666
13667 .file "blowfish-x86_64-asm.S"
13668 .text
13669 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13670 jnz .L__enc_xor;
13671
13672 write_block();
13673 + pax_force_retaddr
13674 ret;
13675 .L__enc_xor:
13676 xor_block();
13677 + pax_force_retaddr
13678 ret;
13679 ENDPROC(__blowfish_enc_blk)
13680
13681 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13682
13683 movq %r11, %rbp;
13684
13685 + pax_force_retaddr
13686 ret;
13687 ENDPROC(blowfish_dec_blk)
13688
13689 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13690
13691 popq %rbx;
13692 popq %rbp;
13693 + pax_force_retaddr
13694 ret;
13695
13696 .L__enc_xor4:
13697 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13698
13699 popq %rbx;
13700 popq %rbp;
13701 + pax_force_retaddr
13702 ret;
13703 ENDPROC(__blowfish_enc_blk_4way)
13704
13705 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13706 popq %rbx;
13707 popq %rbp;
13708
13709 + pax_force_retaddr
13710 ret;
13711 ENDPROC(blowfish_dec_blk_4way)
13712 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13713 index ce71f92..1dce7ec 100644
13714 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13715 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13716 @@ -16,6 +16,7 @@
13717 */
13718
13719 #include <linux/linkage.h>
13720 +#include <asm/alternative-asm.h>
13721
13722 #define CAMELLIA_TABLE_BYTE_LEN 272
13723
13724 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13725 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13726 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13727 %rcx, (%r9));
13728 + pax_force_retaddr
13729 ret;
13730 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13731
13732 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13733 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13734 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13735 %rax, (%r9));
13736 + pax_force_retaddr
13737 ret;
13738 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13739
13740 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13741 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13742 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13743
13744 + pax_force_retaddr
13745 ret;
13746
13747 .align 8
13748 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13749 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13750 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13751
13752 + pax_force_retaddr
13753 ret;
13754
13755 .align 8
13756 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13757 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13758 %xmm8, %rsi);
13759
13760 + pax_force_retaddr
13761 ret;
13762 ENDPROC(camellia_ecb_enc_16way)
13763
13764 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13765 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13766 %xmm8, %rsi);
13767
13768 + pax_force_retaddr
13769 ret;
13770 ENDPROC(camellia_ecb_dec_16way)
13771
13772 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13773 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13774 %xmm8, %rsi);
13775
13776 + pax_force_retaddr
13777 ret;
13778 ENDPROC(camellia_cbc_dec_16way)
13779
13780 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13781 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13782 %xmm8, %rsi);
13783
13784 + pax_force_retaddr
13785 ret;
13786 ENDPROC(camellia_ctr_16way)
13787
13788 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13789 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13790 %xmm8, %rsi);
13791
13792 + pax_force_retaddr
13793 ret;
13794 ENDPROC(camellia_xts_crypt_16way)
13795
13796 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13797 index 0e0b886..5a3123c 100644
13798 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13799 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13800 @@ -11,6 +11,7 @@
13801 */
13802
13803 #include <linux/linkage.h>
13804 +#include <asm/alternative-asm.h>
13805
13806 #define CAMELLIA_TABLE_BYTE_LEN 272
13807
13808 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13809 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13810 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13811 %rcx, (%r9));
13812 + pax_force_retaddr
13813 ret;
13814 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13815
13816 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13817 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13818 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13819 %rax, (%r9));
13820 + pax_force_retaddr
13821 ret;
13822 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13823
13824 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13825 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13826 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13827
13828 + pax_force_retaddr
13829 ret;
13830
13831 .align 8
13832 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13833 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13834 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13835
13836 + pax_force_retaddr
13837 ret;
13838
13839 .align 8
13840 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13841
13842 vzeroupper;
13843
13844 + pax_force_retaddr
13845 ret;
13846 ENDPROC(camellia_ecb_enc_32way)
13847
13848 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13849
13850 vzeroupper;
13851
13852 + pax_force_retaddr
13853 ret;
13854 ENDPROC(camellia_ecb_dec_32way)
13855
13856 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13857
13858 vzeroupper;
13859
13860 + pax_force_retaddr
13861 ret;
13862 ENDPROC(camellia_cbc_dec_32way)
13863
13864 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13865
13866 vzeroupper;
13867
13868 + pax_force_retaddr
13869 ret;
13870 ENDPROC(camellia_ctr_32way)
13871
13872 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13873
13874 vzeroupper;
13875
13876 + pax_force_retaddr
13877 ret;
13878 ENDPROC(camellia_xts_crypt_32way)
13879
13880 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13881 index 310319c..db3d7b5 100644
13882 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13883 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13884 @@ -21,6 +21,7 @@
13885 */
13886
13887 #include <linux/linkage.h>
13888 +#include <asm/alternative-asm.h>
13889
13890 .file "camellia-x86_64-asm_64.S"
13891 .text
13892 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13893 enc_outunpack(mov, RT1);
13894
13895 movq RRBP, %rbp;
13896 + pax_force_retaddr
13897 ret;
13898
13899 .L__enc_xor:
13900 enc_outunpack(xor, RT1);
13901
13902 movq RRBP, %rbp;
13903 + pax_force_retaddr
13904 ret;
13905 ENDPROC(__camellia_enc_blk)
13906
13907 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13908 dec_outunpack();
13909
13910 movq RRBP, %rbp;
13911 + pax_force_retaddr
13912 ret;
13913 ENDPROC(camellia_dec_blk)
13914
13915 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13916
13917 movq RRBP, %rbp;
13918 popq %rbx;
13919 + pax_force_retaddr
13920 ret;
13921
13922 .L__enc2_xor:
13923 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13924
13925 movq RRBP, %rbp;
13926 popq %rbx;
13927 + pax_force_retaddr
13928 ret;
13929 ENDPROC(__camellia_enc_blk_2way)
13930
13931 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13932
13933 movq RRBP, %rbp;
13934 movq RXOR, %rbx;
13935 + pax_force_retaddr
13936 ret;
13937 ENDPROC(camellia_dec_blk_2way)
13938 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13939 index c35fd5d..2d8c7db 100644
13940 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13941 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13942 @@ -24,6 +24,7 @@
13943 */
13944
13945 #include <linux/linkage.h>
13946 +#include <asm/alternative-asm.h>
13947
13948 .file "cast5-avx-x86_64-asm_64.S"
13949
13950 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13951 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13952 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13953
13954 + pax_force_retaddr
13955 ret;
13956 ENDPROC(__cast5_enc_blk16)
13957
13958 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13959 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13960 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13961
13962 + pax_force_retaddr
13963 ret;
13964
13965 .L__skip_dec:
13966 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13967 vmovdqu RR4, (6*4*4)(%r11);
13968 vmovdqu RL4, (7*4*4)(%r11);
13969
13970 + pax_force_retaddr
13971 ret;
13972 ENDPROC(cast5_ecb_enc_16way)
13973
13974 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13975 vmovdqu RR4, (6*4*4)(%r11);
13976 vmovdqu RL4, (7*4*4)(%r11);
13977
13978 + pax_force_retaddr
13979 ret;
13980 ENDPROC(cast5_ecb_dec_16way)
13981
13982 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13983 * %rdx: src
13984 */
13985
13986 - pushq %r12;
13987 + pushq %r14;
13988
13989 movq %rsi, %r11;
13990 - movq %rdx, %r12;
13991 + movq %rdx, %r14;
13992
13993 vmovdqu (0*16)(%rdx), RL1;
13994 vmovdqu (1*16)(%rdx), RR1;
13995 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13996 call __cast5_dec_blk16;
13997
13998 /* xor with src */
13999 - vmovq (%r12), RX;
14000 + vmovq (%r14), RX;
14001 vpshufd $0x4f, RX, RX;
14002 vpxor RX, RR1, RR1;
14003 - vpxor 0*16+8(%r12), RL1, RL1;
14004 - vpxor 1*16+8(%r12), RR2, RR2;
14005 - vpxor 2*16+8(%r12), RL2, RL2;
14006 - vpxor 3*16+8(%r12), RR3, RR3;
14007 - vpxor 4*16+8(%r12), RL3, RL3;
14008 - vpxor 5*16+8(%r12), RR4, RR4;
14009 - vpxor 6*16+8(%r12), RL4, RL4;
14010 + vpxor 0*16+8(%r14), RL1, RL1;
14011 + vpxor 1*16+8(%r14), RR2, RR2;
14012 + vpxor 2*16+8(%r14), RL2, RL2;
14013 + vpxor 3*16+8(%r14), RR3, RR3;
14014 + vpxor 4*16+8(%r14), RL3, RL3;
14015 + vpxor 5*16+8(%r14), RR4, RR4;
14016 + vpxor 6*16+8(%r14), RL4, RL4;
14017
14018 vmovdqu RR1, (0*16)(%r11);
14019 vmovdqu RL1, (1*16)(%r11);
14020 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14021 vmovdqu RR4, (6*16)(%r11);
14022 vmovdqu RL4, (7*16)(%r11);
14023
14024 - popq %r12;
14025 + popq %r14;
14026
14027 + pax_force_retaddr
14028 ret;
14029 ENDPROC(cast5_cbc_dec_16way)
14030
14031 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14032 * %rcx: iv (big endian, 64bit)
14033 */
14034
14035 - pushq %r12;
14036 + pushq %r14;
14037
14038 movq %rsi, %r11;
14039 - movq %rdx, %r12;
14040 + movq %rdx, %r14;
14041
14042 vpcmpeqd RTMP, RTMP, RTMP;
14043 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14044 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14045 call __cast5_enc_blk16;
14046
14047 /* dst = src ^ iv */
14048 - vpxor (0*16)(%r12), RR1, RR1;
14049 - vpxor (1*16)(%r12), RL1, RL1;
14050 - vpxor (2*16)(%r12), RR2, RR2;
14051 - vpxor (3*16)(%r12), RL2, RL2;
14052 - vpxor (4*16)(%r12), RR3, RR3;
14053 - vpxor (5*16)(%r12), RL3, RL3;
14054 - vpxor (6*16)(%r12), RR4, RR4;
14055 - vpxor (7*16)(%r12), RL4, RL4;
14056 + vpxor (0*16)(%r14), RR1, RR1;
14057 + vpxor (1*16)(%r14), RL1, RL1;
14058 + vpxor (2*16)(%r14), RR2, RR2;
14059 + vpxor (3*16)(%r14), RL2, RL2;
14060 + vpxor (4*16)(%r14), RR3, RR3;
14061 + vpxor (5*16)(%r14), RL3, RL3;
14062 + vpxor (6*16)(%r14), RR4, RR4;
14063 + vpxor (7*16)(%r14), RL4, RL4;
14064 vmovdqu RR1, (0*16)(%r11);
14065 vmovdqu RL1, (1*16)(%r11);
14066 vmovdqu RR2, (2*16)(%r11);
14067 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14068 vmovdqu RR4, (6*16)(%r11);
14069 vmovdqu RL4, (7*16)(%r11);
14070
14071 - popq %r12;
14072 + popq %r14;
14073
14074 + pax_force_retaddr
14075 ret;
14076 ENDPROC(cast5_ctr_16way)
14077 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14078 index e3531f8..e123f35 100644
14079 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14080 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14081 @@ -24,6 +24,7 @@
14082 */
14083
14084 #include <linux/linkage.h>
14085 +#include <asm/alternative-asm.h>
14086 #include "glue_helper-asm-avx.S"
14087
14088 .file "cast6-avx-x86_64-asm_64.S"
14089 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14090 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14091 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14092
14093 + pax_force_retaddr
14094 ret;
14095 ENDPROC(__cast6_enc_blk8)
14096
14097 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14098 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14099 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14100
14101 + pax_force_retaddr
14102 ret;
14103 ENDPROC(__cast6_dec_blk8)
14104
14105 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14106
14107 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14108
14109 + pax_force_retaddr
14110 ret;
14111 ENDPROC(cast6_ecb_enc_8way)
14112
14113 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14114
14115 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14116
14117 + pax_force_retaddr
14118 ret;
14119 ENDPROC(cast6_ecb_dec_8way)
14120
14121 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14122 * %rdx: src
14123 */
14124
14125 - pushq %r12;
14126 + pushq %r14;
14127
14128 movq %rsi, %r11;
14129 - movq %rdx, %r12;
14130 + movq %rdx, %r14;
14131
14132 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14133
14134 call __cast6_dec_blk8;
14135
14136 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14138
14139 - popq %r12;
14140 + popq %r14;
14141
14142 + pax_force_retaddr
14143 ret;
14144 ENDPROC(cast6_cbc_dec_8way)
14145
14146 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14147 * %rcx: iv (little endian, 128bit)
14148 */
14149
14150 - pushq %r12;
14151 + pushq %r14;
14152
14153 movq %rsi, %r11;
14154 - movq %rdx, %r12;
14155 + movq %rdx, %r14;
14156
14157 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14158 RD2, RX, RKR, RKM);
14159
14160 call __cast6_enc_blk8;
14161
14162 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14163 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14164
14165 - popq %r12;
14166 + popq %r14;
14167
14168 + pax_force_retaddr
14169 ret;
14170 ENDPROC(cast6_ctr_8way)
14171
14172 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14173 /* dst <= regs xor IVs(in dst) */
14174 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14175
14176 + pax_force_retaddr
14177 ret;
14178 ENDPROC(cast6_xts_enc_8way)
14179
14180 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14181 /* dst <= regs xor IVs(in dst) */
14182 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14183
14184 + pax_force_retaddr
14185 ret;
14186 ENDPROC(cast6_xts_dec_8way)
14187 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14188 index 26d49eb..c0a8c84 100644
14189 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14190 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14191 @@ -45,6 +45,7 @@
14192
14193 #include <asm/inst.h>
14194 #include <linux/linkage.h>
14195 +#include <asm/alternative-asm.h>
14196
14197 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14198
14199 @@ -309,6 +310,7 @@ do_return:
14200 popq %rsi
14201 popq %rdi
14202 popq %rbx
14203 + pax_force_retaddr
14204 ret
14205
14206 ################################################################
14207 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14208 index 5d1e007..098cb4f 100644
14209 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14210 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14211 @@ -18,6 +18,7 @@
14212
14213 #include <linux/linkage.h>
14214 #include <asm/inst.h>
14215 +#include <asm/alternative-asm.h>
14216
14217 .data
14218
14219 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14220 psrlq $1, T2
14221 pxor T2, T1
14222 pxor T1, DATA
14223 + pax_force_retaddr
14224 ret
14225 ENDPROC(__clmul_gf128mul_ble)
14226
14227 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14228 call __clmul_gf128mul_ble
14229 PSHUFB_XMM BSWAP DATA
14230 movups DATA, (%rdi)
14231 + pax_force_retaddr
14232 ret
14233 ENDPROC(clmul_ghash_mul)
14234
14235 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14236 PSHUFB_XMM BSWAP DATA
14237 movups DATA, (%rdi)
14238 .Lupdate_just_ret:
14239 + pax_force_retaddr
14240 ret
14241 ENDPROC(clmul_ghash_update)
14242 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14243 index 9279e0b..c4b3d2c 100644
14244 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14245 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14246 @@ -1,4 +1,5 @@
14247 #include <linux/linkage.h>
14248 +#include <asm/alternative-asm.h>
14249
14250 # enter salsa20_encrypt_bytes
14251 ENTRY(salsa20_encrypt_bytes)
14252 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14253 add %r11,%rsp
14254 mov %rdi,%rax
14255 mov %rsi,%rdx
14256 + pax_force_retaddr
14257 ret
14258 # bytesatleast65:
14259 ._bytesatleast65:
14260 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14261 add %r11,%rsp
14262 mov %rdi,%rax
14263 mov %rsi,%rdx
14264 + pax_force_retaddr
14265 ret
14266 ENDPROC(salsa20_keysetup)
14267
14268 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14269 add %r11,%rsp
14270 mov %rdi,%rax
14271 mov %rsi,%rdx
14272 + pax_force_retaddr
14273 ret
14274 ENDPROC(salsa20_ivsetup)
14275 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14276 index 2f202f4..d9164d6 100644
14277 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14278 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14279 @@ -24,6 +24,7 @@
14280 */
14281
14282 #include <linux/linkage.h>
14283 +#include <asm/alternative-asm.h>
14284 #include "glue_helper-asm-avx.S"
14285
14286 .file "serpent-avx-x86_64-asm_64.S"
14287 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14288 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14289 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14290
14291 + pax_force_retaddr
14292 ret;
14293 ENDPROC(__serpent_enc_blk8_avx)
14294
14295 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14296 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14297 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14298
14299 + pax_force_retaddr
14300 ret;
14301 ENDPROC(__serpent_dec_blk8_avx)
14302
14303 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14304
14305 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14306
14307 + pax_force_retaddr
14308 ret;
14309 ENDPROC(serpent_ecb_enc_8way_avx)
14310
14311 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14312
14313 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14314
14315 + pax_force_retaddr
14316 ret;
14317 ENDPROC(serpent_ecb_dec_8way_avx)
14318
14319 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14320
14321 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14322
14323 + pax_force_retaddr
14324 ret;
14325 ENDPROC(serpent_cbc_dec_8way_avx)
14326
14327 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14328
14329 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14330
14331 + pax_force_retaddr
14332 ret;
14333 ENDPROC(serpent_ctr_8way_avx)
14334
14335 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14336 /* dst <= regs xor IVs(in dst) */
14337 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14338
14339 + pax_force_retaddr
14340 ret;
14341 ENDPROC(serpent_xts_enc_8way_avx)
14342
14343 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14344 /* dst <= regs xor IVs(in dst) */
14345 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14346
14347 + pax_force_retaddr
14348 ret;
14349 ENDPROC(serpent_xts_dec_8way_avx)
14350 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14351 index b222085..abd483c 100644
14352 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14353 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14354 @@ -15,6 +15,7 @@
14355 */
14356
14357 #include <linux/linkage.h>
14358 +#include <asm/alternative-asm.h>
14359 #include "glue_helper-asm-avx2.S"
14360
14361 .file "serpent-avx2-asm_64.S"
14362 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14363 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14364 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14365
14366 + pax_force_retaddr
14367 ret;
14368 ENDPROC(__serpent_enc_blk16)
14369
14370 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14371 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14372 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14373
14374 + pax_force_retaddr
14375 ret;
14376 ENDPROC(__serpent_dec_blk16)
14377
14378 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14379
14380 vzeroupper;
14381
14382 + pax_force_retaddr
14383 ret;
14384 ENDPROC(serpent_ecb_enc_16way)
14385
14386 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14387
14388 vzeroupper;
14389
14390 + pax_force_retaddr
14391 ret;
14392 ENDPROC(serpent_ecb_dec_16way)
14393
14394 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14395
14396 vzeroupper;
14397
14398 + pax_force_retaddr
14399 ret;
14400 ENDPROC(serpent_cbc_dec_16way)
14401
14402 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14403
14404 vzeroupper;
14405
14406 + pax_force_retaddr
14407 ret;
14408 ENDPROC(serpent_ctr_16way)
14409
14410 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14411
14412 vzeroupper;
14413
14414 + pax_force_retaddr
14415 ret;
14416 ENDPROC(serpent_xts_enc_16way)
14417
14418 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14419
14420 vzeroupper;
14421
14422 + pax_force_retaddr
14423 ret;
14424 ENDPROC(serpent_xts_dec_16way)
14425 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14426 index acc066c..1559cc4 100644
14427 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14428 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14429 @@ -25,6 +25,7 @@
14430 */
14431
14432 #include <linux/linkage.h>
14433 +#include <asm/alternative-asm.h>
14434
14435 .file "serpent-sse2-x86_64-asm_64.S"
14436 .text
14437 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14438 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14439 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14440
14441 + pax_force_retaddr
14442 ret;
14443
14444 .L__enc_xor8:
14445 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14446 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14447
14448 + pax_force_retaddr
14449 ret;
14450 ENDPROC(__serpent_enc_blk_8way)
14451
14452 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14453 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14454 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14455
14456 + pax_force_retaddr
14457 ret;
14458 ENDPROC(serpent_dec_blk_8way)
14459 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14460 index a410950..9dfe7ad 100644
14461 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14462 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14463 @@ -29,6 +29,7 @@
14464 */
14465
14466 #include <linux/linkage.h>
14467 +#include <asm/alternative-asm.h>
14468
14469 #define CTX %rdi // arg1
14470 #define BUF %rsi // arg2
14471 @@ -75,9 +76,9 @@
14472
14473 push %rbx
14474 push %rbp
14475 - push %r12
14476 + push %r14
14477
14478 - mov %rsp, %r12
14479 + mov %rsp, %r14
14480 sub $64, %rsp # allocate workspace
14481 and $~15, %rsp # align stack
14482
14483 @@ -99,11 +100,12 @@
14484 xor %rax, %rax
14485 rep stosq
14486
14487 - mov %r12, %rsp # deallocate workspace
14488 + mov %r14, %rsp # deallocate workspace
14489
14490 - pop %r12
14491 + pop %r14
14492 pop %rbp
14493 pop %rbx
14494 + pax_force_retaddr
14495 ret
14496
14497 ENDPROC(\name)
14498 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14499 index 642f156..51a513c 100644
14500 --- a/arch/x86/crypto/sha256-avx-asm.S
14501 +++ b/arch/x86/crypto/sha256-avx-asm.S
14502 @@ -49,6 +49,7 @@
14503
14504 #ifdef CONFIG_AS_AVX
14505 #include <linux/linkage.h>
14506 +#include <asm/alternative-asm.h>
14507
14508 ## assume buffers not aligned
14509 #define VMOVDQ vmovdqu
14510 @@ -460,6 +461,7 @@ done_hash:
14511 popq %r13
14512 popq %rbp
14513 popq %rbx
14514 + pax_force_retaddr
14515 ret
14516 ENDPROC(sha256_transform_avx)
14517
14518 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14519 index 9e86944..3795e6a 100644
14520 --- a/arch/x86/crypto/sha256-avx2-asm.S
14521 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14522 @@ -50,6 +50,7 @@
14523
14524 #ifdef CONFIG_AS_AVX2
14525 #include <linux/linkage.h>
14526 +#include <asm/alternative-asm.h>
14527
14528 ## assume buffers not aligned
14529 #define VMOVDQ vmovdqu
14530 @@ -720,6 +721,7 @@ done_hash:
14531 popq %r12
14532 popq %rbp
14533 popq %rbx
14534 + pax_force_retaddr
14535 ret
14536 ENDPROC(sha256_transform_rorx)
14537
14538 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14539 index f833b74..8c62a9e 100644
14540 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14541 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14542 @@ -47,6 +47,7 @@
14543 ########################################################################
14544
14545 #include <linux/linkage.h>
14546 +#include <asm/alternative-asm.h>
14547
14548 ## assume buffers not aligned
14549 #define MOVDQ movdqu
14550 @@ -471,6 +472,7 @@ done_hash:
14551 popq %rbp
14552 popq %rbx
14553
14554 + pax_force_retaddr
14555 ret
14556 ENDPROC(sha256_transform_ssse3)
14557
14558 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14559 index 974dde9..a823ff9 100644
14560 --- a/arch/x86/crypto/sha512-avx-asm.S
14561 +++ b/arch/x86/crypto/sha512-avx-asm.S
14562 @@ -49,6 +49,7 @@
14563
14564 #ifdef CONFIG_AS_AVX
14565 #include <linux/linkage.h>
14566 +#include <asm/alternative-asm.h>
14567
14568 .text
14569
14570 @@ -364,6 +365,7 @@ updateblock:
14571 mov frame_RSPSAVE(%rsp), %rsp
14572
14573 nowork:
14574 + pax_force_retaddr
14575 ret
14576 ENDPROC(sha512_transform_avx)
14577
14578 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14579 index 568b961..ed20c37 100644
14580 --- a/arch/x86/crypto/sha512-avx2-asm.S
14581 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14582 @@ -51,6 +51,7 @@
14583
14584 #ifdef CONFIG_AS_AVX2
14585 #include <linux/linkage.h>
14586 +#include <asm/alternative-asm.h>
14587
14588 .text
14589
14590 @@ -678,6 +679,7 @@ done_hash:
14591
14592 # Restore Stack Pointer
14593 mov frame_RSPSAVE(%rsp), %rsp
14594 + pax_force_retaddr
14595 ret
14596 ENDPROC(sha512_transform_rorx)
14597
14598 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14599 index fb56855..6edd768 100644
14600 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14601 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14602 @@ -48,6 +48,7 @@
14603 ########################################################################
14604
14605 #include <linux/linkage.h>
14606 +#include <asm/alternative-asm.h>
14607
14608 .text
14609
14610 @@ -363,6 +364,7 @@ updateblock:
14611 mov frame_RSPSAVE(%rsp), %rsp
14612
14613 nowork:
14614 + pax_force_retaddr
14615 ret
14616 ENDPROC(sha512_transform_ssse3)
14617
14618 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14619 index 0505813..b067311 100644
14620 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14621 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14622 @@ -24,6 +24,7 @@
14623 */
14624
14625 #include <linux/linkage.h>
14626 +#include <asm/alternative-asm.h>
14627 #include "glue_helper-asm-avx.S"
14628
14629 .file "twofish-avx-x86_64-asm_64.S"
14630 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14631 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14632 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14633
14634 + pax_force_retaddr
14635 ret;
14636 ENDPROC(__twofish_enc_blk8)
14637
14638 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14639 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14640 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14641
14642 + pax_force_retaddr
14643 ret;
14644 ENDPROC(__twofish_dec_blk8)
14645
14646 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14647
14648 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14649
14650 + pax_force_retaddr
14651 ret;
14652 ENDPROC(twofish_ecb_enc_8way)
14653
14654 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14655
14656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14657
14658 + pax_force_retaddr
14659 ret;
14660 ENDPROC(twofish_ecb_dec_8way)
14661
14662 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14663 * %rdx: src
14664 */
14665
14666 - pushq %r12;
14667 + pushq %r14;
14668
14669 movq %rsi, %r11;
14670 - movq %rdx, %r12;
14671 + movq %rdx, %r14;
14672
14673 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14674
14675 call __twofish_dec_blk8;
14676
14677 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14678 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14679
14680 - popq %r12;
14681 + popq %r14;
14682
14683 + pax_force_retaddr
14684 ret;
14685 ENDPROC(twofish_cbc_dec_8way)
14686
14687 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14688 * %rcx: iv (little endian, 128bit)
14689 */
14690
14691 - pushq %r12;
14692 + pushq %r14;
14693
14694 movq %rsi, %r11;
14695 - movq %rdx, %r12;
14696 + movq %rdx, %r14;
14697
14698 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14699 RD2, RX0, RX1, RY0);
14700
14701 call __twofish_enc_blk8;
14702
14703 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14704 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14705
14706 - popq %r12;
14707 + popq %r14;
14708
14709 + pax_force_retaddr
14710 ret;
14711 ENDPROC(twofish_ctr_8way)
14712
14713 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14714 /* dst <= regs xor IVs(in dst) */
14715 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14716
14717 + pax_force_retaddr
14718 ret;
14719 ENDPROC(twofish_xts_enc_8way)
14720
14721 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14722 /* dst <= regs xor IVs(in dst) */
14723 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14724
14725 + pax_force_retaddr
14726 ret;
14727 ENDPROC(twofish_xts_dec_8way)
14728 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14729 index 1c3b7ce..02f578d 100644
14730 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14731 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14732 @@ -21,6 +21,7 @@
14733 */
14734
14735 #include <linux/linkage.h>
14736 +#include <asm/alternative-asm.h>
14737
14738 .file "twofish-x86_64-asm-3way.S"
14739 .text
14740 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14741 popq %r13;
14742 popq %r14;
14743 popq %r15;
14744 + pax_force_retaddr
14745 ret;
14746
14747 .L__enc_xor3:
14748 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14749 popq %r13;
14750 popq %r14;
14751 popq %r15;
14752 + pax_force_retaddr
14753 ret;
14754 ENDPROC(__twofish_enc_blk_3way)
14755
14756 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14757 popq %r13;
14758 popq %r14;
14759 popq %r15;
14760 + pax_force_retaddr
14761 ret;
14762 ENDPROC(twofish_dec_blk_3way)
14763 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14764 index a039d21..524b8b2 100644
14765 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14766 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14767 @@ -22,6 +22,7 @@
14768
14769 #include <linux/linkage.h>
14770 #include <asm/asm-offsets.h>
14771 +#include <asm/alternative-asm.h>
14772
14773 #define a_offset 0
14774 #define b_offset 4
14775 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14776
14777 popq R1
14778 movq $1,%rax
14779 + pax_force_retaddr
14780 ret
14781 ENDPROC(twofish_enc_blk)
14782
14783 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14784
14785 popq R1
14786 movq $1,%rax
14787 + pax_force_retaddr
14788 ret
14789 ENDPROC(twofish_dec_blk)
14790 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14791 index d21ff89..6da8e6e 100644
14792 --- a/arch/x86/ia32/ia32_aout.c
14793 +++ b/arch/x86/ia32/ia32_aout.c
14794 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14795 unsigned long dump_start, dump_size;
14796 struct user32 dump;
14797
14798 + memset(&dump, 0, sizeof(dump));
14799 +
14800 fs = get_fs();
14801 set_fs(KERNEL_DS);
14802 has_dumped = 1;
14803 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14804 index f9e181a..db313b5 100644
14805 --- a/arch/x86/ia32/ia32_signal.c
14806 +++ b/arch/x86/ia32/ia32_signal.c
14807 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14808 if (__get_user(set.sig[0], &frame->sc.oldmask)
14809 || (_COMPAT_NSIG_WORDS > 1
14810 && __copy_from_user((((char *) &set.sig) + 4),
14811 - &frame->extramask,
14812 + frame->extramask,
14813 sizeof(frame->extramask))))
14814 goto badframe;
14815
14816 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14817 sp -= frame_size;
14818 /* Align the stack pointer according to the i386 ABI,
14819 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14820 - sp = ((sp + 4) & -16ul) - 4;
14821 + sp = ((sp - 12) & -16ul) - 4;
14822 return (void __user *) sp;
14823 }
14824
14825 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14826 } else {
14827 /* Return stub is in 32bit vsyscall page */
14828 if (current->mm->context.vdso)
14829 - restorer = current->mm->context.vdso +
14830 - selected_vdso32->sym___kernel_sigreturn;
14831 + restorer = (void __force_user *)(current->mm->context.vdso +
14832 + selected_vdso32->sym___kernel_sigreturn);
14833 else
14834 - restorer = &frame->retcode;
14835 + restorer = frame->retcode;
14836 }
14837
14838 put_user_try {
14839 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14840 * These are actually not used anymore, but left because some
14841 * gdb versions depend on them as a marker.
14842 */
14843 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14844 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14845 } put_user_catch(err);
14846
14847 if (err)
14848 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14849 0xb8,
14850 __NR_ia32_rt_sigreturn,
14851 0x80cd,
14852 - 0,
14853 + 0
14854 };
14855
14856 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14857 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14858
14859 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14860 restorer = ksig->ka.sa.sa_restorer;
14861 - else
14862 + else if (current->mm->context.vdso)
14863 + /* Return stub is in 32bit vsyscall page */
14864 restorer = current->mm->context.vdso +
14865 selected_vdso32->sym___kernel_rt_sigreturn;
14866 + else
14867 + restorer = frame->retcode;
14868 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14869
14870 /*
14871 * Not actually used anymore, but left because some gdb
14872 * versions need it.
14873 */
14874 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14875 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14876 } put_user_catch(err);
14877
14878 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14879 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14880 index 4299eb0..fefe70e 100644
14881 --- a/arch/x86/ia32/ia32entry.S
14882 +++ b/arch/x86/ia32/ia32entry.S
14883 @@ -15,8 +15,10 @@
14884 #include <asm/irqflags.h>
14885 #include <asm/asm.h>
14886 #include <asm/smap.h>
14887 +#include <asm/pgtable.h>
14888 #include <linux/linkage.h>
14889 #include <linux/err.h>
14890 +#include <asm/alternative-asm.h>
14891
14892 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14893 #include <linux/elf-em.h>
14894 @@ -62,12 +64,12 @@
14895 */
14896 .macro LOAD_ARGS32 offset, _r9=0
14897 .if \_r9
14898 - movl \offset+16(%rsp),%r9d
14899 + movl \offset+R9(%rsp),%r9d
14900 .endif
14901 - movl \offset+40(%rsp),%ecx
14902 - movl \offset+48(%rsp),%edx
14903 - movl \offset+56(%rsp),%esi
14904 - movl \offset+64(%rsp),%edi
14905 + movl \offset+RCX(%rsp),%ecx
14906 + movl \offset+RDX(%rsp),%edx
14907 + movl \offset+RSI(%rsp),%esi
14908 + movl \offset+RDI(%rsp),%edi
14909 movl %eax,%eax /* zero extension */
14910 .endm
14911
14912 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14913 ENDPROC(native_irq_enable_sysexit)
14914 #endif
14915
14916 + .macro pax_enter_kernel_user
14917 + pax_set_fptr_mask
14918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14919 + call pax_enter_kernel_user
14920 +#endif
14921 + .endm
14922 +
14923 + .macro pax_exit_kernel_user
14924 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14925 + call pax_exit_kernel_user
14926 +#endif
14927 +#ifdef CONFIG_PAX_RANDKSTACK
14928 + pushq %rax
14929 + pushq %r11
14930 + call pax_randomize_kstack
14931 + popq %r11
14932 + popq %rax
14933 +#endif
14934 + .endm
14935 +
14936 + .macro pax_erase_kstack
14937 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14938 + call pax_erase_kstack
14939 +#endif
14940 + .endm
14941 +
14942 /*
14943 * 32bit SYSENTER instruction entry.
14944 *
14945 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14946 CFI_REGISTER rsp,rbp
14947 SWAPGS_UNSAFE_STACK
14948 movq PER_CPU_VAR(kernel_stack), %rsp
14949 - addq $(KERNEL_STACK_OFFSET),%rsp
14950 - /*
14951 - * No need to follow this irqs on/off section: the syscall
14952 - * disabled irqs, here we enable it straight after entry:
14953 - */
14954 - ENABLE_INTERRUPTS(CLBR_NONE)
14955 movl %ebp,%ebp /* zero extension */
14956 pushq_cfi $__USER32_DS
14957 /*CFI_REL_OFFSET ss,0*/
14958 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14959 CFI_REL_OFFSET rsp,0
14960 pushfq_cfi
14961 /*CFI_REL_OFFSET rflags,0*/
14962 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14963 - CFI_REGISTER rip,r10
14964 + orl $X86_EFLAGS_IF,(%rsp)
14965 + GET_THREAD_INFO(%r11)
14966 + movl TI_sysenter_return(%r11), %r11d
14967 + CFI_REGISTER rip,r11
14968 pushq_cfi $__USER32_CS
14969 /*CFI_REL_OFFSET cs,0*/
14970 movl %eax, %eax
14971 - pushq_cfi %r10
14972 + pushq_cfi %r11
14973 CFI_REL_OFFSET rip,0
14974 pushq_cfi %rax
14975 cld
14976 SAVE_ARGS 0,1,0
14977 + pax_enter_kernel_user
14978 +
14979 +#ifdef CONFIG_PAX_RANDKSTACK
14980 + pax_erase_kstack
14981 +#endif
14982 +
14983 + /*
14984 + * No need to follow this irqs on/off section: the syscall
14985 + * disabled irqs, here we enable it straight after entry:
14986 + */
14987 + ENABLE_INTERRUPTS(CLBR_NONE)
14988 /* no need to do an access_ok check here because rbp has been
14989 32bit zero extended */
14990 +
14991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14992 + addq pax_user_shadow_base,%rbp
14993 + ASM_PAX_OPEN_USERLAND
14994 +#endif
14995 +
14996 ASM_STAC
14997 1: movl (%rbp),%ebp
14998 _ASM_EXTABLE(1b,ia32_badarg)
14999 ASM_CLAC
15000 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15001 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15002 +
15003 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15004 + ASM_PAX_CLOSE_USERLAND
15005 +#endif
15006 +
15007 + GET_THREAD_INFO(%r11)
15008 + orl $TS_COMPAT,TI_status(%r11)
15009 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15010 CFI_REMEMBER_STATE
15011 jnz sysenter_tracesys
15012 cmpq $(IA32_NR_syscalls-1),%rax
15013 @@ -162,15 +209,18 @@ sysenter_do_call:
15014 sysenter_dispatch:
15015 call *ia32_sys_call_table(,%rax,8)
15016 movq %rax,RAX-ARGOFFSET(%rsp)
15017 + GET_THREAD_INFO(%r11)
15018 DISABLE_INTERRUPTS(CLBR_NONE)
15019 TRACE_IRQS_OFF
15020 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15021 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15022 jnz sysexit_audit
15023 sysexit_from_sys_call:
15024 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15025 + pax_exit_kernel_user
15026 + pax_erase_kstack
15027 + andl $~TS_COMPAT,TI_status(%r11)
15028 /* clear IF, that popfq doesn't enable interrupts early */
15029 - andl $~0x200,EFLAGS-R11(%rsp)
15030 - movl RIP-R11(%rsp),%edx /* User %eip */
15031 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15032 + movl RIP(%rsp),%edx /* User %eip */
15033 CFI_REGISTER rip,rdx
15034 RESTORE_ARGS 0,24,0,0,0,0
15035 xorq %r8,%r8
15036 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
15037 movl %eax,%esi /* 2nd arg: syscall number */
15038 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15039 call __audit_syscall_entry
15040 +
15041 + pax_erase_kstack
15042 +
15043 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15044 cmpq $(IA32_NR_syscalls-1),%rax
15045 ja ia32_badsys
15046 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
15047 .endm
15048
15049 .macro auditsys_exit exit
15050 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15051 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15052 jnz ia32_ret_from_sys_call
15053 TRACE_IRQS_ON
15054 ENABLE_INTERRUPTS(CLBR_NONE)
15055 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
15056 1: setbe %al /* 1 if error, 0 if not */
15057 movzbl %al,%edi /* zero-extend that into %edi */
15058 call __audit_syscall_exit
15059 + GET_THREAD_INFO(%r11)
15060 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15061 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15062 DISABLE_INTERRUPTS(CLBR_NONE)
15063 TRACE_IRQS_OFF
15064 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15065 + testl %edi,TI_flags(%r11)
15066 jz \exit
15067 CLEAR_RREGS -ARGOFFSET
15068 jmp int_with_check
15069 @@ -237,7 +291,7 @@ sysexit_audit:
15070
15071 sysenter_tracesys:
15072 #ifdef CONFIG_AUDITSYSCALL
15073 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15074 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15075 jz sysenter_auditsys
15076 #endif
15077 SAVE_REST
15078 @@ -249,6 +303,9 @@ sysenter_tracesys:
15079 RESTORE_REST
15080 cmpq $(IA32_NR_syscalls-1),%rax
15081 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15082 +
15083 + pax_erase_kstack
15084 +
15085 jmp sysenter_do_call
15086 CFI_ENDPROC
15087 ENDPROC(ia32_sysenter_target)
15088 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
15089 ENTRY(ia32_cstar_target)
15090 CFI_STARTPROC32 simple
15091 CFI_SIGNAL_FRAME
15092 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15093 + CFI_DEF_CFA rsp,0
15094 CFI_REGISTER rip,rcx
15095 /*CFI_REGISTER rflags,r11*/
15096 SWAPGS_UNSAFE_STACK
15097 movl %esp,%r8d
15098 CFI_REGISTER rsp,r8
15099 movq PER_CPU_VAR(kernel_stack),%rsp
15100 + SAVE_ARGS 8*6,0,0
15101 + pax_enter_kernel_user
15102 +
15103 +#ifdef CONFIG_PAX_RANDKSTACK
15104 + pax_erase_kstack
15105 +#endif
15106 +
15107 /*
15108 * No need to follow this irqs on/off section: the syscall
15109 * disabled irqs and here we enable it straight after entry:
15110 */
15111 ENABLE_INTERRUPTS(CLBR_NONE)
15112 - SAVE_ARGS 8,0,0
15113 movl %eax,%eax /* zero extension */
15114 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15115 movq %rcx,RIP-ARGOFFSET(%rsp)
15116 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15117 /* no need to do an access_ok check here because r8 has been
15118 32bit zero extended */
15119 /* hardware stack frame is complete now */
15120 +
15121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15122 + ASM_PAX_OPEN_USERLAND
15123 + movq pax_user_shadow_base,%r8
15124 + addq RSP-ARGOFFSET(%rsp),%r8
15125 +#endif
15126 +
15127 ASM_STAC
15128 1: movl (%r8),%r9d
15129 _ASM_EXTABLE(1b,ia32_badarg)
15130 ASM_CLAC
15131 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15132 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15133 +
15134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15135 + ASM_PAX_CLOSE_USERLAND
15136 +#endif
15137 +
15138 + GET_THREAD_INFO(%r11)
15139 + orl $TS_COMPAT,TI_status(%r11)
15140 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15141 CFI_REMEMBER_STATE
15142 jnz cstar_tracesys
15143 cmpq $IA32_NR_syscalls-1,%rax
15144 @@ -319,13 +395,16 @@ cstar_do_call:
15145 cstar_dispatch:
15146 call *ia32_sys_call_table(,%rax,8)
15147 movq %rax,RAX-ARGOFFSET(%rsp)
15148 + GET_THREAD_INFO(%r11)
15149 DISABLE_INTERRUPTS(CLBR_NONE)
15150 TRACE_IRQS_OFF
15151 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15152 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15153 jnz sysretl_audit
15154 sysretl_from_sys_call:
15155 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15156 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15157 + pax_exit_kernel_user
15158 + pax_erase_kstack
15159 + andl $~TS_COMPAT,TI_status(%r11)
15160 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15161 movl RIP-ARGOFFSET(%rsp),%ecx
15162 CFI_REGISTER rip,rcx
15163 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15164 @@ -352,7 +431,7 @@ sysretl_audit:
15165
15166 cstar_tracesys:
15167 #ifdef CONFIG_AUDITSYSCALL
15168 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15169 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15170 jz cstar_auditsys
15171 #endif
15172 xchgl %r9d,%ebp
15173 @@ -366,11 +445,19 @@ cstar_tracesys:
15174 xchgl %ebp,%r9d
15175 cmpq $(IA32_NR_syscalls-1),%rax
15176 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15177 +
15178 + pax_erase_kstack
15179 +
15180 jmp cstar_do_call
15181 END(ia32_cstar_target)
15182
15183 ia32_badarg:
15184 ASM_CLAC
15185 +
15186 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15187 + ASM_PAX_CLOSE_USERLAND
15188 +#endif
15189 +
15190 movq $-EFAULT,%rax
15191 jmp ia32_sysret
15192 CFI_ENDPROC
15193 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15194 CFI_REL_OFFSET rip,RIP-RIP
15195 PARAVIRT_ADJUST_EXCEPTION_FRAME
15196 SWAPGS
15197 - /*
15198 - * No need to follow this irqs on/off section: the syscall
15199 - * disabled irqs and here we enable it straight after entry:
15200 - */
15201 - ENABLE_INTERRUPTS(CLBR_NONE)
15202 movl %eax,%eax
15203 pushq_cfi %rax
15204 cld
15205 /* note the registers are not zero extended to the sf.
15206 this could be a problem. */
15207 SAVE_ARGS 0,1,0
15208 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15209 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15210 + pax_enter_kernel_user
15211 +
15212 +#ifdef CONFIG_PAX_RANDKSTACK
15213 + pax_erase_kstack
15214 +#endif
15215 +
15216 + /*
15217 + * No need to follow this irqs on/off section: the syscall
15218 + * disabled irqs and here we enable it straight after entry:
15219 + */
15220 + ENABLE_INTERRUPTS(CLBR_NONE)
15221 + GET_THREAD_INFO(%r11)
15222 + orl $TS_COMPAT,TI_status(%r11)
15223 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15224 jnz ia32_tracesys
15225 cmpq $(IA32_NR_syscalls-1),%rax
15226 ja ia32_badsys
15227 @@ -442,6 +536,9 @@ ia32_tracesys:
15228 RESTORE_REST
15229 cmpq $(IA32_NR_syscalls-1),%rax
15230 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15231 +
15232 + pax_erase_kstack
15233 +
15234 jmp ia32_do_call
15235 END(ia32_syscall)
15236
15237 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15238 index 8e0ceec..af13504 100644
15239 --- a/arch/x86/ia32/sys_ia32.c
15240 +++ b/arch/x86/ia32/sys_ia32.c
15241 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15242 */
15243 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15244 {
15245 - typeof(ubuf->st_uid) uid = 0;
15246 - typeof(ubuf->st_gid) gid = 0;
15247 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15248 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15249 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15250 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15251 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15252 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15253 index 372231c..51b537d 100644
15254 --- a/arch/x86/include/asm/alternative-asm.h
15255 +++ b/arch/x86/include/asm/alternative-asm.h
15256 @@ -18,6 +18,45 @@
15257 .endm
15258 #endif
15259
15260 +#ifdef KERNEXEC_PLUGIN
15261 + .macro pax_force_retaddr_bts rip=0
15262 + btsq $63,\rip(%rsp)
15263 + .endm
15264 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15265 + .macro pax_force_retaddr rip=0, reload=0
15266 + btsq $63,\rip(%rsp)
15267 + .endm
15268 + .macro pax_force_fptr ptr
15269 + btsq $63,\ptr
15270 + .endm
15271 + .macro pax_set_fptr_mask
15272 + .endm
15273 +#endif
15274 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15275 + .macro pax_force_retaddr rip=0, reload=0
15276 + .if \reload
15277 + pax_set_fptr_mask
15278 + .endif
15279 + orq %r12,\rip(%rsp)
15280 + .endm
15281 + .macro pax_force_fptr ptr
15282 + orq %r12,\ptr
15283 + .endm
15284 + .macro pax_set_fptr_mask
15285 + movabs $0x8000000000000000,%r12
15286 + .endm
15287 +#endif
15288 +#else
15289 + .macro pax_force_retaddr rip=0, reload=0
15290 + .endm
15291 + .macro pax_force_fptr ptr
15292 + .endm
15293 + .macro pax_force_retaddr_bts rip=0
15294 + .endm
15295 + .macro pax_set_fptr_mask
15296 + .endm
15297 +#endif
15298 +
15299 .macro altinstruction_entry orig alt feature orig_len alt_len
15300 .long \orig - .
15301 .long \alt - .
15302 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15303 index 473bdbe..b1e3377 100644
15304 --- a/arch/x86/include/asm/alternative.h
15305 +++ b/arch/x86/include/asm/alternative.h
15306 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15307 ".pushsection .discard,\"aw\",@progbits\n" \
15308 DISCARD_ENTRY(1) \
15309 ".popsection\n" \
15310 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15311 + ".pushsection .altinstr_replacement, \"a\"\n" \
15312 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15313 ".popsection"
15314
15315 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15316 DISCARD_ENTRY(1) \
15317 DISCARD_ENTRY(2) \
15318 ".popsection\n" \
15319 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15320 + ".pushsection .altinstr_replacement, \"a\"\n" \
15321 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15322 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15323 ".popsection"
15324 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15325 index 465b309..ab7e51f 100644
15326 --- a/arch/x86/include/asm/apic.h
15327 +++ b/arch/x86/include/asm/apic.h
15328 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15329
15330 #ifdef CONFIG_X86_LOCAL_APIC
15331
15332 -extern unsigned int apic_verbosity;
15333 +extern int apic_verbosity;
15334 extern int local_apic_timer_c2_ok;
15335
15336 extern int disable_apic;
15337 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15338 index 20370c6..a2eb9b0 100644
15339 --- a/arch/x86/include/asm/apm.h
15340 +++ b/arch/x86/include/asm/apm.h
15341 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15342 __asm__ __volatile__(APM_DO_ZERO_SEGS
15343 "pushl %%edi\n\t"
15344 "pushl %%ebp\n\t"
15345 - "lcall *%%cs:apm_bios_entry\n\t"
15346 + "lcall *%%ss:apm_bios_entry\n\t"
15347 "setc %%al\n\t"
15348 "popl %%ebp\n\t"
15349 "popl %%edi\n\t"
15350 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15351 __asm__ __volatile__(APM_DO_ZERO_SEGS
15352 "pushl %%edi\n\t"
15353 "pushl %%ebp\n\t"
15354 - "lcall *%%cs:apm_bios_entry\n\t"
15355 + "lcall *%%ss:apm_bios_entry\n\t"
15356 "setc %%bl\n\t"
15357 "popl %%ebp\n\t"
15358 "popl %%edi\n\t"
15359 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15360 index 6dd1c7dd..2edd216 100644
15361 --- a/arch/x86/include/asm/atomic.h
15362 +++ b/arch/x86/include/asm/atomic.h
15363 @@ -24,7 +24,18 @@
15364 */
15365 static inline int atomic_read(const atomic_t *v)
15366 {
15367 - return (*(volatile int *)&(v)->counter);
15368 + return (*(volatile const int *)&(v)->counter);
15369 +}
15370 +
15371 +/**
15372 + * atomic_read_unchecked - read atomic variable
15373 + * @v: pointer of type atomic_unchecked_t
15374 + *
15375 + * Atomically reads the value of @v.
15376 + */
15377 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15378 +{
15379 + return (*(volatile const int *)&(v)->counter);
15380 }
15381
15382 /**
15383 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15384 }
15385
15386 /**
15387 + * atomic_set_unchecked - set atomic variable
15388 + * @v: pointer of type atomic_unchecked_t
15389 + * @i: required value
15390 + *
15391 + * Atomically sets the value of @v to @i.
15392 + */
15393 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15394 +{
15395 + v->counter = i;
15396 +}
15397 +
15398 +/**
15399 * atomic_add - add integer to atomic variable
15400 * @i: integer value to add
15401 * @v: pointer of type atomic_t
15402 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15403 */
15404 static inline void atomic_add(int i, atomic_t *v)
15405 {
15406 - asm volatile(LOCK_PREFIX "addl %1,%0"
15407 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15408 +
15409 +#ifdef CONFIG_PAX_REFCOUNT
15410 + "jno 0f\n"
15411 + LOCK_PREFIX "subl %1,%0\n"
15412 + "int $4\n0:\n"
15413 + _ASM_EXTABLE(0b, 0b)
15414 +#endif
15415 +
15416 + : "+m" (v->counter)
15417 + : "ir" (i));
15418 +}
15419 +
15420 +/**
15421 + * atomic_add_unchecked - add integer to atomic variable
15422 + * @i: integer value to add
15423 + * @v: pointer of type atomic_unchecked_t
15424 + *
15425 + * Atomically adds @i to @v.
15426 + */
15427 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15428 +{
15429 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15430 : "+m" (v->counter)
15431 : "ir" (i));
15432 }
15433 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15434 */
15435 static inline void atomic_sub(int i, atomic_t *v)
15436 {
15437 - asm volatile(LOCK_PREFIX "subl %1,%0"
15438 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15439 +
15440 +#ifdef CONFIG_PAX_REFCOUNT
15441 + "jno 0f\n"
15442 + LOCK_PREFIX "addl %1,%0\n"
15443 + "int $4\n0:\n"
15444 + _ASM_EXTABLE(0b, 0b)
15445 +#endif
15446 +
15447 + : "+m" (v->counter)
15448 + : "ir" (i));
15449 +}
15450 +
15451 +/**
15452 + * atomic_sub_unchecked - subtract integer from atomic variable
15453 + * @i: integer value to subtract
15454 + * @v: pointer of type atomic_unchecked_t
15455 + *
15456 + * Atomically subtracts @i from @v.
15457 + */
15458 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15459 +{
15460 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15461 : "+m" (v->counter)
15462 : "ir" (i));
15463 }
15464 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15465 */
15466 static inline int atomic_sub_and_test(int i, atomic_t *v)
15467 {
15468 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15469 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15470 }
15471
15472 /**
15473 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15474 */
15475 static inline void atomic_inc(atomic_t *v)
15476 {
15477 - asm volatile(LOCK_PREFIX "incl %0"
15478 + asm volatile(LOCK_PREFIX "incl %0\n"
15479 +
15480 +#ifdef CONFIG_PAX_REFCOUNT
15481 + "jno 0f\n"
15482 + LOCK_PREFIX "decl %0\n"
15483 + "int $4\n0:\n"
15484 + _ASM_EXTABLE(0b, 0b)
15485 +#endif
15486 +
15487 + : "+m" (v->counter));
15488 +}
15489 +
15490 +/**
15491 + * atomic_inc_unchecked - increment atomic variable
15492 + * @v: pointer of type atomic_unchecked_t
15493 + *
15494 + * Atomically increments @v by 1.
15495 + */
15496 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15497 +{
15498 + asm volatile(LOCK_PREFIX "incl %0\n"
15499 : "+m" (v->counter));
15500 }
15501
15502 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15503 */
15504 static inline void atomic_dec(atomic_t *v)
15505 {
15506 - asm volatile(LOCK_PREFIX "decl %0"
15507 + asm volatile(LOCK_PREFIX "decl %0\n"
15508 +
15509 +#ifdef CONFIG_PAX_REFCOUNT
15510 + "jno 0f\n"
15511 + LOCK_PREFIX "incl %0\n"
15512 + "int $4\n0:\n"
15513 + _ASM_EXTABLE(0b, 0b)
15514 +#endif
15515 +
15516 + : "+m" (v->counter));
15517 +}
15518 +
15519 +/**
15520 + * atomic_dec_unchecked - decrement atomic variable
15521 + * @v: pointer of type atomic_unchecked_t
15522 + *
15523 + * Atomically decrements @v by 1.
15524 + */
15525 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15526 +{
15527 + asm volatile(LOCK_PREFIX "decl %0\n"
15528 : "+m" (v->counter));
15529 }
15530
15531 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15532 */
15533 static inline int atomic_dec_and_test(atomic_t *v)
15534 {
15535 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15536 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15537 }
15538
15539 /**
15540 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15541 */
15542 static inline int atomic_inc_and_test(atomic_t *v)
15543 {
15544 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15545 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15546 +}
15547 +
15548 +/**
15549 + * atomic_inc_and_test_unchecked - increment and test
15550 + * @v: pointer of type atomic_unchecked_t
15551 + *
15552 + * Atomically increments @v by 1
15553 + * and returns true if the result is zero, or false for all
15554 + * other cases.
15555 + */
15556 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15557 +{
15558 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15559 }
15560
15561 /**
15562 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15563 */
15564 static inline int atomic_add_negative(int i, atomic_t *v)
15565 {
15566 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15567 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15568 }
15569
15570 /**
15571 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15572 */
15573 static inline int atomic_add_return(int i, atomic_t *v)
15574 {
15575 + return i + xadd_check_overflow(&v->counter, i);
15576 +}
15577 +
15578 +/**
15579 + * atomic_add_return_unchecked - add integer and return
15580 + * @i: integer value to add
15581 + * @v: pointer of type atomic_unchecked_t
15582 + *
15583 + * Atomically adds @i to @v and returns @i + @v
15584 + */
15585 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15586 +{
15587 return i + xadd(&v->counter, i);
15588 }
15589
15590 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15591 }
15592
15593 #define atomic_inc_return(v) (atomic_add_return(1, v))
15594 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15595 +{
15596 + return atomic_add_return_unchecked(1, v);
15597 +}
15598 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15599
15600 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15601 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15602 +{
15603 + return cmpxchg(&v->counter, old, new);
15604 +}
15605 +
15606 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15607 {
15608 return cmpxchg(&v->counter, old, new);
15609 }
15610 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15611 return xchg(&v->counter, new);
15612 }
15613
15614 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15615 +{
15616 + return xchg(&v->counter, new);
15617 +}
15618 +
15619 /**
15620 * __atomic_add_unless - add unless the number is already a given value
15621 * @v: pointer of type atomic_t
15622 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15623 * Atomically adds @a to @v, so long as @v was not already @u.
15624 * Returns the old value of @v.
15625 */
15626 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15627 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15628 {
15629 - int c, old;
15630 + int c, old, new;
15631 c = atomic_read(v);
15632 for (;;) {
15633 - if (unlikely(c == (u)))
15634 + if (unlikely(c == u))
15635 break;
15636 - old = atomic_cmpxchg((v), c, c + (a));
15637 +
15638 + asm volatile("addl %2,%0\n"
15639 +
15640 +#ifdef CONFIG_PAX_REFCOUNT
15641 + "jno 0f\n"
15642 + "subl %2,%0\n"
15643 + "int $4\n0:\n"
15644 + _ASM_EXTABLE(0b, 0b)
15645 +#endif
15646 +
15647 + : "=r" (new)
15648 + : "0" (c), "ir" (a));
15649 +
15650 + old = atomic_cmpxchg(v, c, new);
15651 if (likely(old == c))
15652 break;
15653 c = old;
15654 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15655 }
15656
15657 /**
15658 + * atomic_inc_not_zero_hint - increment if not null
15659 + * @v: pointer of type atomic_t
15660 + * @hint: probable value of the atomic before the increment
15661 + *
15662 + * This version of atomic_inc_not_zero() gives a hint of probable
15663 + * value of the atomic. This helps processor to not read the memory
15664 + * before doing the atomic read/modify/write cycle, lowering
15665 + * number of bus transactions on some arches.
15666 + *
15667 + * Returns: 0 if increment was not done, 1 otherwise.
15668 + */
15669 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15670 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15671 +{
15672 + int val, c = hint, new;
15673 +
15674 + /* sanity test, should be removed by compiler if hint is a constant */
15675 + if (!hint)
15676 + return __atomic_add_unless(v, 1, 0);
15677 +
15678 + do {
15679 + asm volatile("incl %0\n"
15680 +
15681 +#ifdef CONFIG_PAX_REFCOUNT
15682 + "jno 0f\n"
15683 + "decl %0\n"
15684 + "int $4\n0:\n"
15685 + _ASM_EXTABLE(0b, 0b)
15686 +#endif
15687 +
15688 + : "=r" (new)
15689 + : "0" (c));
15690 +
15691 + val = atomic_cmpxchg(v, c, new);
15692 + if (val == c)
15693 + return 1;
15694 + c = val;
15695 + } while (c);
15696 +
15697 + return 0;
15698 +}
15699 +
15700 +/**
15701 * atomic_inc_short - increment of a short integer
15702 * @v: pointer to type int
15703 *
15704 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15705 #endif
15706
15707 /* These are x86-specific, used by some header files */
15708 -#define atomic_clear_mask(mask, addr) \
15709 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15710 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15711 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15712 +{
15713 + asm volatile(LOCK_PREFIX "andl %1,%0"
15714 + : "+m" (v->counter)
15715 + : "r" (~(mask))
15716 + : "memory");
15717 +}
15718
15719 -#define atomic_set_mask(mask, addr) \
15720 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15721 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15722 - : "memory")
15723 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15724 +{
15725 + asm volatile(LOCK_PREFIX "andl %1,%0"
15726 + : "+m" (v->counter)
15727 + : "r" (~(mask))
15728 + : "memory");
15729 +}
15730 +
15731 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15732 +{
15733 + asm volatile(LOCK_PREFIX "orl %1,%0"
15734 + : "+m" (v->counter)
15735 + : "r" (mask)
15736 + : "memory");
15737 +}
15738 +
15739 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15740 +{
15741 + asm volatile(LOCK_PREFIX "orl %1,%0"
15742 + : "+m" (v->counter)
15743 + : "r" (mask)
15744 + : "memory");
15745 +}
15746
15747 #ifdef CONFIG_X86_32
15748 # include <asm/atomic64_32.h>
15749 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15750 index b154de7..bf18a5a 100644
15751 --- a/arch/x86/include/asm/atomic64_32.h
15752 +++ b/arch/x86/include/asm/atomic64_32.h
15753 @@ -12,6 +12,14 @@ typedef struct {
15754 u64 __aligned(8) counter;
15755 } atomic64_t;
15756
15757 +#ifdef CONFIG_PAX_REFCOUNT
15758 +typedef struct {
15759 + u64 __aligned(8) counter;
15760 +} atomic64_unchecked_t;
15761 +#else
15762 +typedef atomic64_t atomic64_unchecked_t;
15763 +#endif
15764 +
15765 #define ATOMIC64_INIT(val) { (val) }
15766
15767 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15768 @@ -37,21 +45,31 @@ typedef struct {
15769 ATOMIC64_DECL_ONE(sym##_386)
15770
15771 ATOMIC64_DECL_ONE(add_386);
15772 +ATOMIC64_DECL_ONE(add_unchecked_386);
15773 ATOMIC64_DECL_ONE(sub_386);
15774 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15775 ATOMIC64_DECL_ONE(inc_386);
15776 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15777 ATOMIC64_DECL_ONE(dec_386);
15778 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15779 #endif
15780
15781 #define alternative_atomic64(f, out, in...) \
15782 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15783
15784 ATOMIC64_DECL(read);
15785 +ATOMIC64_DECL(read_unchecked);
15786 ATOMIC64_DECL(set);
15787 +ATOMIC64_DECL(set_unchecked);
15788 ATOMIC64_DECL(xchg);
15789 ATOMIC64_DECL(add_return);
15790 +ATOMIC64_DECL(add_return_unchecked);
15791 ATOMIC64_DECL(sub_return);
15792 +ATOMIC64_DECL(sub_return_unchecked);
15793 ATOMIC64_DECL(inc_return);
15794 +ATOMIC64_DECL(inc_return_unchecked);
15795 ATOMIC64_DECL(dec_return);
15796 +ATOMIC64_DECL(dec_return_unchecked);
15797 ATOMIC64_DECL(dec_if_positive);
15798 ATOMIC64_DECL(inc_not_zero);
15799 ATOMIC64_DECL(add_unless);
15800 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15801 }
15802
15803 /**
15804 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15805 + * @p: pointer to type atomic64_unchecked_t
15806 + * @o: expected value
15807 + * @n: new value
15808 + *
15809 + * Atomically sets @v to @n if it was equal to @o and returns
15810 + * the old value.
15811 + */
15812 +
15813 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15814 +{
15815 + return cmpxchg64(&v->counter, o, n);
15816 +}
15817 +
15818 +/**
15819 * atomic64_xchg - xchg atomic64 variable
15820 * @v: pointer to type atomic64_t
15821 * @n: value to assign
15822 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15823 }
15824
15825 /**
15826 + * atomic64_set_unchecked - set atomic64 variable
15827 + * @v: pointer to type atomic64_unchecked_t
15828 + * @n: value to assign
15829 + *
15830 + * Atomically sets the value of @v to @n.
15831 + */
15832 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15833 +{
15834 + unsigned high = (unsigned)(i >> 32);
15835 + unsigned low = (unsigned)i;
15836 + alternative_atomic64(set, /* no output */,
15837 + "S" (v), "b" (low), "c" (high)
15838 + : "eax", "edx", "memory");
15839 +}
15840 +
15841 +/**
15842 * atomic64_read - read atomic64 variable
15843 * @v: pointer to type atomic64_t
15844 *
15845 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15846 }
15847
15848 /**
15849 + * atomic64_read_unchecked - read atomic64 variable
15850 + * @v: pointer to type atomic64_unchecked_t
15851 + *
15852 + * Atomically reads the value of @v and returns it.
15853 + */
15854 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15855 +{
15856 + long long r;
15857 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15858 + return r;
15859 + }
15860 +
15861 +/**
15862 * atomic64_add_return - add and return
15863 * @i: integer value to add
15864 * @v: pointer to type atomic64_t
15865 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15866 return i;
15867 }
15868
15869 +/**
15870 + * atomic64_add_return_unchecked - add and return
15871 + * @i: integer value to add
15872 + * @v: pointer to type atomic64_unchecked_t
15873 + *
15874 + * Atomically adds @i to @v and returns @i + *@v
15875 + */
15876 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15877 +{
15878 + alternative_atomic64(add_return_unchecked,
15879 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15880 + ASM_NO_INPUT_CLOBBER("memory"));
15881 + return i;
15882 +}
15883 +
15884 /*
15885 * Other variants with different arithmetic operators:
15886 */
15887 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15888 return a;
15889 }
15890
15891 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15892 +{
15893 + long long a;
15894 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15895 + "S" (v) : "memory", "ecx");
15896 + return a;
15897 +}
15898 +
15899 static inline long long atomic64_dec_return(atomic64_t *v)
15900 {
15901 long long a;
15902 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15903 }
15904
15905 /**
15906 + * atomic64_add_unchecked - add integer to atomic64 variable
15907 + * @i: integer value to add
15908 + * @v: pointer to type atomic64_unchecked_t
15909 + *
15910 + * Atomically adds @i to @v.
15911 + */
15912 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15913 +{
15914 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15915 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15916 + ASM_NO_INPUT_CLOBBER("memory"));
15917 + return i;
15918 +}
15919 +
15920 +/**
15921 * atomic64_sub - subtract the atomic64 variable
15922 * @i: integer value to subtract
15923 * @v: pointer to type atomic64_t
15924 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15925 index 46e9052..ae45136 100644
15926 --- a/arch/x86/include/asm/atomic64_64.h
15927 +++ b/arch/x86/include/asm/atomic64_64.h
15928 @@ -18,7 +18,19 @@
15929 */
15930 static inline long atomic64_read(const atomic64_t *v)
15931 {
15932 - return (*(volatile long *)&(v)->counter);
15933 + return (*(volatile const long *)&(v)->counter);
15934 +}
15935 +
15936 +/**
15937 + * atomic64_read_unchecked - read atomic64 variable
15938 + * @v: pointer of type atomic64_unchecked_t
15939 + *
15940 + * Atomically reads the value of @v.
15941 + * Doesn't imply a read memory barrier.
15942 + */
15943 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15944 +{
15945 + return (*(volatile const long *)&(v)->counter);
15946 }
15947
15948 /**
15949 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15950 }
15951
15952 /**
15953 + * atomic64_set_unchecked - set atomic64 variable
15954 + * @v: pointer to type atomic64_unchecked_t
15955 + * @i: required value
15956 + *
15957 + * Atomically sets the value of @v to @i.
15958 + */
15959 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15960 +{
15961 + v->counter = i;
15962 +}
15963 +
15964 +/**
15965 * atomic64_add - add integer to atomic64 variable
15966 * @i: integer value to add
15967 * @v: pointer to type atomic64_t
15968 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15969 */
15970 static inline void atomic64_add(long i, atomic64_t *v)
15971 {
15972 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15973 +
15974 +#ifdef CONFIG_PAX_REFCOUNT
15975 + "jno 0f\n"
15976 + LOCK_PREFIX "subq %1,%0\n"
15977 + "int $4\n0:\n"
15978 + _ASM_EXTABLE(0b, 0b)
15979 +#endif
15980 +
15981 + : "=m" (v->counter)
15982 + : "er" (i), "m" (v->counter));
15983 +}
15984 +
15985 +/**
15986 + * atomic64_add_unchecked - add integer to atomic64 variable
15987 + * @i: integer value to add
15988 + * @v: pointer to type atomic64_unchecked_t
15989 + *
15990 + * Atomically adds @i to @v.
15991 + */
15992 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15993 +{
15994 asm volatile(LOCK_PREFIX "addq %1,%0"
15995 : "=m" (v->counter)
15996 : "er" (i), "m" (v->counter));
15997 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15998 */
15999 static inline void atomic64_sub(long i, atomic64_t *v)
16000 {
16001 - asm volatile(LOCK_PREFIX "subq %1,%0"
16002 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16003 +
16004 +#ifdef CONFIG_PAX_REFCOUNT
16005 + "jno 0f\n"
16006 + LOCK_PREFIX "addq %1,%0\n"
16007 + "int $4\n0:\n"
16008 + _ASM_EXTABLE(0b, 0b)
16009 +#endif
16010 +
16011 + : "=m" (v->counter)
16012 + : "er" (i), "m" (v->counter));
16013 +}
16014 +
16015 +/**
16016 + * atomic64_sub_unchecked - subtract the atomic64 variable
16017 + * @i: integer value to subtract
16018 + * @v: pointer to type atomic64_unchecked_t
16019 + *
16020 + * Atomically subtracts @i from @v.
16021 + */
16022 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16023 +{
16024 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16025 : "=m" (v->counter)
16026 : "er" (i), "m" (v->counter));
16027 }
16028 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16029 */
16030 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16031 {
16032 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16033 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16034 }
16035
16036 /**
16037 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16038 */
16039 static inline void atomic64_inc(atomic64_t *v)
16040 {
16041 + asm volatile(LOCK_PREFIX "incq %0\n"
16042 +
16043 +#ifdef CONFIG_PAX_REFCOUNT
16044 + "jno 0f\n"
16045 + LOCK_PREFIX "decq %0\n"
16046 + "int $4\n0:\n"
16047 + _ASM_EXTABLE(0b, 0b)
16048 +#endif
16049 +
16050 + : "=m" (v->counter)
16051 + : "m" (v->counter));
16052 +}
16053 +
16054 +/**
16055 + * atomic64_inc_unchecked - increment atomic64 variable
16056 + * @v: pointer to type atomic64_unchecked_t
16057 + *
16058 + * Atomically increments @v by 1.
16059 + */
16060 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16061 +{
16062 asm volatile(LOCK_PREFIX "incq %0"
16063 : "=m" (v->counter)
16064 : "m" (v->counter));
16065 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16066 */
16067 static inline void atomic64_dec(atomic64_t *v)
16068 {
16069 - asm volatile(LOCK_PREFIX "decq %0"
16070 + asm volatile(LOCK_PREFIX "decq %0\n"
16071 +
16072 +#ifdef CONFIG_PAX_REFCOUNT
16073 + "jno 0f\n"
16074 + LOCK_PREFIX "incq %0\n"
16075 + "int $4\n0:\n"
16076 + _ASM_EXTABLE(0b, 0b)
16077 +#endif
16078 +
16079 + : "=m" (v->counter)
16080 + : "m" (v->counter));
16081 +}
16082 +
16083 +/**
16084 + * atomic64_dec_unchecked - decrement atomic64 variable
16085 + * @v: pointer to type atomic64_t
16086 + *
16087 + * Atomically decrements @v by 1.
16088 + */
16089 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16090 +{
16091 + asm volatile(LOCK_PREFIX "decq %0\n"
16092 : "=m" (v->counter)
16093 : "m" (v->counter));
16094 }
16095 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16096 */
16097 static inline int atomic64_dec_and_test(atomic64_t *v)
16098 {
16099 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16100 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16101 }
16102
16103 /**
16104 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16105 */
16106 static inline int atomic64_inc_and_test(atomic64_t *v)
16107 {
16108 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16109 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16110 }
16111
16112 /**
16113 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16114 */
16115 static inline int atomic64_add_negative(long i, atomic64_t *v)
16116 {
16117 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16118 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16119 }
16120
16121 /**
16122 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16123 */
16124 static inline long atomic64_add_return(long i, atomic64_t *v)
16125 {
16126 + return i + xadd_check_overflow(&v->counter, i);
16127 +}
16128 +
16129 +/**
16130 + * atomic64_add_return_unchecked - add and return
16131 + * @i: integer value to add
16132 + * @v: pointer to type atomic64_unchecked_t
16133 + *
16134 + * Atomically adds @i to @v and returns @i + @v
16135 + */
16136 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16137 +{
16138 return i + xadd(&v->counter, i);
16139 }
16140
16141 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16142 }
16143
16144 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16145 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16146 +{
16147 + return atomic64_add_return_unchecked(1, v);
16148 +}
16149 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16150
16151 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16152 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16153 return cmpxchg(&v->counter, old, new);
16154 }
16155
16156 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16157 +{
16158 + return cmpxchg(&v->counter, old, new);
16159 +}
16160 +
16161 static inline long atomic64_xchg(atomic64_t *v, long new)
16162 {
16163 return xchg(&v->counter, new);
16164 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16165 */
16166 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16167 {
16168 - long c, old;
16169 + long c, old, new;
16170 c = atomic64_read(v);
16171 for (;;) {
16172 - if (unlikely(c == (u)))
16173 + if (unlikely(c == u))
16174 break;
16175 - old = atomic64_cmpxchg((v), c, c + (a));
16176 +
16177 + asm volatile("add %2,%0\n"
16178 +
16179 +#ifdef CONFIG_PAX_REFCOUNT
16180 + "jno 0f\n"
16181 + "sub %2,%0\n"
16182 + "int $4\n0:\n"
16183 + _ASM_EXTABLE(0b, 0b)
16184 +#endif
16185 +
16186 + : "=r" (new)
16187 + : "0" (c), "ir" (a));
16188 +
16189 + old = atomic64_cmpxchg(v, c, new);
16190 if (likely(old == c))
16191 break;
16192 c = old;
16193 }
16194 - return c != (u);
16195 + return c != u;
16196 }
16197
16198 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16199 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16200 index 0f4460b..fa1ee19 100644
16201 --- a/arch/x86/include/asm/barrier.h
16202 +++ b/arch/x86/include/asm/barrier.h
16203 @@ -107,7 +107,7 @@
16204 do { \
16205 compiletime_assert_atomic_type(*p); \
16206 smp_mb(); \
16207 - ACCESS_ONCE(*p) = (v); \
16208 + ACCESS_ONCE_RW(*p) = (v); \
16209 } while (0)
16210
16211 #define smp_load_acquire(p) \
16212 @@ -124,7 +124,7 @@ do { \
16213 do { \
16214 compiletime_assert_atomic_type(*p); \
16215 barrier(); \
16216 - ACCESS_ONCE(*p) = (v); \
16217 + ACCESS_ONCE_RW(*p) = (v); \
16218 } while (0)
16219
16220 #define smp_load_acquire(p) \
16221 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16222 index cfe3b95..d01b118 100644
16223 --- a/arch/x86/include/asm/bitops.h
16224 +++ b/arch/x86/include/asm/bitops.h
16225 @@ -50,7 +50,7 @@
16226 * a mask operation on a byte.
16227 */
16228 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16229 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16230 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16231 #define CONST_MASK(nr) (1 << ((nr) & 7))
16232
16233 /**
16234 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16235 */
16236 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16237 {
16238 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16239 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16240 }
16241
16242 /**
16243 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16244 */
16245 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16246 {
16247 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16248 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16249 }
16250
16251 /**
16252 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16253 */
16254 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16255 {
16256 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16257 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16258 }
16259
16260 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16261 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16262 *
16263 * Undefined if no bit exists, so code should check against 0 first.
16264 */
16265 -static inline unsigned long __ffs(unsigned long word)
16266 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16267 {
16268 asm("rep; bsf %1,%0"
16269 : "=r" (word)
16270 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16271 *
16272 * Undefined if no zero exists, so code should check against ~0UL first.
16273 */
16274 -static inline unsigned long ffz(unsigned long word)
16275 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16276 {
16277 asm("rep; bsf %1,%0"
16278 : "=r" (word)
16279 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16280 *
16281 * Undefined if no set bit exists, so code should check against 0 first.
16282 */
16283 -static inline unsigned long __fls(unsigned long word)
16284 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16285 {
16286 asm("bsr %1,%0"
16287 : "=r" (word)
16288 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16289 * set bit if value is nonzero. The last (most significant) bit is
16290 * at position 32.
16291 */
16292 -static inline int fls(int x)
16293 +static inline int __intentional_overflow(-1) fls(int x)
16294 {
16295 int r;
16296
16297 @@ -476,7 +476,7 @@ static inline int fls(int x)
16298 * at position 64.
16299 */
16300 #ifdef CONFIG_X86_64
16301 -static __always_inline int fls64(__u64 x)
16302 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16303 {
16304 int bitpos = -1;
16305 /*
16306 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16307 index 4fa687a..60f2d39 100644
16308 --- a/arch/x86/include/asm/boot.h
16309 +++ b/arch/x86/include/asm/boot.h
16310 @@ -6,10 +6,15 @@
16311 #include <uapi/asm/boot.h>
16312
16313 /* Physical address where kernel should be loaded. */
16314 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16315 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16316 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16317 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16318
16319 +#ifndef __ASSEMBLY__
16320 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16321 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16322 +#endif
16323 +
16324 /* Minimum kernel alignment, as a power of two */
16325 #ifdef CONFIG_X86_64
16326 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16327 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16328 index 48f99f1..d78ebf9 100644
16329 --- a/arch/x86/include/asm/cache.h
16330 +++ b/arch/x86/include/asm/cache.h
16331 @@ -5,12 +5,13 @@
16332
16333 /* L1 cache line size */
16334 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16335 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16336 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16337
16338 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16339 +#define __read_only __attribute__((__section__(".data..read_only")))
16340
16341 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16342 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16343 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16344
16345 #ifdef CONFIG_X86_VSMP
16346 #ifdef CONFIG_SMP
16347 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16348 index 9863ee3..4a1f8e1 100644
16349 --- a/arch/x86/include/asm/cacheflush.h
16350 +++ b/arch/x86/include/asm/cacheflush.h
16351 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16352 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16353
16354 if (pg_flags == _PGMT_DEFAULT)
16355 - return -1;
16356 + return ~0UL;
16357 else if (pg_flags == _PGMT_WC)
16358 return _PAGE_CACHE_WC;
16359 else if (pg_flags == _PGMT_UC_MINUS)
16360 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16361 index cb4c73b..c473c29 100644
16362 --- a/arch/x86/include/asm/calling.h
16363 +++ b/arch/x86/include/asm/calling.h
16364 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16365 #define RSP 152
16366 #define SS 160
16367
16368 -#define ARGOFFSET R11
16369 -#define SWFRAME ORIG_RAX
16370 +#define ARGOFFSET R15
16371
16372 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16373 - subq $9*8+\addskip, %rsp
16374 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16375 - movq_cfi rdi, 8*8
16376 - movq_cfi rsi, 7*8
16377 - movq_cfi rdx, 6*8
16378 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16379 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16380 + movq_cfi rdi, RDI
16381 + movq_cfi rsi, RSI
16382 + movq_cfi rdx, RDX
16383
16384 .if \save_rcx
16385 - movq_cfi rcx, 5*8
16386 + movq_cfi rcx, RCX
16387 .endif
16388
16389 - movq_cfi rax, 4*8
16390 + movq_cfi rax, RAX
16391
16392 .if \save_r891011
16393 - movq_cfi r8, 3*8
16394 - movq_cfi r9, 2*8
16395 - movq_cfi r10, 1*8
16396 - movq_cfi r11, 0*8
16397 + movq_cfi r8, R8
16398 + movq_cfi r9, R9
16399 + movq_cfi r10, R10
16400 + movq_cfi r11, R11
16401 .endif
16402
16403 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16404 + movq_cfi r12, R12
16405 +#endif
16406 +
16407 .endm
16408
16409 -#define ARG_SKIP (9*8)
16410 +#define ARG_SKIP ORIG_RAX
16411
16412 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16413 rstor_r8910=1, rstor_rdx=1
16414 +
16415 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16416 + movq_cfi_restore R12, r12
16417 +#endif
16418 +
16419 .if \rstor_r11
16420 - movq_cfi_restore 0*8, r11
16421 + movq_cfi_restore R11, r11
16422 .endif
16423
16424 .if \rstor_r8910
16425 - movq_cfi_restore 1*8, r10
16426 - movq_cfi_restore 2*8, r9
16427 - movq_cfi_restore 3*8, r8
16428 + movq_cfi_restore R10, r10
16429 + movq_cfi_restore R9, r9
16430 + movq_cfi_restore R8, r8
16431 .endif
16432
16433 .if \rstor_rax
16434 - movq_cfi_restore 4*8, rax
16435 + movq_cfi_restore RAX, rax
16436 .endif
16437
16438 .if \rstor_rcx
16439 - movq_cfi_restore 5*8, rcx
16440 + movq_cfi_restore RCX, rcx
16441 .endif
16442
16443 .if \rstor_rdx
16444 - movq_cfi_restore 6*8, rdx
16445 + movq_cfi_restore RDX, rdx
16446 .endif
16447
16448 - movq_cfi_restore 7*8, rsi
16449 - movq_cfi_restore 8*8, rdi
16450 + movq_cfi_restore RSI, rsi
16451 + movq_cfi_restore RDI, rdi
16452
16453 - .if ARG_SKIP+\addskip > 0
16454 - addq $ARG_SKIP+\addskip, %rsp
16455 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16456 + .if ORIG_RAX+\addskip > 0
16457 + addq $ORIG_RAX+\addskip, %rsp
16458 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16459 .endif
16460 .endm
16461
16462 - .macro LOAD_ARGS offset, skiprax=0
16463 - movq \offset(%rsp), %r11
16464 - movq \offset+8(%rsp), %r10
16465 - movq \offset+16(%rsp), %r9
16466 - movq \offset+24(%rsp), %r8
16467 - movq \offset+40(%rsp), %rcx
16468 - movq \offset+48(%rsp), %rdx
16469 - movq \offset+56(%rsp), %rsi
16470 - movq \offset+64(%rsp), %rdi
16471 + .macro LOAD_ARGS skiprax=0
16472 + movq R11(%rsp), %r11
16473 + movq R10(%rsp), %r10
16474 + movq R9(%rsp), %r9
16475 + movq R8(%rsp), %r8
16476 + movq RCX(%rsp), %rcx
16477 + movq RDX(%rsp), %rdx
16478 + movq RSI(%rsp), %rsi
16479 + movq RDI(%rsp), %rdi
16480 .if \skiprax
16481 .else
16482 - movq \offset+72(%rsp), %rax
16483 + movq RAX(%rsp), %rax
16484 .endif
16485 .endm
16486
16487 -#define REST_SKIP (6*8)
16488 -
16489 .macro SAVE_REST
16490 - subq $REST_SKIP, %rsp
16491 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16492 - movq_cfi rbx, 5*8
16493 - movq_cfi rbp, 4*8
16494 - movq_cfi r12, 3*8
16495 - movq_cfi r13, 2*8
16496 - movq_cfi r14, 1*8
16497 - movq_cfi r15, 0*8
16498 + movq_cfi rbx, RBX
16499 + movq_cfi rbp, RBP
16500 +
16501 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16502 + movq_cfi r12, R12
16503 +#endif
16504 +
16505 + movq_cfi r13, R13
16506 + movq_cfi r14, R14
16507 + movq_cfi r15, R15
16508 .endm
16509
16510 .macro RESTORE_REST
16511 - movq_cfi_restore 0*8, r15
16512 - movq_cfi_restore 1*8, r14
16513 - movq_cfi_restore 2*8, r13
16514 - movq_cfi_restore 3*8, r12
16515 - movq_cfi_restore 4*8, rbp
16516 - movq_cfi_restore 5*8, rbx
16517 - addq $REST_SKIP, %rsp
16518 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16519 + movq_cfi_restore R15, r15
16520 + movq_cfi_restore R14, r14
16521 + movq_cfi_restore R13, r13
16522 +
16523 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16524 + movq_cfi_restore R12, r12
16525 +#endif
16526 +
16527 + movq_cfi_restore RBP, rbp
16528 + movq_cfi_restore RBX, rbx
16529 .endm
16530
16531 .macro SAVE_ALL
16532 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16533 index f50de69..2b0a458 100644
16534 --- a/arch/x86/include/asm/checksum_32.h
16535 +++ b/arch/x86/include/asm/checksum_32.h
16536 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16537 int len, __wsum sum,
16538 int *src_err_ptr, int *dst_err_ptr);
16539
16540 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16541 + int len, __wsum sum,
16542 + int *src_err_ptr, int *dst_err_ptr);
16543 +
16544 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16545 + int len, __wsum sum,
16546 + int *src_err_ptr, int *dst_err_ptr);
16547 +
16548 /*
16549 * Note: when you get a NULL pointer exception here this means someone
16550 * passed in an incorrect kernel address to one of these functions.
16551 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16552
16553 might_sleep();
16554 stac();
16555 - ret = csum_partial_copy_generic((__force void *)src, dst,
16556 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16557 len, sum, err_ptr, NULL);
16558 clac();
16559
16560 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16561 might_sleep();
16562 if (access_ok(VERIFY_WRITE, dst, len)) {
16563 stac();
16564 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16565 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16566 len, sum, NULL, err_ptr);
16567 clac();
16568 return ret;
16569 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16570 index 99c105d7..2f667ac 100644
16571 --- a/arch/x86/include/asm/cmpxchg.h
16572 +++ b/arch/x86/include/asm/cmpxchg.h
16573 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16574 __compiletime_error("Bad argument size for cmpxchg");
16575 extern void __xadd_wrong_size(void)
16576 __compiletime_error("Bad argument size for xadd");
16577 +extern void __xadd_check_overflow_wrong_size(void)
16578 + __compiletime_error("Bad argument size for xadd_check_overflow");
16579 extern void __add_wrong_size(void)
16580 __compiletime_error("Bad argument size for add");
16581 +extern void __add_check_overflow_wrong_size(void)
16582 + __compiletime_error("Bad argument size for add_check_overflow");
16583
16584 /*
16585 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16586 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16587 __ret; \
16588 })
16589
16590 +#ifdef CONFIG_PAX_REFCOUNT
16591 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16592 + ({ \
16593 + __typeof__ (*(ptr)) __ret = (arg); \
16594 + switch (sizeof(*(ptr))) { \
16595 + case __X86_CASE_L: \
16596 + asm volatile (lock #op "l %0, %1\n" \
16597 + "jno 0f\n" \
16598 + "mov %0,%1\n" \
16599 + "int $4\n0:\n" \
16600 + _ASM_EXTABLE(0b, 0b) \
16601 + : "+r" (__ret), "+m" (*(ptr)) \
16602 + : : "memory", "cc"); \
16603 + break; \
16604 + case __X86_CASE_Q: \
16605 + asm volatile (lock #op "q %q0, %1\n" \
16606 + "jno 0f\n" \
16607 + "mov %0,%1\n" \
16608 + "int $4\n0:\n" \
16609 + _ASM_EXTABLE(0b, 0b) \
16610 + : "+r" (__ret), "+m" (*(ptr)) \
16611 + : : "memory", "cc"); \
16612 + break; \
16613 + default: \
16614 + __ ## op ## _check_overflow_wrong_size(); \
16615 + } \
16616 + __ret; \
16617 + })
16618 +#else
16619 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16620 +#endif
16621 +
16622 /*
16623 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16624 * Since this is generally used to protect other memory information, we
16625 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16626 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16627 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16628
16629 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16630 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16631 +
16632 #define __add(ptr, inc, lock) \
16633 ({ \
16634 __typeof__ (*(ptr)) __ret = (inc); \
16635 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16636 index 59c6c40..5e0b22c 100644
16637 --- a/arch/x86/include/asm/compat.h
16638 +++ b/arch/x86/include/asm/compat.h
16639 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16640 typedef u32 compat_uint_t;
16641 typedef u32 compat_ulong_t;
16642 typedef u64 __attribute__((aligned(4))) compat_u64;
16643 -typedef u32 compat_uptr_t;
16644 +typedef u32 __user compat_uptr_t;
16645
16646 struct compat_timespec {
16647 compat_time_t tv_sec;
16648 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16649 index bb9b258..5fad1bf 100644
16650 --- a/arch/x86/include/asm/cpufeature.h
16651 +++ b/arch/x86/include/asm/cpufeature.h
16652 @@ -203,14 +203,14 @@
16653 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16654 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16655
16656 -
16657 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16658 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16659 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16660 #define X86_FEATURE_TSC_ADJUST ( 9*32+ 1) /* TSC adjustment MSR 0x3b */
16661 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16662 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16663 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16664 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16665 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16666 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16667 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16668 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16669 @@ -370,6 +370,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16670 #undef cpu_has_centaur_mcr
16671 #define cpu_has_centaur_mcr 0
16672
16673 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16674 #endif /* CONFIG_X86_64 */
16675
16676 #if __GNUC__ >= 4
16677 @@ -422,7 +423,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16678
16679 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16680 t_warn:
16681 - warn_pre_alternatives();
16682 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16683 + warn_pre_alternatives();
16684 return false;
16685 #endif
16686
16687 @@ -442,7 +444,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16688 ".section .discard,\"aw\",@progbits\n"
16689 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16690 ".previous\n"
16691 - ".section .altinstr_replacement,\"ax\"\n"
16692 + ".section .altinstr_replacement,\"a\"\n"
16693 "3: movb $1,%0\n"
16694 "4:\n"
16695 ".previous\n"
16696 @@ -479,7 +481,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16697 " .byte 2b - 1b\n" /* src len */
16698 " .byte 4f - 3f\n" /* repl len */
16699 ".previous\n"
16700 - ".section .altinstr_replacement,\"ax\"\n"
16701 + ".section .altinstr_replacement,\"a\"\n"
16702 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16703 "4:\n"
16704 ".previous\n"
16705 @@ -512,7 +514,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16706 ".section .discard,\"aw\",@progbits\n"
16707 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16708 ".previous\n"
16709 - ".section .altinstr_replacement,\"ax\"\n"
16710 + ".section .altinstr_replacement,\"a\"\n"
16711 "3: movb $0,%0\n"
16712 "4:\n"
16713 ".previous\n"
16714 @@ -526,7 +528,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16715 ".section .discard,\"aw\",@progbits\n"
16716 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16717 ".previous\n"
16718 - ".section .altinstr_replacement,\"ax\"\n"
16719 + ".section .altinstr_replacement,\"a\"\n"
16720 "5: movb $1,%0\n"
16721 "6:\n"
16722 ".previous\n"
16723 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16724 index 50d033a..37deb26 100644
16725 --- a/arch/x86/include/asm/desc.h
16726 +++ b/arch/x86/include/asm/desc.h
16727 @@ -4,6 +4,7 @@
16728 #include <asm/desc_defs.h>
16729 #include <asm/ldt.h>
16730 #include <asm/mmu.h>
16731 +#include <asm/pgtable.h>
16732
16733 #include <linux/smp.h>
16734 #include <linux/percpu.h>
16735 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16736
16737 desc->type = (info->read_exec_only ^ 1) << 1;
16738 desc->type |= info->contents << 2;
16739 + desc->type |= info->seg_not_present ^ 1;
16740
16741 desc->s = 1;
16742 desc->dpl = 0x3;
16743 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16744 }
16745
16746 extern struct desc_ptr idt_descr;
16747 -extern gate_desc idt_table[];
16748 -extern struct desc_ptr debug_idt_descr;
16749 -extern gate_desc debug_idt_table[];
16750 -
16751 -struct gdt_page {
16752 - struct desc_struct gdt[GDT_ENTRIES];
16753 -} __attribute__((aligned(PAGE_SIZE)));
16754 -
16755 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16756 +extern gate_desc idt_table[IDT_ENTRIES];
16757 +extern const struct desc_ptr debug_idt_descr;
16758 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16759
16760 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16761 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16762 {
16763 - return per_cpu(gdt_page, cpu).gdt;
16764 + return cpu_gdt_table[cpu];
16765 }
16766
16767 #ifdef CONFIG_X86_64
16768 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16769 unsigned long base, unsigned dpl, unsigned flags,
16770 unsigned short seg)
16771 {
16772 - gate->a = (seg << 16) | (base & 0xffff);
16773 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16774 + gate->gate.offset_low = base;
16775 + gate->gate.seg = seg;
16776 + gate->gate.reserved = 0;
16777 + gate->gate.type = type;
16778 + gate->gate.s = 0;
16779 + gate->gate.dpl = dpl;
16780 + gate->gate.p = 1;
16781 + gate->gate.offset_high = base >> 16;
16782 }
16783
16784 #endif
16785 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16786
16787 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16788 {
16789 + pax_open_kernel();
16790 memcpy(&idt[entry], gate, sizeof(*gate));
16791 + pax_close_kernel();
16792 }
16793
16794 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16795 {
16796 + pax_open_kernel();
16797 memcpy(&ldt[entry], desc, 8);
16798 + pax_close_kernel();
16799 }
16800
16801 static inline void
16802 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16803 default: size = sizeof(*gdt); break;
16804 }
16805
16806 + pax_open_kernel();
16807 memcpy(&gdt[entry], desc, size);
16808 + pax_close_kernel();
16809 }
16810
16811 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16812 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16813
16814 static inline void native_load_tr_desc(void)
16815 {
16816 + pax_open_kernel();
16817 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16818 + pax_close_kernel();
16819 }
16820
16821 static inline void native_load_gdt(const struct desc_ptr *dtr)
16822 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16823 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16824 unsigned int i;
16825
16826 + pax_open_kernel();
16827 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16828 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16829 + pax_close_kernel();
16830 }
16831
16832 #define _LDT_empty(info) \
16833 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16834 preempt_enable();
16835 }
16836
16837 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16838 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16839 {
16840 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16841 }
16842 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16843 }
16844
16845 #ifdef CONFIG_X86_64
16846 -static inline void set_nmi_gate(int gate, void *addr)
16847 +static inline void set_nmi_gate(int gate, const void *addr)
16848 {
16849 gate_desc s;
16850
16851 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16852 #endif
16853
16854 #ifdef CONFIG_TRACING
16855 -extern struct desc_ptr trace_idt_descr;
16856 -extern gate_desc trace_idt_table[];
16857 +extern const struct desc_ptr trace_idt_descr;
16858 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16859 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16860 {
16861 write_idt_entry(trace_idt_table, entry, gate);
16862 }
16863
16864 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16865 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16866 unsigned dpl, unsigned ist, unsigned seg)
16867 {
16868 gate_desc s;
16869 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16870 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16871 #endif
16872
16873 -static inline void _set_gate(int gate, unsigned type, void *addr,
16874 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16875 unsigned dpl, unsigned ist, unsigned seg)
16876 {
16877 gate_desc s;
16878 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16879 #define set_intr_gate(n, addr) \
16880 do { \
16881 BUG_ON((unsigned)n > 0xFF); \
16882 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16883 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16884 __KERNEL_CS); \
16885 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16886 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16887 0, 0, __KERNEL_CS); \
16888 } while (0)
16889
16890 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16891 /*
16892 * This routine sets up an interrupt gate at directory privilege level 3.
16893 */
16894 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16895 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16896 {
16897 BUG_ON((unsigned)n > 0xFF);
16898 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16899 }
16900
16901 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16902 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16903 {
16904 BUG_ON((unsigned)n > 0xFF);
16905 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16906 }
16907
16908 -static inline void set_trap_gate(unsigned int n, void *addr)
16909 +static inline void set_trap_gate(unsigned int n, const void *addr)
16910 {
16911 BUG_ON((unsigned)n > 0xFF);
16912 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16913 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16914 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16915 {
16916 BUG_ON((unsigned)n > 0xFF);
16917 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16918 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16919 }
16920
16921 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16922 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16923 {
16924 BUG_ON((unsigned)n > 0xFF);
16925 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16926 }
16927
16928 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16929 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16930 {
16931 BUG_ON((unsigned)n > 0xFF);
16932 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16933 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16934 else
16935 load_idt((const struct desc_ptr *)&idt_descr);
16936 }
16937 +
16938 +#ifdef CONFIG_X86_32
16939 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16940 +{
16941 + struct desc_struct d;
16942 +
16943 + if (likely(limit))
16944 + limit = (limit - 1UL) >> PAGE_SHIFT;
16945 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16946 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16947 +}
16948 +#endif
16949 +
16950 #endif /* _ASM_X86_DESC_H */
16951 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16952 index 278441f..b95a174 100644
16953 --- a/arch/x86/include/asm/desc_defs.h
16954 +++ b/arch/x86/include/asm/desc_defs.h
16955 @@ -31,6 +31,12 @@ struct desc_struct {
16956 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16957 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16958 };
16959 + struct {
16960 + u16 offset_low;
16961 + u16 seg;
16962 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16963 + unsigned offset_high: 16;
16964 + } gate;
16965 };
16966 } __attribute__((packed));
16967
16968 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16969 index ced283a..ffe04cc 100644
16970 --- a/arch/x86/include/asm/div64.h
16971 +++ b/arch/x86/include/asm/div64.h
16972 @@ -39,7 +39,7 @@
16973 __mod; \
16974 })
16975
16976 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16977 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16978 {
16979 union {
16980 u64 v64;
16981 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16982 index 1a055c8..1a5082a 100644
16983 --- a/arch/x86/include/asm/elf.h
16984 +++ b/arch/x86/include/asm/elf.h
16985 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16986
16987 #include <asm/vdso.h>
16988
16989 -#ifdef CONFIG_X86_64
16990 -extern unsigned int vdso64_enabled;
16991 -#endif
16992 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16993 extern unsigned int vdso32_enabled;
16994 #endif
16995 @@ -160,8 +157,9 @@ do { \
16996 #define elf_check_arch(x) \
16997 ((x)->e_machine == EM_X86_64)
16998
16999 -#define compat_elf_check_arch(x) \
17000 - (elf_check_arch_ia32(x) || (x)->e_machine == EM_X86_64)
17001 +#define compat_elf_check_arch(x) \
17002 + (elf_check_arch_ia32(x) || \
17003 + (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
17004
17005 #if __USER32_DS != __USER_DS
17006 # error "The following code assumes __USER32_DS == __USER_DS"
17007 @@ -248,7 +246,25 @@ extern int force_personality32;
17008 the loader. We need to make sure that it is out of the way of the program
17009 that it will "exec", and that there is sufficient room for the brk. */
17010
17011 +#ifdef CONFIG_PAX_SEGMEXEC
17012 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17013 +#else
17014 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17015 +#endif
17016 +
17017 +#ifdef CONFIG_PAX_ASLR
17018 +#ifdef CONFIG_X86_32
17019 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17020 +
17021 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17022 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17023 +#else
17024 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17025 +
17026 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17027 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17028 +#endif
17029 +#endif
17030
17031 /* This yields a mask that user programs can use to figure out what
17032 instruction set this CPU supports. This could be done in user space,
17033 @@ -297,17 +313,13 @@ do { \
17034
17035 #define ARCH_DLINFO \
17036 do { \
17037 - if (vdso64_enabled) \
17038 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17039 - (unsigned long __force)current->mm->context.vdso); \
17040 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17041 } while (0)
17042
17043 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17044 #define ARCH_DLINFO_X32 \
17045 do { \
17046 - if (vdso64_enabled) \
17047 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17048 - (unsigned long __force)current->mm->context.vdso); \
17049 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17050 } while (0)
17051
17052 #define AT_SYSINFO 32
17053 @@ -322,10 +334,10 @@ else \
17054
17055 #endif /* !CONFIG_X86_32 */
17056
17057 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17058 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17059
17060 #define VDSO_ENTRY \
17061 - ((unsigned long)current->mm->context.vdso + \
17062 + (current->mm->context.vdso + \
17063 selected_vdso32->sym___kernel_vsyscall)
17064
17065 struct linux_binprm;
17066 @@ -337,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17067 int uses_interp);
17068 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17069
17070 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17071 -#define arch_randomize_brk arch_randomize_brk
17072 -
17073 /*
17074 * True on X86_32 or when emulating IA32 on X86_64
17075 */
17076 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17077 index 77a99ac..39ff7f5 100644
17078 --- a/arch/x86/include/asm/emergency-restart.h
17079 +++ b/arch/x86/include/asm/emergency-restart.h
17080 @@ -1,6 +1,6 @@
17081 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17082 #define _ASM_X86_EMERGENCY_RESTART_H
17083
17084 -extern void machine_emergency_restart(void);
17085 +extern void machine_emergency_restart(void) __noreturn;
17086
17087 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17088 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17089 index 1c7eefe..d0e4702 100644
17090 --- a/arch/x86/include/asm/floppy.h
17091 +++ b/arch/x86/include/asm/floppy.h
17092 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17093 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17094 } fd_routine[] = {
17095 {
17096 - request_dma,
17097 - free_dma,
17098 - get_dma_residue,
17099 - dma_mem_alloc,
17100 - hard_dma_setup
17101 + ._request_dma = request_dma,
17102 + ._free_dma = free_dma,
17103 + ._get_dma_residue = get_dma_residue,
17104 + ._dma_mem_alloc = dma_mem_alloc,
17105 + ._dma_setup = hard_dma_setup
17106 },
17107 {
17108 - vdma_request_dma,
17109 - vdma_nop,
17110 - vdma_get_dma_residue,
17111 - vdma_mem_alloc,
17112 - vdma_dma_setup
17113 + ._request_dma = vdma_request_dma,
17114 + ._free_dma = vdma_nop,
17115 + ._get_dma_residue = vdma_get_dma_residue,
17116 + ._dma_mem_alloc = vdma_mem_alloc,
17117 + ._dma_setup = vdma_dma_setup
17118 }
17119 };
17120
17121 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17122 index 412ecec..c1ea43a 100644
17123 --- a/arch/x86/include/asm/fpu-internal.h
17124 +++ b/arch/x86/include/asm/fpu-internal.h
17125 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17126 #define user_insn(insn, output, input...) \
17127 ({ \
17128 int err; \
17129 + pax_open_userland(); \
17130 asm volatile(ASM_STAC "\n" \
17131 - "1:" #insn "\n\t" \
17132 + "1:" \
17133 + __copyuser_seg \
17134 + #insn "\n\t" \
17135 "2: " ASM_CLAC "\n" \
17136 ".section .fixup,\"ax\"\n" \
17137 "3: movl $-1,%[err]\n" \
17138 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17139 _ASM_EXTABLE(1b, 3b) \
17140 : [err] "=r" (err), output \
17141 : "0"(0), input); \
17142 + pax_close_userland(); \
17143 err; \
17144 })
17145
17146 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17147 "fnclex\n\t"
17148 "emms\n\t"
17149 "fildl %P[addr]" /* set F?P to defined value */
17150 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17151 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17152 }
17153
17154 return fpu_restore_checking(&tsk->thread.fpu);
17155 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17156 index b4c1f54..e290c08 100644
17157 --- a/arch/x86/include/asm/futex.h
17158 +++ b/arch/x86/include/asm/futex.h
17159 @@ -12,6 +12,7 @@
17160 #include <asm/smap.h>
17161
17162 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17163 + typecheck(u32 __user *, uaddr); \
17164 asm volatile("\t" ASM_STAC "\n" \
17165 "1:\t" insn "\n" \
17166 "2:\t" ASM_CLAC "\n" \
17167 @@ -20,15 +21,16 @@
17168 "\tjmp\t2b\n" \
17169 "\t.previous\n" \
17170 _ASM_EXTABLE(1b, 3b) \
17171 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17172 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17173 : "i" (-EFAULT), "0" (oparg), "1" (0))
17174
17175 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17176 + typecheck(u32 __user *, uaddr); \
17177 asm volatile("\t" ASM_STAC "\n" \
17178 "1:\tmovl %2, %0\n" \
17179 "\tmovl\t%0, %3\n" \
17180 "\t" insn "\n" \
17181 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17182 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17183 "\tjnz\t1b\n" \
17184 "3:\t" ASM_CLAC "\n" \
17185 "\t.section .fixup,\"ax\"\n" \
17186 @@ -38,7 +40,7 @@
17187 _ASM_EXTABLE(1b, 4b) \
17188 _ASM_EXTABLE(2b, 4b) \
17189 : "=&a" (oldval), "=&r" (ret), \
17190 - "+m" (*uaddr), "=&r" (tem) \
17191 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17192 : "r" (oparg), "i" (-EFAULT), "1" (0))
17193
17194 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17195 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17196
17197 pagefault_disable();
17198
17199 + pax_open_userland();
17200 switch (op) {
17201 case FUTEX_OP_SET:
17202 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17203 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17204 break;
17205 case FUTEX_OP_ADD:
17206 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17207 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17208 uaddr, oparg);
17209 break;
17210 case FUTEX_OP_OR:
17211 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17212 default:
17213 ret = -ENOSYS;
17214 }
17215 + pax_close_userland();
17216
17217 pagefault_enable();
17218
17219 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17220 index 4615906..788c817 100644
17221 --- a/arch/x86/include/asm/hw_irq.h
17222 +++ b/arch/x86/include/asm/hw_irq.h
17223 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17224 extern void enable_IO_APIC(void);
17225
17226 /* Statistics */
17227 -extern atomic_t irq_err_count;
17228 -extern atomic_t irq_mis_count;
17229 +extern atomic_unchecked_t irq_err_count;
17230 +extern atomic_unchecked_t irq_mis_count;
17231
17232 /* EISA */
17233 extern void eisa_set_level_irq(unsigned int irq);
17234 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17235 index ccffa53..3c90c87 100644
17236 --- a/arch/x86/include/asm/i8259.h
17237 +++ b/arch/x86/include/asm/i8259.h
17238 @@ -62,7 +62,7 @@ struct legacy_pic {
17239 void (*init)(int auto_eoi);
17240 int (*irq_pending)(unsigned int irq);
17241 void (*make_irq)(unsigned int irq);
17242 -};
17243 +} __do_const;
17244
17245 extern struct legacy_pic *legacy_pic;
17246 extern struct legacy_pic null_legacy_pic;
17247 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17248 index b8237d8..3e8864e 100644
17249 --- a/arch/x86/include/asm/io.h
17250 +++ b/arch/x86/include/asm/io.h
17251 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17252 "m" (*(volatile type __force *)addr) barrier); }
17253
17254 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17255 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17256 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17257 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17258 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17259
17260 build_mmio_read(__readb, "b", unsigned char, "=q", )
17261 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17262 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17263 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17264 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17265
17266 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17267 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17268 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17269 * this function
17270 */
17271
17272 -static inline phys_addr_t virt_to_phys(volatile void *address)
17273 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17274 {
17275 return __pa(address);
17276 }
17277 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17278 return ioremap_nocache(offset, size);
17279 }
17280
17281 -extern void iounmap(volatile void __iomem *addr);
17282 +extern void iounmap(const volatile void __iomem *addr);
17283
17284 extern void set_iounmap_nonlazy(void);
17285
17286 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17287
17288 #include <linux/vmalloc.h>
17289
17290 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17291 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17292 +{
17293 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17294 +}
17295 +
17296 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17297 +{
17298 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17299 +}
17300 +
17301 /*
17302 * Convert a virtual cached pointer to an uncached pointer
17303 */
17304 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17305 index 0a8b519..80e7d5b 100644
17306 --- a/arch/x86/include/asm/irqflags.h
17307 +++ b/arch/x86/include/asm/irqflags.h
17308 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17309 sti; \
17310 sysexit
17311
17312 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17313 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17314 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17315 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17316 +
17317 #else
17318 #define INTERRUPT_RETURN iret
17319 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17320 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17321 index 53cdfb2..d1369e6 100644
17322 --- a/arch/x86/include/asm/kprobes.h
17323 +++ b/arch/x86/include/asm/kprobes.h
17324 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17325 #define RELATIVEJUMP_SIZE 5
17326 #define RELATIVECALL_OPCODE 0xe8
17327 #define RELATIVE_ADDR_SIZE 4
17328 -#define MAX_STACK_SIZE 64
17329 -#define MIN_STACK_SIZE(ADDR) \
17330 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17331 - THREAD_SIZE - (unsigned long)(ADDR))) \
17332 - ? (MAX_STACK_SIZE) \
17333 - : (((unsigned long)current_thread_info()) + \
17334 - THREAD_SIZE - (unsigned long)(ADDR)))
17335 +#define MAX_STACK_SIZE 64UL
17336 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17337
17338 #define flush_insn_slot(p) do { } while (0)
17339
17340 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17341 index 7c492ed..d16311f 100644
17342 --- a/arch/x86/include/asm/kvm_host.h
17343 +++ b/arch/x86/include/asm/kvm_host.h
17344 @@ -990,6 +990,20 @@ static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code)
17345 kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
17346 }
17347
17348 +static inline u64 get_canonical(u64 la)
17349 +{
17350 + return ((int64_t)la << 16) >> 16;
17351 +}
17352 +
17353 +static inline bool is_noncanonical_address(u64 la)
17354 +{
17355 +#ifdef CONFIG_X86_64
17356 + return get_canonical(la) != la;
17357 +#else
17358 + return false;
17359 +#endif
17360 +}
17361 +
17362 #define TSS_IOPB_BASE_OFFSET 0x66
17363 #define TSS_BASE_SIZE 0x68
17364 #define TSS_IOPB_SIZE (65536 / 8)
17365 @@ -1048,7 +1062,7 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
17366 void kvm_vcpu_reset(struct kvm_vcpu *vcpu);
17367
17368 void kvm_define_shared_msr(unsigned index, u32 msr);
17369 -void kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
17370 +int kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
17371
17372 bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip);
17373
17374 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17375 index 4ad6560..75c7bdd 100644
17376 --- a/arch/x86/include/asm/local.h
17377 +++ b/arch/x86/include/asm/local.h
17378 @@ -10,33 +10,97 @@ typedef struct {
17379 atomic_long_t a;
17380 } local_t;
17381
17382 +typedef struct {
17383 + atomic_long_unchecked_t a;
17384 +} local_unchecked_t;
17385 +
17386 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17387
17388 #define local_read(l) atomic_long_read(&(l)->a)
17389 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17390 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17391 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17392
17393 static inline void local_inc(local_t *l)
17394 {
17395 - asm volatile(_ASM_INC "%0"
17396 + asm volatile(_ASM_INC "%0\n"
17397 +
17398 +#ifdef CONFIG_PAX_REFCOUNT
17399 + "jno 0f\n"
17400 + _ASM_DEC "%0\n"
17401 + "int $4\n0:\n"
17402 + _ASM_EXTABLE(0b, 0b)
17403 +#endif
17404 +
17405 + : "+m" (l->a.counter));
17406 +}
17407 +
17408 +static inline void local_inc_unchecked(local_unchecked_t *l)
17409 +{
17410 + asm volatile(_ASM_INC "%0\n"
17411 : "+m" (l->a.counter));
17412 }
17413
17414 static inline void local_dec(local_t *l)
17415 {
17416 - asm volatile(_ASM_DEC "%0"
17417 + asm volatile(_ASM_DEC "%0\n"
17418 +
17419 +#ifdef CONFIG_PAX_REFCOUNT
17420 + "jno 0f\n"
17421 + _ASM_INC "%0\n"
17422 + "int $4\n0:\n"
17423 + _ASM_EXTABLE(0b, 0b)
17424 +#endif
17425 +
17426 + : "+m" (l->a.counter));
17427 +}
17428 +
17429 +static inline void local_dec_unchecked(local_unchecked_t *l)
17430 +{
17431 + asm volatile(_ASM_DEC "%0\n"
17432 : "+m" (l->a.counter));
17433 }
17434
17435 static inline void local_add(long i, local_t *l)
17436 {
17437 - asm volatile(_ASM_ADD "%1,%0"
17438 + asm volatile(_ASM_ADD "%1,%0\n"
17439 +
17440 +#ifdef CONFIG_PAX_REFCOUNT
17441 + "jno 0f\n"
17442 + _ASM_SUB "%1,%0\n"
17443 + "int $4\n0:\n"
17444 + _ASM_EXTABLE(0b, 0b)
17445 +#endif
17446 +
17447 + : "+m" (l->a.counter)
17448 + : "ir" (i));
17449 +}
17450 +
17451 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17452 +{
17453 + asm volatile(_ASM_ADD "%1,%0\n"
17454 : "+m" (l->a.counter)
17455 : "ir" (i));
17456 }
17457
17458 static inline void local_sub(long i, local_t *l)
17459 {
17460 - asm volatile(_ASM_SUB "%1,%0"
17461 + asm volatile(_ASM_SUB "%1,%0\n"
17462 +
17463 +#ifdef CONFIG_PAX_REFCOUNT
17464 + "jno 0f\n"
17465 + _ASM_ADD "%1,%0\n"
17466 + "int $4\n0:\n"
17467 + _ASM_EXTABLE(0b, 0b)
17468 +#endif
17469 +
17470 + : "+m" (l->a.counter)
17471 + : "ir" (i));
17472 +}
17473 +
17474 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17475 +{
17476 + asm volatile(_ASM_SUB "%1,%0\n"
17477 : "+m" (l->a.counter)
17478 : "ir" (i));
17479 }
17480 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17481 */
17482 static inline int local_sub_and_test(long i, local_t *l)
17483 {
17484 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17485 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17486 }
17487
17488 /**
17489 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17490 */
17491 static inline int local_dec_and_test(local_t *l)
17492 {
17493 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17494 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17495 }
17496
17497 /**
17498 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17499 */
17500 static inline int local_inc_and_test(local_t *l)
17501 {
17502 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17503 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17504 }
17505
17506 /**
17507 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17508 */
17509 static inline int local_add_negative(long i, local_t *l)
17510 {
17511 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17512 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17513 }
17514
17515 /**
17516 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17517 static inline long local_add_return(long i, local_t *l)
17518 {
17519 long __i = i;
17520 + asm volatile(_ASM_XADD "%0, %1\n"
17521 +
17522 +#ifdef CONFIG_PAX_REFCOUNT
17523 + "jno 0f\n"
17524 + _ASM_MOV "%0,%1\n"
17525 + "int $4\n0:\n"
17526 + _ASM_EXTABLE(0b, 0b)
17527 +#endif
17528 +
17529 + : "+r" (i), "+m" (l->a.counter)
17530 + : : "memory");
17531 + return i + __i;
17532 +}
17533 +
17534 +/**
17535 + * local_add_return_unchecked - add and return
17536 + * @i: integer value to add
17537 + * @l: pointer to type local_unchecked_t
17538 + *
17539 + * Atomically adds @i to @l and returns @i + @l
17540 + */
17541 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17542 +{
17543 + long __i = i;
17544 asm volatile(_ASM_XADD "%0, %1;"
17545 : "+r" (i), "+m" (l->a.counter)
17546 : : "memory");
17547 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17548
17549 #define local_cmpxchg(l, o, n) \
17550 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17551 +#define local_cmpxchg_unchecked(l, o, n) \
17552 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17553 /* Always has a lock prefix */
17554 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17555
17556 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17557 new file mode 100644
17558 index 0000000..2bfd3ba
17559 --- /dev/null
17560 +++ b/arch/x86/include/asm/mman.h
17561 @@ -0,0 +1,15 @@
17562 +#ifndef _X86_MMAN_H
17563 +#define _X86_MMAN_H
17564 +
17565 +#include <uapi/asm/mman.h>
17566 +
17567 +#ifdef __KERNEL__
17568 +#ifndef __ASSEMBLY__
17569 +#ifdef CONFIG_X86_32
17570 +#define arch_mmap_check i386_mmap_check
17571 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17572 +#endif
17573 +#endif
17574 +#endif
17575 +
17576 +#endif /* X86_MMAN_H */
17577 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17578 index 876e74e..e20bfb1 100644
17579 --- a/arch/x86/include/asm/mmu.h
17580 +++ b/arch/x86/include/asm/mmu.h
17581 @@ -9,7 +9,7 @@
17582 * we put the segment information here.
17583 */
17584 typedef struct {
17585 - void *ldt;
17586 + struct desc_struct *ldt;
17587 int size;
17588
17589 #ifdef CONFIG_X86_64
17590 @@ -18,7 +18,19 @@ typedef struct {
17591 #endif
17592
17593 struct mutex lock;
17594 - void __user *vdso;
17595 + unsigned long vdso;
17596 +
17597 +#ifdef CONFIG_X86_32
17598 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17599 + unsigned long user_cs_base;
17600 + unsigned long user_cs_limit;
17601 +
17602 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17603 + cpumask_t cpu_user_cs_mask;
17604 +#endif
17605 +
17606 +#endif
17607 +#endif
17608 } mm_context_t;
17609
17610 #ifdef CONFIG_SMP
17611 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17612 index 166af2a..648c200 100644
17613 --- a/arch/x86/include/asm/mmu_context.h
17614 +++ b/arch/x86/include/asm/mmu_context.h
17615 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17616
17617 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17618 {
17619 +
17620 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17621 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17622 + unsigned int i;
17623 + pgd_t *pgd;
17624 +
17625 + pax_open_kernel();
17626 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17627 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17628 + set_pgd_batched(pgd+i, native_make_pgd(0));
17629 + pax_close_kernel();
17630 + }
17631 +#endif
17632 +
17633 #ifdef CONFIG_SMP
17634 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17635 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17636 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17637 struct task_struct *tsk)
17638 {
17639 unsigned cpu = smp_processor_id();
17640 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17641 + int tlbstate = TLBSTATE_OK;
17642 +#endif
17643
17644 if (likely(prev != next)) {
17645 #ifdef CONFIG_SMP
17646 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17647 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17648 +#endif
17649 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17650 this_cpu_write(cpu_tlbstate.active_mm, next);
17651 #endif
17652 cpumask_set_cpu(cpu, mm_cpumask(next));
17653
17654 /* Re-load page tables */
17655 +#ifdef CONFIG_PAX_PER_CPU_PGD
17656 + pax_open_kernel();
17657 +
17658 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17659 + if (static_cpu_has(X86_FEATURE_PCID))
17660 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17661 + else
17662 +#endif
17663 +
17664 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17665 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17666 + pax_close_kernel();
17667 + 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));
17668 +
17669 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17670 + if (static_cpu_has(X86_FEATURE_PCID)) {
17671 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17672 + u64 descriptor[2];
17673 + descriptor[0] = PCID_USER;
17674 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17675 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17676 + descriptor[0] = PCID_KERNEL;
17677 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17678 + }
17679 + } else {
17680 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17681 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17682 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17683 + else
17684 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17685 + }
17686 + } else
17687 +#endif
17688 +
17689 + load_cr3(get_cpu_pgd(cpu, kernel));
17690 +#else
17691 load_cr3(next->pgd);
17692 +#endif
17693 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17694
17695 /* Stop flush ipis for the previous mm */
17696 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17697 /* Load the LDT, if the LDT is different: */
17698 if (unlikely(prev->context.ldt != next->context.ldt))
17699 load_LDT_nolock(&next->context);
17700 +
17701 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17702 + if (!(__supported_pte_mask & _PAGE_NX)) {
17703 + smp_mb__before_atomic();
17704 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17705 + smp_mb__after_atomic();
17706 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17707 + }
17708 +#endif
17709 +
17710 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17711 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17712 + prev->context.user_cs_limit != next->context.user_cs_limit))
17713 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17714 +#ifdef CONFIG_SMP
17715 + else if (unlikely(tlbstate != TLBSTATE_OK))
17716 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17717 +#endif
17718 +#endif
17719 +
17720 }
17721 + else {
17722 +
17723 +#ifdef CONFIG_PAX_PER_CPU_PGD
17724 + pax_open_kernel();
17725 +
17726 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17727 + if (static_cpu_has(X86_FEATURE_PCID))
17728 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17729 + else
17730 +#endif
17731 +
17732 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17733 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17734 + pax_close_kernel();
17735 + 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));
17736 +
17737 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17738 + if (static_cpu_has(X86_FEATURE_PCID)) {
17739 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17740 + u64 descriptor[2];
17741 + descriptor[0] = PCID_USER;
17742 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17743 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17744 + descriptor[0] = PCID_KERNEL;
17745 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17746 + }
17747 + } else {
17748 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17749 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17750 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17751 + else
17752 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17753 + }
17754 + } else
17755 +#endif
17756 +
17757 + load_cr3(get_cpu_pgd(cpu, kernel));
17758 +#endif
17759 +
17760 #ifdef CONFIG_SMP
17761 - else {
17762 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17763 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17764
17765 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17766 * tlb flush IPI delivery. We must reload CR3
17767 * to make sure to use no freed page tables.
17768 */
17769 +
17770 +#ifndef CONFIG_PAX_PER_CPU_PGD
17771 load_cr3(next->pgd);
17772 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17773 +#endif
17774 +
17775 load_LDT_nolock(&next->context);
17776 +
17777 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17778 + if (!(__supported_pte_mask & _PAGE_NX))
17779 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17780 +#endif
17781 +
17782 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17783 +#ifdef CONFIG_PAX_PAGEEXEC
17784 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17785 +#endif
17786 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17787 +#endif
17788 +
17789 }
17790 +#endif
17791 }
17792 -#endif
17793 }
17794
17795 #define activate_mm(prev, next) \
17796 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17797 index e3b7819..b257c64 100644
17798 --- a/arch/x86/include/asm/module.h
17799 +++ b/arch/x86/include/asm/module.h
17800 @@ -5,6 +5,7 @@
17801
17802 #ifdef CONFIG_X86_64
17803 /* X86_64 does not define MODULE_PROC_FAMILY */
17804 +#define MODULE_PROC_FAMILY ""
17805 #elif defined CONFIG_M486
17806 #define MODULE_PROC_FAMILY "486 "
17807 #elif defined CONFIG_M586
17808 @@ -57,8 +58,20 @@
17809 #error unknown processor family
17810 #endif
17811
17812 -#ifdef CONFIG_X86_32
17813 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17814 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17815 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17816 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17817 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17818 +#else
17819 +#define MODULE_PAX_KERNEXEC ""
17820 #endif
17821
17822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17823 +#define MODULE_PAX_UDEREF "UDEREF "
17824 +#else
17825 +#define MODULE_PAX_UDEREF ""
17826 +#endif
17827 +
17828 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17829 +
17830 #endif /* _ASM_X86_MODULE_H */
17831 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17832 index 5f2fc44..106caa6 100644
17833 --- a/arch/x86/include/asm/nmi.h
17834 +++ b/arch/x86/include/asm/nmi.h
17835 @@ -36,26 +36,35 @@ enum {
17836
17837 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17838
17839 +struct nmiaction;
17840 +
17841 +struct nmiwork {
17842 + const struct nmiaction *action;
17843 + u64 max_duration;
17844 + struct irq_work irq_work;
17845 +};
17846 +
17847 struct nmiaction {
17848 struct list_head list;
17849 nmi_handler_t handler;
17850 - u64 max_duration;
17851 - struct irq_work irq_work;
17852 unsigned long flags;
17853 const char *name;
17854 -};
17855 + struct nmiwork *work;
17856 +} __do_const;
17857
17858 #define register_nmi_handler(t, fn, fg, n, init...) \
17859 ({ \
17860 - static struct nmiaction init fn##_na = { \
17861 + static struct nmiwork fn##_nw; \
17862 + static const struct nmiaction init fn##_na = { \
17863 .handler = (fn), \
17864 .name = (n), \
17865 .flags = (fg), \
17866 + .work = &fn##_nw, \
17867 }; \
17868 __register_nmi_handler((t), &fn##_na); \
17869 })
17870
17871 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17872 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17873
17874 void unregister_nmi_handler(unsigned int, const char *);
17875
17876 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17877 index 802dde3..9183e68 100644
17878 --- a/arch/x86/include/asm/page.h
17879 +++ b/arch/x86/include/asm/page.h
17880 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17881 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17882
17883 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17884 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17885
17886 #define __boot_va(x) __va(x)
17887 #define __boot_pa(x) __pa(x)
17888 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17889 * virt_to_page(kaddr) returns a valid pointer if and only if
17890 * virt_addr_valid(kaddr) returns true.
17891 */
17892 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17893 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17894 extern bool __virt_addr_valid(unsigned long kaddr);
17895 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17896
17897 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17898 +#define virt_to_page(kaddr) \
17899 + ({ \
17900 + const void *__kaddr = (const void *)(kaddr); \
17901 + BUG_ON(!virt_addr_valid(__kaddr)); \
17902 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17903 + })
17904 +#else
17905 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17906 +#endif
17907 +
17908 #endif /* __ASSEMBLY__ */
17909
17910 #include <asm-generic/memory_model.h>
17911 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17912 index f408caf..4a0455e 100644
17913 --- a/arch/x86/include/asm/page_64.h
17914 +++ b/arch/x86/include/asm/page_64.h
17915 @@ -7,9 +7,9 @@
17916
17917 /* duplicated to the one in bootmem.h */
17918 extern unsigned long max_pfn;
17919 -extern unsigned long phys_base;
17920 +extern const unsigned long phys_base;
17921
17922 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17923 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17924 {
17925 unsigned long y = x - __START_KERNEL_map;
17926
17927 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17928 index cd6e1610..70f4418 100644
17929 --- a/arch/x86/include/asm/paravirt.h
17930 +++ b/arch/x86/include/asm/paravirt.h
17931 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17932 return (pmd_t) { ret };
17933 }
17934
17935 -static inline pmdval_t pmd_val(pmd_t pmd)
17936 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17937 {
17938 pmdval_t ret;
17939
17940 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17941 val);
17942 }
17943
17944 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17945 +{
17946 + pgdval_t val = native_pgd_val(pgd);
17947 +
17948 + if (sizeof(pgdval_t) > sizeof(long))
17949 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17950 + val, (u64)val >> 32);
17951 + else
17952 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17953 + val);
17954 +}
17955 +
17956 static inline void pgd_clear(pgd_t *pgdp)
17957 {
17958 set_pgd(pgdp, __pgd(0));
17959 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17960 pv_mmu_ops.set_fixmap(idx, phys, flags);
17961 }
17962
17963 +#ifdef CONFIG_PAX_KERNEXEC
17964 +static inline unsigned long pax_open_kernel(void)
17965 +{
17966 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17967 +}
17968 +
17969 +static inline unsigned long pax_close_kernel(void)
17970 +{
17971 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17972 +}
17973 +#else
17974 +static inline unsigned long pax_open_kernel(void) { return 0; }
17975 +static inline unsigned long pax_close_kernel(void) { return 0; }
17976 +#endif
17977 +
17978 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17979
17980 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17981 @@ -906,7 +933,7 @@ extern void default_banner(void);
17982
17983 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17984 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17985 -#define PARA_INDIRECT(addr) *%cs:addr
17986 +#define PARA_INDIRECT(addr) *%ss:addr
17987 #endif
17988
17989 #define INTERRUPT_RETURN \
17990 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17991 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17992 CLBR_NONE, \
17993 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17994 +
17995 +#define GET_CR0_INTO_RDI \
17996 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17997 + mov %rax,%rdi
17998 +
17999 +#define SET_RDI_INTO_CR0 \
18000 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18001 +
18002 +#define GET_CR3_INTO_RDI \
18003 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18004 + mov %rax,%rdi
18005 +
18006 +#define SET_RDI_INTO_CR3 \
18007 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18008 +
18009 #endif /* CONFIG_X86_32 */
18010
18011 #endif /* __ASSEMBLY__ */
18012 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18013 index 7549b8b..f0edfda 100644
18014 --- a/arch/x86/include/asm/paravirt_types.h
18015 +++ b/arch/x86/include/asm/paravirt_types.h
18016 @@ -84,7 +84,7 @@ struct pv_init_ops {
18017 */
18018 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18019 unsigned long addr, unsigned len);
18020 -};
18021 +} __no_const __no_randomize_layout;
18022
18023
18024 struct pv_lazy_ops {
18025 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18026 void (*enter)(void);
18027 void (*leave)(void);
18028 void (*flush)(void);
18029 -};
18030 +} __no_randomize_layout;
18031
18032 struct pv_time_ops {
18033 unsigned long long (*sched_clock)(void);
18034 unsigned long long (*steal_clock)(int cpu);
18035 unsigned long (*get_tsc_khz)(void);
18036 -};
18037 +} __no_const __no_randomize_layout;
18038
18039 struct pv_cpu_ops {
18040 /* hooks for various privileged instructions */
18041 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18042
18043 void (*start_context_switch)(struct task_struct *prev);
18044 void (*end_context_switch)(struct task_struct *next);
18045 -};
18046 +} __no_const __no_randomize_layout;
18047
18048 struct pv_irq_ops {
18049 /*
18050 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18051 #ifdef CONFIG_X86_64
18052 void (*adjust_exception_frame)(void);
18053 #endif
18054 -};
18055 +} __no_randomize_layout;
18056
18057 struct pv_apic_ops {
18058 #ifdef CONFIG_X86_LOCAL_APIC
18059 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18060 unsigned long start_eip,
18061 unsigned long start_esp);
18062 #endif
18063 -};
18064 +} __no_const __no_randomize_layout;
18065
18066 struct pv_mmu_ops {
18067 unsigned long (*read_cr2)(void);
18068 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18069 struct paravirt_callee_save make_pud;
18070
18071 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18072 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18073 #endif /* PAGETABLE_LEVELS == 4 */
18074 #endif /* PAGETABLE_LEVELS >= 3 */
18075
18076 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18077 an mfn. We can tell which is which from the index. */
18078 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18079 phys_addr_t phys, pgprot_t flags);
18080 -};
18081 +
18082 +#ifdef CONFIG_PAX_KERNEXEC
18083 + unsigned long (*pax_open_kernel)(void);
18084 + unsigned long (*pax_close_kernel)(void);
18085 +#endif
18086 +
18087 +} __no_randomize_layout;
18088
18089 struct arch_spinlock;
18090 #ifdef CONFIG_SMP
18091 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18092 struct pv_lock_ops {
18093 struct paravirt_callee_save lock_spinning;
18094 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18095 -};
18096 +} __no_randomize_layout;
18097
18098 /* This contains all the paravirt structures: we get a convenient
18099 * number for each function using the offset which we use to indicate
18100 - * what to patch. */
18101 + * what to patch.
18102 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18103 + */
18104 +
18105 struct paravirt_patch_template {
18106 struct pv_init_ops pv_init_ops;
18107 struct pv_time_ops pv_time_ops;
18108 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18109 struct pv_apic_ops pv_apic_ops;
18110 struct pv_mmu_ops pv_mmu_ops;
18111 struct pv_lock_ops pv_lock_ops;
18112 -};
18113 +} __no_randomize_layout;
18114
18115 extern struct pv_info pv_info;
18116 extern struct pv_init_ops pv_init_ops;
18117 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18118 index c4412e9..90e88c5 100644
18119 --- a/arch/x86/include/asm/pgalloc.h
18120 +++ b/arch/x86/include/asm/pgalloc.h
18121 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18122 pmd_t *pmd, pte_t *pte)
18123 {
18124 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18125 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18126 +}
18127 +
18128 +static inline void pmd_populate_user(struct mm_struct *mm,
18129 + pmd_t *pmd, pte_t *pte)
18130 +{
18131 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18132 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18133 }
18134
18135 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18136
18137 #ifdef CONFIG_X86_PAE
18138 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18139 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18140 +{
18141 + pud_populate(mm, pudp, pmd);
18142 +}
18143 #else /* !CONFIG_X86_PAE */
18144 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18145 {
18146 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18147 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18148 }
18149 +
18150 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18151 +{
18152 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18153 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18154 +}
18155 #endif /* CONFIG_X86_PAE */
18156
18157 #if PAGETABLE_LEVELS > 3
18158 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18159 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18160 }
18161
18162 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18163 +{
18164 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18165 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18166 +}
18167 +
18168 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18169 {
18170 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18171 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18172 index 206a87f..1623b06 100644
18173 --- a/arch/x86/include/asm/pgtable-2level.h
18174 +++ b/arch/x86/include/asm/pgtable-2level.h
18175 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18176
18177 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18178 {
18179 + pax_open_kernel();
18180 *pmdp = pmd;
18181 + pax_close_kernel();
18182 }
18183
18184 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18185 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18186 index 81bb91b..9392125 100644
18187 --- a/arch/x86/include/asm/pgtable-3level.h
18188 +++ b/arch/x86/include/asm/pgtable-3level.h
18189 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18190
18191 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18192 {
18193 + pax_open_kernel();
18194 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18195 + pax_close_kernel();
18196 }
18197
18198 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18199 {
18200 + pax_open_kernel();
18201 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18202 + pax_close_kernel();
18203 }
18204
18205 /*
18206 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18207 index aa97a07..5c53c32 100644
18208 --- a/arch/x86/include/asm/pgtable.h
18209 +++ b/arch/x86/include/asm/pgtable.h
18210 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18211
18212 #ifndef __PAGETABLE_PUD_FOLDED
18213 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18214 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18215 #define pgd_clear(pgd) native_pgd_clear(pgd)
18216 #endif
18217
18218 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18219
18220 #define arch_end_context_switch(prev) do {} while(0)
18221
18222 +#define pax_open_kernel() native_pax_open_kernel()
18223 +#define pax_close_kernel() native_pax_close_kernel()
18224 #endif /* CONFIG_PARAVIRT */
18225
18226 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18227 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18228 +
18229 +#ifdef CONFIG_PAX_KERNEXEC
18230 +static inline unsigned long native_pax_open_kernel(void)
18231 +{
18232 + unsigned long cr0;
18233 +
18234 + preempt_disable();
18235 + barrier();
18236 + cr0 = read_cr0() ^ X86_CR0_WP;
18237 + BUG_ON(cr0 & X86_CR0_WP);
18238 + write_cr0(cr0);
18239 + barrier();
18240 + return cr0 ^ X86_CR0_WP;
18241 +}
18242 +
18243 +static inline unsigned long native_pax_close_kernel(void)
18244 +{
18245 + unsigned long cr0;
18246 +
18247 + barrier();
18248 + cr0 = read_cr0() ^ X86_CR0_WP;
18249 + BUG_ON(!(cr0 & X86_CR0_WP));
18250 + write_cr0(cr0);
18251 + barrier();
18252 + preempt_enable_no_resched();
18253 + return cr0 ^ X86_CR0_WP;
18254 +}
18255 +#else
18256 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18257 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18258 +#endif
18259 +
18260 /*
18261 * The following only work if pte_present() is true.
18262 * Undefined behaviour if not..
18263 */
18264 +static inline int pte_user(pte_t pte)
18265 +{
18266 + return pte_val(pte) & _PAGE_USER;
18267 +}
18268 +
18269 static inline int pte_dirty(pte_t pte)
18270 {
18271 return pte_flags(pte) & _PAGE_DIRTY;
18272 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18273 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18274 }
18275
18276 +static inline unsigned long pgd_pfn(pgd_t pgd)
18277 +{
18278 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18279 +}
18280 +
18281 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18282
18283 static inline int pmd_large(pmd_t pte)
18284 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18285 return pte_clear_flags(pte, _PAGE_RW);
18286 }
18287
18288 +static inline pte_t pte_mkread(pte_t pte)
18289 +{
18290 + return __pte(pte_val(pte) | _PAGE_USER);
18291 +}
18292 +
18293 static inline pte_t pte_mkexec(pte_t pte)
18294 {
18295 - return pte_clear_flags(pte, _PAGE_NX);
18296 +#ifdef CONFIG_X86_PAE
18297 + if (__supported_pte_mask & _PAGE_NX)
18298 + return pte_clear_flags(pte, _PAGE_NX);
18299 + else
18300 +#endif
18301 + return pte_set_flags(pte, _PAGE_USER);
18302 +}
18303 +
18304 +static inline pte_t pte_exprotect(pte_t pte)
18305 +{
18306 +#ifdef CONFIG_X86_PAE
18307 + if (__supported_pte_mask & _PAGE_NX)
18308 + return pte_set_flags(pte, _PAGE_NX);
18309 + else
18310 +#endif
18311 + return pte_clear_flags(pte, _PAGE_USER);
18312 }
18313
18314 static inline pte_t pte_mkdirty(pte_t pte)
18315 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18316 #endif
18317
18318 #ifndef __ASSEMBLY__
18319 +
18320 +#ifdef CONFIG_PAX_PER_CPU_PGD
18321 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18322 +enum cpu_pgd_type {kernel = 0, user = 1};
18323 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18324 +{
18325 + return cpu_pgd[cpu][type];
18326 +}
18327 +#endif
18328 +
18329 #include <linux/mm_types.h>
18330 #include <linux/mmdebug.h>
18331 #include <linux/log2.h>
18332 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18333 * Currently stuck as a macro due to indirect forward reference to
18334 * linux/mmzone.h's __section_mem_map_addr() definition:
18335 */
18336 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18337 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18338
18339 /* Find an entry in the second-level page table.. */
18340 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18341 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18342 * Currently stuck as a macro due to indirect forward reference to
18343 * linux/mmzone.h's __section_mem_map_addr() definition:
18344 */
18345 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18346 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18347
18348 /* to find an entry in a page-table-directory. */
18349 static inline unsigned long pud_index(unsigned long address)
18350 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18351
18352 static inline int pgd_bad(pgd_t pgd)
18353 {
18354 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18355 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18356 }
18357
18358 static inline int pgd_none(pgd_t pgd)
18359 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18360 * pgd_offset() returns a (pgd_t *)
18361 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18362 */
18363 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18364 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18365 +
18366 +#ifdef CONFIG_PAX_PER_CPU_PGD
18367 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18368 +#endif
18369 +
18370 /*
18371 * a shortcut which implies the use of the kernel's pgd, instead
18372 * of a process's
18373 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18374 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18375 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18376
18377 +#ifdef CONFIG_X86_32
18378 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18379 +#else
18380 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18381 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18382 +
18383 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18384 +#ifdef __ASSEMBLY__
18385 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18386 +#else
18387 +extern unsigned long pax_user_shadow_base;
18388 +extern pgdval_t clone_pgd_mask;
18389 +#endif
18390 +#endif
18391 +
18392 +#endif
18393 +
18394 #ifndef __ASSEMBLY__
18395
18396 extern int direct_gbpages;
18397 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18398 * dst and src can be on the same page, but the range must not overlap,
18399 * and must not cross a page boundary.
18400 */
18401 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18402 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18403 {
18404 - memcpy(dst, src, count * sizeof(pgd_t));
18405 + pax_open_kernel();
18406 + while (count--)
18407 + *dst++ = *src++;
18408 + pax_close_kernel();
18409 }
18410
18411 +#ifdef CONFIG_PAX_PER_CPU_PGD
18412 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18413 +#endif
18414 +
18415 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18416 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18417 +#else
18418 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18419 +#endif
18420 +
18421 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18422 static inline int page_level_shift(enum pg_level level)
18423 {
18424 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18425 index 9ee3221..b979c6b 100644
18426 --- a/arch/x86/include/asm/pgtable_32.h
18427 +++ b/arch/x86/include/asm/pgtable_32.h
18428 @@ -25,9 +25,6 @@
18429 struct mm_struct;
18430 struct vm_area_struct;
18431
18432 -extern pgd_t swapper_pg_dir[1024];
18433 -extern pgd_t initial_page_table[1024];
18434 -
18435 static inline void pgtable_cache_init(void) { }
18436 static inline void check_pgt_cache(void) { }
18437 void paging_init(void);
18438 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18439 # include <asm/pgtable-2level.h>
18440 #endif
18441
18442 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18443 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18444 +#ifdef CONFIG_X86_PAE
18445 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18446 +#endif
18447 +
18448 #if defined(CONFIG_HIGHPTE)
18449 #define pte_offset_map(dir, address) \
18450 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18451 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18452 /* Clear a kernel PTE and flush it from the TLB */
18453 #define kpte_clear_flush(ptep, vaddr) \
18454 do { \
18455 + pax_open_kernel(); \
18456 pte_clear(&init_mm, (vaddr), (ptep)); \
18457 + pax_close_kernel(); \
18458 __flush_tlb_one((vaddr)); \
18459 } while (0)
18460
18461 #endif /* !__ASSEMBLY__ */
18462
18463 +#define HAVE_ARCH_UNMAPPED_AREA
18464 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18465 +
18466 /*
18467 * kern_addr_valid() is (1) for FLATMEM and (0) for
18468 * SPARSEMEM and DISCONTIGMEM
18469 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18470 index ed5903b..c7fe163 100644
18471 --- a/arch/x86/include/asm/pgtable_32_types.h
18472 +++ b/arch/x86/include/asm/pgtable_32_types.h
18473 @@ -8,7 +8,7 @@
18474 */
18475 #ifdef CONFIG_X86_PAE
18476 # include <asm/pgtable-3level_types.h>
18477 -# define PMD_SIZE (1UL << PMD_SHIFT)
18478 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18479 # define PMD_MASK (~(PMD_SIZE - 1))
18480 #else
18481 # include <asm/pgtable-2level_types.h>
18482 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18483 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18484 #endif
18485
18486 +#ifdef CONFIG_PAX_KERNEXEC
18487 +#ifndef __ASSEMBLY__
18488 +extern unsigned char MODULES_EXEC_VADDR[];
18489 +extern unsigned char MODULES_EXEC_END[];
18490 +#endif
18491 +#include <asm/boot.h>
18492 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18493 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18494 +#else
18495 +#define ktla_ktva(addr) (addr)
18496 +#define ktva_ktla(addr) (addr)
18497 +#endif
18498 +
18499 #define MODULES_VADDR VMALLOC_START
18500 #define MODULES_END VMALLOC_END
18501 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18502 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18503 index 3874693..d7906ac 100644
18504 --- a/arch/x86/include/asm/pgtable_64.h
18505 +++ b/arch/x86/include/asm/pgtable_64.h
18506 @@ -16,11 +16,16 @@
18507
18508 extern pud_t level3_kernel_pgt[512];
18509 extern pud_t level3_ident_pgt[512];
18510 +extern pud_t level3_vmalloc_start_pgt[512];
18511 +extern pud_t level3_vmalloc_end_pgt[512];
18512 +extern pud_t level3_vmemmap_pgt[512];
18513 +extern pud_t level2_vmemmap_pgt[512];
18514 extern pmd_t level2_kernel_pgt[512];
18515 extern pmd_t level2_fixmap_pgt[512];
18516 -extern pmd_t level2_ident_pgt[512];
18517 +extern pmd_t level2_ident_pgt[512*2];
18518 extern pte_t level1_fixmap_pgt[512];
18519 -extern pgd_t init_level4_pgt[];
18520 +extern pte_t level1_vsyscall_pgt[512];
18521 +extern pgd_t init_level4_pgt[512];
18522
18523 #define swapper_pg_dir init_level4_pgt
18524
18525 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18526
18527 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18528 {
18529 + pax_open_kernel();
18530 *pmdp = pmd;
18531 + pax_close_kernel();
18532 }
18533
18534 static inline void native_pmd_clear(pmd_t *pmd)
18535 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18536
18537 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18538 {
18539 + pax_open_kernel();
18540 *pudp = pud;
18541 + pax_close_kernel();
18542 }
18543
18544 static inline void native_pud_clear(pud_t *pud)
18545 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18546
18547 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18548 {
18549 + pax_open_kernel();
18550 + *pgdp = pgd;
18551 + pax_close_kernel();
18552 +}
18553 +
18554 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18555 +{
18556 *pgdp = pgd;
18557 }
18558
18559 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18560 index 7166e25..baaa6fe 100644
18561 --- a/arch/x86/include/asm/pgtable_64_types.h
18562 +++ b/arch/x86/include/asm/pgtable_64_types.h
18563 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18564 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18565 #define MODULES_END _AC(0xffffffffff000000, UL)
18566 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18567 +#define MODULES_EXEC_VADDR MODULES_VADDR
18568 +#define MODULES_EXEC_END MODULES_END
18569 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18570 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18571
18572 +#define ktla_ktva(addr) (addr)
18573 +#define ktva_ktla(addr) (addr)
18574 +
18575 #define EARLY_DYNAMIC_PAGE_TABLES 64
18576
18577 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18578 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18579 index f216963..6bd7c21 100644
18580 --- a/arch/x86/include/asm/pgtable_types.h
18581 +++ b/arch/x86/include/asm/pgtable_types.h
18582 @@ -111,8 +111,10 @@
18583
18584 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18585 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18586 -#else
18587 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18588 #define _PAGE_NX (_AT(pteval_t, 0))
18589 +#else
18590 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18591 #endif
18592
18593 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18594 @@ -151,6 +153,9 @@
18595 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18596 _PAGE_ACCESSED)
18597
18598 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18599 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18600 +
18601 #define __PAGE_KERNEL_EXEC \
18602 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18603 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18604 @@ -161,7 +166,7 @@
18605 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18606 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18607 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18608 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18609 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18610 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18611 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18612 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18613 @@ -218,7 +223,7 @@
18614 #ifdef CONFIG_X86_64
18615 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18616 #else
18617 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18618 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18619 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18620 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18621 #endif
18622 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18623 {
18624 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18625 }
18626 +#endif
18627
18628 +#if PAGETABLE_LEVELS == 3
18629 +#include <asm-generic/pgtable-nopud.h>
18630 +#endif
18631 +
18632 +#if PAGETABLE_LEVELS == 2
18633 +#include <asm-generic/pgtable-nopmd.h>
18634 +#endif
18635 +
18636 +#ifndef __ASSEMBLY__
18637 #if PAGETABLE_LEVELS > 3
18638 typedef struct { pudval_t pud; } pud_t;
18639
18640 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18641 return pud.pud;
18642 }
18643 #else
18644 -#include <asm-generic/pgtable-nopud.h>
18645 -
18646 static inline pudval_t native_pud_val(pud_t pud)
18647 {
18648 return native_pgd_val(pud.pgd);
18649 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18650 return pmd.pmd;
18651 }
18652 #else
18653 -#include <asm-generic/pgtable-nopmd.h>
18654 -
18655 static inline pmdval_t native_pmd_val(pmd_t pmd)
18656 {
18657 return native_pgd_val(pmd.pud.pgd);
18658 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
18659
18660 extern pteval_t __supported_pte_mask;
18661 extern void set_nx(void);
18662 -extern int nx_enabled;
18663
18664 #define pgprot_writecombine pgprot_writecombine
18665 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18666 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18667 index 7024c12..71c46b9 100644
18668 --- a/arch/x86/include/asm/preempt.h
18669 +++ b/arch/x86/include/asm/preempt.h
18670 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18671 */
18672 static __always_inline bool __preempt_count_dec_and_test(void)
18673 {
18674 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18675 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18676 }
18677
18678 /*
18679 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18680 index eb71ec7..f06532a 100644
18681 --- a/arch/x86/include/asm/processor.h
18682 +++ b/arch/x86/include/asm/processor.h
18683 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18684 /* Index into per_cpu list: */
18685 u16 cpu_index;
18686 u32 microcode;
18687 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18688 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18689
18690 #define X86_VENDOR_INTEL 0
18691 #define X86_VENDOR_CYRIX 1
18692 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18693 : "memory");
18694 }
18695
18696 +/* invpcid (%rdx),%rax */
18697 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18698 +
18699 +#define INVPCID_SINGLE_ADDRESS 0UL
18700 +#define INVPCID_SINGLE_CONTEXT 1UL
18701 +#define INVPCID_ALL_GLOBAL 2UL
18702 +#define INVPCID_ALL_NONGLOBAL 3UL
18703 +
18704 +#define PCID_KERNEL 0UL
18705 +#define PCID_USER 1UL
18706 +#define PCID_NOFLUSH (1UL << 63)
18707 +
18708 static inline void load_cr3(pgd_t *pgdir)
18709 {
18710 - write_cr3(__pa(pgdir));
18711 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18712 }
18713
18714 #ifdef CONFIG_X86_32
18715 @@ -282,7 +294,7 @@ struct tss_struct {
18716
18717 } ____cacheline_aligned;
18718
18719 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18720 +extern struct tss_struct init_tss[NR_CPUS];
18721
18722 /*
18723 * Save the original ist values for checking stack pointers during debugging
18724 @@ -478,6 +490,7 @@ struct thread_struct {
18725 unsigned short ds;
18726 unsigned short fsindex;
18727 unsigned short gsindex;
18728 + unsigned short ss;
18729 #endif
18730 #ifdef CONFIG_X86_32
18731 unsigned long ip;
18732 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18733 extern unsigned long mmu_cr4_features;
18734 extern u32 *trampoline_cr4_features;
18735
18736 -static inline void set_in_cr4(unsigned long mask)
18737 -{
18738 - unsigned long cr4;
18739 -
18740 - mmu_cr4_features |= mask;
18741 - if (trampoline_cr4_features)
18742 - *trampoline_cr4_features = mmu_cr4_features;
18743 - cr4 = read_cr4();
18744 - cr4 |= mask;
18745 - write_cr4(cr4);
18746 -}
18747 -
18748 -static inline void clear_in_cr4(unsigned long mask)
18749 -{
18750 - unsigned long cr4;
18751 -
18752 - mmu_cr4_features &= ~mask;
18753 - if (trampoline_cr4_features)
18754 - *trampoline_cr4_features = mmu_cr4_features;
18755 - cr4 = read_cr4();
18756 - cr4 &= ~mask;
18757 - write_cr4(cr4);
18758 -}
18759 +extern void set_in_cr4(unsigned long mask);
18760 +extern void clear_in_cr4(unsigned long mask);
18761
18762 typedef struct {
18763 unsigned long seg;
18764 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18765 */
18766 #define TASK_SIZE PAGE_OFFSET
18767 #define TASK_SIZE_MAX TASK_SIZE
18768 +
18769 +#ifdef CONFIG_PAX_SEGMEXEC
18770 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18771 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18772 +#else
18773 #define STACK_TOP TASK_SIZE
18774 -#define STACK_TOP_MAX STACK_TOP
18775 +#endif
18776 +
18777 +#define STACK_TOP_MAX TASK_SIZE
18778
18779 #define INIT_THREAD { \
18780 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18781 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18782 .vm86_info = NULL, \
18783 .sysenter_cs = __KERNEL_CS, \
18784 .io_bitmap_ptr = NULL, \
18785 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18786 */
18787 #define INIT_TSS { \
18788 .x86_tss = { \
18789 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18790 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18791 .ss0 = __KERNEL_DS, \
18792 .ss1 = __KERNEL_CS, \
18793 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18794 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18795 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18796
18797 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18798 -#define KSTK_TOP(info) \
18799 -({ \
18800 - unsigned long *__ptr = (unsigned long *)(info); \
18801 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18802 -})
18803 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18804
18805 /*
18806 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18807 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18808 #define task_pt_regs(task) \
18809 ({ \
18810 struct pt_regs *__regs__; \
18811 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18812 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18813 __regs__ - 1; \
18814 })
18815
18816 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18817 /*
18818 * User space process size. 47bits minus one guard page.
18819 */
18820 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18821 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18822
18823 /* This decides where the kernel will search for a free chunk of vm
18824 * space during mmap's.
18825 */
18826 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18827 - 0xc0000000 : 0xFFFFe000)
18828 + 0xc0000000 : 0xFFFFf000)
18829
18830 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18831 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18832 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18833 #define STACK_TOP_MAX TASK_SIZE_MAX
18834
18835 #define INIT_THREAD { \
18836 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18837 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18838 }
18839
18840 #define INIT_TSS { \
18841 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18842 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18843 }
18844
18845 /*
18846 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18847 */
18848 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18849
18850 +#ifdef CONFIG_PAX_SEGMEXEC
18851 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18852 +#endif
18853 +
18854 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18855
18856 /* Get/set a process' ability to use the timestamp counter instruction */
18857 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18858 return 0;
18859 }
18860
18861 -extern unsigned long arch_align_stack(unsigned long sp);
18862 +#define arch_align_stack(x) ((x) & ~0xfUL)
18863 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18864
18865 void default_idle(void);
18866 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18867 #define xen_set_default_idle 0
18868 #endif
18869
18870 -void stop_this_cpu(void *dummy);
18871 +void stop_this_cpu(void *dummy) __noreturn;
18872 void df_debug(struct pt_regs *regs, long error_code);
18873 #endif /* _ASM_X86_PROCESSOR_H */
18874 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18875 index 6205f0c..688a3a9 100644
18876 --- a/arch/x86/include/asm/ptrace.h
18877 +++ b/arch/x86/include/asm/ptrace.h
18878 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18879 }
18880
18881 /*
18882 - * user_mode_vm(regs) determines whether a register set came from user mode.
18883 + * user_mode(regs) determines whether a register set came from user mode.
18884 * This is true if V8086 mode was enabled OR if the register set was from
18885 * protected mode with RPL-3 CS value. This tricky test checks that with
18886 * one comparison. Many places in the kernel can bypass this full check
18887 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18888 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18889 + * be used.
18890 */
18891 -static inline int user_mode(struct pt_regs *regs)
18892 +static inline int user_mode_novm(struct pt_regs *regs)
18893 {
18894 #ifdef CONFIG_X86_32
18895 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18896 #else
18897 - return !!(regs->cs & 3);
18898 + return !!(regs->cs & SEGMENT_RPL_MASK);
18899 #endif
18900 }
18901
18902 -static inline int user_mode_vm(struct pt_regs *regs)
18903 +static inline int user_mode(struct pt_regs *regs)
18904 {
18905 #ifdef CONFIG_X86_32
18906 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18907 USER_RPL;
18908 #else
18909 - return user_mode(regs);
18910 + return user_mode_novm(regs);
18911 #endif
18912 }
18913
18914 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18915 #ifdef CONFIG_X86_64
18916 static inline bool user_64bit_mode(struct pt_regs *regs)
18917 {
18918 + unsigned long cs = regs->cs & 0xffff;
18919 #ifndef CONFIG_PARAVIRT
18920 /*
18921 * On non-paravirt systems, this is the only long mode CPL 3
18922 * selector. We do not allow long mode selectors in the LDT.
18923 */
18924 - return regs->cs == __USER_CS;
18925 + return cs == __USER_CS;
18926 #else
18927 /* Headers are too twisted for this to go in paravirt.h. */
18928 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18929 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18930 #endif
18931 }
18932
18933 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18934 * Traps from the kernel do not save sp and ss.
18935 * Use the helper function to retrieve sp.
18936 */
18937 - if (offset == offsetof(struct pt_regs, sp) &&
18938 - regs->cs == __KERNEL_CS)
18939 - return kernel_stack_pointer(regs);
18940 + if (offset == offsetof(struct pt_regs, sp)) {
18941 + unsigned long cs = regs->cs & 0xffff;
18942 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18943 + return kernel_stack_pointer(regs);
18944 + }
18945 #endif
18946 return *(unsigned long *)((unsigned long)regs + offset);
18947 }
18948 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18949 index ae0e241..e80b10b 100644
18950 --- a/arch/x86/include/asm/qrwlock.h
18951 +++ b/arch/x86/include/asm/qrwlock.h
18952 @@ -7,8 +7,8 @@
18953 #define queue_write_unlock queue_write_unlock
18954 static inline void queue_write_unlock(struct qrwlock *lock)
18955 {
18956 - barrier();
18957 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18958 + barrier();
18959 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18960 }
18961 #endif
18962
18963 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18964 index 9c6b890..5305f53 100644
18965 --- a/arch/x86/include/asm/realmode.h
18966 +++ b/arch/x86/include/asm/realmode.h
18967 @@ -22,16 +22,14 @@ struct real_mode_header {
18968 #endif
18969 /* APM/BIOS reboot */
18970 u32 machine_real_restart_asm;
18971 -#ifdef CONFIG_X86_64
18972 u32 machine_real_restart_seg;
18973 -#endif
18974 };
18975
18976 /* This must match data at trampoline_32/64.S */
18977 struct trampoline_header {
18978 #ifdef CONFIG_X86_32
18979 u32 start;
18980 - u16 gdt_pad;
18981 + u16 boot_cs;
18982 u16 gdt_limit;
18983 u32 gdt_base;
18984 #else
18985 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18986 index a82c4f1..ac45053 100644
18987 --- a/arch/x86/include/asm/reboot.h
18988 +++ b/arch/x86/include/asm/reboot.h
18989 @@ -6,13 +6,13 @@
18990 struct pt_regs;
18991
18992 struct machine_ops {
18993 - void (*restart)(char *cmd);
18994 - void (*halt)(void);
18995 - void (*power_off)(void);
18996 + void (* __noreturn restart)(char *cmd);
18997 + void (* __noreturn halt)(void);
18998 + void (* __noreturn power_off)(void);
18999 void (*shutdown)(void);
19000 void (*crash_shutdown)(struct pt_regs *);
19001 - void (*emergency_restart)(void);
19002 -};
19003 + void (* __noreturn emergency_restart)(void);
19004 +} __no_const;
19005
19006 extern struct machine_ops machine_ops;
19007
19008 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19009 index 8f7866a..e442f20 100644
19010 --- a/arch/x86/include/asm/rmwcc.h
19011 +++ b/arch/x86/include/asm/rmwcc.h
19012 @@ -3,7 +3,34 @@
19013
19014 #ifdef CC_HAVE_ASM_GOTO
19015
19016 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19017 +#ifdef CONFIG_PAX_REFCOUNT
19018 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19019 +do { \
19020 + asm_volatile_goto (fullop \
19021 + ";jno 0f\n" \
19022 + fullantiop \
19023 + ";int $4\n0:\n" \
19024 + _ASM_EXTABLE(0b, 0b) \
19025 + ";j" cc " %l[cc_label]" \
19026 + : : "m" (var), ## __VA_ARGS__ \
19027 + : "memory" : cc_label); \
19028 + return 0; \
19029 +cc_label: \
19030 + return 1; \
19031 +} while (0)
19032 +#else
19033 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19034 +do { \
19035 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19036 + : : "m" (var), ## __VA_ARGS__ \
19037 + : "memory" : cc_label); \
19038 + return 0; \
19039 +cc_label: \
19040 + return 1; \
19041 +} while (0)
19042 +#endif
19043 +
19044 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19045 do { \
19046 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19047 : : "m" (var), ## __VA_ARGS__ \
19048 @@ -13,15 +40,46 @@ cc_label: \
19049 return 1; \
19050 } while (0)
19051
19052 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19053 - __GEN_RMWcc(op " " arg0, var, cc)
19054 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19055 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19056
19057 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19058 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19059 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19060 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19061 +
19062 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19063 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19064 +
19065 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19066 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19067
19068 #else /* !CC_HAVE_ASM_GOTO */
19069
19070 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19071 +#ifdef CONFIG_PAX_REFCOUNT
19072 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19073 +do { \
19074 + char c; \
19075 + asm volatile (fullop \
19076 + ";jno 0f\n" \
19077 + fullantiop \
19078 + ";int $4\n0:\n" \
19079 + _ASM_EXTABLE(0b, 0b) \
19080 + "; set" cc " %1" \
19081 + : "+m" (var), "=qm" (c) \
19082 + : __VA_ARGS__ : "memory"); \
19083 + return c != 0; \
19084 +} while (0)
19085 +#else
19086 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19087 +do { \
19088 + char c; \
19089 + asm volatile (fullop "; set" cc " %1" \
19090 + : "+m" (var), "=qm" (c) \
19091 + : __VA_ARGS__ : "memory"); \
19092 + return c != 0; \
19093 +} while (0)
19094 +#endif
19095 +
19096 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19097 do { \
19098 char c; \
19099 asm volatile (fullop "; set" cc " %1" \
19100 @@ -30,11 +88,17 @@ do { \
19101 return c != 0; \
19102 } while (0)
19103
19104 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19105 - __GEN_RMWcc(op " " arg0, var, cc)
19106 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19107 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19108 +
19109 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19110 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19111 +
19112 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19113 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19114
19115 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19116 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19117 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19118 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19119
19120 #endif /* CC_HAVE_ASM_GOTO */
19121
19122 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19123 index cad82c9..2e5c5c1 100644
19124 --- a/arch/x86/include/asm/rwsem.h
19125 +++ b/arch/x86/include/asm/rwsem.h
19126 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19127 {
19128 asm volatile("# beginning down_read\n\t"
19129 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19130 +
19131 +#ifdef CONFIG_PAX_REFCOUNT
19132 + "jno 0f\n"
19133 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19134 + "int $4\n0:\n"
19135 + _ASM_EXTABLE(0b, 0b)
19136 +#endif
19137 +
19138 /* adds 0x00000001 */
19139 " jns 1f\n"
19140 " call call_rwsem_down_read_failed\n"
19141 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19142 "1:\n\t"
19143 " mov %1,%2\n\t"
19144 " add %3,%2\n\t"
19145 +
19146 +#ifdef CONFIG_PAX_REFCOUNT
19147 + "jno 0f\n"
19148 + "sub %3,%2\n"
19149 + "int $4\n0:\n"
19150 + _ASM_EXTABLE(0b, 0b)
19151 +#endif
19152 +
19153 " jle 2f\n\t"
19154 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19155 " jnz 1b\n\t"
19156 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19157 long tmp;
19158 asm volatile("# beginning down_write\n\t"
19159 LOCK_PREFIX " xadd %1,(%2)\n\t"
19160 +
19161 +#ifdef CONFIG_PAX_REFCOUNT
19162 + "jno 0f\n"
19163 + "mov %1,(%2)\n"
19164 + "int $4\n0:\n"
19165 + _ASM_EXTABLE(0b, 0b)
19166 +#endif
19167 +
19168 /* adds 0xffff0001, returns the old value */
19169 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19170 /* was the active mask 0 before? */
19171 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19172 long tmp;
19173 asm volatile("# beginning __up_read\n\t"
19174 LOCK_PREFIX " xadd %1,(%2)\n\t"
19175 +
19176 +#ifdef CONFIG_PAX_REFCOUNT
19177 + "jno 0f\n"
19178 + "mov %1,(%2)\n"
19179 + "int $4\n0:\n"
19180 + _ASM_EXTABLE(0b, 0b)
19181 +#endif
19182 +
19183 /* subtracts 1, returns the old value */
19184 " jns 1f\n\t"
19185 " call call_rwsem_wake\n" /* expects old value in %edx */
19186 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19187 long tmp;
19188 asm volatile("# beginning __up_write\n\t"
19189 LOCK_PREFIX " xadd %1,(%2)\n\t"
19190 +
19191 +#ifdef CONFIG_PAX_REFCOUNT
19192 + "jno 0f\n"
19193 + "mov %1,(%2)\n"
19194 + "int $4\n0:\n"
19195 + _ASM_EXTABLE(0b, 0b)
19196 +#endif
19197 +
19198 /* subtracts 0xffff0001, returns the old value */
19199 " jns 1f\n\t"
19200 " call call_rwsem_wake\n" /* expects old value in %edx */
19201 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19202 {
19203 asm volatile("# beginning __downgrade_write\n\t"
19204 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19205 +
19206 +#ifdef CONFIG_PAX_REFCOUNT
19207 + "jno 0f\n"
19208 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19209 + "int $4\n0:\n"
19210 + _ASM_EXTABLE(0b, 0b)
19211 +#endif
19212 +
19213 /*
19214 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19215 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19216 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19217 */
19218 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19219 {
19220 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19221 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19222 +
19223 +#ifdef CONFIG_PAX_REFCOUNT
19224 + "jno 0f\n"
19225 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19226 + "int $4\n0:\n"
19227 + _ASM_EXTABLE(0b, 0b)
19228 +#endif
19229 +
19230 : "+m" (sem->count)
19231 : "er" (delta));
19232 }
19233 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19234 */
19235 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19236 {
19237 - return delta + xadd(&sem->count, delta);
19238 + return delta + xadd_check_overflow(&sem->count, delta);
19239 }
19240
19241 #endif /* __KERNEL__ */
19242 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19243 index 6f1c3a8..7744f19 100644
19244 --- a/arch/x86/include/asm/segment.h
19245 +++ b/arch/x86/include/asm/segment.h
19246 @@ -64,10 +64,15 @@
19247 * 26 - ESPFIX small SS
19248 * 27 - per-cpu [ offset to per-cpu data area ]
19249 * 28 - stack_canary-20 [ for stack protector ]
19250 - * 29 - unused
19251 - * 30 - unused
19252 + * 29 - PCI BIOS CS
19253 + * 30 - PCI BIOS DS
19254 * 31 - TSS for double fault handler
19255 */
19256 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19257 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19258 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19259 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19260 +
19261 #define GDT_ENTRY_TLS_MIN 6
19262 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19263
19264 @@ -79,6 +84,8 @@
19265
19266 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19267
19268 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19269 +
19270 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19271
19272 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19273 @@ -104,6 +111,12 @@
19274 #define __KERNEL_STACK_CANARY 0
19275 #endif
19276
19277 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19278 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19279 +
19280 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19281 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19282 +
19283 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19284
19285 /*
19286 @@ -141,7 +154,7 @@
19287 */
19288
19289 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19290 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19291 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19292
19293
19294 #else
19295 @@ -165,6 +178,8 @@
19296 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19297 #define __USER32_DS __USER_DS
19298
19299 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19300 +
19301 #define GDT_ENTRY_TSS 8 /* needs two entries */
19302 #define GDT_ENTRY_LDT 10 /* needs two entries */
19303 #define GDT_ENTRY_TLS_MIN 12
19304 @@ -173,6 +188,8 @@
19305 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19306 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19307
19308 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19309 +
19310 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19311 #define FS_TLS 0
19312 #define GS_TLS 1
19313 @@ -180,12 +197,14 @@
19314 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19315 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19316
19317 -#define GDT_ENTRIES 16
19318 +#define GDT_ENTRIES 17
19319
19320 #endif
19321
19322 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19323 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19324 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19325 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19326 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19327 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19328 #ifndef CONFIG_PARAVIRT
19329 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19330 {
19331 unsigned long __limit;
19332 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19333 - return __limit + 1;
19334 + return __limit;
19335 }
19336
19337 #endif /* !__ASSEMBLY__ */
19338 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19339 index 8d3120f..352b440 100644
19340 --- a/arch/x86/include/asm/smap.h
19341 +++ b/arch/x86/include/asm/smap.h
19342 @@ -25,11 +25,40 @@
19343
19344 #include <asm/alternative-asm.h>
19345
19346 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19347 +#define ASM_PAX_OPEN_USERLAND \
19348 + 661: jmp 663f; \
19349 + .pushsection .altinstr_replacement, "a" ; \
19350 + 662: pushq %rax; nop; \
19351 + .popsection ; \
19352 + .pushsection .altinstructions, "a" ; \
19353 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19354 + .popsection ; \
19355 + call __pax_open_userland; \
19356 + popq %rax; \
19357 + 663:
19358 +
19359 +#define ASM_PAX_CLOSE_USERLAND \
19360 + 661: jmp 663f; \
19361 + .pushsection .altinstr_replacement, "a" ; \
19362 + 662: pushq %rax; nop; \
19363 + .popsection; \
19364 + .pushsection .altinstructions, "a" ; \
19365 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19366 + .popsection; \
19367 + call __pax_close_userland; \
19368 + popq %rax; \
19369 + 663:
19370 +#else
19371 +#define ASM_PAX_OPEN_USERLAND
19372 +#define ASM_PAX_CLOSE_USERLAND
19373 +#endif
19374 +
19375 #ifdef CONFIG_X86_SMAP
19376
19377 #define ASM_CLAC \
19378 661: ASM_NOP3 ; \
19379 - .pushsection .altinstr_replacement, "ax" ; \
19380 + .pushsection .altinstr_replacement, "a" ; \
19381 662: __ASM_CLAC ; \
19382 .popsection ; \
19383 .pushsection .altinstructions, "a" ; \
19384 @@ -38,7 +67,7 @@
19385
19386 #define ASM_STAC \
19387 661: ASM_NOP3 ; \
19388 - .pushsection .altinstr_replacement, "ax" ; \
19389 + .pushsection .altinstr_replacement, "a" ; \
19390 662: __ASM_STAC ; \
19391 .popsection ; \
19392 .pushsection .altinstructions, "a" ; \
19393 @@ -56,6 +85,37 @@
19394
19395 #include <asm/alternative.h>
19396
19397 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19398 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19399 +
19400 +extern void __pax_open_userland(void);
19401 +static __always_inline unsigned long pax_open_userland(void)
19402 +{
19403 +
19404 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19405 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19406 + :
19407 + : [open] "i" (__pax_open_userland)
19408 + : "memory", "rax");
19409 +#endif
19410 +
19411 + return 0;
19412 +}
19413 +
19414 +extern void __pax_close_userland(void);
19415 +static __always_inline unsigned long pax_close_userland(void)
19416 +{
19417 +
19418 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19419 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19420 + :
19421 + : [close] "i" (__pax_close_userland)
19422 + : "memory", "rax");
19423 +#endif
19424 +
19425 + return 0;
19426 +}
19427 +
19428 #ifdef CONFIG_X86_SMAP
19429
19430 static __always_inline void clac(void)
19431 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19432 index 8cd27e0..7f05ec8 100644
19433 --- a/arch/x86/include/asm/smp.h
19434 +++ b/arch/x86/include/asm/smp.h
19435 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19436 /* cpus sharing the last level cache: */
19437 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19438 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19439 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19440 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19441
19442 static inline struct cpumask *cpu_sibling_mask(int cpu)
19443 {
19444 @@ -78,7 +78,7 @@ struct smp_ops {
19445
19446 void (*send_call_func_ipi)(const struct cpumask *mask);
19447 void (*send_call_func_single_ipi)(int cpu);
19448 -};
19449 +} __no_const;
19450
19451 /* Globals due to paravirt */
19452 extern void set_cpu_sibling_map(int cpu);
19453 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19454 extern int safe_smp_processor_id(void);
19455
19456 #elif defined(CONFIG_X86_64_SMP)
19457 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19458 -
19459 -#define stack_smp_processor_id() \
19460 -({ \
19461 - struct thread_info *ti; \
19462 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19463 - ti->cpu; \
19464 -})
19465 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19466 +#define stack_smp_processor_id() raw_smp_processor_id()
19467 #define safe_smp_processor_id() smp_processor_id()
19468
19469 #endif
19470 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19471 index 54f1c80..39362a5 100644
19472 --- a/arch/x86/include/asm/spinlock.h
19473 +++ b/arch/x86/include/asm/spinlock.h
19474 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19475 static inline void arch_read_lock(arch_rwlock_t *rw)
19476 {
19477 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19478 +
19479 +#ifdef CONFIG_PAX_REFCOUNT
19480 + "jno 0f\n"
19481 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19482 + "int $4\n0:\n"
19483 + _ASM_EXTABLE(0b, 0b)
19484 +#endif
19485 +
19486 "jns 1f\n"
19487 "call __read_lock_failed\n\t"
19488 "1:\n"
19489 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19490 static inline void arch_write_lock(arch_rwlock_t *rw)
19491 {
19492 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19493 +
19494 +#ifdef CONFIG_PAX_REFCOUNT
19495 + "jno 0f\n"
19496 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19497 + "int $4\n0:\n"
19498 + _ASM_EXTABLE(0b, 0b)
19499 +#endif
19500 +
19501 "jz 1f\n"
19502 "call __write_lock_failed\n\t"
19503 "1:\n"
19504 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19505
19506 static inline void arch_read_unlock(arch_rwlock_t *rw)
19507 {
19508 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19509 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19510 +
19511 +#ifdef CONFIG_PAX_REFCOUNT
19512 + "jno 0f\n"
19513 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19514 + "int $4\n0:\n"
19515 + _ASM_EXTABLE(0b, 0b)
19516 +#endif
19517 +
19518 :"+m" (rw->lock) : : "memory");
19519 }
19520
19521 static inline void arch_write_unlock(arch_rwlock_t *rw)
19522 {
19523 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19524 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19525 +
19526 +#ifdef CONFIG_PAX_REFCOUNT
19527 + "jno 0f\n"
19528 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19529 + "int $4\n0:\n"
19530 + _ASM_EXTABLE(0b, 0b)
19531 +#endif
19532 +
19533 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19534 }
19535 #else
19536 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19537 index 6a99859..03cb807 100644
19538 --- a/arch/x86/include/asm/stackprotector.h
19539 +++ b/arch/x86/include/asm/stackprotector.h
19540 @@ -47,7 +47,7 @@
19541 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19542 */
19543 #define GDT_STACK_CANARY_INIT \
19544 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19545 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19546
19547 /*
19548 * Initialize the stackprotector canary value.
19549 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19550
19551 static inline void load_stack_canary_segment(void)
19552 {
19553 -#ifdef CONFIG_X86_32
19554 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19555 asm volatile ("mov %0, %%gs" : : "r" (0));
19556 #endif
19557 }
19558 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19559 index 70bbe39..4ae2bd4 100644
19560 --- a/arch/x86/include/asm/stacktrace.h
19561 +++ b/arch/x86/include/asm/stacktrace.h
19562 @@ -11,28 +11,20 @@
19563
19564 extern int kstack_depth_to_print;
19565
19566 -struct thread_info;
19567 +struct task_struct;
19568 struct stacktrace_ops;
19569
19570 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19571 - unsigned long *stack,
19572 - unsigned long bp,
19573 - const struct stacktrace_ops *ops,
19574 - void *data,
19575 - unsigned long *end,
19576 - int *graph);
19577 +typedef unsigned long walk_stack_t(struct task_struct *task,
19578 + void *stack_start,
19579 + unsigned long *stack,
19580 + unsigned long bp,
19581 + const struct stacktrace_ops *ops,
19582 + void *data,
19583 + unsigned long *end,
19584 + int *graph);
19585
19586 -extern unsigned long
19587 -print_context_stack(struct thread_info *tinfo,
19588 - unsigned long *stack, unsigned long bp,
19589 - const struct stacktrace_ops *ops, void *data,
19590 - unsigned long *end, int *graph);
19591 -
19592 -extern unsigned long
19593 -print_context_stack_bp(struct thread_info *tinfo,
19594 - unsigned long *stack, unsigned long bp,
19595 - const struct stacktrace_ops *ops, void *data,
19596 - unsigned long *end, int *graph);
19597 +extern walk_stack_t print_context_stack;
19598 +extern walk_stack_t print_context_stack_bp;
19599
19600 /* Generic stack tracer with callbacks */
19601
19602 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19603 void (*address)(void *data, unsigned long address, int reliable);
19604 /* On negative return stop dumping */
19605 int (*stack)(void *data, char *name);
19606 - walk_stack_t walk_stack;
19607 + walk_stack_t *walk_stack;
19608 };
19609
19610 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19611 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19612 index d7f3b3b..3cc39f1 100644
19613 --- a/arch/x86/include/asm/switch_to.h
19614 +++ b/arch/x86/include/asm/switch_to.h
19615 @@ -108,7 +108,7 @@ do { \
19616 "call __switch_to\n\t" \
19617 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19618 __switch_canary \
19619 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19620 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19621 "movq %%rax,%%rdi\n\t" \
19622 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19623 "jnz ret_from_fork\n\t" \
19624 @@ -119,7 +119,7 @@ do { \
19625 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19626 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19627 [_tif_fork] "i" (_TIF_FORK), \
19628 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19629 + [thread_info] "m" (current_tinfo), \
19630 [current_task] "m" (current_task) \
19631 __switch_canary_iparam \
19632 : "memory", "cc" __EXTRA_CLOBBER)
19633 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19634 index 8540538..4b0b5e9 100644
19635 --- a/arch/x86/include/asm/thread_info.h
19636 +++ b/arch/x86/include/asm/thread_info.h
19637 @@ -24,7 +24,6 @@ struct exec_domain;
19638 #include <linux/atomic.h>
19639
19640 struct thread_info {
19641 - struct task_struct *task; /* main task structure */
19642 struct exec_domain *exec_domain; /* execution domain */
19643 __u32 flags; /* low level flags */
19644 __u32 status; /* thread synchronous flags */
19645 @@ -33,13 +32,13 @@ struct thread_info {
19646 mm_segment_t addr_limit;
19647 struct restart_block restart_block;
19648 void __user *sysenter_return;
19649 + unsigned long lowest_stack;
19650 unsigned int sig_on_uaccess_error:1;
19651 unsigned int uaccess_err:1; /* uaccess failed */
19652 };
19653
19654 -#define INIT_THREAD_INFO(tsk) \
19655 +#define INIT_THREAD_INFO \
19656 { \
19657 - .task = &tsk, \
19658 .exec_domain = &default_exec_domain, \
19659 .flags = 0, \
19660 .cpu = 0, \
19661 @@ -50,7 +49,7 @@ struct thread_info {
19662 }, \
19663 }
19664
19665 -#define init_thread_info (init_thread_union.thread_info)
19666 +#define init_thread_info (init_thread_union.stack)
19667 #define init_stack (init_thread_union.stack)
19668
19669 #else /* !__ASSEMBLY__ */
19670 @@ -91,6 +90,7 @@ struct thread_info {
19671 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19672 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19673 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19674 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19675
19676 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19677 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19678 @@ -115,17 +115,18 @@ struct thread_info {
19679 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19680 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19681 #define _TIF_X32 (1 << TIF_X32)
19682 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19683
19684 /* work to do in syscall_trace_enter() */
19685 #define _TIF_WORK_SYSCALL_ENTRY \
19686 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19687 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19688 - _TIF_NOHZ)
19689 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19690
19691 /* work to do in syscall_trace_leave() */
19692 #define _TIF_WORK_SYSCALL_EXIT \
19693 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19694 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19695 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19696
19697 /* work to do on interrupt/exception return */
19698 #define _TIF_WORK_MASK \
19699 @@ -136,7 +137,7 @@ struct thread_info {
19700 /* work to do on any return to user space */
19701 #define _TIF_ALLWORK_MASK \
19702 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19703 - _TIF_NOHZ)
19704 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19705
19706 /* Only used for 64 bit */
19707 #define _TIF_DO_NOTIFY_MASK \
19708 @@ -151,7 +152,6 @@ struct thread_info {
19709 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19710
19711 #define STACK_WARN (THREAD_SIZE/8)
19712 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19713
19714 /*
19715 * macros/functions for gaining access to the thread information structure
19716 @@ -162,26 +162,18 @@ struct thread_info {
19717
19718 DECLARE_PER_CPU(unsigned long, kernel_stack);
19719
19720 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19721 +
19722 static inline struct thread_info *current_thread_info(void)
19723 {
19724 - struct thread_info *ti;
19725 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19726 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19727 - return ti;
19728 + return this_cpu_read_stable(current_tinfo);
19729 }
19730
19731 #else /* !__ASSEMBLY__ */
19732
19733 /* how to get the thread information struct from ASM */
19734 #define GET_THREAD_INFO(reg) \
19735 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19736 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19737 -
19738 -/*
19739 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19740 - * a certain register (to be used in assembler memory operands).
19741 - */
19742 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19743 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19744
19745 #endif
19746
19747 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19748 extern void arch_task_cache_init(void);
19749 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19750 extern void arch_release_task_struct(struct task_struct *tsk);
19751 +
19752 +#define __HAVE_THREAD_FUNCTIONS
19753 +#define task_thread_info(task) (&(task)->tinfo)
19754 +#define task_stack_page(task) ((task)->stack)
19755 +#define setup_thread_stack(p, org) do {} while (0)
19756 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19757 +
19758 #endif
19759 #endif /* _ASM_X86_THREAD_INFO_H */
19760 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19761 index 04905bf..1178cdf 100644
19762 --- a/arch/x86/include/asm/tlbflush.h
19763 +++ b/arch/x86/include/asm/tlbflush.h
19764 @@ -17,18 +17,44 @@
19765
19766 static inline void __native_flush_tlb(void)
19767 {
19768 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19769 + u64 descriptor[2];
19770 +
19771 + descriptor[0] = PCID_KERNEL;
19772 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19773 + return;
19774 + }
19775 +
19776 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19777 + if (static_cpu_has(X86_FEATURE_PCID)) {
19778 + unsigned int cpu = raw_get_cpu();
19779 +
19780 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19781 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19782 + raw_put_cpu_no_resched();
19783 + return;
19784 + }
19785 +#endif
19786 +
19787 native_write_cr3(native_read_cr3());
19788 }
19789
19790 static inline void __native_flush_tlb_global_irq_disabled(void)
19791 {
19792 - unsigned long cr4;
19793 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19794 + u64 descriptor[2];
19795
19796 - cr4 = native_read_cr4();
19797 - /* clear PGE */
19798 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19799 - /* write old PGE again and flush TLBs */
19800 - native_write_cr4(cr4);
19801 + descriptor[0] = PCID_KERNEL;
19802 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19803 + } else {
19804 + unsigned long cr4;
19805 +
19806 + cr4 = native_read_cr4();
19807 + /* clear PGE */
19808 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19809 + /* write old PGE again and flush TLBs */
19810 + native_write_cr4(cr4);
19811 + }
19812 }
19813
19814 static inline void __native_flush_tlb_global(void)
19815 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19816
19817 static inline void __native_flush_tlb_single(unsigned long addr)
19818 {
19819 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19820 + u64 descriptor[2];
19821 +
19822 + descriptor[0] = PCID_KERNEL;
19823 + descriptor[1] = addr;
19824 +
19825 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19826 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19827 + if (addr < TASK_SIZE_MAX)
19828 + descriptor[1] += pax_user_shadow_base;
19829 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19830 + }
19831 +
19832 + descriptor[0] = PCID_USER;
19833 + descriptor[1] = addr;
19834 +#endif
19835 +
19836 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19837 + return;
19838 + }
19839 +
19840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19841 + if (static_cpu_has(X86_FEATURE_PCID)) {
19842 + unsigned int cpu = raw_get_cpu();
19843 +
19844 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19845 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19846 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19847 + raw_put_cpu_no_resched();
19848 +
19849 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19850 + addr += pax_user_shadow_base;
19851 + }
19852 +#endif
19853 +
19854 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19855 }
19856
19857 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19858 index 0d592e0..526f797 100644
19859 --- a/arch/x86/include/asm/uaccess.h
19860 +++ b/arch/x86/include/asm/uaccess.h
19861 @@ -7,6 +7,7 @@
19862 #include <linux/compiler.h>
19863 #include <linux/thread_info.h>
19864 #include <linux/string.h>
19865 +#include <linux/spinlock.h>
19866 #include <asm/asm.h>
19867 #include <asm/page.h>
19868 #include <asm/smap.h>
19869 @@ -29,7 +30,12 @@
19870
19871 #define get_ds() (KERNEL_DS)
19872 #define get_fs() (current_thread_info()->addr_limit)
19873 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19874 +void __set_fs(mm_segment_t x);
19875 +void set_fs(mm_segment_t x);
19876 +#else
19877 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19878 +#endif
19879
19880 #define segment_eq(a, b) ((a).seg == (b).seg)
19881
19882 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19883 * checks that the pointer is in the user space range - after calling
19884 * this function, memory access functions may still return -EFAULT.
19885 */
19886 -#define access_ok(type, addr, size) \
19887 - likely(!__range_not_ok(addr, size, user_addr_max()))
19888 +extern int _cond_resched(void);
19889 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19890 +#define access_ok(type, addr, size) \
19891 +({ \
19892 + unsigned long __size = size; \
19893 + unsigned long __addr = (unsigned long)addr; \
19894 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19895 + if (__ret_ao && __size) { \
19896 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19897 + unsigned long __end_ao = __addr + __size - 1; \
19898 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19899 + while (__addr_ao <= __end_ao) { \
19900 + char __c_ao; \
19901 + __addr_ao += PAGE_SIZE; \
19902 + if (__size > PAGE_SIZE) \
19903 + _cond_resched(); \
19904 + if (__get_user(__c_ao, (char __user *)__addr)) \
19905 + break; \
19906 + if (type != VERIFY_WRITE) { \
19907 + __addr = __addr_ao; \
19908 + continue; \
19909 + } \
19910 + if (__put_user(__c_ao, (char __user *)__addr)) \
19911 + break; \
19912 + __addr = __addr_ao; \
19913 + } \
19914 + } \
19915 + } \
19916 + __ret_ao; \
19917 +})
19918
19919 /*
19920 * The exception table consists of pairs of addresses relative to the
19921 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19922 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19923 __chk_user_ptr(ptr); \
19924 might_fault(); \
19925 + pax_open_userland(); \
19926 asm volatile("call __get_user_%P3" \
19927 : "=a" (__ret_gu), "=r" (__val_gu) \
19928 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19929 (x) = (__typeof__(*(ptr))) __val_gu; \
19930 + pax_close_userland(); \
19931 __ret_gu; \
19932 })
19933
19934 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19935 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19936 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19937
19938 -
19939 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19940 +#define __copyuser_seg "gs;"
19941 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19942 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19943 +#else
19944 +#define __copyuser_seg
19945 +#define __COPYUSER_SET_ES
19946 +#define __COPYUSER_RESTORE_ES
19947 +#endif
19948
19949 #ifdef CONFIG_X86_32
19950 #define __put_user_asm_u64(x, addr, err, errret) \
19951 asm volatile(ASM_STAC "\n" \
19952 - "1: movl %%eax,0(%2)\n" \
19953 - "2: movl %%edx,4(%2)\n" \
19954 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19955 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19956 "3: " ASM_CLAC "\n" \
19957 ".section .fixup,\"ax\"\n" \
19958 "4: movl %3,%0\n" \
19959 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19960
19961 #define __put_user_asm_ex_u64(x, addr) \
19962 asm volatile(ASM_STAC "\n" \
19963 - "1: movl %%eax,0(%1)\n" \
19964 - "2: movl %%edx,4(%1)\n" \
19965 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19966 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19967 "3: " ASM_CLAC "\n" \
19968 _ASM_EXTABLE_EX(1b, 2b) \
19969 _ASM_EXTABLE_EX(2b, 3b) \
19970 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19971 __typeof__(*(ptr)) __pu_val; \
19972 __chk_user_ptr(ptr); \
19973 might_fault(); \
19974 - __pu_val = x; \
19975 + __pu_val = (x); \
19976 + pax_open_userland(); \
19977 switch (sizeof(*(ptr))) { \
19978 case 1: \
19979 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19980 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19981 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19982 break; \
19983 } \
19984 + pax_close_userland(); \
19985 __ret_pu; \
19986 })
19987
19988 @@ -355,8 +401,10 @@ do { \
19989 } while (0)
19990
19991 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19992 +do { \
19993 + pax_open_userland(); \
19994 asm volatile(ASM_STAC "\n" \
19995 - "1: mov"itype" %2,%"rtype"1\n" \
19996 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19997 "2: " ASM_CLAC "\n" \
19998 ".section .fixup,\"ax\"\n" \
19999 "3: mov %3,%0\n" \
20000 @@ -364,8 +412,10 @@ do { \
20001 " jmp 2b\n" \
20002 ".previous\n" \
20003 _ASM_EXTABLE(1b, 3b) \
20004 - : "=r" (err), ltype(x) \
20005 - : "m" (__m(addr)), "i" (errret), "0" (err))
20006 + : "=r" (err), ltype (x) \
20007 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20008 + pax_close_userland(); \
20009 +} while (0)
20010
20011 #define __get_user_size_ex(x, ptr, size) \
20012 do { \
20013 @@ -389,7 +439,7 @@ do { \
20014 } while (0)
20015
20016 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20017 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20018 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20019 "2:\n" \
20020 _ASM_EXTABLE_EX(1b, 2b) \
20021 : ltype(x) : "m" (__m(addr)))
20022 @@ -406,13 +456,24 @@ do { \
20023 int __gu_err; \
20024 unsigned long __gu_val; \
20025 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20026 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20027 + (x) = (__typeof__(*(ptr)))__gu_val; \
20028 __gu_err; \
20029 })
20030
20031 /* FIXME: this hack is definitely wrong -AK */
20032 struct __large_struct { unsigned long buf[100]; };
20033 -#define __m(x) (*(struct __large_struct __user *)(x))
20034 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20035 +#define ____m(x) \
20036 +({ \
20037 + unsigned long ____x = (unsigned long)(x); \
20038 + if (____x < pax_user_shadow_base) \
20039 + ____x += pax_user_shadow_base; \
20040 + (typeof(x))____x; \
20041 +})
20042 +#else
20043 +#define ____m(x) (x)
20044 +#endif
20045 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20046
20047 /*
20048 * Tell gcc we read from memory instead of writing: this is because
20049 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20050 * aliasing issues.
20051 */
20052 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20053 +do { \
20054 + pax_open_userland(); \
20055 asm volatile(ASM_STAC "\n" \
20056 - "1: mov"itype" %"rtype"1,%2\n" \
20057 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20058 "2: " ASM_CLAC "\n" \
20059 ".section .fixup,\"ax\"\n" \
20060 "3: mov %3,%0\n" \
20061 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20062 ".previous\n" \
20063 _ASM_EXTABLE(1b, 3b) \
20064 : "=r"(err) \
20065 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20066 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20067 + pax_close_userland(); \
20068 +} while (0)
20069
20070 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20071 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20072 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20073 "2:\n" \
20074 _ASM_EXTABLE_EX(1b, 2b) \
20075 : : ltype(x), "m" (__m(addr)))
20076 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20077 */
20078 #define uaccess_try do { \
20079 current_thread_info()->uaccess_err = 0; \
20080 + pax_open_userland(); \
20081 stac(); \
20082 barrier();
20083
20084 #define uaccess_catch(err) \
20085 clac(); \
20086 + pax_close_userland(); \
20087 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20088 } while (0)
20089
20090 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20091 * On error, the variable @x is set to zero.
20092 */
20093
20094 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20095 +#define __get_user(x, ptr) get_user((x), (ptr))
20096 +#else
20097 #define __get_user(x, ptr) \
20098 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20099 +#endif
20100
20101 /**
20102 * __put_user: - Write a simple value into user space, with less checking.
20103 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20104 * Returns zero on success, or -EFAULT on error.
20105 */
20106
20107 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20108 +#define __put_user(x, ptr) put_user((x), (ptr))
20109 +#else
20110 #define __put_user(x, ptr) \
20111 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20112 +#endif
20113
20114 #define __get_user_unaligned __get_user
20115 #define __put_user_unaligned __put_user
20116 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20117 #define get_user_ex(x, ptr) do { \
20118 unsigned long __gue_val; \
20119 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20120 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20121 + (x) = (__typeof__(*(ptr)))__gue_val; \
20122 } while (0)
20123
20124 #define put_user_try uaccess_try
20125 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20126 __typeof__(ptr) __uval = (uval); \
20127 __typeof__(*(ptr)) __old = (old); \
20128 __typeof__(*(ptr)) __new = (new); \
20129 + pax_open_userland(); \
20130 switch (size) { \
20131 case 1: \
20132 { \
20133 asm volatile("\t" ASM_STAC "\n" \
20134 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20135 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20136 "2:\t" ASM_CLAC "\n" \
20137 "\t.section .fixup, \"ax\"\n" \
20138 "3:\tmov %3, %0\n" \
20139 "\tjmp 2b\n" \
20140 "\t.previous\n" \
20141 _ASM_EXTABLE(1b, 3b) \
20142 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20143 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20144 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20145 : "memory" \
20146 ); \
20147 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20148 case 2: \
20149 { \
20150 asm volatile("\t" ASM_STAC "\n" \
20151 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20152 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20153 "2:\t" ASM_CLAC "\n" \
20154 "\t.section .fixup, \"ax\"\n" \
20155 "3:\tmov %3, %0\n" \
20156 "\tjmp 2b\n" \
20157 "\t.previous\n" \
20158 _ASM_EXTABLE(1b, 3b) \
20159 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20160 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20161 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20162 : "memory" \
20163 ); \
20164 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20165 case 4: \
20166 { \
20167 asm volatile("\t" ASM_STAC "\n" \
20168 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20169 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20170 "2:\t" ASM_CLAC "\n" \
20171 "\t.section .fixup, \"ax\"\n" \
20172 "3:\tmov %3, %0\n" \
20173 "\tjmp 2b\n" \
20174 "\t.previous\n" \
20175 _ASM_EXTABLE(1b, 3b) \
20176 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20177 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20178 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20179 : "memory" \
20180 ); \
20181 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20182 __cmpxchg_wrong_size(); \
20183 \
20184 asm volatile("\t" ASM_STAC "\n" \
20185 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20186 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20187 "2:\t" ASM_CLAC "\n" \
20188 "\t.section .fixup, \"ax\"\n" \
20189 "3:\tmov %3, %0\n" \
20190 "\tjmp 2b\n" \
20191 "\t.previous\n" \
20192 _ASM_EXTABLE(1b, 3b) \
20193 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20194 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20195 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20196 : "memory" \
20197 ); \
20198 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20199 default: \
20200 __cmpxchg_wrong_size(); \
20201 } \
20202 + pax_close_userland(); \
20203 *__uval = __old; \
20204 __ret; \
20205 })
20206 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20207
20208 #define ARCH_HAS_NOCACHE_UACCESS 1
20209
20210 -#ifdef CONFIG_X86_32
20211 -# include <asm/uaccess_32.h>
20212 -#else
20213 -# include <asm/uaccess_64.h>
20214 -#endif
20215 -
20216 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20217 - unsigned n);
20218 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20219 - unsigned n);
20220 -
20221 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20222 # define copy_user_diag __compiletime_error
20223 #else
20224 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20225 extern void copy_user_diag("copy_from_user() buffer size is too small")
20226 copy_from_user_overflow(void);
20227 extern void copy_user_diag("copy_to_user() buffer size is too small")
20228 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20229 +copy_to_user_overflow(void);
20230
20231 #undef copy_user_diag
20232
20233 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20234
20235 extern void
20236 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20237 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20238 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20239 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20240
20241 #else
20242 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20243
20244 #endif
20245
20246 +#ifdef CONFIG_X86_32
20247 +# include <asm/uaccess_32.h>
20248 +#else
20249 +# include <asm/uaccess_64.h>
20250 +#endif
20251 +
20252 static inline unsigned long __must_check
20253 copy_from_user(void *to, const void __user *from, unsigned long n)
20254 {
20255 - int sz = __compiletime_object_size(to);
20256 + size_t sz = __compiletime_object_size(to);
20257
20258 might_fault();
20259
20260 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20261 * case, and do only runtime checking for non-constant sizes.
20262 */
20263
20264 - if (likely(sz < 0 || sz >= n))
20265 - n = _copy_from_user(to, from, n);
20266 - else if(__builtin_constant_p(n))
20267 - copy_from_user_overflow();
20268 - else
20269 - __copy_from_user_overflow(sz, n);
20270 + if (likely(sz != (size_t)-1 && sz < n)) {
20271 + if(__builtin_constant_p(n))
20272 + copy_from_user_overflow();
20273 + else
20274 + __copy_from_user_overflow(sz, n);
20275 + } else if (access_ok(VERIFY_READ, from, n))
20276 + n = __copy_from_user(to, from, n);
20277 + else if ((long)n > 0)
20278 + memset(to, 0, n);
20279
20280 return n;
20281 }
20282 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20283 static inline unsigned long __must_check
20284 copy_to_user(void __user *to, const void *from, unsigned long n)
20285 {
20286 - int sz = __compiletime_object_size(from);
20287 + size_t sz = __compiletime_object_size(from);
20288
20289 might_fault();
20290
20291 /* See the comment in copy_from_user() above. */
20292 - if (likely(sz < 0 || sz >= n))
20293 - n = _copy_to_user(to, from, n);
20294 - else if(__builtin_constant_p(n))
20295 - copy_to_user_overflow();
20296 - else
20297 - __copy_to_user_overflow(sz, n);
20298 + if (likely(sz != (size_t)-1 && sz < n)) {
20299 + if(__builtin_constant_p(n))
20300 + copy_to_user_overflow();
20301 + else
20302 + __copy_to_user_overflow(sz, n);
20303 + } else if (access_ok(VERIFY_WRITE, to, n))
20304 + n = __copy_to_user(to, from, n);
20305
20306 return n;
20307 }
20308 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20309 index 3c03a5d..1071638 100644
20310 --- a/arch/x86/include/asm/uaccess_32.h
20311 +++ b/arch/x86/include/asm/uaccess_32.h
20312 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20313 static __always_inline unsigned long __must_check
20314 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20315 {
20316 + if ((long)n < 0)
20317 + return n;
20318 +
20319 + check_object_size(from, n, true);
20320 +
20321 if (__builtin_constant_p(n)) {
20322 unsigned long ret;
20323
20324 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20325 __copy_to_user(void __user *to, const void *from, unsigned long n)
20326 {
20327 might_fault();
20328 +
20329 return __copy_to_user_inatomic(to, from, n);
20330 }
20331
20332 static __always_inline unsigned long
20333 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20334 {
20335 + if ((long)n < 0)
20336 + return n;
20337 +
20338 /* Avoid zeroing the tail if the copy fails..
20339 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20340 * but as the zeroing behaviour is only significant when n is not
20341 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20342 __copy_from_user(void *to, const void __user *from, unsigned long n)
20343 {
20344 might_fault();
20345 +
20346 + if ((long)n < 0)
20347 + return n;
20348 +
20349 + check_object_size(to, n, false);
20350 +
20351 if (__builtin_constant_p(n)) {
20352 unsigned long ret;
20353
20354 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20355 const void __user *from, unsigned long n)
20356 {
20357 might_fault();
20358 +
20359 + if ((long)n < 0)
20360 + return n;
20361 +
20362 if (__builtin_constant_p(n)) {
20363 unsigned long ret;
20364
20365 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20366 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20367 unsigned long n)
20368 {
20369 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20370 + if ((long)n < 0)
20371 + return n;
20372 +
20373 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20374 }
20375
20376 #endif /* _ASM_X86_UACCESS_32_H */
20377 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20378 index 12a26b9..206c200 100644
20379 --- a/arch/x86/include/asm/uaccess_64.h
20380 +++ b/arch/x86/include/asm/uaccess_64.h
20381 @@ -10,6 +10,9 @@
20382 #include <asm/alternative.h>
20383 #include <asm/cpufeature.h>
20384 #include <asm/page.h>
20385 +#include <asm/pgtable.h>
20386 +
20387 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20388
20389 /*
20390 * Copy To/From Userspace
20391 @@ -17,14 +20,14 @@
20392
20393 /* Handles exceptions in both to and from, but doesn't do access_ok */
20394 __must_check unsigned long
20395 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20396 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20397 __must_check unsigned long
20398 -copy_user_generic_string(void *to, const void *from, unsigned len);
20399 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20400 __must_check unsigned long
20401 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20402 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20403
20404 static __always_inline __must_check unsigned long
20405 -copy_user_generic(void *to, const void *from, unsigned len)
20406 +copy_user_generic(void *to, const void *from, unsigned long len)
20407 {
20408 unsigned ret;
20409
20410 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20411 }
20412
20413 __must_check unsigned long
20414 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20415 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20416
20417 static __always_inline __must_check
20418 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20419 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20420 {
20421 - int ret = 0;
20422 + size_t sz = __compiletime_object_size(dst);
20423 + unsigned ret = 0;
20424 +
20425 + if (size > INT_MAX)
20426 + return size;
20427 +
20428 + check_object_size(dst, size, false);
20429 +
20430 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20431 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20432 + return size;
20433 +#endif
20434 +
20435 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20436 + if(__builtin_constant_p(size))
20437 + copy_from_user_overflow();
20438 + else
20439 + __copy_from_user_overflow(sz, size);
20440 + return size;
20441 + }
20442
20443 if (!__builtin_constant_p(size))
20444 - return copy_user_generic(dst, (__force void *)src, size);
20445 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20446 switch (size) {
20447 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20448 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20449 ret, "b", "b", "=q", 1);
20450 return ret;
20451 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20452 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20453 ret, "w", "w", "=r", 2);
20454 return ret;
20455 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20456 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20457 ret, "l", "k", "=r", 4);
20458 return ret;
20459 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20460 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20461 ret, "q", "", "=r", 8);
20462 return ret;
20463 case 10:
20464 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20465 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20466 ret, "q", "", "=r", 10);
20467 if (unlikely(ret))
20468 return ret;
20469 __get_user_asm(*(u16 *)(8 + (char *)dst),
20470 - (u16 __user *)(8 + (char __user *)src),
20471 + (const u16 __user *)(8 + (const char __user *)src),
20472 ret, "w", "w", "=r", 2);
20473 return ret;
20474 case 16:
20475 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20476 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20477 ret, "q", "", "=r", 16);
20478 if (unlikely(ret))
20479 return ret;
20480 __get_user_asm(*(u64 *)(8 + (char *)dst),
20481 - (u64 __user *)(8 + (char __user *)src),
20482 + (const u64 __user *)(8 + (const char __user *)src),
20483 ret, "q", "", "=r", 8);
20484 return ret;
20485 default:
20486 - return copy_user_generic(dst, (__force void *)src, size);
20487 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20488 }
20489 }
20490
20491 static __always_inline __must_check
20492 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20493 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20494 {
20495 might_fault();
20496 return __copy_from_user_nocheck(dst, src, size);
20497 }
20498
20499 static __always_inline __must_check
20500 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20501 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20502 {
20503 - int ret = 0;
20504 + size_t sz = __compiletime_object_size(src);
20505 + unsigned ret = 0;
20506 +
20507 + if (size > INT_MAX)
20508 + return size;
20509 +
20510 + check_object_size(src, size, true);
20511 +
20512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20513 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20514 + return size;
20515 +#endif
20516 +
20517 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20518 + if(__builtin_constant_p(size))
20519 + copy_to_user_overflow();
20520 + else
20521 + __copy_to_user_overflow(sz, size);
20522 + return size;
20523 + }
20524
20525 if (!__builtin_constant_p(size))
20526 - return copy_user_generic((__force void *)dst, src, size);
20527 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20528 switch (size) {
20529 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20530 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20531 ret, "b", "b", "iq", 1);
20532 return ret;
20533 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20534 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20535 ret, "w", "w", "ir", 2);
20536 return ret;
20537 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20538 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20539 ret, "l", "k", "ir", 4);
20540 return ret;
20541 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20542 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20543 ret, "q", "", "er", 8);
20544 return ret;
20545 case 10:
20546 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20547 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20548 ret, "q", "", "er", 10);
20549 if (unlikely(ret))
20550 return ret;
20551 asm("":::"memory");
20552 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20553 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20554 ret, "w", "w", "ir", 2);
20555 return ret;
20556 case 16:
20557 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20558 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20559 ret, "q", "", "er", 16);
20560 if (unlikely(ret))
20561 return ret;
20562 asm("":::"memory");
20563 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20564 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20565 ret, "q", "", "er", 8);
20566 return ret;
20567 default:
20568 - return copy_user_generic((__force void *)dst, src, size);
20569 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20570 }
20571 }
20572
20573 static __always_inline __must_check
20574 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20575 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20576 {
20577 might_fault();
20578 return __copy_to_user_nocheck(dst, src, size);
20579 }
20580
20581 static __always_inline __must_check
20582 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20583 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20584 {
20585 - int ret = 0;
20586 + unsigned ret = 0;
20587
20588 might_fault();
20589 +
20590 + if (size > INT_MAX)
20591 + return size;
20592 +
20593 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20594 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20595 + return size;
20596 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20597 + return size;
20598 +#endif
20599 +
20600 if (!__builtin_constant_p(size))
20601 - return copy_user_generic((__force void *)dst,
20602 - (__force void *)src, size);
20603 + return copy_user_generic((__force_kernel void *)____m(dst),
20604 + (__force_kernel const void *)____m(src), size);
20605 switch (size) {
20606 case 1: {
20607 u8 tmp;
20608 - __get_user_asm(tmp, (u8 __user *)src,
20609 + __get_user_asm(tmp, (const u8 __user *)src,
20610 ret, "b", "b", "=q", 1);
20611 if (likely(!ret))
20612 __put_user_asm(tmp, (u8 __user *)dst,
20613 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20614 }
20615 case 2: {
20616 u16 tmp;
20617 - __get_user_asm(tmp, (u16 __user *)src,
20618 + __get_user_asm(tmp, (const u16 __user *)src,
20619 ret, "w", "w", "=r", 2);
20620 if (likely(!ret))
20621 __put_user_asm(tmp, (u16 __user *)dst,
20622 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20623
20624 case 4: {
20625 u32 tmp;
20626 - __get_user_asm(tmp, (u32 __user *)src,
20627 + __get_user_asm(tmp, (const u32 __user *)src,
20628 ret, "l", "k", "=r", 4);
20629 if (likely(!ret))
20630 __put_user_asm(tmp, (u32 __user *)dst,
20631 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20632 }
20633 case 8: {
20634 u64 tmp;
20635 - __get_user_asm(tmp, (u64 __user *)src,
20636 + __get_user_asm(tmp, (const u64 __user *)src,
20637 ret, "q", "", "=r", 8);
20638 if (likely(!ret))
20639 __put_user_asm(tmp, (u64 __user *)dst,
20640 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20641 return ret;
20642 }
20643 default:
20644 - return copy_user_generic((__force void *)dst,
20645 - (__force void *)src, size);
20646 + return copy_user_generic((__force_kernel void *)____m(dst),
20647 + (__force_kernel const void *)____m(src), size);
20648 }
20649 }
20650
20651 -static __must_check __always_inline int
20652 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20653 +static __must_check __always_inline unsigned long
20654 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20655 {
20656 return __copy_from_user_nocheck(dst, src, size);
20657 }
20658
20659 -static __must_check __always_inline int
20660 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20661 +static __must_check __always_inline unsigned long
20662 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20663 {
20664 return __copy_to_user_nocheck(dst, src, size);
20665 }
20666
20667 -extern long __copy_user_nocache(void *dst, const void __user *src,
20668 - unsigned size, int zerorest);
20669 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20670 + unsigned long size, int zerorest);
20671
20672 -static inline int
20673 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20674 +static inline unsigned long
20675 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20676 {
20677 might_fault();
20678 +
20679 + if (size > INT_MAX)
20680 + return size;
20681 +
20682 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20683 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20684 + return size;
20685 +#endif
20686 +
20687 return __copy_user_nocache(dst, src, size, 1);
20688 }
20689
20690 -static inline int
20691 +static inline unsigned long
20692 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20693 - unsigned size)
20694 + unsigned long size)
20695 {
20696 + if (size > INT_MAX)
20697 + return size;
20698 +
20699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20700 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20701 + return size;
20702 +#endif
20703 +
20704 return __copy_user_nocache(dst, src, size, 0);
20705 }
20706
20707 unsigned long
20708 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20709 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20710
20711 #endif /* _ASM_X86_UACCESS_64_H */
20712 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20713 index 5b238981..77fdd78 100644
20714 --- a/arch/x86/include/asm/word-at-a-time.h
20715 +++ b/arch/x86/include/asm/word-at-a-time.h
20716 @@ -11,7 +11,7 @@
20717 * and shift, for example.
20718 */
20719 struct word_at_a_time {
20720 - const unsigned long one_bits, high_bits;
20721 + unsigned long one_bits, high_bits;
20722 };
20723
20724 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20725 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20726 index e45e4da..44e8572 100644
20727 --- a/arch/x86/include/asm/x86_init.h
20728 +++ b/arch/x86/include/asm/x86_init.h
20729 @@ -129,7 +129,7 @@ struct x86_init_ops {
20730 struct x86_init_timers timers;
20731 struct x86_init_iommu iommu;
20732 struct x86_init_pci pci;
20733 -};
20734 +} __no_const;
20735
20736 /**
20737 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20738 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20739 void (*setup_percpu_clockev)(void);
20740 void (*early_percpu_clock_init)(void);
20741 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20742 -};
20743 +} __no_const;
20744
20745 struct timespec;
20746
20747 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20748 void (*save_sched_clock_state)(void);
20749 void (*restore_sched_clock_state)(void);
20750 void (*apic_post_init)(void);
20751 -};
20752 +} __no_const;
20753
20754 struct pci_dev;
20755 struct msi_msg;
20756 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20757 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20758 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20759 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20760 -};
20761 +} __no_const;
20762
20763 struct IO_APIC_route_entry;
20764 struct io_apic_irq_attr;
20765 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20766 unsigned int destination, int vector,
20767 struct io_apic_irq_attr *attr);
20768 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20769 -};
20770 +} __no_const;
20771
20772 extern struct x86_init_ops x86_init;
20773 extern struct x86_cpuinit_ops x86_cpuinit;
20774 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20775 index c949923..c22bfa4 100644
20776 --- a/arch/x86/include/asm/xen/page.h
20777 +++ b/arch/x86/include/asm/xen/page.h
20778 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20779 extern struct page *m2p_find_override(unsigned long mfn);
20780 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20781
20782 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20783 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20784 {
20785 unsigned long mfn;
20786
20787 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20788 index 7e7a79a..0824666 100644
20789 --- a/arch/x86/include/asm/xsave.h
20790 +++ b/arch/x86/include/asm/xsave.h
20791 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20792 if (unlikely(err))
20793 return -EFAULT;
20794
20795 + pax_open_userland();
20796 __asm__ __volatile__(ASM_STAC "\n"
20797 - "1:"XSAVE"\n"
20798 + "1:"
20799 + __copyuser_seg
20800 + XSAVE"\n"
20801 "2: " ASM_CLAC "\n"
20802 xstate_fault
20803 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20804 : "memory");
20805 + pax_close_userland();
20806 return err;
20807 }
20808
20809 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20810 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20811 {
20812 int err = 0;
20813 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20814 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20815 u32 lmask = mask;
20816 u32 hmask = mask >> 32;
20817
20818 + pax_open_userland();
20819 __asm__ __volatile__(ASM_STAC "\n"
20820 - "1:"XRSTOR"\n"
20821 + "1:"
20822 + __copyuser_seg
20823 + XRSTOR"\n"
20824 "2: " ASM_CLAC "\n"
20825 xstate_fault
20826 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20827 : "memory"); /* memory required? */
20828 + pax_close_userland();
20829 return err;
20830 }
20831
20832 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20833 index bbae024..e1528f9 100644
20834 --- a/arch/x86/include/uapi/asm/e820.h
20835 +++ b/arch/x86/include/uapi/asm/e820.h
20836 @@ -63,7 +63,7 @@ struct e820map {
20837 #define ISA_START_ADDRESS 0xa0000
20838 #define ISA_END_ADDRESS 0x100000
20839
20840 -#define BIOS_BEGIN 0x000a0000
20841 +#define BIOS_BEGIN 0x000c0000
20842 #define BIOS_END 0x00100000
20843
20844 #define BIOS_ROM_BASE 0xffe00000
20845 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20846 index 7b0a55a..ad115bf 100644
20847 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20848 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20849 @@ -49,7 +49,6 @@
20850 #define EFLAGS 144
20851 #define RSP 152
20852 #define SS 160
20853 -#define ARGOFFSET R11
20854 #endif /* __ASSEMBLY__ */
20855
20856 /* top of stack page */
20857 diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vmx.h
20858 index 0e79420..990a2fe 100644
20859 --- a/arch/x86/include/uapi/asm/vmx.h
20860 +++ b/arch/x86/include/uapi/asm/vmx.h
20861 @@ -67,6 +67,7 @@
20862 #define EXIT_REASON_EPT_MISCONFIG 49
20863 #define EXIT_REASON_INVEPT 50
20864 #define EXIT_REASON_PREEMPTION_TIMER 52
20865 +#define EXIT_REASON_INVVPID 53
20866 #define EXIT_REASON_WBINVD 54
20867 #define EXIT_REASON_XSETBV 55
20868 #define EXIT_REASON_APIC_WRITE 56
20869 @@ -114,6 +115,7 @@
20870 { EXIT_REASON_EOI_INDUCED, "EOI_INDUCED" }, \
20871 { EXIT_REASON_INVALID_STATE, "INVALID_STATE" }, \
20872 { EXIT_REASON_INVD, "INVD" }, \
20873 + { EXIT_REASON_INVVPID, "INVVPID" }, \
20874 { EXIT_REASON_INVPCID, "INVPCID" }
20875
20876 #endif /* _UAPIVMX_H */
20877 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20878 index ada2e2d..ca69e16 100644
20879 --- a/arch/x86/kernel/Makefile
20880 +++ b/arch/x86/kernel/Makefile
20881 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20882 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20883 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20884 obj-y += probe_roms.o
20885 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20886 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20887 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20888 obj-$(CONFIG_X86_64) += mcount_64.o
20889 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20890 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20891 index b436fc7..1ba7044 100644
20892 --- a/arch/x86/kernel/acpi/boot.c
20893 +++ b/arch/x86/kernel/acpi/boot.c
20894 @@ -1272,7 +1272,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20895 * If your system is blacklisted here, but you find that acpi=force
20896 * works for you, please contact linux-acpi@vger.kernel.org
20897 */
20898 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20899 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20900 /*
20901 * Boxes that need ACPI disabled
20902 */
20903 @@ -1347,7 +1347,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20904 };
20905
20906 /* second table for DMI checks that should run after early-quirks */
20907 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20908 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20909 /*
20910 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20911 * which includes some code which overrides all temperature
20912 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20913 index 3136820..e2c6577 100644
20914 --- a/arch/x86/kernel/acpi/sleep.c
20915 +++ b/arch/x86/kernel/acpi/sleep.c
20916 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20917 #else /* CONFIG_64BIT */
20918 #ifdef CONFIG_SMP
20919 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20920 +
20921 + pax_open_kernel();
20922 early_gdt_descr.address =
20923 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20924 + pax_close_kernel();
20925 +
20926 initial_gs = per_cpu_offset(smp_processor_id());
20927 #endif
20928 initial_code = (unsigned long)wakeup_long64;
20929 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20930 index 665c6b7..eae4d56 100644
20931 --- a/arch/x86/kernel/acpi/wakeup_32.S
20932 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20933 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20934 # and restore the stack ... but you need gdt for this to work
20935 movl saved_context_esp, %esp
20936
20937 - movl %cs:saved_magic, %eax
20938 - cmpl $0x12345678, %eax
20939 + cmpl $0x12345678, saved_magic
20940 jne bogus_magic
20941
20942 # jump to place where we left off
20943 - movl saved_eip, %eax
20944 - jmp *%eax
20945 + jmp *(saved_eip)
20946
20947 bogus_magic:
20948 jmp bogus_magic
20949 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20950 index 703130f..27a155d 100644
20951 --- a/arch/x86/kernel/alternative.c
20952 +++ b/arch/x86/kernel/alternative.c
20953 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20954 */
20955 for (a = start; a < end; a++) {
20956 instr = (u8 *)&a->instr_offset + a->instr_offset;
20957 +
20958 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20959 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20960 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20961 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20962 +#endif
20963 +
20964 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20965 BUG_ON(a->replacementlen > a->instrlen);
20966 BUG_ON(a->instrlen > sizeof(insnbuf));
20967 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20968 add_nops(insnbuf + a->replacementlen,
20969 a->instrlen - a->replacementlen);
20970
20971 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20972 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20973 + instr = ktva_ktla(instr);
20974 +#endif
20975 +
20976 text_poke_early(instr, insnbuf, a->instrlen);
20977 }
20978 }
20979 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20980 for (poff = start; poff < end; poff++) {
20981 u8 *ptr = (u8 *)poff + *poff;
20982
20983 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20984 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20985 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20986 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20987 +#endif
20988 +
20989 if (!*poff || ptr < text || ptr >= text_end)
20990 continue;
20991 /* turn DS segment override prefix into lock prefix */
20992 - if (*ptr == 0x3e)
20993 + if (*ktla_ktva(ptr) == 0x3e)
20994 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20995 }
20996 mutex_unlock(&text_mutex);
20997 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20998 for (poff = start; poff < end; poff++) {
20999 u8 *ptr = (u8 *)poff + *poff;
21000
21001 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21002 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21003 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21004 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21005 +#endif
21006 +
21007 if (!*poff || ptr < text || ptr >= text_end)
21008 continue;
21009 /* turn lock prefix into DS segment override prefix */
21010 - if (*ptr == 0xf0)
21011 + if (*ktla_ktva(ptr) == 0xf0)
21012 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21013 }
21014 mutex_unlock(&text_mutex);
21015 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21016
21017 BUG_ON(p->len > MAX_PATCH_LEN);
21018 /* prep the buffer with the original instructions */
21019 - memcpy(insnbuf, p->instr, p->len);
21020 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21021 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21022 (unsigned long)p->instr, p->len);
21023
21024 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21025 if (!uniproc_patched || num_possible_cpus() == 1)
21026 free_init_pages("SMP alternatives",
21027 (unsigned long)__smp_locks,
21028 - (unsigned long)__smp_locks_end);
21029 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21030 #endif
21031
21032 apply_paravirt(__parainstructions, __parainstructions_end);
21033 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21034 * instructions. And on the local CPU you need to be protected again NMI or MCE
21035 * handlers seeing an inconsistent instruction while you patch.
21036 */
21037 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21038 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21039 size_t len)
21040 {
21041 unsigned long flags;
21042 local_irq_save(flags);
21043 - memcpy(addr, opcode, len);
21044 +
21045 + pax_open_kernel();
21046 + memcpy(ktla_ktva(addr), opcode, len);
21047 sync_core();
21048 + pax_close_kernel();
21049 +
21050 local_irq_restore(flags);
21051 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21052 that causes hangs on some VIA CPUs. */
21053 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21054 */
21055 void *text_poke(void *addr, const void *opcode, size_t len)
21056 {
21057 - unsigned long flags;
21058 - char *vaddr;
21059 + unsigned char *vaddr = ktla_ktva(addr);
21060 struct page *pages[2];
21061 - int i;
21062 + size_t i;
21063
21064 if (!core_kernel_text((unsigned long)addr)) {
21065 - pages[0] = vmalloc_to_page(addr);
21066 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21067 + pages[0] = vmalloc_to_page(vaddr);
21068 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21069 } else {
21070 - pages[0] = virt_to_page(addr);
21071 + pages[0] = virt_to_page(vaddr);
21072 WARN_ON(!PageReserved(pages[0]));
21073 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21074 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21075 }
21076 BUG_ON(!pages[0]);
21077 - local_irq_save(flags);
21078 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21079 - if (pages[1])
21080 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21081 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21082 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21083 - clear_fixmap(FIX_TEXT_POKE0);
21084 - if (pages[1])
21085 - clear_fixmap(FIX_TEXT_POKE1);
21086 - local_flush_tlb();
21087 - sync_core();
21088 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21089 - that causes hangs on some VIA CPUs. */
21090 + text_poke_early(addr, opcode, len);
21091 for (i = 0; i < len; i++)
21092 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21093 - local_irq_restore(flags);
21094 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21095 return addr;
21096 }
21097
21098 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21099 if (likely(!bp_patching_in_progress))
21100 return 0;
21101
21102 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21103 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21104 return 0;
21105
21106 /* set up the specified breakpoint handler */
21107 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21108 */
21109 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21110 {
21111 - unsigned char int3 = 0xcc;
21112 + const unsigned char int3 = 0xcc;
21113
21114 bp_int3_handler = handler;
21115 bp_int3_addr = (u8 *)addr + sizeof(int3);
21116 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21117 index 6776027..972266c 100644
21118 --- a/arch/x86/kernel/apic/apic.c
21119 +++ b/arch/x86/kernel/apic/apic.c
21120 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21121 /*
21122 * Debug level, exported for io_apic.c
21123 */
21124 -unsigned int apic_verbosity;
21125 +int apic_verbosity;
21126
21127 int pic_mode;
21128
21129 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21130 apic_write(APIC_ESR, 0);
21131 v = apic_read(APIC_ESR);
21132 ack_APIC_irq();
21133 - atomic_inc(&irq_err_count);
21134 + atomic_inc_unchecked(&irq_err_count);
21135
21136 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21137 smp_processor_id(), v);
21138 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21139 index de918c4..32eed23 100644
21140 --- a/arch/x86/kernel/apic/apic_flat_64.c
21141 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21142 @@ -154,7 +154,7 @@ static int flat_probe(void)
21143 return 1;
21144 }
21145
21146 -static struct apic apic_flat = {
21147 +static struct apic apic_flat __read_only = {
21148 .name = "flat",
21149 .probe = flat_probe,
21150 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21151 @@ -260,7 +260,7 @@ static int physflat_probe(void)
21152 return 0;
21153 }
21154
21155 -static struct apic apic_physflat = {
21156 +static struct apic apic_physflat __read_only = {
21157
21158 .name = "physical flat",
21159 .probe = physflat_probe,
21160 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21161 index b205cdb..d8503ff 100644
21162 --- a/arch/x86/kernel/apic/apic_noop.c
21163 +++ b/arch/x86/kernel/apic/apic_noop.c
21164 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21165 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21166 }
21167
21168 -struct apic apic_noop = {
21169 +struct apic apic_noop __read_only = {
21170 .name = "noop",
21171 .probe = noop_probe,
21172 .acpi_madt_oem_check = NULL,
21173 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21174 index c4a8d63..fe893ac 100644
21175 --- a/arch/x86/kernel/apic/bigsmp_32.c
21176 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21177 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21178 return dmi_bigsmp;
21179 }
21180
21181 -static struct apic apic_bigsmp = {
21182 +static struct apic apic_bigsmp __read_only = {
21183
21184 .name = "bigsmp",
21185 .probe = probe_bigsmp,
21186 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21187 index 337ce5a..c8d98b4 100644
21188 --- a/arch/x86/kernel/apic/io_apic.c
21189 +++ b/arch/x86/kernel/apic/io_apic.c
21190 @@ -1230,7 +1230,7 @@ out:
21191 }
21192 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21193
21194 -void lock_vector_lock(void)
21195 +void lock_vector_lock(void) __acquires(vector_lock)
21196 {
21197 /* Used to the online set of cpus does not change
21198 * during assign_irq_vector.
21199 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21200 raw_spin_lock(&vector_lock);
21201 }
21202
21203 -void unlock_vector_lock(void)
21204 +void unlock_vector_lock(void) __releases(vector_lock)
21205 {
21206 raw_spin_unlock(&vector_lock);
21207 }
21208 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21209 ack_APIC_irq();
21210 }
21211
21212 -atomic_t irq_mis_count;
21213 +atomic_unchecked_t irq_mis_count;
21214
21215 #ifdef CONFIG_GENERIC_PENDING_IRQ
21216 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21217 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21218 * at the cpu.
21219 */
21220 if (!(v & (1 << (i & 0x1f)))) {
21221 - atomic_inc(&irq_mis_count);
21222 + atomic_inc_unchecked(&irq_mis_count);
21223
21224 eoi_ioapic_irq(irq, cfg);
21225 }
21226 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21227 index bda4886..f9c7195 100644
21228 --- a/arch/x86/kernel/apic/probe_32.c
21229 +++ b/arch/x86/kernel/apic/probe_32.c
21230 @@ -72,7 +72,7 @@ static int probe_default(void)
21231 return 1;
21232 }
21233
21234 -static struct apic apic_default = {
21235 +static struct apic apic_default __read_only = {
21236
21237 .name = "default",
21238 .probe = probe_default,
21239 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21240 index 6ce600f..cb44af8 100644
21241 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21242 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21243 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21244 return notifier_from_errno(err);
21245 }
21246
21247 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21248 +static struct notifier_block x2apic_cpu_notifier = {
21249 .notifier_call = update_clusterinfo,
21250 };
21251
21252 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21253 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21254 }
21255
21256 -static struct apic apic_x2apic_cluster = {
21257 +static struct apic apic_x2apic_cluster __read_only = {
21258
21259 .name = "cluster x2apic",
21260 .probe = x2apic_cluster_probe,
21261 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21262 index 6fae733..5ca17af 100644
21263 --- a/arch/x86/kernel/apic/x2apic_phys.c
21264 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21265 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21266 return apic == &apic_x2apic_phys;
21267 }
21268
21269 -static struct apic apic_x2apic_phys = {
21270 +static struct apic apic_x2apic_phys __read_only = {
21271
21272 .name = "physical x2apic",
21273 .probe = x2apic_phys_probe,
21274 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21275 index 004f017..8fbc8b5 100644
21276 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21277 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21278 @@ -350,7 +350,7 @@ static int uv_probe(void)
21279 return apic == &apic_x2apic_uv_x;
21280 }
21281
21282 -static struct apic __refdata apic_x2apic_uv_x = {
21283 +static struct apic apic_x2apic_uv_x __read_only = {
21284
21285 .name = "UV large system",
21286 .probe = uv_probe,
21287 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21288 index 5848744..56cb598 100644
21289 --- a/arch/x86/kernel/apm_32.c
21290 +++ b/arch/x86/kernel/apm_32.c
21291 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21292 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21293 * even though they are called in protected mode.
21294 */
21295 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21296 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21297 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21298
21299 static const char driver_version[] = "1.16ac"; /* no spaces */
21300 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21301 BUG_ON(cpu != 0);
21302 gdt = get_cpu_gdt_table(cpu);
21303 save_desc_40 = gdt[0x40 / 8];
21304 +
21305 + pax_open_kernel();
21306 gdt[0x40 / 8] = bad_bios_desc;
21307 + pax_close_kernel();
21308
21309 apm_irq_save(flags);
21310 APM_DO_SAVE_SEGS;
21311 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21312 &call->esi);
21313 APM_DO_RESTORE_SEGS;
21314 apm_irq_restore(flags);
21315 +
21316 + pax_open_kernel();
21317 gdt[0x40 / 8] = save_desc_40;
21318 + pax_close_kernel();
21319 +
21320 put_cpu();
21321
21322 return call->eax & 0xff;
21323 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21324 BUG_ON(cpu != 0);
21325 gdt = get_cpu_gdt_table(cpu);
21326 save_desc_40 = gdt[0x40 / 8];
21327 +
21328 + pax_open_kernel();
21329 gdt[0x40 / 8] = bad_bios_desc;
21330 + pax_close_kernel();
21331
21332 apm_irq_save(flags);
21333 APM_DO_SAVE_SEGS;
21334 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21335 &call->eax);
21336 APM_DO_RESTORE_SEGS;
21337 apm_irq_restore(flags);
21338 +
21339 + pax_open_kernel();
21340 gdt[0x40 / 8] = save_desc_40;
21341 + pax_close_kernel();
21342 +
21343 put_cpu();
21344 return error;
21345 }
21346 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21347 * code to that CPU.
21348 */
21349 gdt = get_cpu_gdt_table(0);
21350 +
21351 + pax_open_kernel();
21352 set_desc_base(&gdt[APM_CS >> 3],
21353 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21354 set_desc_base(&gdt[APM_CS_16 >> 3],
21355 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21356 set_desc_base(&gdt[APM_DS >> 3],
21357 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21358 + pax_close_kernel();
21359
21360 proc_create("apm", 0, NULL, &apm_file_ops);
21361
21362 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21363 index 9f6b934..cf5ffb3 100644
21364 --- a/arch/x86/kernel/asm-offsets.c
21365 +++ b/arch/x86/kernel/asm-offsets.c
21366 @@ -32,6 +32,8 @@ void common(void) {
21367 OFFSET(TI_flags, thread_info, flags);
21368 OFFSET(TI_status, thread_info, status);
21369 OFFSET(TI_addr_limit, thread_info, addr_limit);
21370 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21371 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21372
21373 BLANK();
21374 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21375 @@ -52,8 +54,26 @@ void common(void) {
21376 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21377 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21378 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21379 +
21380 +#ifdef CONFIG_PAX_KERNEXEC
21381 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21382 #endif
21383
21384 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21385 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21386 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21387 +#ifdef CONFIG_X86_64
21388 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21389 +#endif
21390 +#endif
21391 +
21392 +#endif
21393 +
21394 + BLANK();
21395 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21396 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21397 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21398 +
21399 #ifdef CONFIG_XEN
21400 BLANK();
21401 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21402 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21403 index e7c798b..2b2019b 100644
21404 --- a/arch/x86/kernel/asm-offsets_64.c
21405 +++ b/arch/x86/kernel/asm-offsets_64.c
21406 @@ -77,6 +77,7 @@ int main(void)
21407 BLANK();
21408 #undef ENTRY
21409
21410 + DEFINE(TSS_size, sizeof(struct tss_struct));
21411 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21412 BLANK();
21413
21414 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21415 index 7fd54f0..0691410 100644
21416 --- a/arch/x86/kernel/cpu/Makefile
21417 +++ b/arch/x86/kernel/cpu/Makefile
21418 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21419 CFLAGS_REMOVE_perf_event.o = -pg
21420 endif
21421
21422 -# Make sure load_percpu_segment has no stackprotector
21423 -nostackp := $(call cc-option, -fno-stack-protector)
21424 -CFLAGS_common.o := $(nostackp)
21425 -
21426 obj-y := intel_cacheinfo.o scattered.o topology.o
21427 obj-y += proc.o capflags.o powerflags.o common.o
21428 obj-y += rdrand.o
21429 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21430 index 60e5497..8efbd2f 100644
21431 --- a/arch/x86/kernel/cpu/amd.c
21432 +++ b/arch/x86/kernel/cpu/amd.c
21433 @@ -711,7 +711,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21434 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21435 {
21436 /* AMD errata T13 (order #21922) */
21437 - if ((c->x86 == 6)) {
21438 + if (c->x86 == 6) {
21439 /* Duron Rev A0 */
21440 if (c->x86_model == 3 && c->x86_mask == 0)
21441 size = 64;
21442 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21443 index e4ab2b4..d487ba5 100644
21444 --- a/arch/x86/kernel/cpu/common.c
21445 +++ b/arch/x86/kernel/cpu/common.c
21446 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21447
21448 static const struct cpu_dev *this_cpu = &default_cpu;
21449
21450 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21451 -#ifdef CONFIG_X86_64
21452 - /*
21453 - * We need valid kernel segments for data and code in long mode too
21454 - * IRET will check the segment types kkeil 2000/10/28
21455 - * Also sysret mandates a special GDT layout
21456 - *
21457 - * TLS descriptors are currently at a different place compared to i386.
21458 - * Hopefully nobody expects them at a fixed place (Wine?)
21459 - */
21460 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21461 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21462 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21463 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21464 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21465 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21466 -#else
21467 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21468 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21469 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21470 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21471 - /*
21472 - * Segments used for calling PnP BIOS have byte granularity.
21473 - * They code segments and data segments have fixed 64k limits,
21474 - * the transfer segment sizes are set at run time.
21475 - */
21476 - /* 32-bit code */
21477 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21478 - /* 16-bit code */
21479 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21480 - /* 16-bit data */
21481 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21482 - /* 16-bit data */
21483 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21484 - /* 16-bit data */
21485 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21486 - /*
21487 - * The APM segments have byte granularity and their bases
21488 - * are set at run time. All have 64k limits.
21489 - */
21490 - /* 32-bit code */
21491 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21492 - /* 16-bit code */
21493 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21494 - /* data */
21495 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21496 -
21497 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21498 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21499 - GDT_STACK_CANARY_INIT
21500 -#endif
21501 -} };
21502 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21503 -
21504 static int __init x86_xsave_setup(char *s)
21505 {
21506 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21507 @@ -303,6 +249,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21508 }
21509 }
21510
21511 +#ifdef CONFIG_X86_64
21512 +static __init int setup_disable_pcid(char *arg)
21513 +{
21514 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21515 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21516 +
21517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21518 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21519 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21520 +#endif
21521 +
21522 + return 1;
21523 +}
21524 +__setup("nopcid", setup_disable_pcid);
21525 +
21526 +static void setup_pcid(struct cpuinfo_x86 *c)
21527 +{
21528 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21529 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21530 +
21531 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21532 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21533 + pax_open_kernel();
21534 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21535 + pax_close_kernel();
21536 + printk("PAX: slow and weak UDEREF enabled\n");
21537 + } else
21538 + printk("PAX: UDEREF disabled\n");
21539 +#endif
21540 +
21541 + return;
21542 + }
21543 +
21544 + printk("PAX: PCID detected\n");
21545 + set_in_cr4(X86_CR4_PCIDE);
21546 +
21547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21548 + pax_open_kernel();
21549 + clone_pgd_mask = ~(pgdval_t)0UL;
21550 + pax_close_kernel();
21551 + if (pax_user_shadow_base)
21552 + printk("PAX: weak UDEREF enabled\n");
21553 + else {
21554 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21555 + printk("PAX: strong UDEREF enabled\n");
21556 + }
21557 +#endif
21558 +
21559 + if (cpu_has(c, X86_FEATURE_INVPCID))
21560 + printk("PAX: INVPCID detected\n");
21561 +}
21562 +#endif
21563 +
21564 /*
21565 * Some CPU features depend on higher CPUID levels, which may not always
21566 * be available due to CPUID level capping or broken virtualization
21567 @@ -403,7 +402,7 @@ void switch_to_new_gdt(int cpu)
21568 {
21569 struct desc_ptr gdt_descr;
21570
21571 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21572 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21573 gdt_descr.size = GDT_SIZE - 1;
21574 load_gdt(&gdt_descr);
21575 /* Reload the per-cpu base */
21576 @@ -893,6 +892,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21577 setup_smep(c);
21578 setup_smap(c);
21579
21580 +#ifdef CONFIG_X86_64
21581 + setup_pcid(c);
21582 +#endif
21583 +
21584 /*
21585 * The vendor-specific functions might have changed features.
21586 * Now we do "generic changes."
21587 @@ -901,6 +904,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21588 /* Filter out anything that depends on CPUID levels we don't have */
21589 filter_cpuid_features(c, true);
21590
21591 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21592 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21593 +#endif
21594 +
21595 /* If the model name is still unset, do table lookup. */
21596 if (!c->x86_model_id[0]) {
21597 const char *p;
21598 @@ -981,7 +988,7 @@ static void syscall32_cpu_init(void)
21599 void enable_sep_cpu(void)
21600 {
21601 int cpu = get_cpu();
21602 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21603 + struct tss_struct *tss = init_tss + cpu;
21604
21605 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21606 put_cpu();
21607 @@ -1121,14 +1128,16 @@ static __init int setup_disablecpuid(char *arg)
21608 }
21609 __setup("clearcpuid=", setup_disablecpuid);
21610
21611 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21612 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21613 +
21614 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21615 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21616 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21617 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21618
21619 #ifdef CONFIG_X86_64
21620 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21621 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21622 - (unsigned long) debug_idt_table };
21623 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21624 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21625
21626 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21627 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21628 @@ -1291,7 +1300,7 @@ void cpu_init(void)
21629 load_ucode_ap();
21630
21631 cpu = stack_smp_processor_id();
21632 - t = &per_cpu(init_tss, cpu);
21633 + t = init_tss + cpu;
21634 oist = &per_cpu(orig_ist, cpu);
21635
21636 #ifdef CONFIG_NUMA
21637 @@ -1326,7 +1335,6 @@ void cpu_init(void)
21638 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21639 barrier();
21640
21641 - x86_configure_nx();
21642 enable_x2apic();
21643
21644 /*
21645 @@ -1378,7 +1386,7 @@ void cpu_init(void)
21646 {
21647 int cpu = smp_processor_id();
21648 struct task_struct *curr = current;
21649 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21650 + struct tss_struct *t = init_tss + cpu;
21651 struct thread_struct *thread = &curr->thread;
21652
21653 show_ucode_info_early();
21654 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21655 index c703507..28535e3 100644
21656 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21657 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21658 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21659 };
21660
21661 #ifdef CONFIG_AMD_NB
21662 +static struct attribute *default_attrs_amd_nb[] = {
21663 + &type.attr,
21664 + &level.attr,
21665 + &coherency_line_size.attr,
21666 + &physical_line_partition.attr,
21667 + &ways_of_associativity.attr,
21668 + &number_of_sets.attr,
21669 + &size.attr,
21670 + &shared_cpu_map.attr,
21671 + &shared_cpu_list.attr,
21672 + NULL,
21673 + NULL,
21674 + NULL,
21675 + NULL
21676 +};
21677 +
21678 static struct attribute **amd_l3_attrs(void)
21679 {
21680 static struct attribute **attrs;
21681 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21682
21683 n = ARRAY_SIZE(default_attrs);
21684
21685 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21686 - n += 2;
21687 -
21688 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21689 - n += 1;
21690 -
21691 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21692 - if (attrs == NULL)
21693 - return attrs = default_attrs;
21694 -
21695 - for (n = 0; default_attrs[n]; n++)
21696 - attrs[n] = default_attrs[n];
21697 + attrs = default_attrs_amd_nb;
21698
21699 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21700 attrs[n++] = &cache_disable_0.attr;
21701 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21702 .default_attrs = default_attrs,
21703 };
21704
21705 +#ifdef CONFIG_AMD_NB
21706 +static struct kobj_type ktype_cache_amd_nb = {
21707 + .sysfs_ops = &sysfs_ops,
21708 + .default_attrs = default_attrs_amd_nb,
21709 +};
21710 +#endif
21711 +
21712 static struct kobj_type ktype_percpu_entry = {
21713 .sysfs_ops = &sysfs_ops,
21714 };
21715 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21716 return retval;
21717 }
21718
21719 +#ifdef CONFIG_AMD_NB
21720 + amd_l3_attrs();
21721 +#endif
21722 +
21723 for (i = 0; i < num_cache_leaves; i++) {
21724 + struct kobj_type *ktype;
21725 +
21726 this_object = INDEX_KOBJECT_PTR(cpu, i);
21727 this_object->cpu = cpu;
21728 this_object->index = i;
21729
21730 this_leaf = CPUID4_INFO_IDX(cpu, i);
21731
21732 - ktype_cache.default_attrs = default_attrs;
21733 + ktype = &ktype_cache;
21734 #ifdef CONFIG_AMD_NB
21735 if (this_leaf->base.nb)
21736 - ktype_cache.default_attrs = amd_l3_attrs();
21737 + ktype = &ktype_cache_amd_nb;
21738 #endif
21739 retval = kobject_init_and_add(&(this_object->kobj),
21740 - &ktype_cache,
21741 + ktype,
21742 per_cpu(ici_cache_kobject, cpu),
21743 "index%1lu", i);
21744 if (unlikely(retval)) {
21745 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21746 index bd9ccda..38314e7 100644
21747 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21748 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21749 @@ -45,6 +45,7 @@
21750 #include <asm/processor.h>
21751 #include <asm/mce.h>
21752 #include <asm/msr.h>
21753 +#include <asm/local.h>
21754
21755 #include "mce-internal.h"
21756
21757 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21758 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21759 m->cs, m->ip);
21760
21761 - if (m->cs == __KERNEL_CS)
21762 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21763 print_symbol("{%s}", m->ip);
21764 pr_cont("\n");
21765 }
21766 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21767
21768 #define PANIC_TIMEOUT 5 /* 5 seconds */
21769
21770 -static atomic_t mce_paniced;
21771 +static atomic_unchecked_t mce_paniced;
21772
21773 static int fake_panic;
21774 -static atomic_t mce_fake_paniced;
21775 +static atomic_unchecked_t mce_fake_paniced;
21776
21777 /* Panic in progress. Enable interrupts and wait for final IPI */
21778 static void wait_for_panic(void)
21779 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21780 /*
21781 * Make sure only one CPU runs in machine check panic
21782 */
21783 - if (atomic_inc_return(&mce_paniced) > 1)
21784 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21785 wait_for_panic();
21786 barrier();
21787
21788 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21789 console_verbose();
21790 } else {
21791 /* Don't log too much for fake panic */
21792 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21793 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21794 return;
21795 }
21796 /* First print corrected ones that are still unlogged */
21797 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21798 if (!fake_panic) {
21799 if (panic_timeout == 0)
21800 panic_timeout = mca_cfg.panic_timeout;
21801 - panic(msg);
21802 + panic("%s", msg);
21803 } else
21804 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21805 }
21806 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21807 * might have been modified by someone else.
21808 */
21809 rmb();
21810 - if (atomic_read(&mce_paniced))
21811 + if (atomic_read_unchecked(&mce_paniced))
21812 wait_for_panic();
21813 if (!mca_cfg.monarch_timeout)
21814 goto out;
21815 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21816 }
21817
21818 /* Call the installed machine check handler for this CPU setup. */
21819 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21820 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21821 unexpected_machine_check;
21822
21823 /*
21824 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21825 return;
21826 }
21827
21828 + pax_open_kernel();
21829 machine_check_vector = do_machine_check;
21830 + pax_close_kernel();
21831
21832 __mcheck_cpu_init_generic();
21833 __mcheck_cpu_init_vendor(c);
21834 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21835 */
21836
21837 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21838 -static int mce_chrdev_open_count; /* #times opened */
21839 +static local_t mce_chrdev_open_count; /* #times opened */
21840 static int mce_chrdev_open_exclu; /* already open exclusive? */
21841
21842 static int mce_chrdev_open(struct inode *inode, struct file *file)
21843 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21844 spin_lock(&mce_chrdev_state_lock);
21845
21846 if (mce_chrdev_open_exclu ||
21847 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21848 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21849 spin_unlock(&mce_chrdev_state_lock);
21850
21851 return -EBUSY;
21852 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21853
21854 if (file->f_flags & O_EXCL)
21855 mce_chrdev_open_exclu = 1;
21856 - mce_chrdev_open_count++;
21857 + local_inc(&mce_chrdev_open_count);
21858
21859 spin_unlock(&mce_chrdev_state_lock);
21860
21861 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21862 {
21863 spin_lock(&mce_chrdev_state_lock);
21864
21865 - mce_chrdev_open_count--;
21866 + local_dec(&mce_chrdev_open_count);
21867 mce_chrdev_open_exclu = 0;
21868
21869 spin_unlock(&mce_chrdev_state_lock);
21870 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21871
21872 for (i = 0; i < mca_cfg.banks; i++) {
21873 struct mce_bank *b = &mce_banks[i];
21874 - struct device_attribute *a = &b->attr;
21875 + device_attribute_no_const *a = &b->attr;
21876
21877 sysfs_attr_init(&a->attr);
21878 a->attr.name = b->attrname;
21879 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21880 static void mce_reset(void)
21881 {
21882 cpu_missing = 0;
21883 - atomic_set(&mce_fake_paniced, 0);
21884 + atomic_set_unchecked(&mce_fake_paniced, 0);
21885 atomic_set(&mce_executing, 0);
21886 atomic_set(&mce_callin, 0);
21887 atomic_set(&global_nwo, 0);
21888 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21889 index a304298..49b6d06 100644
21890 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21891 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21892 @@ -10,6 +10,7 @@
21893 #include <asm/processor.h>
21894 #include <asm/mce.h>
21895 #include <asm/msr.h>
21896 +#include <asm/pgtable.h>
21897
21898 /* By default disabled */
21899 int mce_p5_enabled __read_mostly;
21900 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21901 if (!cpu_has(c, X86_FEATURE_MCE))
21902 return;
21903
21904 + pax_open_kernel();
21905 machine_check_vector = pentium_machine_check;
21906 + pax_close_kernel();
21907 /* Make sure the vector pointer is visible before we enable MCEs: */
21908 wmb();
21909
21910 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21911 index 7dc5564..1273569 100644
21912 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21913 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21914 @@ -9,6 +9,7 @@
21915 #include <asm/processor.h>
21916 #include <asm/mce.h>
21917 #include <asm/msr.h>
21918 +#include <asm/pgtable.h>
21919
21920 /* Machine check handler for WinChip C6: */
21921 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21922 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21923 {
21924 u32 lo, hi;
21925
21926 + pax_open_kernel();
21927 machine_check_vector = winchip_machine_check;
21928 + pax_close_kernel();
21929 /* Make sure the vector pointer is visible before we enable MCEs: */
21930 wmb();
21931
21932 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21933 index dd9d619..86e1d81 100644
21934 --- a/arch/x86/kernel/cpu/microcode/core.c
21935 +++ b/arch/x86/kernel/cpu/microcode/core.c
21936 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21937 return NOTIFY_OK;
21938 }
21939
21940 -static struct notifier_block __refdata mc_cpu_notifier = {
21941 +static struct notifier_block mc_cpu_notifier = {
21942 .notifier_call = mc_cpu_callback,
21943 };
21944
21945 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21946 index a276fa7..e66810f 100644
21947 --- a/arch/x86/kernel/cpu/microcode/intel.c
21948 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21949 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21950
21951 static int get_ucode_user(void *to, const void *from, size_t n)
21952 {
21953 - return copy_from_user(to, from, n);
21954 + return copy_from_user(to, (const void __force_user *)from, n);
21955 }
21956
21957 static enum ucode_state
21958 request_microcode_user(int cpu, const void __user *buf, size_t size)
21959 {
21960 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21961 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21962 }
21963
21964 static void microcode_fini_cpu(int cpu)
21965 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21966 index f961de9..8a9d332 100644
21967 --- a/arch/x86/kernel/cpu/mtrr/main.c
21968 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21969 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21970 u64 size_or_mask, size_and_mask;
21971 static bool mtrr_aps_delayed_init;
21972
21973 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21974 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21975
21976 const struct mtrr_ops *mtrr_if;
21977
21978 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21979 index df5e41f..816c719 100644
21980 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21981 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21982 @@ -25,7 +25,7 @@ struct mtrr_ops {
21983 int (*validate_add_page)(unsigned long base, unsigned long size,
21984 unsigned int type);
21985 int (*have_wrcomb)(void);
21986 -};
21987 +} __do_const;
21988
21989 extern int generic_get_free_region(unsigned long base, unsigned long size,
21990 int replace_reg);
21991 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21992 index 2879ecd..bb8c80b 100644
21993 --- a/arch/x86/kernel/cpu/perf_event.c
21994 +++ b/arch/x86/kernel/cpu/perf_event.c
21995 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
21996
21997 }
21998
21999 -static struct attribute_group x86_pmu_format_group = {
22000 +static attribute_group_no_const x86_pmu_format_group = {
22001 .name = "format",
22002 .attrs = NULL,
22003 };
22004 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22005 NULL,
22006 };
22007
22008 -static struct attribute_group x86_pmu_events_group = {
22009 +static attribute_group_no_const x86_pmu_events_group = {
22010 .name = "events",
22011 .attrs = events_attr,
22012 };
22013 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22014 if (idx > GDT_ENTRIES)
22015 return 0;
22016
22017 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22018 + desc = get_cpu_gdt_table(smp_processor_id());
22019 }
22020
22021 return get_desc_base(desc + idx);
22022 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22023 break;
22024
22025 perf_callchain_store(entry, frame.return_address);
22026 - fp = frame.next_frame;
22027 + fp = (const void __force_user *)frame.next_frame;
22028 }
22029 }
22030
22031 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22032 index 639d128..e92d7e5 100644
22033 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22034 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22035 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22036 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22037 {
22038 struct attribute **attrs;
22039 - struct attribute_group *attr_group;
22040 + attribute_group_no_const *attr_group;
22041 int i = 0, j;
22042
22043 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22044 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22045 index 2502d0d..e5cc05c 100644
22046 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22047 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22048 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22049 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22050
22051 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22052 - u64 capabilities;
22053 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22054
22055 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22056 - x86_pmu.intel_cap.capabilities = capabilities;
22057 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22058 + x86_pmu.intel_cap.capabilities = capabilities;
22059 }
22060
22061 intel_ds_init();
22062 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22063 index 619f769..d510008 100644
22064 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22065 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22066 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22067 NULL,
22068 };
22069
22070 -static struct attribute_group rapl_pmu_events_group = {
22071 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22072 .name = "events",
22073 .attrs = NULL, /* patched at runtime */
22074 };
22075 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22076 index 0939f86..69730af 100644
22077 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22078 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22079 @@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22080 static int __init uncore_type_init(struct intel_uncore_type *type)
22081 {
22082 struct intel_uncore_pmu *pmus;
22083 - struct attribute_group *attr_group;
22084 + attribute_group_no_const *attr_group;
22085 struct attribute **attrs;
22086 int i, j;
22087
22088 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22089 index 90236f0..54cb20d 100644
22090 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22091 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22092 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22093 struct uncore_event_desc {
22094 struct kobj_attribute attr;
22095 const char *config;
22096 -};
22097 +} __do_const;
22098
22099 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22100 { \
22101 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22102 index 3225ae6c..ee3c6db 100644
22103 --- a/arch/x86/kernel/cpuid.c
22104 +++ b/arch/x86/kernel/cpuid.c
22105 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22106 return notifier_from_errno(err);
22107 }
22108
22109 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22110 +static struct notifier_block cpuid_class_cpu_notifier =
22111 {
22112 .notifier_call = cpuid_class_cpu_callback,
22113 };
22114 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22115 index a618fcd..200e95b 100644
22116 --- a/arch/x86/kernel/crash.c
22117 +++ b/arch/x86/kernel/crash.c
22118 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22119 #ifdef CONFIG_X86_32
22120 struct pt_regs fixed_regs;
22121
22122 - if (!user_mode_vm(regs)) {
22123 + if (!user_mode(regs)) {
22124 crash_fixup_ss_esp(&fixed_regs, regs);
22125 regs = &fixed_regs;
22126 }
22127 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22128 index afa64ad..dce67dd 100644
22129 --- a/arch/x86/kernel/crash_dump_64.c
22130 +++ b/arch/x86/kernel/crash_dump_64.c
22131 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22132 return -ENOMEM;
22133
22134 if (userbuf) {
22135 - if (copy_to_user(buf, vaddr + offset, csize)) {
22136 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22137 iounmap(vaddr);
22138 return -EFAULT;
22139 }
22140 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22141 index f6dfd93..892ade4 100644
22142 --- a/arch/x86/kernel/doublefault.c
22143 +++ b/arch/x86/kernel/doublefault.c
22144 @@ -12,7 +12,7 @@
22145
22146 #define DOUBLEFAULT_STACKSIZE (1024)
22147 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22148 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22149 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22150
22151 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22152
22153 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22154 unsigned long gdt, tss;
22155
22156 native_store_gdt(&gdt_desc);
22157 - gdt = gdt_desc.address;
22158 + gdt = (unsigned long)gdt_desc.address;
22159
22160 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22161
22162 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22163 /* 0x2 bit is always set */
22164 .flags = X86_EFLAGS_SF | 0x2,
22165 .sp = STACK_START,
22166 - .es = __USER_DS,
22167 + .es = __KERNEL_DS,
22168 .cs = __KERNEL_CS,
22169 .ss = __KERNEL_DS,
22170 - .ds = __USER_DS,
22171 + .ds = __KERNEL_DS,
22172 .fs = __KERNEL_PERCPU,
22173
22174 .__cr3 = __pa_nodebug(swapper_pg_dir),
22175 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22176 index b74ebc7..2c95874 100644
22177 --- a/arch/x86/kernel/dumpstack.c
22178 +++ b/arch/x86/kernel/dumpstack.c
22179 @@ -2,6 +2,9 @@
22180 * Copyright (C) 1991, 1992 Linus Torvalds
22181 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22182 */
22183 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22184 +#define __INCLUDED_BY_HIDESYM 1
22185 +#endif
22186 #include <linux/kallsyms.h>
22187 #include <linux/kprobes.h>
22188 #include <linux/uaccess.h>
22189 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22190
22191 void printk_address(unsigned long address)
22192 {
22193 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22194 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22195 }
22196
22197 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22198 static void
22199 print_ftrace_graph_addr(unsigned long addr, void *data,
22200 const struct stacktrace_ops *ops,
22201 - struct thread_info *tinfo, int *graph)
22202 + struct task_struct *task, int *graph)
22203 {
22204 - struct task_struct *task;
22205 unsigned long ret_addr;
22206 int index;
22207
22208 if (addr != (unsigned long)return_to_handler)
22209 return;
22210
22211 - task = tinfo->task;
22212 index = task->curr_ret_stack;
22213
22214 if (!task->ret_stack || index < *graph)
22215 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22216 static inline void
22217 print_ftrace_graph_addr(unsigned long addr, void *data,
22218 const struct stacktrace_ops *ops,
22219 - struct thread_info *tinfo, int *graph)
22220 + struct task_struct *task, int *graph)
22221 { }
22222 #endif
22223
22224 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22225 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22226 */
22227
22228 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22229 - void *p, unsigned int size, void *end)
22230 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22231 {
22232 - void *t = tinfo;
22233 if (end) {
22234 if (p < end && p >= (end-THREAD_SIZE))
22235 return 1;
22236 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22237 }
22238
22239 unsigned long
22240 -print_context_stack(struct thread_info *tinfo,
22241 +print_context_stack(struct task_struct *task, void *stack_start,
22242 unsigned long *stack, unsigned long bp,
22243 const struct stacktrace_ops *ops, void *data,
22244 unsigned long *end, int *graph)
22245 {
22246 struct stack_frame *frame = (struct stack_frame *)bp;
22247
22248 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22249 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22250 unsigned long addr;
22251
22252 addr = *stack;
22253 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22254 } else {
22255 ops->address(data, addr, 0);
22256 }
22257 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22258 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22259 }
22260 stack++;
22261 }
22262 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22263 EXPORT_SYMBOL_GPL(print_context_stack);
22264
22265 unsigned long
22266 -print_context_stack_bp(struct thread_info *tinfo,
22267 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22268 unsigned long *stack, unsigned long bp,
22269 const struct stacktrace_ops *ops, void *data,
22270 unsigned long *end, int *graph)
22271 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22272 struct stack_frame *frame = (struct stack_frame *)bp;
22273 unsigned long *ret_addr = &frame->return_address;
22274
22275 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22276 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22277 unsigned long addr = *ret_addr;
22278
22279 if (!__kernel_text_address(addr))
22280 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22281 ops->address(data, addr, 1);
22282 frame = frame->next_frame;
22283 ret_addr = &frame->return_address;
22284 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22285 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22286 }
22287
22288 return (unsigned long)frame;
22289 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22290 static void print_trace_address(void *data, unsigned long addr, int reliable)
22291 {
22292 touch_nmi_watchdog();
22293 - printk(data);
22294 + printk("%s", (char *)data);
22295 printk_stack_address(addr, reliable);
22296 }
22297
22298 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22299 EXPORT_SYMBOL_GPL(oops_begin);
22300 NOKPROBE_SYMBOL(oops_begin);
22301
22302 +extern void gr_handle_kernel_exploit(void);
22303 +
22304 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22305 {
22306 if (regs && kexec_should_crash(current))
22307 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22308 panic("Fatal exception in interrupt");
22309 if (panic_on_oops)
22310 panic("Fatal exception");
22311 - do_exit(signr);
22312 +
22313 + gr_handle_kernel_exploit();
22314 +
22315 + do_group_exit(signr);
22316 }
22317 NOKPROBE_SYMBOL(oops_end);
22318
22319 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22320 print_modules();
22321 show_regs(regs);
22322 #ifdef CONFIG_X86_32
22323 - if (user_mode_vm(regs)) {
22324 + if (user_mode(regs)) {
22325 sp = regs->sp;
22326 ss = regs->ss & 0xffff;
22327 } else {
22328 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22329 unsigned long flags = oops_begin();
22330 int sig = SIGSEGV;
22331
22332 - if (!user_mode_vm(regs))
22333 + if (!user_mode(regs))
22334 report_bug(regs->ip, regs);
22335
22336 if (__die(str, regs, err))
22337 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22338 index 5abd4cd..c65733b 100644
22339 --- a/arch/x86/kernel/dumpstack_32.c
22340 +++ b/arch/x86/kernel/dumpstack_32.c
22341 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22342 bp = stack_frame(task, regs);
22343
22344 for (;;) {
22345 - struct thread_info *context;
22346 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22347 void *end_stack;
22348
22349 end_stack = is_hardirq_stack(stack, cpu);
22350 if (!end_stack)
22351 end_stack = is_softirq_stack(stack, cpu);
22352
22353 - context = task_thread_info(task);
22354 - bp = ops->walk_stack(context, stack, bp, ops, data,
22355 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22356 end_stack, &graph);
22357
22358 /* Stop if not on irq stack */
22359 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22360 int i;
22361
22362 show_regs_print_info(KERN_EMERG);
22363 - __show_regs(regs, !user_mode_vm(regs));
22364 + __show_regs(regs, !user_mode(regs));
22365
22366 /*
22367 * When in-kernel, we also print out the stack and code at the
22368 * time of the fault..
22369 */
22370 - if (!user_mode_vm(regs)) {
22371 + if (!user_mode(regs)) {
22372 unsigned int code_prologue = code_bytes * 43 / 64;
22373 unsigned int code_len = code_bytes;
22374 unsigned char c;
22375 u8 *ip;
22376 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22377
22378 pr_emerg("Stack:\n");
22379 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22380
22381 pr_emerg("Code:");
22382
22383 - ip = (u8 *)regs->ip - code_prologue;
22384 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22385 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22386 /* try starting at IP */
22387 - ip = (u8 *)regs->ip;
22388 + ip = (u8 *)regs->ip + cs_base;
22389 code_len = code_len - code_prologue + 1;
22390 }
22391 for (i = 0; i < code_len; i++, ip++) {
22392 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22393 pr_cont(" Bad EIP value.");
22394 break;
22395 }
22396 - if (ip == (u8 *)regs->ip)
22397 + if (ip == (u8 *)regs->ip + cs_base)
22398 pr_cont(" <%02x>", c);
22399 else
22400 pr_cont(" %02x", c);
22401 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22402 {
22403 unsigned short ud2;
22404
22405 + ip = ktla_ktva(ip);
22406 if (ip < PAGE_OFFSET)
22407 return 0;
22408 if (probe_kernel_address((unsigned short *)ip, ud2))
22409 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22410
22411 return ud2 == 0x0b0f;
22412 }
22413 +
22414 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22415 +void pax_check_alloca(unsigned long size)
22416 +{
22417 + unsigned long sp = (unsigned long)&sp, stack_left;
22418 +
22419 + /* all kernel stacks are of the same size */
22420 + stack_left = sp & (THREAD_SIZE - 1);
22421 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22422 +}
22423 +EXPORT_SYMBOL(pax_check_alloca);
22424 +#endif
22425 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22426 index 1abcb50..6c8d702 100644
22427 --- a/arch/x86/kernel/dumpstack_64.c
22428 +++ b/arch/x86/kernel/dumpstack_64.c
22429 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22430 const struct stacktrace_ops *ops, void *data)
22431 {
22432 const unsigned cpu = get_cpu();
22433 - struct thread_info *tinfo;
22434 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22435 unsigned long dummy;
22436 unsigned used = 0;
22437 int graph = 0;
22438 int done = 0;
22439 + void *stack_start;
22440
22441 if (!task)
22442 task = current;
22443 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22444 * current stack address. If the stacks consist of nested
22445 * exceptions
22446 */
22447 - tinfo = task_thread_info(task);
22448 while (!done) {
22449 unsigned long *stack_end;
22450 enum stack_type stype;
22451 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22452 if (ops->stack(data, id) < 0)
22453 break;
22454
22455 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22456 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22457 data, stack_end, &graph);
22458 ops->stack(data, "<EOE>");
22459 /*
22460 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22461 * second-to-last pointer (index -2 to end) in the
22462 * exception stack:
22463 */
22464 + if ((u16)stack_end[-1] != __KERNEL_DS)
22465 + goto out;
22466 stack = (unsigned long *) stack_end[-2];
22467 done = 0;
22468 break;
22469 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22470
22471 if (ops->stack(data, "IRQ") < 0)
22472 break;
22473 - bp = ops->walk_stack(tinfo, stack, bp,
22474 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22475 ops, data, stack_end, &graph);
22476 /*
22477 * We link to the next stack (which would be
22478 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22479 /*
22480 * This handles the process stack:
22481 */
22482 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22483 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22484 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22485 +out:
22486 put_cpu();
22487 }
22488 EXPORT_SYMBOL(dump_trace);
22489 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22490
22491 return ud2 == 0x0b0f;
22492 }
22493 +
22494 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22495 +void pax_check_alloca(unsigned long size)
22496 +{
22497 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22498 + unsigned cpu, used;
22499 + char *id;
22500 +
22501 + /* check the process stack first */
22502 + stack_start = (unsigned long)task_stack_page(current);
22503 + stack_end = stack_start + THREAD_SIZE;
22504 + if (likely(stack_start <= sp && sp < stack_end)) {
22505 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22506 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22507 + return;
22508 + }
22509 +
22510 + cpu = get_cpu();
22511 +
22512 + /* check the irq stacks */
22513 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22514 + stack_start = stack_end - IRQ_STACK_SIZE;
22515 + if (stack_start <= sp && sp < stack_end) {
22516 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22517 + put_cpu();
22518 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22519 + return;
22520 + }
22521 +
22522 + /* check the exception stacks */
22523 + used = 0;
22524 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22525 + stack_start = stack_end - EXCEPTION_STKSZ;
22526 + if (stack_end && stack_start <= sp && sp < stack_end) {
22527 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22528 + put_cpu();
22529 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22530 + return;
22531 + }
22532 +
22533 + put_cpu();
22534 +
22535 + /* unknown stack */
22536 + BUG();
22537 +}
22538 +EXPORT_SYMBOL(pax_check_alloca);
22539 +#endif
22540 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22541 index 988c00a..4f673b6 100644
22542 --- a/arch/x86/kernel/e820.c
22543 +++ b/arch/x86/kernel/e820.c
22544 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22545
22546 static void early_panic(char *msg)
22547 {
22548 - early_printk(msg);
22549 - panic(msg);
22550 + early_printk("%s", msg);
22551 + panic("%s", msg);
22552 }
22553
22554 static int userdef __initdata;
22555 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22556 index 01d1c18..8073693 100644
22557 --- a/arch/x86/kernel/early_printk.c
22558 +++ b/arch/x86/kernel/early_printk.c
22559 @@ -7,6 +7,7 @@
22560 #include <linux/pci_regs.h>
22561 #include <linux/pci_ids.h>
22562 #include <linux/errno.h>
22563 +#include <linux/sched.h>
22564 #include <asm/io.h>
22565 #include <asm/processor.h>
22566 #include <asm/fcntl.h>
22567 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22568 index 4b0e1df..884b67e 100644
22569 --- a/arch/x86/kernel/entry_32.S
22570 +++ b/arch/x86/kernel/entry_32.S
22571 @@ -177,13 +177,153 @@
22572 /*CFI_REL_OFFSET gs, PT_GS*/
22573 .endm
22574 .macro SET_KERNEL_GS reg
22575 +
22576 +#ifdef CONFIG_CC_STACKPROTECTOR
22577 movl $(__KERNEL_STACK_CANARY), \reg
22578 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22579 + movl $(__USER_DS), \reg
22580 +#else
22581 + xorl \reg, \reg
22582 +#endif
22583 +
22584 movl \reg, %gs
22585 .endm
22586
22587 #endif /* CONFIG_X86_32_LAZY_GS */
22588
22589 -.macro SAVE_ALL
22590 +.macro pax_enter_kernel
22591 +#ifdef CONFIG_PAX_KERNEXEC
22592 + call pax_enter_kernel
22593 +#endif
22594 +.endm
22595 +
22596 +.macro pax_exit_kernel
22597 +#ifdef CONFIG_PAX_KERNEXEC
22598 + call pax_exit_kernel
22599 +#endif
22600 +.endm
22601 +
22602 +#ifdef CONFIG_PAX_KERNEXEC
22603 +ENTRY(pax_enter_kernel)
22604 +#ifdef CONFIG_PARAVIRT
22605 + pushl %eax
22606 + pushl %ecx
22607 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22608 + mov %eax, %esi
22609 +#else
22610 + mov %cr0, %esi
22611 +#endif
22612 + bts $16, %esi
22613 + jnc 1f
22614 + mov %cs, %esi
22615 + cmp $__KERNEL_CS, %esi
22616 + jz 3f
22617 + ljmp $__KERNEL_CS, $3f
22618 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22619 +2:
22620 +#ifdef CONFIG_PARAVIRT
22621 + mov %esi, %eax
22622 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22623 +#else
22624 + mov %esi, %cr0
22625 +#endif
22626 +3:
22627 +#ifdef CONFIG_PARAVIRT
22628 + popl %ecx
22629 + popl %eax
22630 +#endif
22631 + ret
22632 +ENDPROC(pax_enter_kernel)
22633 +
22634 +ENTRY(pax_exit_kernel)
22635 +#ifdef CONFIG_PARAVIRT
22636 + pushl %eax
22637 + pushl %ecx
22638 +#endif
22639 + mov %cs, %esi
22640 + cmp $__KERNEXEC_KERNEL_CS, %esi
22641 + jnz 2f
22642 +#ifdef CONFIG_PARAVIRT
22643 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22644 + mov %eax, %esi
22645 +#else
22646 + mov %cr0, %esi
22647 +#endif
22648 + btr $16, %esi
22649 + ljmp $__KERNEL_CS, $1f
22650 +1:
22651 +#ifdef CONFIG_PARAVIRT
22652 + mov %esi, %eax
22653 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22654 +#else
22655 + mov %esi, %cr0
22656 +#endif
22657 +2:
22658 +#ifdef CONFIG_PARAVIRT
22659 + popl %ecx
22660 + popl %eax
22661 +#endif
22662 + ret
22663 +ENDPROC(pax_exit_kernel)
22664 +#endif
22665 +
22666 + .macro pax_erase_kstack
22667 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22668 + call pax_erase_kstack
22669 +#endif
22670 + .endm
22671 +
22672 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22673 +/*
22674 + * ebp: thread_info
22675 + */
22676 +ENTRY(pax_erase_kstack)
22677 + pushl %edi
22678 + pushl %ecx
22679 + pushl %eax
22680 +
22681 + mov TI_lowest_stack(%ebp), %edi
22682 + mov $-0xBEEF, %eax
22683 + std
22684 +
22685 +1: mov %edi, %ecx
22686 + and $THREAD_SIZE_asm - 1, %ecx
22687 + shr $2, %ecx
22688 + repne scasl
22689 + jecxz 2f
22690 +
22691 + cmp $2*16, %ecx
22692 + jc 2f
22693 +
22694 + mov $2*16, %ecx
22695 + repe scasl
22696 + jecxz 2f
22697 + jne 1b
22698 +
22699 +2: cld
22700 + mov %esp, %ecx
22701 + sub %edi, %ecx
22702 +
22703 + cmp $THREAD_SIZE_asm, %ecx
22704 + jb 3f
22705 + ud2
22706 +3:
22707 +
22708 + shr $2, %ecx
22709 + rep stosl
22710 +
22711 + mov TI_task_thread_sp0(%ebp), %edi
22712 + sub $128, %edi
22713 + mov %edi, TI_lowest_stack(%ebp)
22714 +
22715 + popl %eax
22716 + popl %ecx
22717 + popl %edi
22718 + ret
22719 +ENDPROC(pax_erase_kstack)
22720 +#endif
22721 +
22722 +.macro __SAVE_ALL _DS
22723 cld
22724 PUSH_GS
22725 pushl_cfi %fs
22726 @@ -206,7 +346,7 @@
22727 CFI_REL_OFFSET ecx, 0
22728 pushl_cfi %ebx
22729 CFI_REL_OFFSET ebx, 0
22730 - movl $(__USER_DS), %edx
22731 + movl $\_DS, %edx
22732 movl %edx, %ds
22733 movl %edx, %es
22734 movl $(__KERNEL_PERCPU), %edx
22735 @@ -214,6 +354,15 @@
22736 SET_KERNEL_GS %edx
22737 .endm
22738
22739 +.macro SAVE_ALL
22740 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22741 + __SAVE_ALL __KERNEL_DS
22742 + pax_enter_kernel
22743 +#else
22744 + __SAVE_ALL __USER_DS
22745 +#endif
22746 +.endm
22747 +
22748 .macro RESTORE_INT_REGS
22749 popl_cfi %ebx
22750 CFI_RESTORE ebx
22751 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22752 popfl_cfi
22753 jmp syscall_exit
22754 CFI_ENDPROC
22755 -END(ret_from_fork)
22756 +ENDPROC(ret_from_fork)
22757
22758 ENTRY(ret_from_kernel_thread)
22759 CFI_STARTPROC
22760 @@ -340,7 +489,15 @@ ret_from_intr:
22761 andl $SEGMENT_RPL_MASK, %eax
22762 #endif
22763 cmpl $USER_RPL, %eax
22764 +
22765 +#ifdef CONFIG_PAX_KERNEXEC
22766 + jae resume_userspace
22767 +
22768 + pax_exit_kernel
22769 + jmp resume_kernel
22770 +#else
22771 jb resume_kernel # not returning to v8086 or userspace
22772 +#endif
22773
22774 ENTRY(resume_userspace)
22775 LOCKDEP_SYS_EXIT
22776 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22777 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22778 # int/exception return?
22779 jne work_pending
22780 - jmp restore_all
22781 -END(ret_from_exception)
22782 + jmp restore_all_pax
22783 +ENDPROC(ret_from_exception)
22784
22785 #ifdef CONFIG_PREEMPT
22786 ENTRY(resume_kernel)
22787 @@ -365,7 +522,7 @@ need_resched:
22788 jz restore_all
22789 call preempt_schedule_irq
22790 jmp need_resched
22791 -END(resume_kernel)
22792 +ENDPROC(resume_kernel)
22793 #endif
22794 CFI_ENDPROC
22795
22796 @@ -395,30 +552,45 @@ sysenter_past_esp:
22797 /*CFI_REL_OFFSET cs, 0*/
22798 /*
22799 * Push current_thread_info()->sysenter_return to the stack.
22800 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22801 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22802 */
22803 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22804 + pushl_cfi $0
22805 CFI_REL_OFFSET eip, 0
22806
22807 pushl_cfi %eax
22808 SAVE_ALL
22809 + GET_THREAD_INFO(%ebp)
22810 + movl TI_sysenter_return(%ebp),%ebp
22811 + movl %ebp,PT_EIP(%esp)
22812 ENABLE_INTERRUPTS(CLBR_NONE)
22813
22814 /*
22815 * Load the potential sixth argument from user stack.
22816 * Careful about security.
22817 */
22818 + movl PT_OLDESP(%esp),%ebp
22819 +
22820 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22821 + mov PT_OLDSS(%esp),%ds
22822 +1: movl %ds:(%ebp),%ebp
22823 + push %ss
22824 + pop %ds
22825 +#else
22826 cmpl $__PAGE_OFFSET-3,%ebp
22827 jae syscall_fault
22828 ASM_STAC
22829 1: movl (%ebp),%ebp
22830 ASM_CLAC
22831 +#endif
22832 +
22833 movl %ebp,PT_EBP(%esp)
22834 _ASM_EXTABLE(1b,syscall_fault)
22835
22836 GET_THREAD_INFO(%ebp)
22837
22838 +#ifdef CONFIG_PAX_RANDKSTACK
22839 + pax_erase_kstack
22840 +#endif
22841 +
22842 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22843 jnz sysenter_audit
22844 sysenter_do_call:
22845 @@ -434,12 +606,24 @@ sysenter_after_call:
22846 testl $_TIF_ALLWORK_MASK, %ecx
22847 jne sysexit_audit
22848 sysenter_exit:
22849 +
22850 +#ifdef CONFIG_PAX_RANDKSTACK
22851 + pushl_cfi %eax
22852 + movl %esp, %eax
22853 + call pax_randomize_kstack
22854 + popl_cfi %eax
22855 +#endif
22856 +
22857 + pax_erase_kstack
22858 +
22859 /* if something modifies registers it must also disable sysexit */
22860 movl PT_EIP(%esp), %edx
22861 movl PT_OLDESP(%esp), %ecx
22862 xorl %ebp,%ebp
22863 TRACE_IRQS_ON
22864 1: mov PT_FS(%esp), %fs
22865 +2: mov PT_DS(%esp), %ds
22866 +3: mov PT_ES(%esp), %es
22867 PTGS_TO_GS
22868 ENABLE_INTERRUPTS_SYSEXIT
22869
22870 @@ -456,6 +640,9 @@ sysenter_audit:
22871 movl %eax,%edx /* 2nd arg: syscall number */
22872 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22873 call __audit_syscall_entry
22874 +
22875 + pax_erase_kstack
22876 +
22877 pushl_cfi %ebx
22878 movl PT_EAX(%esp),%eax /* reload syscall number */
22879 jmp sysenter_do_call
22880 @@ -481,10 +668,16 @@ sysexit_audit:
22881
22882 CFI_ENDPROC
22883 .pushsection .fixup,"ax"
22884 -2: movl $0,PT_FS(%esp)
22885 +4: movl $0,PT_FS(%esp)
22886 + jmp 1b
22887 +5: movl $0,PT_DS(%esp)
22888 + jmp 1b
22889 +6: movl $0,PT_ES(%esp)
22890 jmp 1b
22891 .popsection
22892 - _ASM_EXTABLE(1b,2b)
22893 + _ASM_EXTABLE(1b,4b)
22894 + _ASM_EXTABLE(2b,5b)
22895 + _ASM_EXTABLE(3b,6b)
22896 PTGS_TO_GS_EX
22897 ENDPROC(ia32_sysenter_target)
22898
22899 @@ -495,6 +688,11 @@ ENTRY(system_call)
22900 pushl_cfi %eax # save orig_eax
22901 SAVE_ALL
22902 GET_THREAD_INFO(%ebp)
22903 +
22904 +#ifdef CONFIG_PAX_RANDKSTACK
22905 + pax_erase_kstack
22906 +#endif
22907 +
22908 # system call tracing in operation / emulation
22909 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22910 jnz syscall_trace_entry
22911 @@ -514,6 +712,15 @@ syscall_exit:
22912 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22913 jne syscall_exit_work
22914
22915 +restore_all_pax:
22916 +
22917 +#ifdef CONFIG_PAX_RANDKSTACK
22918 + movl %esp, %eax
22919 + call pax_randomize_kstack
22920 +#endif
22921 +
22922 + pax_erase_kstack
22923 +
22924 restore_all:
22925 TRACE_IRQS_IRET
22926 restore_all_notrace:
22927 @@ -568,14 +775,34 @@ ldt_ss:
22928 * compensating for the offset by changing to the ESPFIX segment with
22929 * a base address that matches for the difference.
22930 */
22931 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22932 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22933 mov %esp, %edx /* load kernel esp */
22934 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22935 mov %dx, %ax /* eax: new kernel esp */
22936 sub %eax, %edx /* offset (low word is 0) */
22937 +#ifdef CONFIG_SMP
22938 + movl PER_CPU_VAR(cpu_number), %ebx
22939 + shll $PAGE_SHIFT_asm, %ebx
22940 + addl $cpu_gdt_table, %ebx
22941 +#else
22942 + movl $cpu_gdt_table, %ebx
22943 +#endif
22944 shr $16, %edx
22945 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22946 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22947 +
22948 +#ifdef CONFIG_PAX_KERNEXEC
22949 + mov %cr0, %esi
22950 + btr $16, %esi
22951 + mov %esi, %cr0
22952 +#endif
22953 +
22954 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22955 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22956 +
22957 +#ifdef CONFIG_PAX_KERNEXEC
22958 + bts $16, %esi
22959 + mov %esi, %cr0
22960 +#endif
22961 +
22962 pushl_cfi $__ESPFIX_SS
22963 pushl_cfi %eax /* new kernel esp */
22964 /* Disable interrupts, but do not irqtrace this section: we
22965 @@ -605,20 +832,18 @@ work_resched:
22966 movl TI_flags(%ebp), %ecx
22967 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22968 # than syscall tracing?
22969 - jz restore_all
22970 + jz restore_all_pax
22971 testb $_TIF_NEED_RESCHED, %cl
22972 jnz work_resched
22973
22974 work_notifysig: # deal with pending signals and
22975 # notify-resume requests
22976 + movl %esp, %eax
22977 #ifdef CONFIG_VM86
22978 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22979 - movl %esp, %eax
22980 jne work_notifysig_v86 # returning to kernel-space or
22981 # vm86-space
22982 1:
22983 -#else
22984 - movl %esp, %eax
22985 #endif
22986 TRACE_IRQS_ON
22987 ENABLE_INTERRUPTS(CLBR_NONE)
22988 @@ -639,7 +864,7 @@ work_notifysig_v86:
22989 movl %eax, %esp
22990 jmp 1b
22991 #endif
22992 -END(work_pending)
22993 +ENDPROC(work_pending)
22994
22995 # perform syscall exit tracing
22996 ALIGN
22997 @@ -647,11 +872,14 @@ syscall_trace_entry:
22998 movl $-ENOSYS,PT_EAX(%esp)
22999 movl %esp, %eax
23000 call syscall_trace_enter
23001 +
23002 + pax_erase_kstack
23003 +
23004 /* What it returned is what we'll actually use. */
23005 cmpl $(NR_syscalls), %eax
23006 jnae syscall_call
23007 jmp syscall_exit
23008 -END(syscall_trace_entry)
23009 +ENDPROC(syscall_trace_entry)
23010
23011 # perform syscall exit tracing
23012 ALIGN
23013 @@ -664,26 +892,30 @@ syscall_exit_work:
23014 movl %esp, %eax
23015 call syscall_trace_leave
23016 jmp resume_userspace
23017 -END(syscall_exit_work)
23018 +ENDPROC(syscall_exit_work)
23019 CFI_ENDPROC
23020
23021 RING0_INT_FRAME # can't unwind into user space anyway
23022 syscall_fault:
23023 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23024 + push %ss
23025 + pop %ds
23026 +#endif
23027 ASM_CLAC
23028 GET_THREAD_INFO(%ebp)
23029 movl $-EFAULT,PT_EAX(%esp)
23030 jmp resume_userspace
23031 -END(syscall_fault)
23032 +ENDPROC(syscall_fault)
23033
23034 syscall_badsys:
23035 movl $-ENOSYS,%eax
23036 jmp syscall_after_call
23037 -END(syscall_badsys)
23038 +ENDPROC(syscall_badsys)
23039
23040 sysenter_badsys:
23041 movl $-ENOSYS,%eax
23042 jmp sysenter_after_call
23043 -END(sysenter_badsys)
23044 +ENDPROC(sysenter_badsys)
23045 CFI_ENDPROC
23046
23047 .macro FIXUP_ESPFIX_STACK
23048 @@ -696,8 +928,15 @@ END(sysenter_badsys)
23049 */
23050 #ifdef CONFIG_X86_ESPFIX32
23051 /* fixup the stack */
23052 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23053 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23054 +#ifdef CONFIG_SMP
23055 + movl PER_CPU_VAR(cpu_number), %ebx
23056 + shll $PAGE_SHIFT_asm, %ebx
23057 + addl $cpu_gdt_table, %ebx
23058 +#else
23059 + movl $cpu_gdt_table, %ebx
23060 +#endif
23061 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23062 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23063 shl $16, %eax
23064 addl %esp, %eax /* the adjusted stack pointer */
23065 pushl_cfi $__KERNEL_DS
23066 @@ -753,7 +992,7 @@ vector=vector+1
23067 .endr
23068 2: jmp common_interrupt
23069 .endr
23070 -END(irq_entries_start)
23071 +ENDPROC(irq_entries_start)
23072
23073 .previous
23074 END(interrupt)
23075 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23076 pushl_cfi $do_coprocessor_error
23077 jmp error_code
23078 CFI_ENDPROC
23079 -END(coprocessor_error)
23080 +ENDPROC(coprocessor_error)
23081
23082 ENTRY(simd_coprocessor_error)
23083 RING0_INT_FRAME
23084 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23085 .section .altinstructions,"a"
23086 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23087 .previous
23088 -.section .altinstr_replacement,"ax"
23089 +.section .altinstr_replacement,"a"
23090 663: pushl $do_simd_coprocessor_error
23091 664:
23092 .previous
23093 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23094 #endif
23095 jmp error_code
23096 CFI_ENDPROC
23097 -END(simd_coprocessor_error)
23098 +ENDPROC(simd_coprocessor_error)
23099
23100 ENTRY(device_not_available)
23101 RING0_INT_FRAME
23102 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23103 pushl_cfi $do_device_not_available
23104 jmp error_code
23105 CFI_ENDPROC
23106 -END(device_not_available)
23107 +ENDPROC(device_not_available)
23108
23109 #ifdef CONFIG_PARAVIRT
23110 ENTRY(native_iret)
23111 iret
23112 _ASM_EXTABLE(native_iret, iret_exc)
23113 -END(native_iret)
23114 +ENDPROC(native_iret)
23115
23116 ENTRY(native_irq_enable_sysexit)
23117 sti
23118 sysexit
23119 -END(native_irq_enable_sysexit)
23120 +ENDPROC(native_irq_enable_sysexit)
23121 #endif
23122
23123 ENTRY(overflow)
23124 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23125 pushl_cfi $do_overflow
23126 jmp error_code
23127 CFI_ENDPROC
23128 -END(overflow)
23129 +ENDPROC(overflow)
23130
23131 ENTRY(bounds)
23132 RING0_INT_FRAME
23133 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23134 pushl_cfi $do_bounds
23135 jmp error_code
23136 CFI_ENDPROC
23137 -END(bounds)
23138 +ENDPROC(bounds)
23139
23140 ENTRY(invalid_op)
23141 RING0_INT_FRAME
23142 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23143 pushl_cfi $do_invalid_op
23144 jmp error_code
23145 CFI_ENDPROC
23146 -END(invalid_op)
23147 +ENDPROC(invalid_op)
23148
23149 ENTRY(coprocessor_segment_overrun)
23150 RING0_INT_FRAME
23151 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23152 pushl_cfi $do_coprocessor_segment_overrun
23153 jmp error_code
23154 CFI_ENDPROC
23155 -END(coprocessor_segment_overrun)
23156 +ENDPROC(coprocessor_segment_overrun)
23157
23158 ENTRY(invalid_TSS)
23159 RING0_EC_FRAME
23160 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23161 pushl_cfi $do_invalid_TSS
23162 jmp error_code
23163 CFI_ENDPROC
23164 -END(invalid_TSS)
23165 +ENDPROC(invalid_TSS)
23166
23167 ENTRY(segment_not_present)
23168 RING0_EC_FRAME
23169 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23170 pushl_cfi $do_segment_not_present
23171 jmp error_code
23172 CFI_ENDPROC
23173 -END(segment_not_present)
23174 +ENDPROC(segment_not_present)
23175
23176 ENTRY(stack_segment)
23177 RING0_EC_FRAME
23178 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23179 pushl_cfi $do_stack_segment
23180 jmp error_code
23181 CFI_ENDPROC
23182 -END(stack_segment)
23183 +ENDPROC(stack_segment)
23184
23185 ENTRY(alignment_check)
23186 RING0_EC_FRAME
23187 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23188 pushl_cfi $do_alignment_check
23189 jmp error_code
23190 CFI_ENDPROC
23191 -END(alignment_check)
23192 +ENDPROC(alignment_check)
23193
23194 ENTRY(divide_error)
23195 RING0_INT_FRAME
23196 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23197 pushl_cfi $do_divide_error
23198 jmp error_code
23199 CFI_ENDPROC
23200 -END(divide_error)
23201 +ENDPROC(divide_error)
23202
23203 #ifdef CONFIG_X86_MCE
23204 ENTRY(machine_check)
23205 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23206 pushl_cfi machine_check_vector
23207 jmp error_code
23208 CFI_ENDPROC
23209 -END(machine_check)
23210 +ENDPROC(machine_check)
23211 #endif
23212
23213 ENTRY(spurious_interrupt_bug)
23214 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23215 pushl_cfi $do_spurious_interrupt_bug
23216 jmp error_code
23217 CFI_ENDPROC
23218 -END(spurious_interrupt_bug)
23219 +ENDPROC(spurious_interrupt_bug)
23220
23221 #ifdef CONFIG_XEN
23222 /* Xen doesn't set %esp to be precisely what the normal sysenter
23223 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23224
23225 ENTRY(mcount)
23226 ret
23227 -END(mcount)
23228 +ENDPROC(mcount)
23229
23230 ENTRY(ftrace_caller)
23231 pushl %eax
23232 @@ -1086,7 +1325,7 @@ ftrace_graph_call:
23233 .globl ftrace_stub
23234 ftrace_stub:
23235 ret
23236 -END(ftrace_caller)
23237 +ENDPROC(ftrace_caller)
23238
23239 ENTRY(ftrace_regs_caller)
23240 pushf /* push flags before compare (in cs location) */
23241 @@ -1184,7 +1423,7 @@ trace:
23242 popl %ecx
23243 popl %eax
23244 jmp ftrace_stub
23245 -END(mcount)
23246 +ENDPROC(mcount)
23247 #endif /* CONFIG_DYNAMIC_FTRACE */
23248 #endif /* CONFIG_FUNCTION_TRACER */
23249
23250 @@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23251 popl %ecx
23252 popl %eax
23253 ret
23254 -END(ftrace_graph_caller)
23255 +ENDPROC(ftrace_graph_caller)
23256
23257 .globl return_to_handler
23258 return_to_handler:
23259 @@ -1263,15 +1502,18 @@ error_code:
23260 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23261 REG_TO_PTGS %ecx
23262 SET_KERNEL_GS %ecx
23263 - movl $(__USER_DS), %ecx
23264 + movl $(__KERNEL_DS), %ecx
23265 movl %ecx, %ds
23266 movl %ecx, %es
23267 +
23268 + pax_enter_kernel
23269 +
23270 TRACE_IRQS_OFF
23271 movl %esp,%eax # pt_regs pointer
23272 call *%edi
23273 jmp ret_from_exception
23274 CFI_ENDPROC
23275 -END(page_fault)
23276 +ENDPROC(page_fault)
23277
23278 /*
23279 * Debug traps and NMI can happen at the one SYSENTER instruction
23280 @@ -1314,7 +1556,7 @@ debug_stack_correct:
23281 call do_debug
23282 jmp ret_from_exception
23283 CFI_ENDPROC
23284 -END(debug)
23285 +ENDPROC(debug)
23286
23287 /*
23288 * NMI is doubly nasty. It can happen _while_ we're handling
23289 @@ -1354,6 +1596,9 @@ nmi_stack_correct:
23290 xorl %edx,%edx # zero error code
23291 movl %esp,%eax # pt_regs pointer
23292 call do_nmi
23293 +
23294 + pax_exit_kernel
23295 +
23296 jmp restore_all_notrace
23297 CFI_ENDPROC
23298
23299 @@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23300 FIXUP_ESPFIX_STACK # %eax == %esp
23301 xorl %edx,%edx # zero error code
23302 call do_nmi
23303 +
23304 + pax_exit_kernel
23305 +
23306 RESTORE_REGS
23307 lss 12+4(%esp), %esp # back to espfix stack
23308 CFI_ADJUST_CFA_OFFSET -24
23309 jmp irq_return
23310 #endif
23311 CFI_ENDPROC
23312 -END(nmi)
23313 +ENDPROC(nmi)
23314
23315 ENTRY(int3)
23316 RING0_INT_FRAME
23317 @@ -1410,14 +1658,14 @@ ENTRY(int3)
23318 call do_int3
23319 jmp ret_from_exception
23320 CFI_ENDPROC
23321 -END(int3)
23322 +ENDPROC(int3)
23323
23324 ENTRY(general_protection)
23325 RING0_EC_FRAME
23326 pushl_cfi $do_general_protection
23327 jmp error_code
23328 CFI_ENDPROC
23329 -END(general_protection)
23330 +ENDPROC(general_protection)
23331
23332 #ifdef CONFIG_KVM_GUEST
23333 ENTRY(async_page_fault)
23334 @@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23335 pushl_cfi $do_async_page_fault
23336 jmp error_code
23337 CFI_ENDPROC
23338 -END(async_page_fault)
23339 +ENDPROC(async_page_fault)
23340 #endif
23341
23342 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23343 index 2fac134..b020fca 100644
23344 --- a/arch/x86/kernel/entry_64.S
23345 +++ b/arch/x86/kernel/entry_64.S
23346 @@ -59,6 +59,8 @@
23347 #include <asm/smap.h>
23348 #include <asm/pgtable_types.h>
23349 #include <linux/err.h>
23350 +#include <asm/pgtable.h>
23351 +#include <asm/alternative-asm.h>
23352
23353 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23354 #include <linux/elf-em.h>
23355 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23356 ENDPROC(native_usergs_sysret64)
23357 #endif /* CONFIG_PARAVIRT */
23358
23359 + .macro ljmpq sel, off
23360 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23361 + .byte 0x48; ljmp *1234f(%rip)
23362 + .pushsection .rodata
23363 + .align 16
23364 + 1234: .quad \off; .word \sel
23365 + .popsection
23366 +#else
23367 + pushq $\sel
23368 + pushq $\off
23369 + lretq
23370 +#endif
23371 + .endm
23372 +
23373 + .macro pax_enter_kernel
23374 + pax_set_fptr_mask
23375 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23376 + call pax_enter_kernel
23377 +#endif
23378 + .endm
23379 +
23380 + .macro pax_exit_kernel
23381 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23382 + call pax_exit_kernel
23383 +#endif
23384 +
23385 + .endm
23386 +
23387 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23388 +ENTRY(pax_enter_kernel)
23389 + pushq %rdi
23390 +
23391 +#ifdef CONFIG_PARAVIRT
23392 + PV_SAVE_REGS(CLBR_RDI)
23393 +#endif
23394 +
23395 +#ifdef CONFIG_PAX_KERNEXEC
23396 + GET_CR0_INTO_RDI
23397 + bts $16,%rdi
23398 + jnc 3f
23399 + mov %cs,%edi
23400 + cmp $__KERNEL_CS,%edi
23401 + jnz 2f
23402 +1:
23403 +#endif
23404 +
23405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23406 + 661: jmp 111f
23407 + .pushsection .altinstr_replacement, "a"
23408 + 662: ASM_NOP2
23409 + .popsection
23410 + .pushsection .altinstructions, "a"
23411 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23412 + .popsection
23413 + GET_CR3_INTO_RDI
23414 + cmp $0,%dil
23415 + jnz 112f
23416 + mov $__KERNEL_DS,%edi
23417 + mov %edi,%ss
23418 + jmp 111f
23419 +112: cmp $1,%dil
23420 + jz 113f
23421 + ud2
23422 +113: sub $4097,%rdi
23423 + bts $63,%rdi
23424 + SET_RDI_INTO_CR3
23425 + mov $__UDEREF_KERNEL_DS,%edi
23426 + mov %edi,%ss
23427 +111:
23428 +#endif
23429 +
23430 +#ifdef CONFIG_PARAVIRT
23431 + PV_RESTORE_REGS(CLBR_RDI)
23432 +#endif
23433 +
23434 + popq %rdi
23435 + pax_force_retaddr
23436 + retq
23437 +
23438 +#ifdef CONFIG_PAX_KERNEXEC
23439 +2: ljmpq __KERNEL_CS,1b
23440 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23441 +4: SET_RDI_INTO_CR0
23442 + jmp 1b
23443 +#endif
23444 +ENDPROC(pax_enter_kernel)
23445 +
23446 +ENTRY(pax_exit_kernel)
23447 + pushq %rdi
23448 +
23449 +#ifdef CONFIG_PARAVIRT
23450 + PV_SAVE_REGS(CLBR_RDI)
23451 +#endif
23452 +
23453 +#ifdef CONFIG_PAX_KERNEXEC
23454 + mov %cs,%rdi
23455 + cmp $__KERNEXEC_KERNEL_CS,%edi
23456 + jz 2f
23457 + GET_CR0_INTO_RDI
23458 + bts $16,%rdi
23459 + jnc 4f
23460 +1:
23461 +#endif
23462 +
23463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23464 + 661: jmp 111f
23465 + .pushsection .altinstr_replacement, "a"
23466 + 662: ASM_NOP2
23467 + .popsection
23468 + .pushsection .altinstructions, "a"
23469 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23470 + .popsection
23471 + mov %ss,%edi
23472 + cmp $__UDEREF_KERNEL_DS,%edi
23473 + jnz 111f
23474 + GET_CR3_INTO_RDI
23475 + cmp $0,%dil
23476 + jz 112f
23477 + ud2
23478 +112: add $4097,%rdi
23479 + bts $63,%rdi
23480 + SET_RDI_INTO_CR3
23481 + mov $__KERNEL_DS,%edi
23482 + mov %edi,%ss
23483 +111:
23484 +#endif
23485 +
23486 +#ifdef CONFIG_PARAVIRT
23487 + PV_RESTORE_REGS(CLBR_RDI);
23488 +#endif
23489 +
23490 + popq %rdi
23491 + pax_force_retaddr
23492 + retq
23493 +
23494 +#ifdef CONFIG_PAX_KERNEXEC
23495 +2: GET_CR0_INTO_RDI
23496 + btr $16,%rdi
23497 + jnc 4f
23498 + ljmpq __KERNEL_CS,3f
23499 +3: SET_RDI_INTO_CR0
23500 + jmp 1b
23501 +4: ud2
23502 + jmp 4b
23503 +#endif
23504 +ENDPROC(pax_exit_kernel)
23505 +#endif
23506 +
23507 + .macro pax_enter_kernel_user
23508 + pax_set_fptr_mask
23509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23510 + call pax_enter_kernel_user
23511 +#endif
23512 + .endm
23513 +
23514 + .macro pax_exit_kernel_user
23515 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23516 + call pax_exit_kernel_user
23517 +#endif
23518 +#ifdef CONFIG_PAX_RANDKSTACK
23519 + pushq %rax
23520 + pushq %r11
23521 + call pax_randomize_kstack
23522 + popq %r11
23523 + popq %rax
23524 +#endif
23525 + .endm
23526 +
23527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23528 +ENTRY(pax_enter_kernel_user)
23529 + pushq %rdi
23530 + pushq %rbx
23531 +
23532 +#ifdef CONFIG_PARAVIRT
23533 + PV_SAVE_REGS(CLBR_RDI)
23534 +#endif
23535 +
23536 + 661: jmp 111f
23537 + .pushsection .altinstr_replacement, "a"
23538 + 662: ASM_NOP2
23539 + .popsection
23540 + .pushsection .altinstructions, "a"
23541 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23542 + .popsection
23543 + GET_CR3_INTO_RDI
23544 + cmp $1,%dil
23545 + jnz 4f
23546 + sub $4097,%rdi
23547 + bts $63,%rdi
23548 + SET_RDI_INTO_CR3
23549 + jmp 3f
23550 +111:
23551 +
23552 + GET_CR3_INTO_RDI
23553 + mov %rdi,%rbx
23554 + add $__START_KERNEL_map,%rbx
23555 + sub phys_base(%rip),%rbx
23556 +
23557 +#ifdef CONFIG_PARAVIRT
23558 + cmpl $0, pv_info+PARAVIRT_enabled
23559 + jz 1f
23560 + pushq %rdi
23561 + i = 0
23562 + .rept USER_PGD_PTRS
23563 + mov i*8(%rbx),%rsi
23564 + mov $0,%sil
23565 + lea i*8(%rbx),%rdi
23566 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23567 + i = i + 1
23568 + .endr
23569 + popq %rdi
23570 + jmp 2f
23571 +1:
23572 +#endif
23573 +
23574 + i = 0
23575 + .rept USER_PGD_PTRS
23576 + movb $0,i*8(%rbx)
23577 + i = i + 1
23578 + .endr
23579 +
23580 +2: SET_RDI_INTO_CR3
23581 +
23582 +#ifdef CONFIG_PAX_KERNEXEC
23583 + GET_CR0_INTO_RDI
23584 + bts $16,%rdi
23585 + SET_RDI_INTO_CR0
23586 +#endif
23587 +
23588 +3:
23589 +
23590 +#ifdef CONFIG_PARAVIRT
23591 + PV_RESTORE_REGS(CLBR_RDI)
23592 +#endif
23593 +
23594 + popq %rbx
23595 + popq %rdi
23596 + pax_force_retaddr
23597 + retq
23598 +4: ud2
23599 +ENDPROC(pax_enter_kernel_user)
23600 +
23601 +ENTRY(pax_exit_kernel_user)
23602 + pushq %rdi
23603 + pushq %rbx
23604 +
23605 +#ifdef CONFIG_PARAVIRT
23606 + PV_SAVE_REGS(CLBR_RDI)
23607 +#endif
23608 +
23609 + GET_CR3_INTO_RDI
23610 + 661: jmp 1f
23611 + .pushsection .altinstr_replacement, "a"
23612 + 662: ASM_NOP2
23613 + .popsection
23614 + .pushsection .altinstructions, "a"
23615 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23616 + .popsection
23617 + cmp $0,%dil
23618 + jnz 3f
23619 + add $4097,%rdi
23620 + bts $63,%rdi
23621 + SET_RDI_INTO_CR3
23622 + jmp 2f
23623 +1:
23624 +
23625 + mov %rdi,%rbx
23626 +
23627 +#ifdef CONFIG_PAX_KERNEXEC
23628 + GET_CR0_INTO_RDI
23629 + btr $16,%rdi
23630 + jnc 3f
23631 + SET_RDI_INTO_CR0
23632 +#endif
23633 +
23634 + add $__START_KERNEL_map,%rbx
23635 + sub phys_base(%rip),%rbx
23636 +
23637 +#ifdef CONFIG_PARAVIRT
23638 + cmpl $0, pv_info+PARAVIRT_enabled
23639 + jz 1f
23640 + i = 0
23641 + .rept USER_PGD_PTRS
23642 + mov i*8(%rbx),%rsi
23643 + mov $0x67,%sil
23644 + lea i*8(%rbx),%rdi
23645 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23646 + i = i + 1
23647 + .endr
23648 + jmp 2f
23649 +1:
23650 +#endif
23651 +
23652 + i = 0
23653 + .rept USER_PGD_PTRS
23654 + movb $0x67,i*8(%rbx)
23655 + i = i + 1
23656 + .endr
23657 +2:
23658 +
23659 +#ifdef CONFIG_PARAVIRT
23660 + PV_RESTORE_REGS(CLBR_RDI)
23661 +#endif
23662 +
23663 + popq %rbx
23664 + popq %rdi
23665 + pax_force_retaddr
23666 + retq
23667 +3: ud2
23668 +ENDPROC(pax_exit_kernel_user)
23669 +#endif
23670 +
23671 + .macro pax_enter_kernel_nmi
23672 + pax_set_fptr_mask
23673 +
23674 +#ifdef CONFIG_PAX_KERNEXEC
23675 + GET_CR0_INTO_RDI
23676 + bts $16,%rdi
23677 + jc 110f
23678 + SET_RDI_INTO_CR0
23679 + or $2,%ebx
23680 +110:
23681 +#endif
23682 +
23683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23684 + 661: jmp 111f
23685 + .pushsection .altinstr_replacement, "a"
23686 + 662: ASM_NOP2
23687 + .popsection
23688 + .pushsection .altinstructions, "a"
23689 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23690 + .popsection
23691 + GET_CR3_INTO_RDI
23692 + cmp $0,%dil
23693 + jz 111f
23694 + sub $4097,%rdi
23695 + or $4,%ebx
23696 + bts $63,%rdi
23697 + SET_RDI_INTO_CR3
23698 + mov $__UDEREF_KERNEL_DS,%edi
23699 + mov %edi,%ss
23700 +111:
23701 +#endif
23702 + .endm
23703 +
23704 + .macro pax_exit_kernel_nmi
23705 +#ifdef CONFIG_PAX_KERNEXEC
23706 + btr $1,%ebx
23707 + jnc 110f
23708 + GET_CR0_INTO_RDI
23709 + btr $16,%rdi
23710 + SET_RDI_INTO_CR0
23711 +110:
23712 +#endif
23713 +
23714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23715 + btr $2,%ebx
23716 + jnc 111f
23717 + GET_CR3_INTO_RDI
23718 + add $4097,%rdi
23719 + bts $63,%rdi
23720 + SET_RDI_INTO_CR3
23721 + mov $__KERNEL_DS,%edi
23722 + mov %edi,%ss
23723 +111:
23724 +#endif
23725 + .endm
23726 +
23727 + .macro pax_erase_kstack
23728 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23729 + call pax_erase_kstack
23730 +#endif
23731 + .endm
23732 +
23733 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23734 +ENTRY(pax_erase_kstack)
23735 + pushq %rdi
23736 + pushq %rcx
23737 + pushq %rax
23738 + pushq %r11
23739 +
23740 + GET_THREAD_INFO(%r11)
23741 + mov TI_lowest_stack(%r11), %rdi
23742 + mov $-0xBEEF, %rax
23743 + std
23744 +
23745 +1: mov %edi, %ecx
23746 + and $THREAD_SIZE_asm - 1, %ecx
23747 + shr $3, %ecx
23748 + repne scasq
23749 + jecxz 2f
23750 +
23751 + cmp $2*8, %ecx
23752 + jc 2f
23753 +
23754 + mov $2*8, %ecx
23755 + repe scasq
23756 + jecxz 2f
23757 + jne 1b
23758 +
23759 +2: cld
23760 + mov %esp, %ecx
23761 + sub %edi, %ecx
23762 +
23763 + cmp $THREAD_SIZE_asm, %rcx
23764 + jb 3f
23765 + ud2
23766 +3:
23767 +
23768 + shr $3, %ecx
23769 + rep stosq
23770 +
23771 + mov TI_task_thread_sp0(%r11), %rdi
23772 + sub $256, %rdi
23773 + mov %rdi, TI_lowest_stack(%r11)
23774 +
23775 + popq %r11
23776 + popq %rax
23777 + popq %rcx
23778 + popq %rdi
23779 + pax_force_retaddr
23780 + ret
23781 +ENDPROC(pax_erase_kstack)
23782 +#endif
23783
23784 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23785 #ifdef CONFIG_TRACE_IRQFLAGS
23786 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23787 .endm
23788
23789 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23790 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23791 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23792 jnc 1f
23793 TRACE_IRQS_ON_DEBUG
23794 1:
23795 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23796 movq \tmp,R11+\offset(%rsp)
23797 .endm
23798
23799 - .macro FAKE_STACK_FRAME child_rip
23800 - /* push in order ss, rsp, eflags, cs, rip */
23801 - xorl %eax, %eax
23802 - pushq_cfi $__KERNEL_DS /* ss */
23803 - /*CFI_REL_OFFSET ss,0*/
23804 - pushq_cfi %rax /* rsp */
23805 - CFI_REL_OFFSET rsp,0
23806 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23807 - /*CFI_REL_OFFSET rflags,0*/
23808 - pushq_cfi $__KERNEL_CS /* cs */
23809 - /*CFI_REL_OFFSET cs,0*/
23810 - pushq_cfi \child_rip /* rip */
23811 - CFI_REL_OFFSET rip,0
23812 - pushq_cfi %rax /* orig rax */
23813 - .endm
23814 -
23815 - .macro UNFAKE_STACK_FRAME
23816 - addq $8*6, %rsp
23817 - CFI_ADJUST_CFA_OFFSET -(6*8)
23818 - .endm
23819 -
23820 /*
23821 * initial frame state for interrupts (and exceptions without error code)
23822 */
23823 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
23824 /* save partial stack frame */
23825 .macro SAVE_ARGS_IRQ
23826 cld
23827 - /* start from rbp in pt_regs and jump over */
23828 - movq_cfi rdi, (RDI-RBP)
23829 - movq_cfi rsi, (RSI-RBP)
23830 - movq_cfi rdx, (RDX-RBP)
23831 - movq_cfi rcx, (RCX-RBP)
23832 - movq_cfi rax, (RAX-RBP)
23833 - movq_cfi r8, (R8-RBP)
23834 - movq_cfi r9, (R9-RBP)
23835 - movq_cfi r10, (R10-RBP)
23836 - movq_cfi r11, (R11-RBP)
23837 + /* start from r15 in pt_regs and jump over */
23838 + movq_cfi rdi, RDI
23839 + movq_cfi rsi, RSI
23840 + movq_cfi rdx, RDX
23841 + movq_cfi rcx, RCX
23842 + movq_cfi rax, RAX
23843 + movq_cfi r8, R8
23844 + movq_cfi r9, R9
23845 + movq_cfi r10, R10
23846 + movq_cfi r11, R11
23847 + movq_cfi r12, R12
23848
23849 /* Save rbp so that we can unwind from get_irq_regs() */
23850 - movq_cfi rbp, 0
23851 + movq_cfi rbp, RBP
23852
23853 /* Save previous stack value */
23854 movq %rsp, %rsi
23855
23856 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23857 - testl $3, CS-RBP(%rsi)
23858 + movq %rsp,%rdi /* arg1 for handler */
23859 + testb $3, CS(%rsi)
23860 je 1f
23861 SWAPGS
23862 /*
23863 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
23864 0x06 /* DW_OP_deref */, \
23865 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23866 0x22 /* DW_OP_plus */
23867 +
23868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23869 + testb $3, CS(%rdi)
23870 + jnz 1f
23871 + pax_enter_kernel
23872 + jmp 2f
23873 +1: pax_enter_kernel_user
23874 +2:
23875 +#else
23876 + pax_enter_kernel
23877 +#endif
23878 +
23879 /* We entered an interrupt context - irqs are off: */
23880 TRACE_IRQS_OFF
23881 .endm
23882 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
23883 js 1f /* negative -> in kernel */
23884 SWAPGS
23885 xorl %ebx,%ebx
23886 -1: ret
23887 +1:
23888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23889 + testb $3, CS+8(%rsp)
23890 + jnz 1f
23891 + pax_enter_kernel
23892 + jmp 2f
23893 +1: pax_enter_kernel_user
23894 +2:
23895 +#else
23896 + pax_enter_kernel
23897 +#endif
23898 + pax_force_retaddr
23899 + ret
23900 CFI_ENDPROC
23901 -END(save_paranoid)
23902 +ENDPROC(save_paranoid)
23903 +
23904 +ENTRY(save_paranoid_nmi)
23905 + XCPT_FRAME 1 RDI+8
23906 + cld
23907 + movq_cfi rdi, RDI+8
23908 + movq_cfi rsi, RSI+8
23909 + movq_cfi rdx, RDX+8
23910 + movq_cfi rcx, RCX+8
23911 + movq_cfi rax, RAX+8
23912 + movq_cfi r8, R8+8
23913 + movq_cfi r9, R9+8
23914 + movq_cfi r10, R10+8
23915 + movq_cfi r11, R11+8
23916 + movq_cfi rbx, RBX+8
23917 + movq_cfi rbp, RBP+8
23918 + movq_cfi r12, R12+8
23919 + movq_cfi r13, R13+8
23920 + movq_cfi r14, R14+8
23921 + movq_cfi r15, R15+8
23922 + movl $1,%ebx
23923 + movl $MSR_GS_BASE,%ecx
23924 + rdmsr
23925 + testl %edx,%edx
23926 + js 1f /* negative -> in kernel */
23927 + SWAPGS
23928 + xorl %ebx,%ebx
23929 +1: pax_enter_kernel_nmi
23930 + pax_force_retaddr
23931 + ret
23932 + CFI_ENDPROC
23933 +ENDPROC(save_paranoid_nmi)
23934
23935 /*
23936 * A newly forked process directly context switches into this address.
23937 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
23938
23939 RESTORE_REST
23940
23941 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23942 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23943 jz 1f
23944
23945 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23946 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
23947 jmp ret_from_sys_call # go to the SYSRET fastpath
23948
23949 1:
23950 - subq $REST_SKIP, %rsp # leave space for volatiles
23951 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23952 movq %rbp, %rdi
23953 call *%rbx
23954 movl $0, RAX(%rsp)
23955 RESTORE_REST
23956 jmp int_ret_from_sys_call
23957 CFI_ENDPROC
23958 -END(ret_from_fork)
23959 +ENDPROC(ret_from_fork)
23960
23961 /*
23962 * System call entry. Up to 6 arguments in registers are supported.
23963 @@ -386,7 +845,7 @@ END(ret_from_fork)
23964 ENTRY(system_call)
23965 CFI_STARTPROC simple
23966 CFI_SIGNAL_FRAME
23967 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23968 + CFI_DEF_CFA rsp,0
23969 CFI_REGISTER rip,rcx
23970 /*CFI_REGISTER rflags,r11*/
23971 SWAPGS_UNSAFE_STACK
23972 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
23973
23974 movq %rsp,PER_CPU_VAR(old_rsp)
23975 movq PER_CPU_VAR(kernel_stack),%rsp
23976 + SAVE_ARGS 8*6,0
23977 + pax_enter_kernel_user
23978 +
23979 +#ifdef CONFIG_PAX_RANDKSTACK
23980 + pax_erase_kstack
23981 +#endif
23982 +
23983 /*
23984 * No need to follow this irqs off/on section - it's straight
23985 * and short:
23986 */
23987 ENABLE_INTERRUPTS(CLBR_NONE)
23988 - SAVE_ARGS 8,0
23989 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23990 movq %rcx,RIP-ARGOFFSET(%rsp)
23991 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23992 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23993 + GET_THREAD_INFO(%rcx)
23994 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23995 jnz tracesys
23996 system_call_fastpath:
23997 #if __SYSCALL_MASK == ~0
23998 @@ -432,10 +898,13 @@ sysret_check:
23999 LOCKDEP_SYS_EXIT
24000 DISABLE_INTERRUPTS(CLBR_NONE)
24001 TRACE_IRQS_OFF
24002 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24003 + GET_THREAD_INFO(%rcx)
24004 + movl TI_flags(%rcx),%edx
24005 andl %edi,%edx
24006 jnz sysret_careful
24007 CFI_REMEMBER_STATE
24008 + pax_exit_kernel_user
24009 + pax_erase_kstack
24010 /*
24011 * sysretq will re-enable interrupts:
24012 */
24013 @@ -494,6 +963,9 @@ auditsys:
24014 movq %rax,%rsi /* 2nd arg: syscall number */
24015 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24016 call __audit_syscall_entry
24017 +
24018 + pax_erase_kstack
24019 +
24020 LOAD_ARGS 0 /* reload call-clobbered registers */
24021 jmp system_call_fastpath
24022
24023 @@ -515,7 +987,7 @@ sysret_audit:
24024 /* Do syscall tracing */
24025 tracesys:
24026 #ifdef CONFIG_AUDITSYSCALL
24027 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24028 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24029 jz auditsys
24030 #endif
24031 SAVE_REST
24032 @@ -523,12 +995,15 @@ tracesys:
24033 FIXUP_TOP_OF_STACK %rdi
24034 movq %rsp,%rdi
24035 call syscall_trace_enter
24036 +
24037 + pax_erase_kstack
24038 +
24039 /*
24040 * Reload arg registers from stack in case ptrace changed them.
24041 * We don't reload %rax because syscall_trace_enter() returned
24042 * the value it wants us to use in the table lookup.
24043 */
24044 - LOAD_ARGS ARGOFFSET, 1
24045 + LOAD_ARGS 1
24046 RESTORE_REST
24047 #if __SYSCALL_MASK == ~0
24048 cmpq $__NR_syscall_max,%rax
24049 @@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24050 andl %edi,%edx
24051 jnz int_careful
24052 andl $~TS_COMPAT,TI_status(%rcx)
24053 - jmp retint_swapgs
24054 + pax_exit_kernel_user
24055 + pax_erase_kstack
24056 + jmp retint_swapgs_pax
24057
24058 /* Either reschedule or signal or syscall exit tracking needed. */
24059 /* First do a reschedule test. */
24060 @@ -604,7 +1081,7 @@ int_restore_rest:
24061 TRACE_IRQS_OFF
24062 jmp int_with_check
24063 CFI_ENDPROC
24064 -END(system_call)
24065 +ENDPROC(system_call)
24066
24067 .macro FORK_LIKE func
24068 ENTRY(stub_\func)
24069 @@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24070 DEFAULT_FRAME 0 8 /* offset 8: return address */
24071 call sys_\func
24072 RESTORE_TOP_OF_STACK %r11, 8
24073 - ret $REST_SKIP /* pop extended registers */
24074 + pax_force_retaddr
24075 + ret
24076 CFI_ENDPROC
24077 -END(stub_\func)
24078 +ENDPROC(stub_\func)
24079 .endm
24080
24081 .macro FIXED_FRAME label,func
24082 @@ -629,9 +1107,10 @@ ENTRY(\label)
24083 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24084 call \func
24085 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24086 + pax_force_retaddr
24087 ret
24088 CFI_ENDPROC
24089 -END(\label)
24090 +ENDPROC(\label)
24091 .endm
24092
24093 FORK_LIKE clone
24094 @@ -639,19 +1118,6 @@ END(\label)
24095 FORK_LIKE vfork
24096 FIXED_FRAME stub_iopl, sys_iopl
24097
24098 -ENTRY(ptregscall_common)
24099 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24100 - RESTORE_TOP_OF_STACK %r11, 8
24101 - movq_cfi_restore R15+8, r15
24102 - movq_cfi_restore R14+8, r14
24103 - movq_cfi_restore R13+8, r13
24104 - movq_cfi_restore R12+8, r12
24105 - movq_cfi_restore RBP+8, rbp
24106 - movq_cfi_restore RBX+8, rbx
24107 - ret $REST_SKIP /* pop extended registers */
24108 - CFI_ENDPROC
24109 -END(ptregscall_common)
24110 -
24111 ENTRY(stub_execve)
24112 CFI_STARTPROC
24113 addq $8, %rsp
24114 @@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24115 RESTORE_REST
24116 jmp int_ret_from_sys_call
24117 CFI_ENDPROC
24118 -END(stub_execve)
24119 +ENDPROC(stub_execve)
24120
24121 /*
24122 * sigreturn is special because it needs to restore all registers on return.
24123 @@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24124 RESTORE_REST
24125 jmp int_ret_from_sys_call
24126 CFI_ENDPROC
24127 -END(stub_rt_sigreturn)
24128 +ENDPROC(stub_rt_sigreturn)
24129
24130 #ifdef CONFIG_X86_X32_ABI
24131 ENTRY(stub_x32_rt_sigreturn)
24132 @@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24133 RESTORE_REST
24134 jmp int_ret_from_sys_call
24135 CFI_ENDPROC
24136 -END(stub_x32_rt_sigreturn)
24137 +ENDPROC(stub_x32_rt_sigreturn)
24138
24139 ENTRY(stub_x32_execve)
24140 CFI_STARTPROC
24141 @@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24142 RESTORE_REST
24143 jmp int_ret_from_sys_call
24144 CFI_ENDPROC
24145 -END(stub_x32_execve)
24146 +ENDPROC(stub_x32_execve)
24147
24148 #endif
24149
24150 @@ -745,7 +1211,7 @@ vector=vector+1
24151 2: jmp common_interrupt
24152 .endr
24153 CFI_ENDPROC
24154 -END(irq_entries_start)
24155 +ENDPROC(irq_entries_start)
24156
24157 .previous
24158 END(interrupt)
24159 @@ -762,8 +1228,8 @@ END(interrupt)
24160 /* 0(%rsp): ~(interrupt number) */
24161 .macro interrupt func
24162 /* reserve pt_regs for scratch regs and rbp */
24163 - subq $ORIG_RAX-RBP, %rsp
24164 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24165 + subq $ORIG_RAX, %rsp
24166 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24167 SAVE_ARGS_IRQ
24168 call \func
24169 .endm
24170 @@ -786,14 +1252,14 @@ ret_from_intr:
24171
24172 /* Restore saved previous stack */
24173 popq %rsi
24174 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24175 - leaq ARGOFFSET-RBP(%rsi), %rsp
24176 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24177 + movq %rsi, %rsp
24178 CFI_DEF_CFA_REGISTER rsp
24179 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24180 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24181
24182 exit_intr:
24183 GET_THREAD_INFO(%rcx)
24184 - testl $3,CS-ARGOFFSET(%rsp)
24185 + testb $3,CS-ARGOFFSET(%rsp)
24186 je retint_kernel
24187
24188 /* Interrupt came from user space */
24189 @@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24190 * The iretq could re-enable interrupts:
24191 */
24192 DISABLE_INTERRUPTS(CLBR_ANY)
24193 + pax_exit_kernel_user
24194 +retint_swapgs_pax:
24195 TRACE_IRQS_IRETQ
24196 SWAPGS
24197 jmp restore_args
24198
24199 retint_restore_args: /* return to kernel space */
24200 DISABLE_INTERRUPTS(CLBR_ANY)
24201 + pax_exit_kernel
24202 +
24203 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24204 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24205 + * namely calling EFI runtime services with a phys mapping. We're
24206 + * starting off with NOPs and patch in the real instrumentation
24207 + * (BTS/OR) before starting any userland process; even before starting
24208 + * up the APs.
24209 + */
24210 + .pushsection .altinstr_replacement, "a"
24211 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24212 + 602:
24213 + .popsection
24214 + 603: .fill 602b-601b, 1, 0x90
24215 + .pushsection .altinstructions, "a"
24216 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24217 + .popsection
24218 +#else
24219 + pax_force_retaddr (RIP-ARGOFFSET)
24220 +#endif
24221 +
24222 /*
24223 * The iretq could re-enable interrupts:
24224 */
24225 @@ -933,7 +1422,7 @@ ENTRY(retint_kernel)
24226 jmp exit_intr
24227 #endif
24228 CFI_ENDPROC
24229 -END(common_interrupt)
24230 +ENDPROC(common_interrupt)
24231
24232 /*
24233 * If IRET takes a fault on the espfix stack, then we
24234 @@ -955,13 +1444,13 @@ __do_double_fault:
24235 cmpq $native_irq_return_iret,%rax
24236 jne do_double_fault /* This shouldn't happen... */
24237 movq PER_CPU_VAR(kernel_stack),%rax
24238 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24239 + subq $(6*8),%rax /* Reset to original stack */
24240 movq %rax,RSP(%rdi)
24241 movq $0,(%rax) /* Missing (lost) #GP error code */
24242 movq $general_protection,RIP(%rdi)
24243 retq
24244 CFI_ENDPROC
24245 -END(__do_double_fault)
24246 +ENDPROC(__do_double_fault)
24247 #else
24248 # define __do_double_fault do_double_fault
24249 #endif
24250 @@ -978,7 +1467,7 @@ ENTRY(\sym)
24251 interrupt \do_sym
24252 jmp ret_from_intr
24253 CFI_ENDPROC
24254 -END(\sym)
24255 +ENDPROC(\sym)
24256 .endm
24257
24258 #ifdef CONFIG_TRACING
24259 @@ -1051,7 +1540,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24260 /*
24261 * Exception entry points.
24262 */
24263 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24264 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24265
24266 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24267 ENTRY(\sym)
24268 @@ -1102,6 +1591,12 @@ ENTRY(\sym)
24269 .endif
24270
24271 .if \shift_ist != -1
24272 +#ifdef CONFIG_SMP
24273 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24274 + lea init_tss(%r13), %r13
24275 +#else
24276 + lea init_tss(%rip), %r13
24277 +#endif
24278 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24279 .endif
24280
24281 @@ -1118,7 +1613,7 @@ ENTRY(\sym)
24282 .endif
24283
24284 CFI_ENDPROC
24285 -END(\sym)
24286 +ENDPROC(\sym)
24287 .endm
24288
24289 #ifdef CONFIG_TRACING
24290 @@ -1159,9 +1654,10 @@ gs_change:
24291 2: mfence /* workaround */
24292 SWAPGS
24293 popfq_cfi
24294 + pax_force_retaddr
24295 ret
24296 CFI_ENDPROC
24297 -END(native_load_gs_index)
24298 +ENDPROC(native_load_gs_index)
24299
24300 _ASM_EXTABLE(gs_change,bad_gs)
24301 .section .fixup,"ax"
24302 @@ -1189,9 +1685,10 @@ ENTRY(do_softirq_own_stack)
24303 CFI_DEF_CFA_REGISTER rsp
24304 CFI_ADJUST_CFA_OFFSET -8
24305 decl PER_CPU_VAR(irq_count)
24306 + pax_force_retaddr
24307 ret
24308 CFI_ENDPROC
24309 -END(do_softirq_own_stack)
24310 +ENDPROC(do_softirq_own_stack)
24311
24312 #ifdef CONFIG_XEN
24313 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24314 @@ -1229,7 +1726,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24315 decl PER_CPU_VAR(irq_count)
24316 jmp error_exit
24317 CFI_ENDPROC
24318 -END(xen_do_hypervisor_callback)
24319 +ENDPROC(xen_do_hypervisor_callback)
24320
24321 /*
24322 * Hypervisor uses this for application faults while it executes.
24323 @@ -1288,7 +1785,7 @@ ENTRY(xen_failsafe_callback)
24324 SAVE_ALL
24325 jmp error_exit
24326 CFI_ENDPROC
24327 -END(xen_failsafe_callback)
24328 +ENDPROC(xen_failsafe_callback)
24329
24330 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24331 xen_hvm_callback_vector xen_evtchn_do_upcall
24332 @@ -1335,18 +1832,33 @@ ENTRY(paranoid_exit)
24333 DEFAULT_FRAME
24334 DISABLE_INTERRUPTS(CLBR_NONE)
24335 TRACE_IRQS_OFF_DEBUG
24336 - testl %ebx,%ebx /* swapgs needed? */
24337 + testl $1,%ebx /* swapgs needed? */
24338 jnz paranoid_restore
24339 - testl $3,CS(%rsp)
24340 + testb $3,CS(%rsp)
24341 jnz paranoid_userspace
24342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24343 + pax_exit_kernel
24344 + TRACE_IRQS_IRETQ 0
24345 + SWAPGS_UNSAFE_STACK
24346 + RESTORE_ALL 8
24347 + pax_force_retaddr_bts
24348 + jmp irq_return
24349 +#endif
24350 paranoid_swapgs:
24351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24352 + pax_exit_kernel_user
24353 +#else
24354 + pax_exit_kernel
24355 +#endif
24356 TRACE_IRQS_IRETQ 0
24357 SWAPGS_UNSAFE_STACK
24358 RESTORE_ALL 8
24359 jmp irq_return
24360 paranoid_restore:
24361 + pax_exit_kernel
24362 TRACE_IRQS_IRETQ_DEBUG 0
24363 RESTORE_ALL 8
24364 + pax_force_retaddr_bts
24365 jmp irq_return
24366 paranoid_userspace:
24367 GET_THREAD_INFO(%rcx)
24368 @@ -1375,7 +1887,7 @@ paranoid_schedule:
24369 TRACE_IRQS_OFF
24370 jmp paranoid_userspace
24371 CFI_ENDPROC
24372 -END(paranoid_exit)
24373 +ENDPROC(paranoid_exit)
24374
24375 /*
24376 * Exception entry point. This expects an error code/orig_rax on the stack.
24377 @@ -1402,12 +1914,23 @@ ENTRY(error_entry)
24378 movq %r14, R14+8(%rsp)
24379 movq %r15, R15+8(%rsp)
24380 xorl %ebx,%ebx
24381 - testl $3,CS+8(%rsp)
24382 + testb $3,CS+8(%rsp)
24383 je error_kernelspace
24384 error_swapgs:
24385 SWAPGS
24386 error_sti:
24387 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24388 + testb $3, CS+8(%rsp)
24389 + jnz 1f
24390 + pax_enter_kernel
24391 + jmp 2f
24392 +1: pax_enter_kernel_user
24393 +2:
24394 +#else
24395 + pax_enter_kernel
24396 +#endif
24397 TRACE_IRQS_OFF
24398 + pax_force_retaddr
24399 ret
24400
24401 /*
24402 @@ -1435,7 +1958,7 @@ bstep_iret:
24403 movq %rcx,RIP+8(%rsp)
24404 jmp error_swapgs
24405 CFI_ENDPROC
24406 -END(error_entry)
24407 +ENDPROC(error_entry)
24408
24409
24410 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24411 @@ -1446,7 +1969,7 @@ ENTRY(error_exit)
24412 DISABLE_INTERRUPTS(CLBR_NONE)
24413 TRACE_IRQS_OFF
24414 GET_THREAD_INFO(%rcx)
24415 - testl %eax,%eax
24416 + testl $1,%eax
24417 jne retint_kernel
24418 LOCKDEP_SYS_EXIT_IRQ
24419 movl TI_flags(%rcx),%edx
24420 @@ -1455,7 +1978,7 @@ ENTRY(error_exit)
24421 jnz retint_careful
24422 jmp retint_swapgs
24423 CFI_ENDPROC
24424 -END(error_exit)
24425 +ENDPROC(error_exit)
24426
24427 /*
24428 * Test if a given stack is an NMI stack or not.
24429 @@ -1513,9 +2036,11 @@ ENTRY(nmi)
24430 * If %cs was not the kernel segment, then the NMI triggered in user
24431 * space, which means it is definitely not nested.
24432 */
24433 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24434 + je 1f
24435 cmpl $__KERNEL_CS, 16(%rsp)
24436 jne first_nmi
24437 -
24438 +1:
24439 /*
24440 * Check the special variable on the stack to see if NMIs are
24441 * executing.
24442 @@ -1549,8 +2074,7 @@ nested_nmi:
24443
24444 1:
24445 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24446 - leaq -1*8(%rsp), %rdx
24447 - movq %rdx, %rsp
24448 + subq $8, %rsp
24449 CFI_ADJUST_CFA_OFFSET 1*8
24450 leaq -10*8(%rsp), %rdx
24451 pushq_cfi $__KERNEL_DS
24452 @@ -1568,6 +2092,7 @@ nested_nmi_out:
24453 CFI_RESTORE rdx
24454
24455 /* No need to check faults here */
24456 +# pax_force_retaddr_bts
24457 INTERRUPT_RETURN
24458
24459 CFI_RESTORE_STATE
24460 @@ -1664,13 +2189,13 @@ end_repeat_nmi:
24461 subq $ORIG_RAX-R15, %rsp
24462 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24463 /*
24464 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24465 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24466 * as we should not be calling schedule in NMI context.
24467 * Even with normal interrupts enabled. An NMI should not be
24468 * setting NEED_RESCHED or anything that normal interrupts and
24469 * exceptions might do.
24470 */
24471 - call save_paranoid
24472 + call save_paranoid_nmi
24473 DEFAULT_FRAME 0
24474
24475 /*
24476 @@ -1680,9 +2205,9 @@ end_repeat_nmi:
24477 * NMI itself takes a page fault, the page fault that was preempted
24478 * will read the information from the NMI page fault and not the
24479 * origin fault. Save it off and restore it if it changes.
24480 - * Use the r12 callee-saved register.
24481 + * Use the r13 callee-saved register.
24482 */
24483 - movq %cr2, %r12
24484 + movq %cr2, %r13
24485
24486 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24487 movq %rsp,%rdi
24488 @@ -1691,29 +2216,34 @@ end_repeat_nmi:
24489
24490 /* Did the NMI take a page fault? Restore cr2 if it did */
24491 movq %cr2, %rcx
24492 - cmpq %rcx, %r12
24493 + cmpq %rcx, %r13
24494 je 1f
24495 - movq %r12, %cr2
24496 + movq %r13, %cr2
24497 1:
24498
24499 - testl %ebx,%ebx /* swapgs needed? */
24500 + testl $1,%ebx /* swapgs needed? */
24501 jnz nmi_restore
24502 nmi_swapgs:
24503 SWAPGS_UNSAFE_STACK
24504 nmi_restore:
24505 + pax_exit_kernel_nmi
24506 /* Pop the extra iret frame at once */
24507 RESTORE_ALL 6*8
24508 + testb $3, 8(%rsp)
24509 + jnz 1f
24510 + pax_force_retaddr_bts
24511 +1:
24512
24513 /* Clear the NMI executing stack variable */
24514 movq $0, 5*8(%rsp)
24515 jmp irq_return
24516 CFI_ENDPROC
24517 -END(nmi)
24518 +ENDPROC(nmi)
24519
24520 ENTRY(ignore_sysret)
24521 CFI_STARTPROC
24522 mov $-ENOSYS,%eax
24523 sysret
24524 CFI_ENDPROC
24525 -END(ignore_sysret)
24526 +ENDPROC(ignore_sysret)
24527
24528 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24529 index 94d857f..bf1f0bf 100644
24530 --- a/arch/x86/kernel/espfix_64.c
24531 +++ b/arch/x86/kernel/espfix_64.c
24532 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24533 set_pte(&pte_p[n*PTE_STRIDE], pte);
24534
24535 /* Job is done for this CPU and any CPU which shares this page */
24536 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24537 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24538
24539 unlock_done:
24540 mutex_unlock(&espfix_init_mutex);
24541 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24542 index 3386dc9..28bdf81 100644
24543 --- a/arch/x86/kernel/ftrace.c
24544 +++ b/arch/x86/kernel/ftrace.c
24545 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24546 * kernel identity mapping to modify code.
24547 */
24548 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24549 - ip = (unsigned long)__va(__pa_symbol(ip));
24550 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24551
24552 return ip;
24553 }
24554 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24555 {
24556 unsigned char replaced[MCOUNT_INSN_SIZE];
24557
24558 + ip = ktla_ktva(ip);
24559 +
24560 /*
24561 * Note: Due to modules and __init, code can
24562 * disappear and change, we need to protect against faulting
24563 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24564 unsigned char old[MCOUNT_INSN_SIZE];
24565 int ret;
24566
24567 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24568 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24569
24570 ftrace_update_func = ip;
24571 /* Make sure the breakpoints see the ftrace_update_func update */
24572 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24573 unsigned char replaced[MCOUNT_INSN_SIZE];
24574 unsigned char brk = BREAKPOINT_INSTRUCTION;
24575
24576 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24577 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24578 return -EFAULT;
24579
24580 /* Make sure it is what we expect it to be */
24581 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24582 index eda1a86..8f6df48 100644
24583 --- a/arch/x86/kernel/head64.c
24584 +++ b/arch/x86/kernel/head64.c
24585 @@ -67,12 +67,12 @@ again:
24586 pgd = *pgd_p;
24587
24588 /*
24589 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24590 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24591 + * The use of __early_va rather than __va here is critical:
24592 + * __va would point us back into the dynamic
24593 * range and we might end up looping forever...
24594 */
24595 if (pgd)
24596 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24597 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24598 else {
24599 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24600 reset_early_page_tables();
24601 @@ -82,13 +82,13 @@ again:
24602 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24603 for (i = 0; i < PTRS_PER_PUD; i++)
24604 pud_p[i] = 0;
24605 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24606 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24607 }
24608 pud_p += pud_index(address);
24609 pud = *pud_p;
24610
24611 if (pud)
24612 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24613 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24614 else {
24615 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24616 reset_early_page_tables();
24617 @@ -98,7 +98,7 @@ again:
24618 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24619 for (i = 0; i < PTRS_PER_PMD; i++)
24620 pmd_p[i] = 0;
24621 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24622 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24623 }
24624 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24625 pmd_p[pmd_index(address)] = pmd;
24626 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24627 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24628 early_printk("Kernel alive\n");
24629
24630 - clear_page(init_level4_pgt);
24631 /* set init_level4_pgt kernel high mapping*/
24632 init_level4_pgt[511] = early_level4_pgt[511];
24633
24634 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24635 index f36bd42..0ab4474 100644
24636 --- a/arch/x86/kernel/head_32.S
24637 +++ b/arch/x86/kernel/head_32.S
24638 @@ -26,6 +26,12 @@
24639 /* Physical address */
24640 #define pa(X) ((X) - __PAGE_OFFSET)
24641
24642 +#ifdef CONFIG_PAX_KERNEXEC
24643 +#define ta(X) (X)
24644 +#else
24645 +#define ta(X) ((X) - __PAGE_OFFSET)
24646 +#endif
24647 +
24648 /*
24649 * References to members of the new_cpu_data structure.
24650 */
24651 @@ -55,11 +61,7 @@
24652 * and small than max_low_pfn, otherwise will waste some page table entries
24653 */
24654
24655 -#if PTRS_PER_PMD > 1
24656 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24657 -#else
24658 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24659 -#endif
24660 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24661
24662 /* Number of possible pages in the lowmem region */
24663 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24664 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24665 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24666
24667 /*
24668 + * Real beginning of normal "text" segment
24669 + */
24670 +ENTRY(stext)
24671 +ENTRY(_stext)
24672 +
24673 +/*
24674 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24675 * %esi points to the real-mode code as a 32-bit pointer.
24676 * CS and DS must be 4 GB flat segments, but we don't depend on
24677 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24678 * can.
24679 */
24680 __HEAD
24681 +
24682 +#ifdef CONFIG_PAX_KERNEXEC
24683 + jmp startup_32
24684 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24685 +.fill PAGE_SIZE-5,1,0xcc
24686 +#endif
24687 +
24688 ENTRY(startup_32)
24689 movl pa(stack_start),%ecx
24690
24691 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24692 2:
24693 leal -__PAGE_OFFSET(%ecx),%esp
24694
24695 +#ifdef CONFIG_SMP
24696 + movl $pa(cpu_gdt_table),%edi
24697 + movl $__per_cpu_load,%eax
24698 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24699 + rorl $16,%eax
24700 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24701 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24702 + movl $__per_cpu_end - 1,%eax
24703 + subl $__per_cpu_start,%eax
24704 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24705 +#endif
24706 +
24707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24708 + movl $NR_CPUS,%ecx
24709 + movl $pa(cpu_gdt_table),%edi
24710 +1:
24711 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24712 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24713 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24714 + addl $PAGE_SIZE_asm,%edi
24715 + loop 1b
24716 +#endif
24717 +
24718 +#ifdef CONFIG_PAX_KERNEXEC
24719 + movl $pa(boot_gdt),%edi
24720 + movl $__LOAD_PHYSICAL_ADDR,%eax
24721 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24722 + rorl $16,%eax
24723 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24724 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24725 + rorl $16,%eax
24726 +
24727 + ljmp $(__BOOT_CS),$1f
24728 +1:
24729 +
24730 + movl $NR_CPUS,%ecx
24731 + movl $pa(cpu_gdt_table),%edi
24732 + addl $__PAGE_OFFSET,%eax
24733 +1:
24734 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24735 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24736 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24737 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24738 + rorl $16,%eax
24739 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24740 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24741 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24742 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24743 + rorl $16,%eax
24744 + addl $PAGE_SIZE_asm,%edi
24745 + loop 1b
24746 +#endif
24747 +
24748 /*
24749 * Clear BSS first so that there are no surprises...
24750 */
24751 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24752 movl %eax, pa(max_pfn_mapped)
24753
24754 /* Do early initialization of the fixmap area */
24755 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24756 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24757 +#ifdef CONFIG_COMPAT_VDSO
24758 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24759 +#else
24760 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24761 +#endif
24762 #else /* Not PAE */
24763
24764 page_pde_offset = (__PAGE_OFFSET >> 20);
24765 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24766 movl %eax, pa(max_pfn_mapped)
24767
24768 /* Do early initialization of the fixmap area */
24769 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24770 - movl %eax,pa(initial_page_table+0xffc)
24771 +#ifdef CONFIG_COMPAT_VDSO
24772 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24773 +#else
24774 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24775 +#endif
24776 #endif
24777
24778 #ifdef CONFIG_PARAVIRT
24779 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24780 cmpl $num_subarch_entries, %eax
24781 jae bad_subarch
24782
24783 - movl pa(subarch_entries)(,%eax,4), %eax
24784 - subl $__PAGE_OFFSET, %eax
24785 - jmp *%eax
24786 + jmp *pa(subarch_entries)(,%eax,4)
24787
24788 bad_subarch:
24789 WEAK(lguest_entry)
24790 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24791 __INITDATA
24792
24793 subarch_entries:
24794 - .long default_entry /* normal x86/PC */
24795 - .long lguest_entry /* lguest hypervisor */
24796 - .long xen_entry /* Xen hypervisor */
24797 - .long default_entry /* Moorestown MID */
24798 + .long ta(default_entry) /* normal x86/PC */
24799 + .long ta(lguest_entry) /* lguest hypervisor */
24800 + .long ta(xen_entry) /* Xen hypervisor */
24801 + .long ta(default_entry) /* Moorestown MID */
24802 num_subarch_entries = (. - subarch_entries) / 4
24803 .previous
24804 #else
24805 @@ -354,6 +426,7 @@ default_entry:
24806 movl pa(mmu_cr4_features),%eax
24807 movl %eax,%cr4
24808
24809 +#ifdef CONFIG_X86_PAE
24810 testb $X86_CR4_PAE, %al # check if PAE is enabled
24811 jz enable_paging
24812
24813 @@ -382,6 +455,9 @@ default_entry:
24814 /* Make changes effective */
24815 wrmsr
24816
24817 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24818 +#endif
24819 +
24820 enable_paging:
24821
24822 /*
24823 @@ -449,14 +525,20 @@ is486:
24824 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24825 movl %eax,%ss # after changing gdt.
24826
24827 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24828 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24829 movl %eax,%ds
24830 movl %eax,%es
24831
24832 movl $(__KERNEL_PERCPU), %eax
24833 movl %eax,%fs # set this cpu's percpu
24834
24835 +#ifdef CONFIG_CC_STACKPROTECTOR
24836 movl $(__KERNEL_STACK_CANARY),%eax
24837 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24838 + movl $(__USER_DS),%eax
24839 +#else
24840 + xorl %eax,%eax
24841 +#endif
24842 movl %eax,%gs
24843
24844 xorl %eax,%eax # Clear LDT
24845 @@ -512,8 +594,11 @@ setup_once:
24846 * relocation. Manually set base address in stack canary
24847 * segment descriptor.
24848 */
24849 - movl $gdt_page,%eax
24850 + movl $cpu_gdt_table,%eax
24851 movl $stack_canary,%ecx
24852 +#ifdef CONFIG_SMP
24853 + addl $__per_cpu_load,%ecx
24854 +#endif
24855 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24856 shrl $16, %ecx
24857 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24858 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24859 cmpl $2,(%esp) # X86_TRAP_NMI
24860 je is_nmi # Ignore NMI
24861
24862 - cmpl $2,%ss:early_recursion_flag
24863 + cmpl $1,%ss:early_recursion_flag
24864 je hlt_loop
24865 incl %ss:early_recursion_flag
24866
24867 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24868 pushl (20+6*4)(%esp) /* trapno */
24869 pushl $fault_msg
24870 call printk
24871 -#endif
24872 call dump_stack
24873 +#endif
24874 hlt_loop:
24875 hlt
24876 jmp hlt_loop
24877 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24878 /* This is the default interrupt "handler" :-) */
24879 ALIGN
24880 ignore_int:
24881 - cld
24882 #ifdef CONFIG_PRINTK
24883 + cmpl $2,%ss:early_recursion_flag
24884 + je hlt_loop
24885 + incl %ss:early_recursion_flag
24886 + cld
24887 pushl %eax
24888 pushl %ecx
24889 pushl %edx
24890 @@ -617,9 +705,6 @@ ignore_int:
24891 movl $(__KERNEL_DS),%eax
24892 movl %eax,%ds
24893 movl %eax,%es
24894 - cmpl $2,early_recursion_flag
24895 - je hlt_loop
24896 - incl early_recursion_flag
24897 pushl 16(%esp)
24898 pushl 24(%esp)
24899 pushl 32(%esp)
24900 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24901 /*
24902 * BSS section
24903 */
24904 -__PAGE_ALIGNED_BSS
24905 - .align PAGE_SIZE
24906 #ifdef CONFIG_X86_PAE
24907 +.section .initial_pg_pmd,"a",@progbits
24908 initial_pg_pmd:
24909 .fill 1024*KPMDS,4,0
24910 #else
24911 +.section .initial_page_table,"a",@progbits
24912 ENTRY(initial_page_table)
24913 .fill 1024,4,0
24914 #endif
24915 +.section .initial_pg_fixmap,"a",@progbits
24916 initial_pg_fixmap:
24917 .fill 1024,4,0
24918 +.section .empty_zero_page,"a",@progbits
24919 ENTRY(empty_zero_page)
24920 .fill 4096,1,0
24921 +.section .swapper_pg_dir,"a",@progbits
24922 ENTRY(swapper_pg_dir)
24923 +#ifdef CONFIG_X86_PAE
24924 + .fill 4,8,0
24925 +#else
24926 .fill 1024,4,0
24927 +#endif
24928
24929 /*
24930 * This starts the data section.
24931 */
24932 #ifdef CONFIG_X86_PAE
24933 -__PAGE_ALIGNED_DATA
24934 - /* Page-aligned for the benefit of paravirt? */
24935 - .align PAGE_SIZE
24936 +.section .initial_page_table,"a",@progbits
24937 ENTRY(initial_page_table)
24938 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24939 # if KPMDS == 3
24940 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24941 # error "Kernel PMDs should be 1, 2 or 3"
24942 # endif
24943 .align PAGE_SIZE /* needs to be page-sized too */
24944 +
24945 +#ifdef CONFIG_PAX_PER_CPU_PGD
24946 +ENTRY(cpu_pgd)
24947 + .rept 2*NR_CPUS
24948 + .fill 4,8,0
24949 + .endr
24950 +#endif
24951 +
24952 #endif
24953
24954 .data
24955 .balign 4
24956 ENTRY(stack_start)
24957 - .long init_thread_union+THREAD_SIZE
24958 + .long init_thread_union+THREAD_SIZE-8
24959
24960 __INITRODATA
24961 int_msg:
24962 @@ -727,7 +825,7 @@ fault_msg:
24963 * segment size, and 32-bit linear address value:
24964 */
24965
24966 - .data
24967 +.section .rodata,"a",@progbits
24968 .globl boot_gdt_descr
24969 .globl idt_descr
24970
24971 @@ -736,7 +834,7 @@ fault_msg:
24972 .word 0 # 32 bit align gdt_desc.address
24973 boot_gdt_descr:
24974 .word __BOOT_DS+7
24975 - .long boot_gdt - __PAGE_OFFSET
24976 + .long pa(boot_gdt)
24977
24978 .word 0 # 32-bit align idt_desc.address
24979 idt_descr:
24980 @@ -747,7 +845,7 @@ idt_descr:
24981 .word 0 # 32 bit align gdt_desc.address
24982 ENTRY(early_gdt_descr)
24983 .word GDT_ENTRIES*8-1
24984 - .long gdt_page /* Overwritten for secondary CPUs */
24985 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24986
24987 /*
24988 * The boot_gdt must mirror the equivalent in setup.S and is
24989 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24990 .align L1_CACHE_BYTES
24991 ENTRY(boot_gdt)
24992 .fill GDT_ENTRY_BOOT_CS,8,0
24993 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24994 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24995 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24996 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24997 +
24998 + .align PAGE_SIZE_asm
24999 +ENTRY(cpu_gdt_table)
25000 + .rept NR_CPUS
25001 + .quad 0x0000000000000000 /* NULL descriptor */
25002 + .quad 0x0000000000000000 /* 0x0b reserved */
25003 + .quad 0x0000000000000000 /* 0x13 reserved */
25004 + .quad 0x0000000000000000 /* 0x1b reserved */
25005 +
25006 +#ifdef CONFIG_PAX_KERNEXEC
25007 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25008 +#else
25009 + .quad 0x0000000000000000 /* 0x20 unused */
25010 +#endif
25011 +
25012 + .quad 0x0000000000000000 /* 0x28 unused */
25013 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25014 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25015 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25016 + .quad 0x0000000000000000 /* 0x4b reserved */
25017 + .quad 0x0000000000000000 /* 0x53 reserved */
25018 + .quad 0x0000000000000000 /* 0x5b reserved */
25019 +
25020 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25021 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25022 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25023 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25024 +
25025 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25026 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25027 +
25028 + /*
25029 + * Segments used for calling PnP BIOS have byte granularity.
25030 + * The code segments and data segments have fixed 64k limits,
25031 + * the transfer segment sizes are set at run time.
25032 + */
25033 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25034 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25035 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25036 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25037 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25038 +
25039 + /*
25040 + * The APM segments have byte granularity and their bases
25041 + * are set at run time. All have 64k limits.
25042 + */
25043 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25044 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25045 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25046 +
25047 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25048 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25049 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25050 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25051 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25052 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25053 +
25054 + /* Be sure this is zeroed to avoid false validations in Xen */
25055 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25056 + .endr
25057 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25058 index a468c0a..8b5a879 100644
25059 --- a/arch/x86/kernel/head_64.S
25060 +++ b/arch/x86/kernel/head_64.S
25061 @@ -20,6 +20,8 @@
25062 #include <asm/processor-flags.h>
25063 #include <asm/percpu.h>
25064 #include <asm/nops.h>
25065 +#include <asm/cpufeature.h>
25066 +#include <asm/alternative-asm.h>
25067
25068 #ifdef CONFIG_PARAVIRT
25069 #include <asm/asm-offsets.h>
25070 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25071 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25072 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25073 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25074 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25075 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25076 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25077 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25078 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25079 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25080
25081 .text
25082 __HEAD
25083 @@ -89,11 +97,24 @@ startup_64:
25084 * Fixup the physical addresses in the page table
25085 */
25086 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25087 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25088 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25089 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25090 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25091 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25092
25093 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25094 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25095 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25096 +#ifndef CONFIG_XEN
25097 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25098 +#endif
25099 +
25100 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25101 +
25102 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25103 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25104
25105 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25106 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25107
25108 /*
25109 * Set up the identity mapping for the switchover. These
25110 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25111 * after the boot processor executes this code.
25112 */
25113
25114 + orq $-1, %rbp
25115 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25116 1:
25117
25118 - /* Enable PAE mode and PGE */
25119 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25120 + /* Enable PAE mode and PSE/PGE */
25121 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25122 movq %rcx, %cr4
25123
25124 /* Setup early boot stage 4 level pagetables. */
25125 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25126 movl $MSR_EFER, %ecx
25127 rdmsr
25128 btsl $_EFER_SCE, %eax /* Enable System Call */
25129 - btl $20,%edi /* No Execute supported? */
25130 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25131 jnc 1f
25132 btsl $_EFER_NX, %eax
25133 + cmpq $-1, %rbp
25134 + je 1f
25135 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25136 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25137 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25138 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25139 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25140 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25141 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25142 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25143 1: wrmsr /* Make changes effective */
25144
25145 /* Setup cr0 */
25146 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25147 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25148 * address given in m16:64.
25149 */
25150 + pax_set_fptr_mask
25151 movq initial_code(%rip),%rax
25152 pushq $0 # fake return address to stop unwinder
25153 pushq $__KERNEL_CS # set correct cs
25154 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25155 .quad INIT_PER_CPU_VAR(irq_stack_union)
25156
25157 GLOBAL(stack_start)
25158 - .quad init_thread_union+THREAD_SIZE-8
25159 + .quad init_thread_union+THREAD_SIZE-16
25160 .word 0
25161 __FINITDATA
25162
25163 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25164 call dump_stack
25165 #ifdef CONFIG_KALLSYMS
25166 leaq early_idt_ripmsg(%rip),%rdi
25167 - movq 40(%rsp),%rsi # %rip again
25168 + movq 88(%rsp),%rsi # %rip again
25169 call __print_symbol
25170 #endif
25171 #endif /* EARLY_PRINTK */
25172 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25173 early_recursion_flag:
25174 .long 0
25175
25176 + .section .rodata,"a",@progbits
25177 #ifdef CONFIG_EARLY_PRINTK
25178 early_idt_msg:
25179 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25180 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25181 NEXT_PAGE(early_dynamic_pgts)
25182 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25183
25184 - .data
25185 + .section .rodata,"a",@progbits
25186
25187 -#ifndef CONFIG_XEN
25188 NEXT_PAGE(init_level4_pgt)
25189 - .fill 512,8,0
25190 -#else
25191 -NEXT_PAGE(init_level4_pgt)
25192 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25193 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25194 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25195 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25196 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25197 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25198 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25199 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25200 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25201 .org init_level4_pgt + L4_START_KERNEL*8, 0
25202 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25203 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25204
25205 +#ifdef CONFIG_PAX_PER_CPU_PGD
25206 +NEXT_PAGE(cpu_pgd)
25207 + .rept 2*NR_CPUS
25208 + .fill 512,8,0
25209 + .endr
25210 +#endif
25211 +
25212 NEXT_PAGE(level3_ident_pgt)
25213 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25214 +#ifdef CONFIG_XEN
25215 .fill 511, 8, 0
25216 +#else
25217 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25218 + .fill 510,8,0
25219 +#endif
25220 +
25221 +NEXT_PAGE(level3_vmalloc_start_pgt)
25222 + .fill 512,8,0
25223 +
25224 +NEXT_PAGE(level3_vmalloc_end_pgt)
25225 + .fill 512,8,0
25226 +
25227 +NEXT_PAGE(level3_vmemmap_pgt)
25228 + .fill L3_VMEMMAP_START,8,0
25229 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25230 +
25231 NEXT_PAGE(level2_ident_pgt)
25232 - /* Since I easily can, map the first 1G.
25233 + /* Since I easily can, map the first 2G.
25234 * Don't set NX because code runs from these pages.
25235 */
25236 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25237 -#endif
25238 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25239
25240 NEXT_PAGE(level3_kernel_pgt)
25241 .fill L3_START_KERNEL,8,0
25242 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25243 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25244 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25245
25246 +NEXT_PAGE(level2_vmemmap_pgt)
25247 + .fill 512,8,0
25248 +
25249 NEXT_PAGE(level2_kernel_pgt)
25250 /*
25251 * 512 MB kernel mapping. We spend a full page on this pagetable
25252 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25253 NEXT_PAGE(level2_fixmap_pgt)
25254 .fill 506,8,0
25255 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25256 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25257 - .fill 5,8,0
25258 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25259 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25260 + .fill 4,8,0
25261
25262 NEXT_PAGE(level1_fixmap_pgt)
25263 .fill 512,8,0
25264
25265 +NEXT_PAGE(level1_vsyscall_pgt)
25266 + .fill 512,8,0
25267 +
25268 #undef PMDS
25269
25270 - .data
25271 + .align PAGE_SIZE
25272 +ENTRY(cpu_gdt_table)
25273 + .rept NR_CPUS
25274 + .quad 0x0000000000000000 /* NULL descriptor */
25275 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25276 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25277 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25278 + .quad 0x00cffb000000ffff /* __USER32_CS */
25279 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25280 + .quad 0x00affb000000ffff /* __USER_CS */
25281 +
25282 +#ifdef CONFIG_PAX_KERNEXEC
25283 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25284 +#else
25285 + .quad 0x0 /* unused */
25286 +#endif
25287 +
25288 + .quad 0,0 /* TSS */
25289 + .quad 0,0 /* LDT */
25290 + .quad 0,0,0 /* three TLS descriptors */
25291 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25292 + /* asm/segment.h:GDT_ENTRIES must match this */
25293 +
25294 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25295 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25296 +#else
25297 + .quad 0x0 /* unused */
25298 +#endif
25299 +
25300 + /* zero the remaining page */
25301 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25302 + .endr
25303 +
25304 .align 16
25305 .globl early_gdt_descr
25306 early_gdt_descr:
25307 .word GDT_ENTRIES*8-1
25308 early_gdt_descr_base:
25309 - .quad INIT_PER_CPU_VAR(gdt_page)
25310 + .quad cpu_gdt_table
25311
25312 ENTRY(phys_base)
25313 /* This must match the first entry in level2_kernel_pgt */
25314 .quad 0x0000000000000000
25315
25316 #include "../../x86/xen/xen-head.S"
25317 -
25318 - __PAGE_ALIGNED_BSS
25319 +
25320 + .section .rodata,"a",@progbits
25321 NEXT_PAGE(empty_zero_page)
25322 .skip PAGE_SIZE
25323 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25324 index 05fd74f..c3548b1 100644
25325 --- a/arch/x86/kernel/i386_ksyms_32.c
25326 +++ b/arch/x86/kernel/i386_ksyms_32.c
25327 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25328 EXPORT_SYMBOL(cmpxchg8b_emu);
25329 #endif
25330
25331 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25332 +
25333 /* Networking helper routines. */
25334 EXPORT_SYMBOL(csum_partial_copy_generic);
25335 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25336 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25337
25338 EXPORT_SYMBOL(__get_user_1);
25339 EXPORT_SYMBOL(__get_user_2);
25340 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25341 EXPORT_SYMBOL(___preempt_schedule_context);
25342 #endif
25343 #endif
25344 +
25345 +#ifdef CONFIG_PAX_KERNEXEC
25346 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25347 +#endif
25348 +
25349 +#ifdef CONFIG_PAX_PER_CPU_PGD
25350 +EXPORT_SYMBOL(cpu_pgd);
25351 +#endif
25352 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25353 index a9a4229..6f4d476 100644
25354 --- a/arch/x86/kernel/i387.c
25355 +++ b/arch/x86/kernel/i387.c
25356 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25357 static inline bool interrupted_user_mode(void)
25358 {
25359 struct pt_regs *regs = get_irq_regs();
25360 - return regs && user_mode_vm(regs);
25361 + return regs && user_mode(regs);
25362 }
25363
25364 /*
25365 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25366 index 8af8171..f8c1169 100644
25367 --- a/arch/x86/kernel/i8259.c
25368 +++ b/arch/x86/kernel/i8259.c
25369 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25370 static void make_8259A_irq(unsigned int irq)
25371 {
25372 disable_irq_nosync(irq);
25373 - io_apic_irqs &= ~(1<<irq);
25374 + io_apic_irqs &= ~(1UL<<irq);
25375 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25376 i8259A_chip.name);
25377 enable_irq(irq);
25378 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25379 "spurious 8259A interrupt: IRQ%d.\n", irq);
25380 spurious_irq_mask |= irqmask;
25381 }
25382 - atomic_inc(&irq_err_count);
25383 + atomic_inc_unchecked(&irq_err_count);
25384 /*
25385 * Theoretically we do not have to handle this IRQ,
25386 * but in Linux this does not cause problems and is
25387 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25388 /* (slave's support for AEOI in flat mode is to be investigated) */
25389 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25390
25391 + pax_open_kernel();
25392 if (auto_eoi)
25393 /*
25394 * In AEOI mode we just have to mask the interrupt
25395 * when acking.
25396 */
25397 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25398 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25399 else
25400 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25401 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25402 + pax_close_kernel();
25403
25404 udelay(100); /* wait for 8259A to initialize */
25405
25406 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25407 index a979b5b..1d6db75 100644
25408 --- a/arch/x86/kernel/io_delay.c
25409 +++ b/arch/x86/kernel/io_delay.c
25410 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25411 * Quirk table for systems that misbehave (lock up, etc.) if port
25412 * 0x80 is used:
25413 */
25414 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25415 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25416 {
25417 .callback = dmi_io_delay_0xed_port,
25418 .ident = "Compaq Presario V6000",
25419 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25420 index 4ddaf66..49d5c18 100644
25421 --- a/arch/x86/kernel/ioport.c
25422 +++ b/arch/x86/kernel/ioport.c
25423 @@ -6,6 +6,7 @@
25424 #include <linux/sched.h>
25425 #include <linux/kernel.h>
25426 #include <linux/capability.h>
25427 +#include <linux/security.h>
25428 #include <linux/errno.h>
25429 #include <linux/types.h>
25430 #include <linux/ioport.h>
25431 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25432 return -EINVAL;
25433 if (turn_on && !capable(CAP_SYS_RAWIO))
25434 return -EPERM;
25435 +#ifdef CONFIG_GRKERNSEC_IO
25436 + if (turn_on && grsec_disable_privio) {
25437 + gr_handle_ioperm();
25438 + return -ENODEV;
25439 + }
25440 +#endif
25441
25442 /*
25443 * If it's the first ioperm() call in this thread's lifetime, set the
25444 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25445 * because the ->io_bitmap_max value must match the bitmap
25446 * contents:
25447 */
25448 - tss = &per_cpu(init_tss, get_cpu());
25449 + tss = init_tss + get_cpu();
25450
25451 if (turn_on)
25452 bitmap_clear(t->io_bitmap_ptr, from, num);
25453 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25454 if (level > old) {
25455 if (!capable(CAP_SYS_RAWIO))
25456 return -EPERM;
25457 +#ifdef CONFIG_GRKERNSEC_IO
25458 + if (grsec_disable_privio) {
25459 + gr_handle_iopl();
25460 + return -ENODEV;
25461 + }
25462 +#endif
25463 }
25464 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25465 t->iopl = level << 12;
25466 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25467 index 922d285..6d20692 100644
25468 --- a/arch/x86/kernel/irq.c
25469 +++ b/arch/x86/kernel/irq.c
25470 @@ -22,7 +22,7 @@
25471 #define CREATE_TRACE_POINTS
25472 #include <asm/trace/irq_vectors.h>
25473
25474 -atomic_t irq_err_count;
25475 +atomic_unchecked_t irq_err_count;
25476
25477 /* Function pointer for generic interrupt vector handling */
25478 void (*x86_platform_ipi_callback)(void) = NULL;
25479 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25480 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25481 seq_printf(p, " Hypervisor callback interrupts\n");
25482 #endif
25483 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25484 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25485 #if defined(CONFIG_X86_IO_APIC)
25486 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25487 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25488 #endif
25489 return 0;
25490 }
25491 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25492
25493 u64 arch_irq_stat(void)
25494 {
25495 - u64 sum = atomic_read(&irq_err_count);
25496 + u64 sum = atomic_read_unchecked(&irq_err_count);
25497 return sum;
25498 }
25499
25500 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25501 index 63ce838..2ea3e06 100644
25502 --- a/arch/x86/kernel/irq_32.c
25503 +++ b/arch/x86/kernel/irq_32.c
25504 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25505
25506 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25507
25508 +extern void gr_handle_kernel_exploit(void);
25509 +
25510 int sysctl_panic_on_stackoverflow __read_mostly;
25511
25512 /* Debugging check for stack overflow: is there less than 1KB free? */
25513 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25514 __asm__ __volatile__("andl %%esp,%0" :
25515 "=r" (sp) : "0" (THREAD_SIZE - 1));
25516
25517 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25518 + return sp < STACK_WARN;
25519 }
25520
25521 static void print_stack_overflow(void)
25522 {
25523 printk(KERN_WARNING "low stack detected by irq handler\n");
25524 dump_stack();
25525 + gr_handle_kernel_exploit();
25526 if (sysctl_panic_on_stackoverflow)
25527 panic("low stack detected by irq handler - check messages\n");
25528 }
25529 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25530 static inline int
25531 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25532 {
25533 - struct irq_stack *curstk, *irqstk;
25534 + struct irq_stack *irqstk;
25535 u32 *isp, *prev_esp, arg1, arg2;
25536
25537 - curstk = (struct irq_stack *) current_stack();
25538 irqstk = __this_cpu_read(hardirq_stack);
25539
25540 /*
25541 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25542 * handler) we can't do that and just have to keep using the
25543 * current stack (which is the irq stack already after all)
25544 */
25545 - if (unlikely(curstk == irqstk))
25546 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25547 return 0;
25548
25549 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25550 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25551
25552 /* Save the next esp at the bottom of the stack */
25553 prev_esp = (u32 *)irqstk;
25554 *prev_esp = current_stack_pointer;
25555
25556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25557 + __set_fs(MAKE_MM_SEG(0));
25558 +#endif
25559 +
25560 if (unlikely(overflow))
25561 call_on_stack(print_stack_overflow, isp);
25562
25563 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25564 : "0" (irq), "1" (desc), "2" (isp),
25565 "D" (desc->handle_irq)
25566 : "memory", "cc", "ecx");
25567 +
25568 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25569 + __set_fs(current_thread_info()->addr_limit);
25570 +#endif
25571 +
25572 return 1;
25573 }
25574
25575 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25576 */
25577 void irq_ctx_init(int cpu)
25578 {
25579 - struct irq_stack *irqstk;
25580 -
25581 if (per_cpu(hardirq_stack, cpu))
25582 return;
25583
25584 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25585 - THREADINFO_GFP,
25586 - THREAD_SIZE_ORDER));
25587 - per_cpu(hardirq_stack, cpu) = irqstk;
25588 -
25589 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25590 - THREADINFO_GFP,
25591 - THREAD_SIZE_ORDER));
25592 - per_cpu(softirq_stack, cpu) = irqstk;
25593 -
25594 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25595 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25596 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25597 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25598 }
25599
25600 void do_softirq_own_stack(void)
25601 {
25602 - struct thread_info *curstk;
25603 struct irq_stack *irqstk;
25604 u32 *isp, *prev_esp;
25605
25606 - curstk = current_stack();
25607 irqstk = __this_cpu_read(softirq_stack);
25608
25609 /* build the stack frame on the softirq stack */
25610 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25611 prev_esp = (u32 *)irqstk;
25612 *prev_esp = current_stack_pointer;
25613
25614 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25615 + __set_fs(MAKE_MM_SEG(0));
25616 +#endif
25617 +
25618 call_on_stack(__do_softirq, isp);
25619 +
25620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25621 + __set_fs(current_thread_info()->addr_limit);
25622 +#endif
25623 +
25624 }
25625
25626 bool handle_irq(unsigned irq, struct pt_regs *regs)
25627 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25628 if (unlikely(!desc))
25629 return false;
25630
25631 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25632 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25633 if (unlikely(overflow))
25634 print_stack_overflow();
25635 desc->handle_irq(irq, desc);
25636 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25637 index 4d1c746..55a22d6 100644
25638 --- a/arch/x86/kernel/irq_64.c
25639 +++ b/arch/x86/kernel/irq_64.c
25640 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25641 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25642 EXPORT_PER_CPU_SYMBOL(irq_regs);
25643
25644 +extern void gr_handle_kernel_exploit(void);
25645 +
25646 int sysctl_panic_on_stackoverflow;
25647
25648 /*
25649 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25650 u64 estack_top, estack_bottom;
25651 u64 curbase = (u64)task_stack_page(current);
25652
25653 - if (user_mode_vm(regs))
25654 + if (user_mode(regs))
25655 return;
25656
25657 if (regs->sp >= curbase + sizeof(struct thread_info) +
25658 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25659 irq_stack_top, irq_stack_bottom,
25660 estack_top, estack_bottom);
25661
25662 + gr_handle_kernel_exploit();
25663 +
25664 if (sysctl_panic_on_stackoverflow)
25665 panic("low stack detected by irq handler - check messages\n");
25666 #endif
25667 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25668 index 26d5a55..a01160a 100644
25669 --- a/arch/x86/kernel/jump_label.c
25670 +++ b/arch/x86/kernel/jump_label.c
25671 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25672 * Jump label is enabled for the first time.
25673 * So we expect a default_nop...
25674 */
25675 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25676 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25677 != 0))
25678 bug_at((void *)entry->code, __LINE__);
25679 } else {
25680 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25681 * ...otherwise expect an ideal_nop. Otherwise
25682 * something went horribly wrong.
25683 */
25684 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25685 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25686 != 0))
25687 bug_at((void *)entry->code, __LINE__);
25688 }
25689 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25690 * are converting the default nop to the ideal nop.
25691 */
25692 if (init) {
25693 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25694 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25695 bug_at((void *)entry->code, __LINE__);
25696 } else {
25697 code.jump = 0xe9;
25698 code.offset = entry->target -
25699 (entry->code + JUMP_LABEL_NOP_SIZE);
25700 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25701 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25702 bug_at((void *)entry->code, __LINE__);
25703 }
25704 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25705 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25706 index 7ec1d5f..5a7d130 100644
25707 --- a/arch/x86/kernel/kgdb.c
25708 +++ b/arch/x86/kernel/kgdb.c
25709 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25710 #ifdef CONFIG_X86_32
25711 switch (regno) {
25712 case GDB_SS:
25713 - if (!user_mode_vm(regs))
25714 + if (!user_mode(regs))
25715 *(unsigned long *)mem = __KERNEL_DS;
25716 break;
25717 case GDB_SP:
25718 - if (!user_mode_vm(regs))
25719 + if (!user_mode(regs))
25720 *(unsigned long *)mem = kernel_stack_pointer(regs);
25721 break;
25722 case GDB_GS:
25723 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25724 bp->attr.bp_addr = breakinfo[breakno].addr;
25725 bp->attr.bp_len = breakinfo[breakno].len;
25726 bp->attr.bp_type = breakinfo[breakno].type;
25727 - info->address = breakinfo[breakno].addr;
25728 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25729 + info->address = ktla_ktva(breakinfo[breakno].addr);
25730 + else
25731 + info->address = breakinfo[breakno].addr;
25732 info->len = breakinfo[breakno].len;
25733 info->type = breakinfo[breakno].type;
25734 val = arch_install_hw_breakpoint(bp);
25735 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25736 case 'k':
25737 /* clear the trace bit */
25738 linux_regs->flags &= ~X86_EFLAGS_TF;
25739 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25740 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25741
25742 /* set the trace bit if we're stepping */
25743 if (remcomInBuffer[0] == 's') {
25744 linux_regs->flags |= X86_EFLAGS_TF;
25745 - atomic_set(&kgdb_cpu_doing_single_step,
25746 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25747 raw_smp_processor_id());
25748 }
25749
25750 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25751
25752 switch (cmd) {
25753 case DIE_DEBUG:
25754 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25755 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25756 if (user_mode(regs))
25757 return single_step_cont(regs, args);
25758 break;
25759 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25760 #endif /* CONFIG_DEBUG_RODATA */
25761
25762 bpt->type = BP_BREAKPOINT;
25763 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25764 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25765 BREAK_INSTR_SIZE);
25766 if (err)
25767 return err;
25768 - err = probe_kernel_write((char *)bpt->bpt_addr,
25769 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25770 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25771 #ifdef CONFIG_DEBUG_RODATA
25772 if (!err)
25773 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25774 return -EBUSY;
25775 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25776 BREAK_INSTR_SIZE);
25777 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25778 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25779 if (err)
25780 return err;
25781 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25782 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25783 if (mutex_is_locked(&text_mutex))
25784 goto knl_write;
25785 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25786 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25787 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25788 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25789 goto knl_write;
25790 return err;
25791 knl_write:
25792 #endif /* CONFIG_DEBUG_RODATA */
25793 - return probe_kernel_write((char *)bpt->bpt_addr,
25794 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25795 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25796 }
25797
25798 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25799 index 67e6d19..731ed28 100644
25800 --- a/arch/x86/kernel/kprobes/core.c
25801 +++ b/arch/x86/kernel/kprobes/core.c
25802 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25803 s32 raddr;
25804 } __packed *insn;
25805
25806 - insn = (struct __arch_relative_insn *)from;
25807 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25808 +
25809 + pax_open_kernel();
25810 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25811 insn->op = op;
25812 + pax_close_kernel();
25813 }
25814
25815 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25816 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25817 kprobe_opcode_t opcode;
25818 kprobe_opcode_t *orig_opcodes = opcodes;
25819
25820 - if (search_exception_tables((unsigned long)opcodes))
25821 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25822 return 0; /* Page fault may occur on this address. */
25823
25824 retry:
25825 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25826 * for the first byte, we can recover the original instruction
25827 * from it and kp->opcode.
25828 */
25829 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25830 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25831 buf[0] = kp->opcode;
25832 - return (unsigned long)buf;
25833 + return ktva_ktla((unsigned long)buf);
25834 }
25835
25836 /*
25837 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25838 /* Another subsystem puts a breakpoint, failed to recover */
25839 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25840 return 0;
25841 + pax_open_kernel();
25842 memcpy(dest, insn.kaddr, insn.length);
25843 + pax_close_kernel();
25844
25845 #ifdef CONFIG_X86_64
25846 if (insn_rip_relative(&insn)) {
25847 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25848 return 0;
25849 }
25850 disp = (u8 *) dest + insn_offset_displacement(&insn);
25851 + pax_open_kernel();
25852 *(s32 *) disp = (s32) newdisp;
25853 + pax_close_kernel();
25854 }
25855 #endif
25856 return insn.length;
25857 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25858 * nor set current_kprobe, because it doesn't use single
25859 * stepping.
25860 */
25861 - regs->ip = (unsigned long)p->ainsn.insn;
25862 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25863 preempt_enable_no_resched();
25864 return;
25865 }
25866 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25867 regs->flags &= ~X86_EFLAGS_IF;
25868 /* single step inline if the instruction is an int3 */
25869 if (p->opcode == BREAKPOINT_INSTRUCTION)
25870 - regs->ip = (unsigned long)p->addr;
25871 + regs->ip = ktla_ktva((unsigned long)p->addr);
25872 else
25873 - regs->ip = (unsigned long)p->ainsn.insn;
25874 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25875 }
25876 NOKPROBE_SYMBOL(setup_singlestep);
25877
25878 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25879 struct kprobe *p;
25880 struct kprobe_ctlblk *kcb;
25881
25882 - if (user_mode_vm(regs))
25883 + if (user_mode(regs))
25884 return 0;
25885
25886 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25887 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25888 setup_singlestep(p, regs, kcb, 0);
25889 return 1;
25890 }
25891 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25892 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25893 /*
25894 * The breakpoint instruction was removed right
25895 * after we hit it. Another cpu has removed
25896 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25897 " movq %rax, 152(%rsp)\n"
25898 RESTORE_REGS_STRING
25899 " popfq\n"
25900 +#ifdef KERNEXEC_PLUGIN
25901 + " btsq $63,(%rsp)\n"
25902 +#endif
25903 #else
25904 " pushf\n"
25905 SAVE_REGS_STRING
25906 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25907 struct kprobe_ctlblk *kcb)
25908 {
25909 unsigned long *tos = stack_addr(regs);
25910 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25911 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25912 unsigned long orig_ip = (unsigned long)p->addr;
25913 kprobe_opcode_t *insn = p->ainsn.insn;
25914
25915 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25916 struct die_args *args = data;
25917 int ret = NOTIFY_DONE;
25918
25919 - if (args->regs && user_mode_vm(args->regs))
25920 + if (args->regs && user_mode(args->regs))
25921 return ret;
25922
25923 if (val == DIE_GPF) {
25924 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25925 index f1314d0..15f3154 100644
25926 --- a/arch/x86/kernel/kprobes/opt.c
25927 +++ b/arch/x86/kernel/kprobes/opt.c
25928 @@ -79,6 +79,7 @@ found:
25929 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25930 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25931 {
25932 + pax_open_kernel();
25933 #ifdef CONFIG_X86_64
25934 *addr++ = 0x48;
25935 *addr++ = 0xbf;
25936 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25937 *addr++ = 0xb8;
25938 #endif
25939 *(unsigned long *)addr = val;
25940 + pax_close_kernel();
25941 }
25942
25943 asm (
25944 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25945 * Verify if the address gap is in 2GB range, because this uses
25946 * a relative jump.
25947 */
25948 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25949 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25950 if (abs(rel) > 0x7fffffff) {
25951 __arch_remove_optimized_kprobe(op, 0);
25952 return -ERANGE;
25953 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25954 op->optinsn.size = ret;
25955
25956 /* Copy arch-dep-instance from template */
25957 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25958 + pax_open_kernel();
25959 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25960 + pax_close_kernel();
25961
25962 /* Set probe information */
25963 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25964
25965 /* Set probe function call */
25966 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25967 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25968
25969 /* Set returning jmp instruction at the tail of out-of-line buffer */
25970 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25971 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25972 (u8 *)op->kp.addr + op->optinsn.size);
25973
25974 flush_icache_range((unsigned long) buf,
25975 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25976 WARN_ON(kprobe_disabled(&op->kp));
25977
25978 /* Backup instructions which will be replaced by jump address */
25979 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25980 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25981 RELATIVE_ADDR_SIZE);
25982
25983 insn_buf[0] = RELATIVEJUMP_OPCODE;
25984 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25985 /* This kprobe is really able to run optimized path. */
25986 op = container_of(p, struct optimized_kprobe, kp);
25987 /* Detour through copied instructions */
25988 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25989 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25990 if (!reenter)
25991 reset_current_kprobe();
25992 preempt_enable_no_resched();
25993 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25994 index c2bedae..25e7ab60 100644
25995 --- a/arch/x86/kernel/ksysfs.c
25996 +++ b/arch/x86/kernel/ksysfs.c
25997 @@ -184,7 +184,7 @@ out:
25998
25999 static struct kobj_attribute type_attr = __ATTR_RO(type);
26000
26001 -static struct bin_attribute data_attr = {
26002 +static bin_attribute_no_const data_attr __read_only = {
26003 .attr = {
26004 .name = "data",
26005 .mode = S_IRUGO,
26006 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26007 index c37886d..d851d32 100644
26008 --- a/arch/x86/kernel/ldt.c
26009 +++ b/arch/x86/kernel/ldt.c
26010 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26011 if (reload) {
26012 #ifdef CONFIG_SMP
26013 preempt_disable();
26014 - load_LDT(pc);
26015 + load_LDT_nolock(pc);
26016 if (!cpumask_equal(mm_cpumask(current->mm),
26017 cpumask_of(smp_processor_id())))
26018 smp_call_function(flush_ldt, current->mm, 1);
26019 preempt_enable();
26020 #else
26021 - load_LDT(pc);
26022 + load_LDT_nolock(pc);
26023 #endif
26024 }
26025 if (oldsize) {
26026 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26027 return err;
26028
26029 for (i = 0; i < old->size; i++)
26030 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26031 + write_ldt_entry(new->ldt, i, old->ldt + i);
26032 return 0;
26033 }
26034
26035 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26036 retval = copy_ldt(&mm->context, &old_mm->context);
26037 mutex_unlock(&old_mm->context.lock);
26038 }
26039 +
26040 + if (tsk == current) {
26041 + mm->context.vdso = 0;
26042 +
26043 +#ifdef CONFIG_X86_32
26044 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26045 + mm->context.user_cs_base = 0UL;
26046 + mm->context.user_cs_limit = ~0UL;
26047 +
26048 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26049 + cpus_clear(mm->context.cpu_user_cs_mask);
26050 +#endif
26051 +
26052 +#endif
26053 +#endif
26054 +
26055 + }
26056 +
26057 return retval;
26058 }
26059
26060 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26061 }
26062 }
26063
26064 +#ifdef CONFIG_PAX_SEGMEXEC
26065 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26066 + error = -EINVAL;
26067 + goto out_unlock;
26068 + }
26069 +#endif
26070 +
26071 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26072 error = -EINVAL;
26073 goto out_unlock;
26074 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26075 index 1667b1d..16492c5 100644
26076 --- a/arch/x86/kernel/machine_kexec_32.c
26077 +++ b/arch/x86/kernel/machine_kexec_32.c
26078 @@ -25,7 +25,7 @@
26079 #include <asm/cacheflush.h>
26080 #include <asm/debugreg.h>
26081
26082 -static void set_idt(void *newidt, __u16 limit)
26083 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26084 {
26085 struct desc_ptr curidt;
26086
26087 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26088 }
26089
26090
26091 -static void set_gdt(void *newgdt, __u16 limit)
26092 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26093 {
26094 struct desc_ptr curgdt;
26095
26096 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26097 }
26098
26099 control_page = page_address(image->control_code_page);
26100 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26101 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26102
26103 relocate_kernel_ptr = control_page;
26104 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26105 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26106 index c73aecf..4c63630 100644
26107 --- a/arch/x86/kernel/mcount_64.S
26108 +++ b/arch/x86/kernel/mcount_64.S
26109 @@ -7,7 +7,7 @@
26110 #include <linux/linkage.h>
26111 #include <asm/ptrace.h>
26112 #include <asm/ftrace.h>
26113 -
26114 +#include <asm/alternative-asm.h>
26115
26116 .code64
26117 .section .entry.text, "ax"
26118 @@ -24,8 +24,9 @@
26119 #ifdef CONFIG_DYNAMIC_FTRACE
26120
26121 ENTRY(function_hook)
26122 + pax_force_retaddr
26123 retq
26124 -END(function_hook)
26125 +ENDPROC(function_hook)
26126
26127 /* skip is set if stack has been adjusted */
26128 .macro ftrace_caller_setup skip=0
26129 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26130 #endif
26131
26132 GLOBAL(ftrace_stub)
26133 + pax_force_retaddr
26134 retq
26135 -END(ftrace_caller)
26136 +ENDPROC(ftrace_caller)
26137
26138 ENTRY(ftrace_regs_caller)
26139 /* Save the current flags before compare (in SS location)*/
26140 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26141 popfq
26142 jmp ftrace_stub
26143
26144 -END(ftrace_regs_caller)
26145 +ENDPROC(ftrace_regs_caller)
26146
26147
26148 #else /* ! CONFIG_DYNAMIC_FTRACE */
26149 @@ -145,6 +147,7 @@ ENTRY(function_hook)
26150 #endif
26151
26152 GLOBAL(ftrace_stub)
26153 + pax_force_retaddr
26154 retq
26155
26156 trace:
26157 @@ -158,12 +161,13 @@ trace:
26158 #endif
26159 subq $MCOUNT_INSN_SIZE, %rdi
26160
26161 + pax_force_fptr ftrace_trace_function
26162 call *ftrace_trace_function
26163
26164 MCOUNT_RESTORE_FRAME
26165
26166 jmp ftrace_stub
26167 -END(function_hook)
26168 +ENDPROC(function_hook)
26169 #endif /* CONFIG_DYNAMIC_FTRACE */
26170 #endif /* CONFIG_FUNCTION_TRACER */
26171
26172 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26173
26174 MCOUNT_RESTORE_FRAME
26175
26176 + pax_force_retaddr
26177 retq
26178 -END(ftrace_graph_caller)
26179 +ENDPROC(ftrace_graph_caller)
26180
26181 GLOBAL(return_to_handler)
26182 subq $24, %rsp
26183 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26184 movq 8(%rsp), %rdx
26185 movq (%rsp), %rax
26186 addq $24, %rsp
26187 + pax_force_fptr %rdi
26188 jmp *%rdi
26189 +ENDPROC(return_to_handler)
26190 #endif
26191 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26192 index e69f988..da078ea 100644
26193 --- a/arch/x86/kernel/module.c
26194 +++ b/arch/x86/kernel/module.c
26195 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26196 }
26197 #endif
26198
26199 -void *module_alloc(unsigned long size)
26200 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26201 {
26202 - if (PAGE_ALIGN(size) > MODULES_LEN)
26203 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26204 return NULL;
26205 return __vmalloc_node_range(size, 1,
26206 MODULES_VADDR + get_module_load_offset(),
26207 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26208 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26209 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26210 + prot, NUMA_NO_NODE,
26211 __builtin_return_address(0));
26212 }
26213
26214 +void *module_alloc(unsigned long size)
26215 +{
26216 +
26217 +#ifdef CONFIG_PAX_KERNEXEC
26218 + return __module_alloc(size, PAGE_KERNEL);
26219 +#else
26220 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26221 +#endif
26222 +
26223 +}
26224 +
26225 +#ifdef CONFIG_PAX_KERNEXEC
26226 +#ifdef CONFIG_X86_32
26227 +void *module_alloc_exec(unsigned long size)
26228 +{
26229 + struct vm_struct *area;
26230 +
26231 + if (size == 0)
26232 + return NULL;
26233 +
26234 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26235 +return area ? area->addr : NULL;
26236 +}
26237 +EXPORT_SYMBOL(module_alloc_exec);
26238 +
26239 +void module_free_exec(struct module *mod, void *module_region)
26240 +{
26241 + vunmap(module_region);
26242 +}
26243 +EXPORT_SYMBOL(module_free_exec);
26244 +#else
26245 +void module_free_exec(struct module *mod, void *module_region)
26246 +{
26247 + module_free(mod, module_region);
26248 +}
26249 +EXPORT_SYMBOL(module_free_exec);
26250 +
26251 +void *module_alloc_exec(unsigned long size)
26252 +{
26253 + return __module_alloc(size, PAGE_KERNEL_RX);
26254 +}
26255 +EXPORT_SYMBOL(module_alloc_exec);
26256 +#endif
26257 +#endif
26258 +
26259 #ifdef CONFIG_X86_32
26260 int apply_relocate(Elf32_Shdr *sechdrs,
26261 const char *strtab,
26262 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26263 unsigned int i;
26264 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26265 Elf32_Sym *sym;
26266 - uint32_t *location;
26267 + uint32_t *plocation, location;
26268
26269 DEBUGP("Applying relocate section %u to %u\n",
26270 relsec, sechdrs[relsec].sh_info);
26271 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26272 /* This is where to make the change */
26273 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26274 - + rel[i].r_offset;
26275 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26276 + location = (uint32_t)plocation;
26277 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26278 + plocation = ktla_ktva((void *)plocation);
26279 /* This is the symbol it is referring to. Note that all
26280 undefined symbols have been resolved. */
26281 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26282 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26283 switch (ELF32_R_TYPE(rel[i].r_info)) {
26284 case R_386_32:
26285 /* We add the value into the location given */
26286 - *location += sym->st_value;
26287 + pax_open_kernel();
26288 + *plocation += sym->st_value;
26289 + pax_close_kernel();
26290 break;
26291 case R_386_PC32:
26292 /* Add the value, subtract its position */
26293 - *location += sym->st_value - (uint32_t)location;
26294 + pax_open_kernel();
26295 + *plocation += sym->st_value - location;
26296 + pax_close_kernel();
26297 break;
26298 default:
26299 pr_err("%s: Unknown relocation: %u\n",
26300 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26301 case R_X86_64_NONE:
26302 break;
26303 case R_X86_64_64:
26304 + pax_open_kernel();
26305 *(u64 *)loc = val;
26306 + pax_close_kernel();
26307 break;
26308 case R_X86_64_32:
26309 + pax_open_kernel();
26310 *(u32 *)loc = val;
26311 + pax_close_kernel();
26312 if (val != *(u32 *)loc)
26313 goto overflow;
26314 break;
26315 case R_X86_64_32S:
26316 + pax_open_kernel();
26317 *(s32 *)loc = val;
26318 + pax_close_kernel();
26319 if ((s64)val != *(s32 *)loc)
26320 goto overflow;
26321 break;
26322 case R_X86_64_PC32:
26323 val -= (u64)loc;
26324 + pax_open_kernel();
26325 *(u32 *)loc = val;
26326 + pax_close_kernel();
26327 +
26328 #if 0
26329 if ((s64)val != *(s32 *)loc)
26330 goto overflow;
26331 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26332 index c9603ac..9f88728 100644
26333 --- a/arch/x86/kernel/msr.c
26334 +++ b/arch/x86/kernel/msr.c
26335 @@ -37,6 +37,7 @@
26336 #include <linux/notifier.h>
26337 #include <linux/uaccess.h>
26338 #include <linux/gfp.h>
26339 +#include <linux/grsecurity.h>
26340
26341 #include <asm/processor.h>
26342 #include <asm/msr.h>
26343 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26344 int err = 0;
26345 ssize_t bytes = 0;
26346
26347 +#ifdef CONFIG_GRKERNSEC_KMEM
26348 + gr_handle_msr_write();
26349 + return -EPERM;
26350 +#endif
26351 +
26352 if (count % 8)
26353 return -EINVAL; /* Invalid chunk size */
26354
26355 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26356 err = -EBADF;
26357 break;
26358 }
26359 +#ifdef CONFIG_GRKERNSEC_KMEM
26360 + gr_handle_msr_write();
26361 + return -EPERM;
26362 +#endif
26363 if (copy_from_user(&regs, uregs, sizeof regs)) {
26364 err = -EFAULT;
26365 break;
26366 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26367 return notifier_from_errno(err);
26368 }
26369
26370 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26371 +static struct notifier_block msr_class_cpu_notifier = {
26372 .notifier_call = msr_class_cpu_callback,
26373 };
26374
26375 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26376 index c3e985d..110a36a 100644
26377 --- a/arch/x86/kernel/nmi.c
26378 +++ b/arch/x86/kernel/nmi.c
26379 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26380
26381 static void nmi_max_handler(struct irq_work *w)
26382 {
26383 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26384 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26385 int remainder_ns, decimal_msecs;
26386 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26387 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26388
26389 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26390 decimal_msecs = remainder_ns / 1000;
26391
26392 printk_ratelimited(KERN_INFO
26393 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26394 - a->handler, whole_msecs, decimal_msecs);
26395 + n->action->handler, whole_msecs, decimal_msecs);
26396 }
26397
26398 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26399 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26400 delta = sched_clock() - delta;
26401 trace_nmi_handler(a->handler, (int)delta, thishandled);
26402
26403 - if (delta < nmi_longest_ns || delta < a->max_duration)
26404 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26405 continue;
26406
26407 - a->max_duration = delta;
26408 - irq_work_queue(&a->irq_work);
26409 + a->work->max_duration = delta;
26410 + irq_work_queue(&a->work->irq_work);
26411 }
26412
26413 rcu_read_unlock();
26414 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26415 }
26416 NOKPROBE_SYMBOL(nmi_handle);
26417
26418 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26419 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26420 {
26421 struct nmi_desc *desc = nmi_to_desc(type);
26422 unsigned long flags;
26423 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26424 if (!action->handler)
26425 return -EINVAL;
26426
26427 - init_irq_work(&action->irq_work, nmi_max_handler);
26428 + action->work->action = action;
26429 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26430
26431 spin_lock_irqsave(&desc->lock, flags);
26432
26433 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26434 * event confuses some handlers (kdump uses this flag)
26435 */
26436 if (action->flags & NMI_FLAG_FIRST)
26437 - list_add_rcu(&action->list, &desc->head);
26438 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26439 else
26440 - list_add_tail_rcu(&action->list, &desc->head);
26441 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26442
26443 spin_unlock_irqrestore(&desc->lock, flags);
26444 return 0;
26445 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26446 if (!strcmp(n->name, name)) {
26447 WARN(in_nmi(),
26448 "Trying to free NMI (%s) from NMI context!\n", n->name);
26449 - list_del_rcu(&n->list);
26450 + pax_list_del_rcu((struct list_head *)&n->list);
26451 break;
26452 }
26453 }
26454 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26455 dotraplinkage notrace void
26456 do_nmi(struct pt_regs *regs, long error_code)
26457 {
26458 +
26459 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26460 + if (!user_mode(regs)) {
26461 + unsigned long cs = regs->cs & 0xFFFF;
26462 + unsigned long ip = ktva_ktla(regs->ip);
26463 +
26464 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26465 + regs->ip = ip;
26466 + }
26467 +#endif
26468 +
26469 nmi_nesting_preprocess(regs);
26470
26471 nmi_enter();
26472 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26473 index 6d9582e..f746287 100644
26474 --- a/arch/x86/kernel/nmi_selftest.c
26475 +++ b/arch/x86/kernel/nmi_selftest.c
26476 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26477 {
26478 /* trap all the unknown NMIs we may generate */
26479 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26480 - __initdata);
26481 + __initconst);
26482 }
26483
26484 static void __init cleanup_nmi_testsuite(void)
26485 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26486 unsigned long timeout;
26487
26488 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26489 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26490 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26491 nmi_fail = FAILURE;
26492 return;
26493 }
26494 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26495 index bbb6c73..24a58ef 100644
26496 --- a/arch/x86/kernel/paravirt-spinlocks.c
26497 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26498 @@ -8,7 +8,7 @@
26499
26500 #include <asm/paravirt.h>
26501
26502 -struct pv_lock_ops pv_lock_ops = {
26503 +struct pv_lock_ops pv_lock_ops __read_only = {
26504 #ifdef CONFIG_SMP
26505 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26506 .unlock_kick = paravirt_nop,
26507 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26508 index 548d25f..f8fb99c 100644
26509 --- a/arch/x86/kernel/paravirt.c
26510 +++ b/arch/x86/kernel/paravirt.c
26511 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26512 {
26513 return x;
26514 }
26515 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26516 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26517 +#endif
26518
26519 void __init default_banner(void)
26520 {
26521 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26522
26523 if (opfunc == NULL)
26524 /* If there's no function, patch it with a ud2a (BUG) */
26525 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26526 - else if (opfunc == _paravirt_nop)
26527 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26528 + else if (opfunc == (void *)_paravirt_nop)
26529 /* If the operation is a nop, then nop the callsite */
26530 ret = paravirt_patch_nop();
26531
26532 /* identity functions just return their single argument */
26533 - else if (opfunc == _paravirt_ident_32)
26534 + else if (opfunc == (void *)_paravirt_ident_32)
26535 ret = paravirt_patch_ident_32(insnbuf, len);
26536 - else if (opfunc == _paravirt_ident_64)
26537 + else if (opfunc == (void *)_paravirt_ident_64)
26538 ret = paravirt_patch_ident_64(insnbuf, len);
26539 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26540 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26541 + ret = paravirt_patch_ident_64(insnbuf, len);
26542 +#endif
26543
26544 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26545 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26546 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26547 if (insn_len > len || start == NULL)
26548 insn_len = len;
26549 else
26550 - memcpy(insnbuf, start, insn_len);
26551 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26552
26553 return insn_len;
26554 }
26555 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26556 return this_cpu_read(paravirt_lazy_mode);
26557 }
26558
26559 -struct pv_info pv_info = {
26560 +struct pv_info pv_info __read_only = {
26561 .name = "bare hardware",
26562 .paravirt_enabled = 0,
26563 .kernel_rpl = 0,
26564 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26565 #endif
26566 };
26567
26568 -struct pv_init_ops pv_init_ops = {
26569 +struct pv_init_ops pv_init_ops __read_only = {
26570 .patch = native_patch,
26571 };
26572
26573 -struct pv_time_ops pv_time_ops = {
26574 +struct pv_time_ops pv_time_ops __read_only = {
26575 .sched_clock = native_sched_clock,
26576 .steal_clock = native_steal_clock,
26577 };
26578
26579 -__visible struct pv_irq_ops pv_irq_ops = {
26580 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26581 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26582 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26583 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26584 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26585 #endif
26586 };
26587
26588 -__visible struct pv_cpu_ops pv_cpu_ops = {
26589 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26590 .cpuid = native_cpuid,
26591 .get_debugreg = native_get_debugreg,
26592 .set_debugreg = native_set_debugreg,
26593 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26594 NOKPROBE_SYMBOL(native_set_debugreg);
26595 NOKPROBE_SYMBOL(native_load_idt);
26596
26597 -struct pv_apic_ops pv_apic_ops = {
26598 +struct pv_apic_ops pv_apic_ops __read_only= {
26599 #ifdef CONFIG_X86_LOCAL_APIC
26600 .startup_ipi_hook = paravirt_nop,
26601 #endif
26602 };
26603
26604 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26605 +#ifdef CONFIG_X86_32
26606 +#ifdef CONFIG_X86_PAE
26607 +/* 64-bit pagetable entries */
26608 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26609 +#else
26610 /* 32-bit pagetable entries */
26611 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26612 +#endif
26613 #else
26614 /* 64-bit pagetable entries */
26615 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26616 #endif
26617
26618 -struct pv_mmu_ops pv_mmu_ops = {
26619 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26620
26621 .read_cr2 = native_read_cr2,
26622 .write_cr2 = native_write_cr2,
26623 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26624 .make_pud = PTE_IDENT,
26625
26626 .set_pgd = native_set_pgd,
26627 + .set_pgd_batched = native_set_pgd_batched,
26628 #endif
26629 #endif /* PAGETABLE_LEVELS >= 3 */
26630
26631 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26632 },
26633
26634 .set_fixmap = native_set_fixmap,
26635 +
26636 +#ifdef CONFIG_PAX_KERNEXEC
26637 + .pax_open_kernel = native_pax_open_kernel,
26638 + .pax_close_kernel = native_pax_close_kernel,
26639 +#endif
26640 +
26641 };
26642
26643 EXPORT_SYMBOL_GPL(pv_time_ops);
26644 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26645 index 0497f71..7186c0d 100644
26646 --- a/arch/x86/kernel/pci-calgary_64.c
26647 +++ b/arch/x86/kernel/pci-calgary_64.c
26648 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26649 tce_space = be64_to_cpu(readq(target));
26650 tce_space = tce_space & TAR_SW_BITS;
26651
26652 - tce_space = tce_space & (~specified_table_size);
26653 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26654 info->tce_space = (u64 *)__va(tce_space);
26655 }
26656 }
26657 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26658 index 35ccf75..7a15747 100644
26659 --- a/arch/x86/kernel/pci-iommu_table.c
26660 +++ b/arch/x86/kernel/pci-iommu_table.c
26661 @@ -2,7 +2,7 @@
26662 #include <asm/iommu_table.h>
26663 #include <linux/string.h>
26664 #include <linux/kallsyms.h>
26665 -
26666 +#include <linux/sched.h>
26667
26668 #define DEBUG 1
26669
26670 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26671 index 77dd0ad..9ec4723 100644
26672 --- a/arch/x86/kernel/pci-swiotlb.c
26673 +++ b/arch/x86/kernel/pci-swiotlb.c
26674 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26675 struct dma_attrs *attrs)
26676 {
26677 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26678 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26679 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26680 else
26681 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26682 }
26683 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26684 index ca7f0d5..8996469 100644
26685 --- a/arch/x86/kernel/preempt.S
26686 +++ b/arch/x86/kernel/preempt.S
26687 @@ -3,12 +3,14 @@
26688 #include <asm/dwarf2.h>
26689 #include <asm/asm.h>
26690 #include <asm/calling.h>
26691 +#include <asm/alternative-asm.h>
26692
26693 ENTRY(___preempt_schedule)
26694 CFI_STARTPROC
26695 SAVE_ALL
26696 call preempt_schedule
26697 RESTORE_ALL
26698 + pax_force_retaddr
26699 ret
26700 CFI_ENDPROC
26701
26702 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26703 SAVE_ALL
26704 call preempt_schedule_context
26705 RESTORE_ALL
26706 + pax_force_retaddr
26707 ret
26708 CFI_ENDPROC
26709
26710 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26711 index f804dc9..7c62095 100644
26712 --- a/arch/x86/kernel/process.c
26713 +++ b/arch/x86/kernel/process.c
26714 @@ -36,7 +36,8 @@
26715 * section. Since TSS's are completely CPU-local, we want them
26716 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26717 */
26718 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26719 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26720 +EXPORT_SYMBOL(init_tss);
26721
26722 #ifdef CONFIG_X86_64
26723 static DEFINE_PER_CPU(unsigned char, is_idle);
26724 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26725 task_xstate_cachep =
26726 kmem_cache_create("task_xstate", xstate_size,
26727 __alignof__(union thread_xstate),
26728 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26729 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26730 setup_xstate_comp();
26731 }
26732
26733 @@ -106,7 +107,7 @@ void exit_thread(void)
26734 unsigned long *bp = t->io_bitmap_ptr;
26735
26736 if (bp) {
26737 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26738 + struct tss_struct *tss = init_tss + get_cpu();
26739
26740 t->io_bitmap_ptr = NULL;
26741 clear_thread_flag(TIF_IO_BITMAP);
26742 @@ -126,6 +127,9 @@ void flush_thread(void)
26743 {
26744 struct task_struct *tsk = current;
26745
26746 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26747 + loadsegment(gs, 0);
26748 +#endif
26749 flush_ptrace_hw_breakpoint(tsk);
26750 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26751 drop_init_fpu(tsk);
26752 @@ -272,7 +276,7 @@ static void __exit_idle(void)
26753 void exit_idle(void)
26754 {
26755 /* idle loop has pid 0 */
26756 - if (current->pid)
26757 + if (task_pid_nr(current))
26758 return;
26759 __exit_idle();
26760 }
26761 @@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
26762 return ret;
26763 }
26764 #endif
26765 -void stop_this_cpu(void *dummy)
26766 +__noreturn void stop_this_cpu(void *dummy)
26767 {
26768 local_irq_disable();
26769 /*
26770 @@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
26771 }
26772 early_param("idle", idle_setup);
26773
26774 -unsigned long arch_align_stack(unsigned long sp)
26775 +#ifdef CONFIG_PAX_RANDKSTACK
26776 +void pax_randomize_kstack(struct pt_regs *regs)
26777 {
26778 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26779 - sp -= get_random_int() % 8192;
26780 - return sp & ~0xf;
26781 -}
26782 + struct thread_struct *thread = &current->thread;
26783 + unsigned long time;
26784
26785 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26786 -{
26787 - unsigned long range_end = mm->brk + 0x02000000;
26788 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26789 -}
26790 + if (!randomize_va_space)
26791 + return;
26792 +
26793 + if (v8086_mode(regs))
26794 + return;
26795
26796 + rdtscl(time);
26797 +
26798 + /* P4 seems to return a 0 LSB, ignore it */
26799 +#ifdef CONFIG_MPENTIUM4
26800 + time &= 0x3EUL;
26801 + time <<= 2;
26802 +#elif defined(CONFIG_X86_64)
26803 + time &= 0xFUL;
26804 + time <<= 4;
26805 +#else
26806 + time &= 0x1FUL;
26807 + time <<= 3;
26808 +#endif
26809 +
26810 + thread->sp0 ^= time;
26811 + load_sp0(init_tss + smp_processor_id(), thread);
26812 +
26813 +#ifdef CONFIG_X86_64
26814 + this_cpu_write(kernel_stack, thread->sp0);
26815 +#endif
26816 +}
26817 +#endif
26818 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26819 index 7bc86bb..0ea06e8 100644
26820 --- a/arch/x86/kernel/process_32.c
26821 +++ b/arch/x86/kernel/process_32.c
26822 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26823 unsigned long thread_saved_pc(struct task_struct *tsk)
26824 {
26825 return ((unsigned long *)tsk->thread.sp)[3];
26826 +//XXX return tsk->thread.eip;
26827 }
26828
26829 void __show_regs(struct pt_regs *regs, int all)
26830 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26831 unsigned long sp;
26832 unsigned short ss, gs;
26833
26834 - if (user_mode_vm(regs)) {
26835 + if (user_mode(regs)) {
26836 sp = regs->sp;
26837 ss = regs->ss & 0xffff;
26838 - gs = get_user_gs(regs);
26839 } else {
26840 sp = kernel_stack_pointer(regs);
26841 savesegment(ss, ss);
26842 - savesegment(gs, gs);
26843 }
26844 + gs = get_user_gs(regs);
26845
26846 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26847 (u16)regs->cs, regs->ip, regs->flags,
26848 - smp_processor_id());
26849 + raw_smp_processor_id());
26850 print_symbol("EIP is at %s\n", regs->ip);
26851
26852 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26853 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26854 int copy_thread(unsigned long clone_flags, unsigned long sp,
26855 unsigned long arg, struct task_struct *p)
26856 {
26857 - struct pt_regs *childregs = task_pt_regs(p);
26858 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26859 struct task_struct *tsk;
26860 int err;
26861
26862 p->thread.sp = (unsigned long) childregs;
26863 p->thread.sp0 = (unsigned long) (childregs+1);
26864 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26865
26866 if (unlikely(p->flags & PF_KTHREAD)) {
26867 /* kernel thread */
26868 memset(childregs, 0, sizeof(struct pt_regs));
26869 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26870 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26871 - childregs->ds = __USER_DS;
26872 - childregs->es = __USER_DS;
26873 + savesegment(gs, childregs->gs);
26874 + childregs->ds = __KERNEL_DS;
26875 + childregs->es = __KERNEL_DS;
26876 childregs->fs = __KERNEL_PERCPU;
26877 childregs->bx = sp; /* function */
26878 childregs->bp = arg;
26879 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26880 struct thread_struct *prev = &prev_p->thread,
26881 *next = &next_p->thread;
26882 int cpu = smp_processor_id();
26883 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26884 + struct tss_struct *tss = init_tss + cpu;
26885 fpu_switch_t fpu;
26886
26887 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26888 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26889 */
26890 lazy_save_gs(prev->gs);
26891
26892 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26893 + __set_fs(task_thread_info(next_p)->addr_limit);
26894 +#endif
26895 +
26896 /*
26897 * Load the per-thread Thread-Local Storage descriptor.
26898 */
26899 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26900 */
26901 arch_end_context_switch(next_p);
26902
26903 - this_cpu_write(kernel_stack,
26904 - (unsigned long)task_stack_page(next_p) +
26905 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26906 + this_cpu_write(current_task, next_p);
26907 + this_cpu_write(current_tinfo, &next_p->tinfo);
26908 + this_cpu_write(kernel_stack, next->sp0);
26909
26910 /*
26911 * Restore %gs if needed (which is common)
26912 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26913
26914 switch_fpu_finish(next_p, fpu);
26915
26916 - this_cpu_write(current_task, next_p);
26917 -
26918 return prev_p;
26919 }
26920
26921 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26922 } while (count++ < 16);
26923 return 0;
26924 }
26925 -
26926 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26927 index ca5b02d..c0b2f6a 100644
26928 --- a/arch/x86/kernel/process_64.c
26929 +++ b/arch/x86/kernel/process_64.c
26930 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26931 struct pt_regs *childregs;
26932 struct task_struct *me = current;
26933
26934 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26935 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26936 childregs = task_pt_regs(p);
26937 p->thread.sp = (unsigned long) childregs;
26938 p->thread.usersp = me->thread.usersp;
26939 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26940 set_tsk_thread_flag(p, TIF_FORK);
26941 p->thread.fpu_counter = 0;
26942 p->thread.io_bitmap_ptr = NULL;
26943 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26944 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26945 savesegment(es, p->thread.es);
26946 savesegment(ds, p->thread.ds);
26947 + savesegment(ss, p->thread.ss);
26948 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26949 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26950
26951 if (unlikely(p->flags & PF_KTHREAD)) {
26952 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26953 struct thread_struct *prev = &prev_p->thread;
26954 struct thread_struct *next = &next_p->thread;
26955 int cpu = smp_processor_id();
26956 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26957 + struct tss_struct *tss = init_tss + cpu;
26958 unsigned fsindex, gsindex;
26959 fpu_switch_t fpu;
26960
26961 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26962 if (unlikely(next->ds | prev->ds))
26963 loadsegment(ds, next->ds);
26964
26965 + savesegment(ss, prev->ss);
26966 + if (unlikely(next->ss != prev->ss))
26967 + loadsegment(ss, next->ss);
26968
26969 /* We must save %fs and %gs before load_TLS() because
26970 * %fs and %gs may be cleared by load_TLS().
26971 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26972 prev->usersp = this_cpu_read(old_rsp);
26973 this_cpu_write(old_rsp, next->usersp);
26974 this_cpu_write(current_task, next_p);
26975 + this_cpu_write(current_tinfo, &next_p->tinfo);
26976
26977 /*
26978 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26979 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26980 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26981 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26982
26983 - this_cpu_write(kernel_stack,
26984 - (unsigned long)task_stack_page(next_p) +
26985 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26986 + this_cpu_write(kernel_stack, next->sp0);
26987
26988 /*
26989 * Now maybe reload the debug registers and handle I/O bitmaps
26990 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
26991 if (!p || p == current || p->state == TASK_RUNNING)
26992 return 0;
26993 stack = (unsigned long)task_stack_page(p);
26994 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26995 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26996 return 0;
26997 fp = *(u64 *)(p->thread.sp);
26998 do {
26999 - if (fp < (unsigned long)stack ||
27000 - fp >= (unsigned long)stack+THREAD_SIZE)
27001 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27002 return 0;
27003 ip = *(u64 *)(fp+8);
27004 if (!in_sched_functions(ip))
27005 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27006 index 678c0ad..2fc2a7b 100644
27007 --- a/arch/x86/kernel/ptrace.c
27008 +++ b/arch/x86/kernel/ptrace.c
27009 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27010 unsigned long sp = (unsigned long)&regs->sp;
27011 u32 *prev_esp;
27012
27013 - if (context == (sp & ~(THREAD_SIZE - 1)))
27014 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27015 return sp;
27016
27017 - prev_esp = (u32 *)(context);
27018 + prev_esp = *(u32 **)(context);
27019 if (prev_esp)
27020 return (unsigned long)prev_esp;
27021
27022 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27023 if (child->thread.gs != value)
27024 return do_arch_prctl(child, ARCH_SET_GS, value);
27025 return 0;
27026 +
27027 + case offsetof(struct user_regs_struct,ip):
27028 + /*
27029 + * Protect against any attempt to set ip to an
27030 + * impossible address. There are dragons lurking if the
27031 + * address is noncanonical. (This explicitly allows
27032 + * setting ip to TASK_SIZE_MAX, because user code can do
27033 + * that all by itself by running off the end of its
27034 + * address space.
27035 + */
27036 + if (value > TASK_SIZE_MAX)
27037 + return -EIO;
27038 + break;
27039 +
27040 #endif
27041 }
27042
27043 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27044 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27045 {
27046 int i;
27047 - int dr7 = 0;
27048 + unsigned long dr7 = 0;
27049 struct arch_hw_breakpoint *info;
27050
27051 for (i = 0; i < HBP_NUM; i++) {
27052 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27053 unsigned long addr, unsigned long data)
27054 {
27055 int ret;
27056 - unsigned long __user *datap = (unsigned long __user *)data;
27057 + unsigned long __user *datap = (__force unsigned long __user *)data;
27058
27059 switch (request) {
27060 /* read the word at location addr in the USER area. */
27061 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27062 if ((int) addr < 0)
27063 return -EIO;
27064 ret = do_get_thread_area(child, addr,
27065 - (struct user_desc __user *)data);
27066 + (__force struct user_desc __user *) data);
27067 break;
27068
27069 case PTRACE_SET_THREAD_AREA:
27070 if ((int) addr < 0)
27071 return -EIO;
27072 ret = do_set_thread_area(child, addr,
27073 - (struct user_desc __user *)data, 0);
27074 + (__force struct user_desc __user *) data, 0);
27075 break;
27076 #endif
27077
27078 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27079
27080 #ifdef CONFIG_X86_64
27081
27082 -static struct user_regset x86_64_regsets[] __read_mostly = {
27083 +static user_regset_no_const x86_64_regsets[] __read_only = {
27084 [REGSET_GENERAL] = {
27085 .core_note_type = NT_PRSTATUS,
27086 .n = sizeof(struct user_regs_struct) / sizeof(long),
27087 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27088 #endif /* CONFIG_X86_64 */
27089
27090 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27091 -static struct user_regset x86_32_regsets[] __read_mostly = {
27092 +static user_regset_no_const x86_32_regsets[] __read_only = {
27093 [REGSET_GENERAL] = {
27094 .core_note_type = NT_PRSTATUS,
27095 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27096 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27097 */
27098 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27099
27100 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27101 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27102 {
27103 #ifdef CONFIG_X86_64
27104 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27105 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27106 memset(info, 0, sizeof(*info));
27107 info->si_signo = SIGTRAP;
27108 info->si_code = si_code;
27109 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27110 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27111 }
27112
27113 void user_single_step_siginfo(struct task_struct *tsk,
27114 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27115 # define IS_IA32 0
27116 #endif
27117
27118 +#ifdef CONFIG_GRKERNSEC_SETXID
27119 +extern void gr_delayed_cred_worker(void);
27120 +#endif
27121 +
27122 /*
27123 * We must return the syscall number to actually look up in the table.
27124 * This can be -1L to skip running any syscall at all.
27125 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27126
27127 user_exit();
27128
27129 +#ifdef CONFIG_GRKERNSEC_SETXID
27130 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27131 + gr_delayed_cred_worker();
27132 +#endif
27133 +
27134 /*
27135 * If we stepped into a sysenter/syscall insn, it trapped in
27136 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27137 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27138 */
27139 user_exit();
27140
27141 +#ifdef CONFIG_GRKERNSEC_SETXID
27142 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27143 + gr_delayed_cred_worker();
27144 +#endif
27145 +
27146 audit_syscall_exit(regs);
27147
27148 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27149 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27150 index 2f355d2..e75ed0a 100644
27151 --- a/arch/x86/kernel/pvclock.c
27152 +++ b/arch/x86/kernel/pvclock.c
27153 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27154 reset_hung_task_detector();
27155 }
27156
27157 -static atomic64_t last_value = ATOMIC64_INIT(0);
27158 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27159
27160 void pvclock_resume(void)
27161 {
27162 - atomic64_set(&last_value, 0);
27163 + atomic64_set_unchecked(&last_value, 0);
27164 }
27165
27166 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27167 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27168 * updating at the same time, and one of them could be slightly behind,
27169 * making the assumption that last_value always go forward fail to hold.
27170 */
27171 - last = atomic64_read(&last_value);
27172 + last = atomic64_read_unchecked(&last_value);
27173 do {
27174 if (ret < last)
27175 return last;
27176 - last = atomic64_cmpxchg(&last_value, last, ret);
27177 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27178 } while (unlikely(last != ret));
27179
27180 return ret;
27181 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27182 index 17962e6..47f55db 100644
27183 --- a/arch/x86/kernel/reboot.c
27184 +++ b/arch/x86/kernel/reboot.c
27185 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27186
27187 void __noreturn machine_real_restart(unsigned int type)
27188 {
27189 +
27190 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27191 + struct desc_struct *gdt;
27192 +#endif
27193 +
27194 local_irq_disable();
27195
27196 /*
27197 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27198
27199 /* Jump to the identity-mapped low memory code */
27200 #ifdef CONFIG_X86_32
27201 - asm volatile("jmpl *%0" : :
27202 +
27203 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27204 + gdt = get_cpu_gdt_table(smp_processor_id());
27205 + pax_open_kernel();
27206 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27207 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27208 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27209 + loadsegment(ds, __KERNEL_DS);
27210 + loadsegment(es, __KERNEL_DS);
27211 + loadsegment(ss, __KERNEL_DS);
27212 +#endif
27213 +#ifdef CONFIG_PAX_KERNEXEC
27214 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27215 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27216 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27217 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27218 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27219 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27220 +#endif
27221 + pax_close_kernel();
27222 +#endif
27223 +
27224 + asm volatile("ljmpl *%0" : :
27225 "rm" (real_mode_header->machine_real_restart_asm),
27226 "a" (type));
27227 #else
27228 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27229 * This means that this function can never return, it can misbehave
27230 * by not rebooting properly and hanging.
27231 */
27232 -static void native_machine_emergency_restart(void)
27233 +static void __noreturn native_machine_emergency_restart(void)
27234 {
27235 int i;
27236 int attempt = 0;
27237 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27238 #endif
27239 }
27240
27241 -static void __machine_emergency_restart(int emergency)
27242 +static void __noreturn __machine_emergency_restart(int emergency)
27243 {
27244 reboot_emergency = emergency;
27245 machine_ops.emergency_restart();
27246 }
27247
27248 -static void native_machine_restart(char *__unused)
27249 +static void __noreturn native_machine_restart(char *__unused)
27250 {
27251 pr_notice("machine restart\n");
27252
27253 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27254 __machine_emergency_restart(0);
27255 }
27256
27257 -static void native_machine_halt(void)
27258 +static void __noreturn native_machine_halt(void)
27259 {
27260 /* Stop other cpus and apics */
27261 machine_shutdown();
27262 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27263 stop_this_cpu(NULL);
27264 }
27265
27266 -static void native_machine_power_off(void)
27267 +static void __noreturn native_machine_power_off(void)
27268 {
27269 if (pm_power_off) {
27270 if (!reboot_force)
27271 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27272 }
27273 /* A fallback in case there is no PM info available */
27274 tboot_shutdown(TB_SHUTDOWN_HALT);
27275 + unreachable();
27276 }
27277
27278 -struct machine_ops machine_ops = {
27279 +struct machine_ops machine_ops __read_only = {
27280 .power_off = native_machine_power_off,
27281 .shutdown = native_machine_shutdown,
27282 .emergency_restart = native_machine_emergency_restart,
27283 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27284 index c8e41e9..64049ef 100644
27285 --- a/arch/x86/kernel/reboot_fixups_32.c
27286 +++ b/arch/x86/kernel/reboot_fixups_32.c
27287 @@ -57,7 +57,7 @@ struct device_fixup {
27288 unsigned int vendor;
27289 unsigned int device;
27290 void (*reboot_fixup)(struct pci_dev *);
27291 -};
27292 +} __do_const;
27293
27294 /*
27295 * PCI ids solely used for fixups_table go here
27296 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27297 index 3fd2c69..a444264 100644
27298 --- a/arch/x86/kernel/relocate_kernel_64.S
27299 +++ b/arch/x86/kernel/relocate_kernel_64.S
27300 @@ -96,8 +96,7 @@ relocate_kernel:
27301
27302 /* jump to identity mapped page */
27303 addq $(identity_mapped - relocate_kernel), %r8
27304 - pushq %r8
27305 - ret
27306 + jmp *%r8
27307
27308 identity_mapped:
27309 /* set return address to 0 if not preserving context */
27310 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27311 index 41ead8d..7ccde23 100644
27312 --- a/arch/x86/kernel/setup.c
27313 +++ b/arch/x86/kernel/setup.c
27314 @@ -110,6 +110,7 @@
27315 #include <asm/mce.h>
27316 #include <asm/alternative.h>
27317 #include <asm/prom.h>
27318 +#include <asm/boot.h>
27319
27320 /*
27321 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27322 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27323 #endif
27324
27325
27326 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27327 -__visible unsigned long mmu_cr4_features;
27328 +#ifdef CONFIG_X86_64
27329 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27330 +#elif defined(CONFIG_X86_PAE)
27331 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27332 #else
27333 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27334 +__visible unsigned long mmu_cr4_features __read_only;
27335 #endif
27336
27337 +void set_in_cr4(unsigned long mask)
27338 +{
27339 + unsigned long cr4 = read_cr4();
27340 +
27341 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27342 + return;
27343 +
27344 + pax_open_kernel();
27345 + mmu_cr4_features |= mask;
27346 + pax_close_kernel();
27347 +
27348 + if (trampoline_cr4_features)
27349 + *trampoline_cr4_features = mmu_cr4_features;
27350 + cr4 |= mask;
27351 + write_cr4(cr4);
27352 +}
27353 +EXPORT_SYMBOL(set_in_cr4);
27354 +
27355 +void clear_in_cr4(unsigned long mask)
27356 +{
27357 + unsigned long cr4 = read_cr4();
27358 +
27359 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27360 + return;
27361 +
27362 + pax_open_kernel();
27363 + mmu_cr4_features &= ~mask;
27364 + pax_close_kernel();
27365 +
27366 + if (trampoline_cr4_features)
27367 + *trampoline_cr4_features = mmu_cr4_features;
27368 + cr4 &= ~mask;
27369 + write_cr4(cr4);
27370 +}
27371 +EXPORT_SYMBOL(clear_in_cr4);
27372 +
27373 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27374 int bootloader_type, bootloader_version;
27375
27376 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27377 * area (640->1Mb) as ram even though it is not.
27378 * take them out.
27379 */
27380 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27381 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27382
27383 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27384 }
27385 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27386 /* called before trim_bios_range() to spare extra sanitize */
27387 static void __init e820_add_kernel_range(void)
27388 {
27389 - u64 start = __pa_symbol(_text);
27390 + u64 start = __pa_symbol(ktla_ktva(_text));
27391 u64 size = __pa_symbol(_end) - start;
27392
27393 /*
27394 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27395
27396 void __init setup_arch(char **cmdline_p)
27397 {
27398 +#ifdef CONFIG_X86_32
27399 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27400 +#else
27401 memblock_reserve(__pa_symbol(_text),
27402 (unsigned long)__bss_stop - (unsigned long)_text);
27403 +#endif
27404
27405 early_reserve_initrd();
27406
27407 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27408
27409 if (!boot_params.hdr.root_flags)
27410 root_mountflags &= ~MS_RDONLY;
27411 - init_mm.start_code = (unsigned long) _text;
27412 - init_mm.end_code = (unsigned long) _etext;
27413 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27414 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27415 init_mm.end_data = (unsigned long) _edata;
27416 init_mm.brk = _brk_end;
27417
27418 - code_resource.start = __pa_symbol(_text);
27419 - code_resource.end = __pa_symbol(_etext)-1;
27420 - data_resource.start = __pa_symbol(_etext);
27421 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27422 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27423 + data_resource.start = __pa_symbol(_sdata);
27424 data_resource.end = __pa_symbol(_edata)-1;
27425 bss_resource.start = __pa_symbol(__bss_start);
27426 bss_resource.end = __pa_symbol(__bss_stop)-1;
27427 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27428 index 5cdff03..80fa283 100644
27429 --- a/arch/x86/kernel/setup_percpu.c
27430 +++ b/arch/x86/kernel/setup_percpu.c
27431 @@ -21,19 +21,17 @@
27432 #include <asm/cpu.h>
27433 #include <asm/stackprotector.h>
27434
27435 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27436 +#ifdef CONFIG_SMP
27437 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27438 EXPORT_PER_CPU_SYMBOL(cpu_number);
27439 +#endif
27440
27441 -#ifdef CONFIG_X86_64
27442 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27443 -#else
27444 -#define BOOT_PERCPU_OFFSET 0
27445 -#endif
27446
27447 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27448 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27449
27450 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27451 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27452 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27453 };
27454 EXPORT_SYMBOL(__per_cpu_offset);
27455 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27456 {
27457 #ifdef CONFIG_NEED_MULTIPLE_NODES
27458 pg_data_t *last = NULL;
27459 - unsigned int cpu;
27460 + int cpu;
27461
27462 for_each_possible_cpu(cpu) {
27463 int node = early_cpu_to_node(cpu);
27464 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27465 {
27466 #ifdef CONFIG_X86_32
27467 struct desc_struct gdt;
27468 + unsigned long base = per_cpu_offset(cpu);
27469
27470 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27471 - 0x2 | DESCTYPE_S, 0x8);
27472 - gdt.s = 1;
27473 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27474 + 0x83 | DESCTYPE_S, 0xC);
27475 write_gdt_entry(get_cpu_gdt_table(cpu),
27476 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27477 #endif
27478 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27479 /* alrighty, percpu areas up and running */
27480 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27481 for_each_possible_cpu(cpu) {
27482 +#ifdef CONFIG_CC_STACKPROTECTOR
27483 +#ifdef CONFIG_X86_32
27484 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27485 +#endif
27486 +#endif
27487 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27488 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27489 per_cpu(cpu_number, cpu) = cpu;
27490 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27491 */
27492 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27493 #endif
27494 +#ifdef CONFIG_CC_STACKPROTECTOR
27495 +#ifdef CONFIG_X86_32
27496 + if (!cpu)
27497 + per_cpu(stack_canary.canary, cpu) = canary;
27498 +#endif
27499 +#endif
27500 /*
27501 * Up to this point, the boot CPU has been using .init.data
27502 * area. Reload any changed state for the boot CPU.
27503 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27504 index 2851d63..83bf567 100644
27505 --- a/arch/x86/kernel/signal.c
27506 +++ b/arch/x86/kernel/signal.c
27507 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27508 * Align the stack pointer according to the i386 ABI,
27509 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27510 */
27511 - sp = ((sp + 4) & -16ul) - 4;
27512 + sp = ((sp - 12) & -16ul) - 4;
27513 #else /* !CONFIG_X86_32 */
27514 sp = round_down(sp, 16) - 8;
27515 #endif
27516 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27517 }
27518
27519 if (current->mm->context.vdso)
27520 - restorer = current->mm->context.vdso +
27521 - selected_vdso32->sym___kernel_sigreturn;
27522 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27523 else
27524 - restorer = &frame->retcode;
27525 + restorer = (void __user *)&frame->retcode;
27526 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27527 restorer = ksig->ka.sa.sa_restorer;
27528
27529 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27530 * reasons and because gdb uses it as a signature to notice
27531 * signal handler stack frames.
27532 */
27533 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27534 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27535
27536 if (err)
27537 return -EFAULT;
27538 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27539 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27540
27541 /* Set up to return from userspace. */
27542 - restorer = current->mm->context.vdso +
27543 - selected_vdso32->sym___kernel_rt_sigreturn;
27544 + if (current->mm->context.vdso)
27545 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27546 + else
27547 + restorer = (void __user *)&frame->retcode;
27548 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27549 restorer = ksig->ka.sa.sa_restorer;
27550 put_user_ex(restorer, &frame->pretcode);
27551 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27552 * reasons and because gdb uses it as a signature to notice
27553 * signal handler stack frames.
27554 */
27555 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27556 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27557 } put_user_catch(err);
27558
27559 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27560 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27561 {
27562 int usig = signr_convert(ksig->sig);
27563 sigset_t *set = sigmask_to_save();
27564 - compat_sigset_t *cset = (compat_sigset_t *) set;
27565 + sigset_t sigcopy;
27566 + compat_sigset_t *cset;
27567 +
27568 + sigcopy = *set;
27569 +
27570 + cset = (compat_sigset_t *) &sigcopy;
27571
27572 /* Set up the stack frame */
27573 if (is_ia32_frame()) {
27574 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27575 } else if (is_x32_frame()) {
27576 return x32_setup_rt_frame(ksig, cset, regs);
27577 } else {
27578 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27579 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27580 }
27581 }
27582
27583 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27584 index be8e1bd..a3d93fa 100644
27585 --- a/arch/x86/kernel/smp.c
27586 +++ b/arch/x86/kernel/smp.c
27587 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27588
27589 __setup("nonmi_ipi", nonmi_ipi_setup);
27590
27591 -struct smp_ops smp_ops = {
27592 +struct smp_ops smp_ops __read_only = {
27593 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27594 .smp_prepare_cpus = native_smp_prepare_cpus,
27595 .smp_cpus_done = native_smp_cpus_done,
27596 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27597 index 42a2dca..35a07aa 100644
27598 --- a/arch/x86/kernel/smpboot.c
27599 +++ b/arch/x86/kernel/smpboot.c
27600 @@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
27601
27602 enable_start_cpu0 = 0;
27603
27604 -#ifdef CONFIG_X86_32
27605 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27606 + barrier();
27607 +
27608 /* switch away from the initial page table */
27609 +#ifdef CONFIG_PAX_PER_CPU_PGD
27610 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27611 +#else
27612 load_cr3(swapper_pg_dir);
27613 +#endif
27614 __flush_tlb_all();
27615 -#endif
27616
27617 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27618 - barrier();
27619 /*
27620 * Check TSC synchronization with the BP:
27621 */
27622 @@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27623 alternatives_enable_smp();
27624
27625 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27626 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27627 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27628 per_cpu(current_task, cpu) = idle;
27629 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27630
27631 #ifdef CONFIG_X86_32
27632 /* Stack for startup_32 can be just as for start_secondary onwards */
27633 @@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27634 clear_tsk_thread_flag(idle, TIF_FORK);
27635 initial_gs = per_cpu_offset(cpu);
27636 #endif
27637 - per_cpu(kernel_stack, cpu) =
27638 - (unsigned long)task_stack_page(idle) -
27639 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27640 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27641 + pax_open_kernel();
27642 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27643 + pax_close_kernel();
27644 initial_code = (unsigned long)start_secondary;
27645 stack_start = idle->thread.sp;
27646
27647 @@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27648 /* the FPU context is blank, nobody can own it */
27649 __cpu_disable_lazy_restore(cpu);
27650
27651 +#ifdef CONFIG_PAX_PER_CPU_PGD
27652 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27653 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27654 + KERNEL_PGD_PTRS);
27655 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27656 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27657 + KERNEL_PGD_PTRS);
27658 +#endif
27659 +
27660 err = do_boot_cpu(apicid, cpu, tidle);
27661 if (err) {
27662 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27663 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27664 index 9b4d51d..5d28b58 100644
27665 --- a/arch/x86/kernel/step.c
27666 +++ b/arch/x86/kernel/step.c
27667 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27668 struct desc_struct *desc;
27669 unsigned long base;
27670
27671 - seg &= ~7UL;
27672 + seg >>= 3;
27673
27674 mutex_lock(&child->mm->context.lock);
27675 - if (unlikely((seg >> 3) >= child->mm->context.size))
27676 + if (unlikely(seg >= child->mm->context.size))
27677 addr = -1L; /* bogus selector, access would fault */
27678 else {
27679 desc = child->mm->context.ldt + seg;
27680 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27681 addr += base;
27682 }
27683 mutex_unlock(&child->mm->context.lock);
27684 - }
27685 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27686 + addr = ktla_ktva(addr);
27687
27688 return addr;
27689 }
27690 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27691 unsigned char opcode[15];
27692 unsigned long addr = convert_ip_to_linear(child, regs);
27693
27694 + if (addr == -EINVAL)
27695 + return 0;
27696 +
27697 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27698 for (i = 0; i < copied; i++) {
27699 switch (opcode[i]) {
27700 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27701 new file mode 100644
27702 index 0000000..5877189
27703 --- /dev/null
27704 +++ b/arch/x86/kernel/sys_i386_32.c
27705 @@ -0,0 +1,189 @@
27706 +/*
27707 + * This file contains various random system calls that
27708 + * have a non-standard calling sequence on the Linux/i386
27709 + * platform.
27710 + */
27711 +
27712 +#include <linux/errno.h>
27713 +#include <linux/sched.h>
27714 +#include <linux/mm.h>
27715 +#include <linux/fs.h>
27716 +#include <linux/smp.h>
27717 +#include <linux/sem.h>
27718 +#include <linux/msg.h>
27719 +#include <linux/shm.h>
27720 +#include <linux/stat.h>
27721 +#include <linux/syscalls.h>
27722 +#include <linux/mman.h>
27723 +#include <linux/file.h>
27724 +#include <linux/utsname.h>
27725 +#include <linux/ipc.h>
27726 +#include <linux/elf.h>
27727 +
27728 +#include <linux/uaccess.h>
27729 +#include <linux/unistd.h>
27730 +
27731 +#include <asm/syscalls.h>
27732 +
27733 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27734 +{
27735 + unsigned long pax_task_size = TASK_SIZE;
27736 +
27737 +#ifdef CONFIG_PAX_SEGMEXEC
27738 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27739 + pax_task_size = SEGMEXEC_TASK_SIZE;
27740 +#endif
27741 +
27742 + if (flags & MAP_FIXED)
27743 + if (len > pax_task_size || addr > pax_task_size - len)
27744 + return -EINVAL;
27745 +
27746 + return 0;
27747 +}
27748 +
27749 +/*
27750 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27751 + */
27752 +static unsigned long get_align_mask(void)
27753 +{
27754 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27755 + return 0;
27756 +
27757 + if (!(current->flags & PF_RANDOMIZE))
27758 + return 0;
27759 +
27760 + return va_align.mask;
27761 +}
27762 +
27763 +unsigned long
27764 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27765 + unsigned long len, unsigned long pgoff, unsigned long flags)
27766 +{
27767 + struct mm_struct *mm = current->mm;
27768 + struct vm_area_struct *vma;
27769 + unsigned long pax_task_size = TASK_SIZE;
27770 + struct vm_unmapped_area_info info;
27771 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27772 +
27773 +#ifdef CONFIG_PAX_SEGMEXEC
27774 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27775 + pax_task_size = SEGMEXEC_TASK_SIZE;
27776 +#endif
27777 +
27778 + pax_task_size -= PAGE_SIZE;
27779 +
27780 + if (len > pax_task_size)
27781 + return -ENOMEM;
27782 +
27783 + if (flags & MAP_FIXED)
27784 + return addr;
27785 +
27786 +#ifdef CONFIG_PAX_RANDMMAP
27787 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27788 +#endif
27789 +
27790 + if (addr) {
27791 + addr = PAGE_ALIGN(addr);
27792 + if (pax_task_size - len >= addr) {
27793 + vma = find_vma(mm, addr);
27794 + if (check_heap_stack_gap(vma, addr, len, offset))
27795 + return addr;
27796 + }
27797 + }
27798 +
27799 + info.flags = 0;
27800 + info.length = len;
27801 + info.align_mask = filp ? get_align_mask() : 0;
27802 + info.align_offset = pgoff << PAGE_SHIFT;
27803 + info.threadstack_offset = offset;
27804 +
27805 +#ifdef CONFIG_PAX_PAGEEXEC
27806 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27807 + info.low_limit = 0x00110000UL;
27808 + info.high_limit = mm->start_code;
27809 +
27810 +#ifdef CONFIG_PAX_RANDMMAP
27811 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27812 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27813 +#endif
27814 +
27815 + if (info.low_limit < info.high_limit) {
27816 + addr = vm_unmapped_area(&info);
27817 + if (!IS_ERR_VALUE(addr))
27818 + return addr;
27819 + }
27820 + } else
27821 +#endif
27822 +
27823 + info.low_limit = mm->mmap_base;
27824 + info.high_limit = pax_task_size;
27825 +
27826 + return vm_unmapped_area(&info);
27827 +}
27828 +
27829 +unsigned long
27830 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27831 + const unsigned long len, const unsigned long pgoff,
27832 + const unsigned long flags)
27833 +{
27834 + struct vm_area_struct *vma;
27835 + struct mm_struct *mm = current->mm;
27836 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27837 + struct vm_unmapped_area_info info;
27838 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27839 +
27840 +#ifdef CONFIG_PAX_SEGMEXEC
27841 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27842 + pax_task_size = SEGMEXEC_TASK_SIZE;
27843 +#endif
27844 +
27845 + pax_task_size -= PAGE_SIZE;
27846 +
27847 + /* requested length too big for entire address space */
27848 + if (len > pax_task_size)
27849 + return -ENOMEM;
27850 +
27851 + if (flags & MAP_FIXED)
27852 + return addr;
27853 +
27854 +#ifdef CONFIG_PAX_PAGEEXEC
27855 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27856 + goto bottomup;
27857 +#endif
27858 +
27859 +#ifdef CONFIG_PAX_RANDMMAP
27860 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27861 +#endif
27862 +
27863 + /* requesting a specific address */
27864 + if (addr) {
27865 + addr = PAGE_ALIGN(addr);
27866 + if (pax_task_size - len >= addr) {
27867 + vma = find_vma(mm, addr);
27868 + if (check_heap_stack_gap(vma, addr, len, offset))
27869 + return addr;
27870 + }
27871 + }
27872 +
27873 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27874 + info.length = len;
27875 + info.low_limit = PAGE_SIZE;
27876 + info.high_limit = mm->mmap_base;
27877 + info.align_mask = filp ? get_align_mask() : 0;
27878 + info.align_offset = pgoff << PAGE_SHIFT;
27879 + info.threadstack_offset = offset;
27880 +
27881 + addr = vm_unmapped_area(&info);
27882 + if (!(addr & ~PAGE_MASK))
27883 + return addr;
27884 + VM_BUG_ON(addr != -ENOMEM);
27885 +
27886 +bottomup:
27887 + /*
27888 + * A failed mmap() very likely causes application failure,
27889 + * so fall back to the bottom-up function here. This scenario
27890 + * can happen with large stack limits and large mmap()
27891 + * allocations.
27892 + */
27893 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27894 +}
27895 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27896 index 30277e2..5664a29 100644
27897 --- a/arch/x86/kernel/sys_x86_64.c
27898 +++ b/arch/x86/kernel/sys_x86_64.c
27899 @@ -81,8 +81,8 @@ out:
27900 return error;
27901 }
27902
27903 -static void find_start_end(unsigned long flags, unsigned long *begin,
27904 - unsigned long *end)
27905 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27906 + unsigned long *begin, unsigned long *end)
27907 {
27908 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27909 unsigned long new_begin;
27910 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27911 *begin = new_begin;
27912 }
27913 } else {
27914 - *begin = current->mm->mmap_legacy_base;
27915 + *begin = mm->mmap_legacy_base;
27916 *end = TASK_SIZE;
27917 }
27918 }
27919 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27920 struct vm_area_struct *vma;
27921 struct vm_unmapped_area_info info;
27922 unsigned long begin, end;
27923 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27924
27925 if (flags & MAP_FIXED)
27926 return addr;
27927
27928 - find_start_end(flags, &begin, &end);
27929 + find_start_end(mm, flags, &begin, &end);
27930
27931 if (len > end)
27932 return -ENOMEM;
27933
27934 +#ifdef CONFIG_PAX_RANDMMAP
27935 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27936 +#endif
27937 +
27938 if (addr) {
27939 addr = PAGE_ALIGN(addr);
27940 vma = find_vma(mm, addr);
27941 - if (end - len >= addr &&
27942 - (!vma || addr + len <= vma->vm_start))
27943 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27944 return addr;
27945 }
27946
27947 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27948 info.high_limit = end;
27949 info.align_mask = filp ? get_align_mask() : 0;
27950 info.align_offset = pgoff << PAGE_SHIFT;
27951 + info.threadstack_offset = offset;
27952 return vm_unmapped_area(&info);
27953 }
27954
27955 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27956 struct mm_struct *mm = current->mm;
27957 unsigned long addr = addr0;
27958 struct vm_unmapped_area_info info;
27959 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27960
27961 /* requested length too big for entire address space */
27962 if (len > TASK_SIZE)
27963 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27964 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27965 goto bottomup;
27966
27967 +#ifdef CONFIG_PAX_RANDMMAP
27968 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27969 +#endif
27970 +
27971 /* requesting a specific address */
27972 if (addr) {
27973 addr = PAGE_ALIGN(addr);
27974 vma = find_vma(mm, addr);
27975 - if (TASK_SIZE - len >= addr &&
27976 - (!vma || addr + len <= vma->vm_start))
27977 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27978 return addr;
27979 }
27980
27981 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27982 info.high_limit = mm->mmap_base;
27983 info.align_mask = filp ? get_align_mask() : 0;
27984 info.align_offset = pgoff << PAGE_SHIFT;
27985 + info.threadstack_offset = offset;
27986 addr = vm_unmapped_area(&info);
27987 if (!(addr & ~PAGE_MASK))
27988 return addr;
27989 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27990 index 91a4496..bb87552 100644
27991 --- a/arch/x86/kernel/tboot.c
27992 +++ b/arch/x86/kernel/tboot.c
27993 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27994
27995 void tboot_shutdown(u32 shutdown_type)
27996 {
27997 - void (*shutdown)(void);
27998 + void (* __noreturn shutdown)(void);
27999
28000 if (!tboot_enabled())
28001 return;
28002 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28003
28004 switch_to_tboot_pt();
28005
28006 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28007 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28008 shutdown();
28009
28010 /* should not reach here */
28011 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28012 return -ENODEV;
28013 }
28014
28015 -static atomic_t ap_wfs_count;
28016 +static atomic_unchecked_t ap_wfs_count;
28017
28018 static int tboot_wait_for_aps(int num_aps)
28019 {
28020 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28021 {
28022 switch (action) {
28023 case CPU_DYING:
28024 - atomic_inc(&ap_wfs_count);
28025 + atomic_inc_unchecked(&ap_wfs_count);
28026 if (num_online_cpus() == 1)
28027 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28028 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28029 return NOTIFY_BAD;
28030 break;
28031 }
28032 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28033
28034 tboot_create_trampoline();
28035
28036 - atomic_set(&ap_wfs_count, 0);
28037 + atomic_set_unchecked(&ap_wfs_count, 0);
28038 register_hotcpu_notifier(&tboot_cpu_notifier);
28039
28040 #ifdef CONFIG_DEBUG_FS
28041 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28042 index 0fa2960..91eabbe 100644
28043 --- a/arch/x86/kernel/time.c
28044 +++ b/arch/x86/kernel/time.c
28045 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28046 {
28047 unsigned long pc = instruction_pointer(regs);
28048
28049 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28050 + if (!user_mode(regs) && in_lock_functions(pc)) {
28051 #ifdef CONFIG_FRAME_POINTER
28052 - return *(unsigned long *)(regs->bp + sizeof(long));
28053 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28054 #else
28055 unsigned long *sp =
28056 (unsigned long *)kernel_stack_pointer(regs);
28057 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28058 * or above a saved flags. Eflags has bits 22-31 zero,
28059 * kernel addresses don't.
28060 */
28061 +
28062 +#ifdef CONFIG_PAX_KERNEXEC
28063 + return ktla_ktva(sp[0]);
28064 +#else
28065 if (sp[0] >> 22)
28066 return sp[0];
28067 if (sp[1] >> 22)
28068 return sp[1];
28069 #endif
28070 +
28071 +#endif
28072 }
28073 return pc;
28074 }
28075 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28076 index f7fec09..9991981 100644
28077 --- a/arch/x86/kernel/tls.c
28078 +++ b/arch/x86/kernel/tls.c
28079 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28080 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28081 return -EINVAL;
28082
28083 +#ifdef CONFIG_PAX_SEGMEXEC
28084 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28085 + return -EINVAL;
28086 +#endif
28087 +
28088 set_tls_desc(p, idx, &info, 1);
28089
28090 return 0;
28091 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28092
28093 if (kbuf)
28094 info = kbuf;
28095 - else if (__copy_from_user(infobuf, ubuf, count))
28096 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28097 return -EFAULT;
28098 else
28099 info = infobuf;
28100 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28101 index 1c113db..287b42e 100644
28102 --- a/arch/x86/kernel/tracepoint.c
28103 +++ b/arch/x86/kernel/tracepoint.c
28104 @@ -9,11 +9,11 @@
28105 #include <linux/atomic.h>
28106
28107 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28108 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28109 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28110 (unsigned long) trace_idt_table };
28111
28112 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28113 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28114 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28115
28116 static int trace_irq_vector_refcount;
28117 static DEFINE_MUTEX(irq_vector_mutex);
28118 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28119 index 0d0e922..0886373 100644
28120 --- a/arch/x86/kernel/traps.c
28121 +++ b/arch/x86/kernel/traps.c
28122 @@ -67,7 +67,7 @@
28123 #include <asm/proto.h>
28124
28125 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28126 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28127 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28128 #else
28129 #include <asm/processor-flags.h>
28130 #include <asm/setup.h>
28131 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28132 #endif
28133
28134 /* Must be page-aligned because the real IDT is used in a fixmap. */
28135 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28136 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28137
28138 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28139 EXPORT_SYMBOL_GPL(used_vectors);
28140 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28141 }
28142
28143 static nokprobe_inline int
28144 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28145 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28146 struct pt_regs *regs, long error_code)
28147 {
28148 #ifdef CONFIG_X86_32
28149 - if (regs->flags & X86_VM_MASK) {
28150 + if (v8086_mode(regs)) {
28151 /*
28152 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28153 * On nmi (interrupt 2), do_trap should not be called.
28154 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28155 return -1;
28156 }
28157 #endif
28158 - if (!user_mode(regs)) {
28159 + if (!user_mode_novm(regs)) {
28160 if (!fixup_exception(regs)) {
28161 tsk->thread.error_code = error_code;
28162 tsk->thread.trap_nr = trapnr;
28163 +
28164 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28165 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28166 + str = "PAX: suspicious stack segment fault";
28167 +#endif
28168 +
28169 die(str, regs, error_code);
28170 }
28171 +
28172 +#ifdef CONFIG_PAX_REFCOUNT
28173 + if (trapnr == X86_TRAP_OF)
28174 + pax_report_refcount_overflow(regs);
28175 +#endif
28176 +
28177 return 0;
28178 }
28179
28180 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28181 }
28182
28183 static void
28184 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28185 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28186 long error_code, siginfo_t *info)
28187 {
28188 struct task_struct *tsk = current;
28189 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28190 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28191 printk_ratelimit()) {
28192 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28193 - tsk->comm, tsk->pid, str,
28194 + tsk->comm, task_pid_nr(tsk), str,
28195 regs->ip, regs->sp, error_code);
28196 print_vma_addr(" in ", regs->ip);
28197 pr_cont("\n");
28198 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28199 tsk->thread.error_code = error_code;
28200 tsk->thread.trap_nr = X86_TRAP_DF;
28201
28202 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28203 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28204 + die("grsec: kernel stack overflow detected", regs, error_code);
28205 +#endif
28206 +
28207 #ifdef CONFIG_DOUBLEFAULT
28208 df_debug(regs, error_code);
28209 #endif
28210 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28211 conditional_sti(regs);
28212
28213 #ifdef CONFIG_X86_32
28214 - if (regs->flags & X86_VM_MASK) {
28215 + if (v8086_mode(regs)) {
28216 local_irq_enable();
28217 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28218 goto exit;
28219 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28220 #endif
28221
28222 tsk = current;
28223 - if (!user_mode(regs)) {
28224 + if (!user_mode_novm(regs)) {
28225 if (fixup_exception(regs))
28226 goto exit;
28227
28228 tsk->thread.error_code = error_code;
28229 tsk->thread.trap_nr = X86_TRAP_GP;
28230 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28231 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28232 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28233 +
28234 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28235 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28236 + die("PAX: suspicious general protection fault", regs, error_code);
28237 + else
28238 +#endif
28239 +
28240 die("general protection fault", regs, error_code);
28241 + }
28242 goto exit;
28243 }
28244
28245 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28246 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28247 + struct mm_struct *mm = tsk->mm;
28248 + unsigned long limit;
28249 +
28250 + down_write(&mm->mmap_sem);
28251 + limit = mm->context.user_cs_limit;
28252 + if (limit < TASK_SIZE) {
28253 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28254 + up_write(&mm->mmap_sem);
28255 + return;
28256 + }
28257 + up_write(&mm->mmap_sem);
28258 + }
28259 +#endif
28260 +
28261 tsk->thread.error_code = error_code;
28262 tsk->thread.trap_nr = X86_TRAP_GP;
28263
28264 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28265 /* It's safe to allow irq's after DR6 has been saved */
28266 preempt_conditional_sti(regs);
28267
28268 - if (regs->flags & X86_VM_MASK) {
28269 + if (v8086_mode(regs)) {
28270 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28271 X86_TRAP_DB);
28272 preempt_conditional_cli(regs);
28273 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28274 * We already checked v86 mode above, so we can check for kernel mode
28275 * by just checking the CPL of CS.
28276 */
28277 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28278 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28279 tsk->thread.debugreg6 &= ~DR_STEP;
28280 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28281 regs->flags &= ~X86_EFLAGS_TF;
28282 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28283 return;
28284 conditional_sti(regs);
28285
28286 - if (!user_mode_vm(regs))
28287 + if (!user_mode(regs))
28288 {
28289 if (!fixup_exception(regs)) {
28290 task->thread.error_code = error_code;
28291 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28292 index b6025f9..0cc6a1d 100644
28293 --- a/arch/x86/kernel/tsc.c
28294 +++ b/arch/x86/kernel/tsc.c
28295 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28296 */
28297 smp_wmb();
28298
28299 - ACCESS_ONCE(c2n->head) = data;
28300 + ACCESS_ONCE_RW(c2n->head) = data;
28301 }
28302
28303 /*
28304 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28305 index 5d1cbfe..2a21feb 100644
28306 --- a/arch/x86/kernel/uprobes.c
28307 +++ b/arch/x86/kernel/uprobes.c
28308 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28309 int ret = NOTIFY_DONE;
28310
28311 /* We are only interested in userspace traps */
28312 - if (regs && !user_mode_vm(regs))
28313 + if (regs && !user_mode(regs))
28314 return NOTIFY_DONE;
28315
28316 switch (val) {
28317 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28318
28319 if (nleft != rasize) {
28320 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28321 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28322 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28323
28324 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28325 }
28326 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28327 index b9242ba..50c5edd 100644
28328 --- a/arch/x86/kernel/verify_cpu.S
28329 +++ b/arch/x86/kernel/verify_cpu.S
28330 @@ -20,6 +20,7 @@
28331 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28332 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28333 * arch/x86/kernel/head_32.S: processor startup
28334 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28335 *
28336 * verify_cpu, returns the status of longmode and SSE in register %eax.
28337 * 0: Success 1: Failure
28338 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28339 index e8edcf5..27f9344 100644
28340 --- a/arch/x86/kernel/vm86_32.c
28341 +++ b/arch/x86/kernel/vm86_32.c
28342 @@ -44,6 +44,7 @@
28343 #include <linux/ptrace.h>
28344 #include <linux/audit.h>
28345 #include <linux/stddef.h>
28346 +#include <linux/grsecurity.h>
28347
28348 #include <asm/uaccess.h>
28349 #include <asm/io.h>
28350 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28351 do_exit(SIGSEGV);
28352 }
28353
28354 - tss = &per_cpu(init_tss, get_cpu());
28355 + tss = init_tss + get_cpu();
28356 current->thread.sp0 = current->thread.saved_sp0;
28357 current->thread.sysenter_cs = __KERNEL_CS;
28358 load_sp0(tss, &current->thread);
28359 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28360
28361 if (tsk->thread.saved_sp0)
28362 return -EPERM;
28363 +
28364 +#ifdef CONFIG_GRKERNSEC_VM86
28365 + if (!capable(CAP_SYS_RAWIO)) {
28366 + gr_handle_vm86();
28367 + return -EPERM;
28368 + }
28369 +#endif
28370 +
28371 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28372 offsetof(struct kernel_vm86_struct, vm86plus) -
28373 sizeof(info.regs));
28374 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28375 int tmp;
28376 struct vm86plus_struct __user *v86;
28377
28378 +#ifdef CONFIG_GRKERNSEC_VM86
28379 + if (!capable(CAP_SYS_RAWIO)) {
28380 + gr_handle_vm86();
28381 + return -EPERM;
28382 + }
28383 +#endif
28384 +
28385 tsk = current;
28386 switch (cmd) {
28387 case VM86_REQUEST_IRQ:
28388 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28389 tsk->thread.saved_fs = info->regs32->fs;
28390 tsk->thread.saved_gs = get_user_gs(info->regs32);
28391
28392 - tss = &per_cpu(init_tss, get_cpu());
28393 + tss = init_tss + get_cpu();
28394 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28395 if (cpu_has_sep)
28396 tsk->thread.sysenter_cs = 0;
28397 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28398 goto cannot_handle;
28399 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28400 goto cannot_handle;
28401 - intr_ptr = (unsigned long __user *) (i << 2);
28402 + intr_ptr = (__force unsigned long __user *) (i << 2);
28403 if (get_user(segoffs, intr_ptr))
28404 goto cannot_handle;
28405 if ((segoffs >> 16) == BIOSSEG)
28406 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28407 index 49edf2d..c0d1362 100644
28408 --- a/arch/x86/kernel/vmlinux.lds.S
28409 +++ b/arch/x86/kernel/vmlinux.lds.S
28410 @@ -26,6 +26,13 @@
28411 #include <asm/page_types.h>
28412 #include <asm/cache.h>
28413 #include <asm/boot.h>
28414 +#include <asm/segment.h>
28415 +
28416 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28417 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28418 +#else
28419 +#define __KERNEL_TEXT_OFFSET 0
28420 +#endif
28421
28422 #undef i386 /* in case the preprocessor is a 32bit one */
28423
28424 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28425
28426 PHDRS {
28427 text PT_LOAD FLAGS(5); /* R_E */
28428 +#ifdef CONFIG_X86_32
28429 + module PT_LOAD FLAGS(5); /* R_E */
28430 +#endif
28431 +#ifdef CONFIG_XEN
28432 + rodata PT_LOAD FLAGS(5); /* R_E */
28433 +#else
28434 + rodata PT_LOAD FLAGS(4); /* R__ */
28435 +#endif
28436 data PT_LOAD FLAGS(6); /* RW_ */
28437 -#ifdef CONFIG_X86_64
28438 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28439 #ifdef CONFIG_SMP
28440 percpu PT_LOAD FLAGS(6); /* RW_ */
28441 #endif
28442 + text.init PT_LOAD FLAGS(5); /* R_E */
28443 + text.exit PT_LOAD FLAGS(5); /* R_E */
28444 init PT_LOAD FLAGS(7); /* RWE */
28445 -#endif
28446 note PT_NOTE FLAGS(0); /* ___ */
28447 }
28448
28449 SECTIONS
28450 {
28451 #ifdef CONFIG_X86_32
28452 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28453 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28454 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28455 #else
28456 - . = __START_KERNEL;
28457 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28458 + . = __START_KERNEL;
28459 #endif
28460
28461 /* Text and read-only data */
28462 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28463 - _text = .;
28464 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28465 /* bootstrapping code */
28466 +#ifdef CONFIG_X86_32
28467 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28468 +#else
28469 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28470 +#endif
28471 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28472 + _text = .;
28473 HEAD_TEXT
28474 . = ALIGN(8);
28475 _stext = .;
28476 @@ -104,13 +124,47 @@ SECTIONS
28477 IRQENTRY_TEXT
28478 *(.fixup)
28479 *(.gnu.warning)
28480 - /* End of text section */
28481 - _etext = .;
28482 } :text = 0x9090
28483
28484 - NOTES :text :note
28485 + . += __KERNEL_TEXT_OFFSET;
28486
28487 - EXCEPTION_TABLE(16) :text = 0x9090
28488 +#ifdef CONFIG_X86_32
28489 + . = ALIGN(PAGE_SIZE);
28490 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28491 +
28492 +#ifdef CONFIG_PAX_KERNEXEC
28493 + MODULES_EXEC_VADDR = .;
28494 + BYTE(0)
28495 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28496 + . = ALIGN(HPAGE_SIZE) - 1;
28497 + MODULES_EXEC_END = .;
28498 +#endif
28499 +
28500 + } :module
28501 +#endif
28502 +
28503 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28504 + /* End of text section */
28505 + BYTE(0)
28506 + _etext = . - __KERNEL_TEXT_OFFSET;
28507 + }
28508 +
28509 +#ifdef CONFIG_X86_32
28510 + . = ALIGN(PAGE_SIZE);
28511 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28512 + . = ALIGN(PAGE_SIZE);
28513 + *(.empty_zero_page)
28514 + *(.initial_pg_fixmap)
28515 + *(.initial_pg_pmd)
28516 + *(.initial_page_table)
28517 + *(.swapper_pg_dir)
28518 + } :rodata
28519 +#endif
28520 +
28521 + . = ALIGN(PAGE_SIZE);
28522 + NOTES :rodata :note
28523 +
28524 + EXCEPTION_TABLE(16) :rodata
28525
28526 #if defined(CONFIG_DEBUG_RODATA)
28527 /* .text should occupy whole number of pages */
28528 @@ -122,16 +176,20 @@ SECTIONS
28529
28530 /* Data */
28531 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28532 +
28533 +#ifdef CONFIG_PAX_KERNEXEC
28534 + . = ALIGN(HPAGE_SIZE);
28535 +#else
28536 + . = ALIGN(PAGE_SIZE);
28537 +#endif
28538 +
28539 /* Start of data section */
28540 _sdata = .;
28541
28542 /* init_task */
28543 INIT_TASK_DATA(THREAD_SIZE)
28544
28545 -#ifdef CONFIG_X86_32
28546 - /* 32 bit has nosave before _edata */
28547 NOSAVE_DATA
28548 -#endif
28549
28550 PAGE_ALIGNED_DATA(PAGE_SIZE)
28551
28552 @@ -174,12 +232,19 @@ SECTIONS
28553 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28554
28555 /* Init code and data - will be freed after init */
28556 - . = ALIGN(PAGE_SIZE);
28557 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28558 + BYTE(0)
28559 +
28560 +#ifdef CONFIG_PAX_KERNEXEC
28561 + . = ALIGN(HPAGE_SIZE);
28562 +#else
28563 + . = ALIGN(PAGE_SIZE);
28564 +#endif
28565 +
28566 __init_begin = .; /* paired with __init_end */
28567 - }
28568 + } :init.begin
28569
28570 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28571 +#ifdef CONFIG_SMP
28572 /*
28573 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28574 * output PHDR, so the next output section - .init.text - should
28575 @@ -188,12 +253,27 @@ SECTIONS
28576 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28577 #endif
28578
28579 - INIT_TEXT_SECTION(PAGE_SIZE)
28580 -#ifdef CONFIG_X86_64
28581 - :init
28582 -#endif
28583 + . = ALIGN(PAGE_SIZE);
28584 + init_begin = .;
28585 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28586 + VMLINUX_SYMBOL(_sinittext) = .;
28587 + INIT_TEXT
28588 + VMLINUX_SYMBOL(_einittext) = .;
28589 + . = ALIGN(PAGE_SIZE);
28590 + } :text.init
28591
28592 - INIT_DATA_SECTION(16)
28593 + /*
28594 + * .exit.text is discard at runtime, not link time, to deal with
28595 + * references from .altinstructions and .eh_frame
28596 + */
28597 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28598 + EXIT_TEXT
28599 + . = ALIGN(16);
28600 + } :text.exit
28601 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28602 +
28603 + . = ALIGN(PAGE_SIZE);
28604 + INIT_DATA_SECTION(16) :init
28605
28606 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28607 __x86_cpu_dev_start = .;
28608 @@ -264,19 +344,12 @@ SECTIONS
28609 }
28610
28611 . = ALIGN(8);
28612 - /*
28613 - * .exit.text is discard at runtime, not link time, to deal with
28614 - * references from .altinstructions and .eh_frame
28615 - */
28616 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28617 - EXIT_TEXT
28618 - }
28619
28620 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28621 EXIT_DATA
28622 }
28623
28624 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28625 +#ifndef CONFIG_SMP
28626 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28627 #endif
28628
28629 @@ -295,16 +368,10 @@ SECTIONS
28630 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28631 __smp_locks = .;
28632 *(.smp_locks)
28633 - . = ALIGN(PAGE_SIZE);
28634 __smp_locks_end = .;
28635 + . = ALIGN(PAGE_SIZE);
28636 }
28637
28638 -#ifdef CONFIG_X86_64
28639 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28640 - NOSAVE_DATA
28641 - }
28642 -#endif
28643 -
28644 /* BSS */
28645 . = ALIGN(PAGE_SIZE);
28646 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28647 @@ -320,6 +387,7 @@ SECTIONS
28648 __brk_base = .;
28649 . += 64 * 1024; /* 64k alignment slop space */
28650 *(.brk_reservation) /* areas brk users have reserved */
28651 + . = ALIGN(HPAGE_SIZE);
28652 __brk_limit = .;
28653 }
28654
28655 @@ -346,13 +414,12 @@ SECTIONS
28656 * for the boot processor.
28657 */
28658 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28659 -INIT_PER_CPU(gdt_page);
28660 INIT_PER_CPU(irq_stack_union);
28661
28662 /*
28663 * Build-time check on the image size:
28664 */
28665 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28666 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28667 "kernel image bigger than KERNEL_IMAGE_SIZE");
28668
28669 #ifdef CONFIG_SMP
28670 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28671 index e1e1e80..1400089 100644
28672 --- a/arch/x86/kernel/vsyscall_64.c
28673 +++ b/arch/x86/kernel/vsyscall_64.c
28674 @@ -54,15 +54,13 @@
28675
28676 DEFINE_VVAR(int, vgetcpu_mode);
28677
28678 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28679 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28680
28681 static int __init vsyscall_setup(char *str)
28682 {
28683 if (str) {
28684 if (!strcmp("emulate", str))
28685 vsyscall_mode = EMULATE;
28686 - else if (!strcmp("native", str))
28687 - vsyscall_mode = NATIVE;
28688 else if (!strcmp("none", str))
28689 vsyscall_mode = NONE;
28690 else
28691 @@ -279,8 +277,7 @@ do_ret:
28692 return true;
28693
28694 sigsegv:
28695 - force_sig(SIGSEGV, current);
28696 - return true;
28697 + do_group_exit(SIGKILL);
28698 }
28699
28700 /*
28701 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28702 extern char __vsyscall_page;
28703 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28704
28705 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28706 - vsyscall_mode == NATIVE
28707 - ? PAGE_KERNEL_VSYSCALL
28708 - : PAGE_KERNEL_VVAR);
28709 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28710 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28711 (unsigned long)VSYSCALL_ADDR);
28712 }
28713 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28714 index 04068192..4d75aa6 100644
28715 --- a/arch/x86/kernel/x8664_ksyms_64.c
28716 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28717 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28718 EXPORT_SYMBOL(copy_user_generic_unrolled);
28719 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28720 EXPORT_SYMBOL(__copy_user_nocache);
28721 -EXPORT_SYMBOL(_copy_from_user);
28722 -EXPORT_SYMBOL(_copy_to_user);
28723
28724 EXPORT_SYMBOL(copy_page);
28725 EXPORT_SYMBOL(clear_page);
28726 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28727 EXPORT_SYMBOL(___preempt_schedule_context);
28728 #endif
28729 #endif
28730 +
28731 +#ifdef CONFIG_PAX_PER_CPU_PGD
28732 +EXPORT_SYMBOL(cpu_pgd);
28733 +#endif
28734 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28735 index e48b674..a451dd9 100644
28736 --- a/arch/x86/kernel/x86_init.c
28737 +++ b/arch/x86/kernel/x86_init.c
28738 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28739 static void default_nmi_init(void) { };
28740 static int default_i8042_detect(void) { return 1; };
28741
28742 -struct x86_platform_ops x86_platform = {
28743 +struct x86_platform_ops x86_platform __read_only = {
28744 .calibrate_tsc = native_calibrate_tsc,
28745 .get_wallclock = mach_get_cmos_time,
28746 .set_wallclock = mach_set_rtc_mmss,
28747 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28748 EXPORT_SYMBOL_GPL(x86_platform);
28749
28750 #if defined(CONFIG_PCI_MSI)
28751 -struct x86_msi_ops x86_msi = {
28752 +struct x86_msi_ops x86_msi __read_only = {
28753 .setup_msi_irqs = native_setup_msi_irqs,
28754 .compose_msi_msg = native_compose_msi_msg,
28755 .teardown_msi_irq = native_teardown_msi_irq,
28756 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28757 }
28758 #endif
28759
28760 -struct x86_io_apic_ops x86_io_apic_ops = {
28761 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28762 .init = native_io_apic_init_mappings,
28763 .read = native_io_apic_read,
28764 .write = native_io_apic_write,
28765 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28766 index 940b142..0ad3a10 100644
28767 --- a/arch/x86/kernel/xsave.c
28768 +++ b/arch/x86/kernel/xsave.c
28769 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28770
28771 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28772 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28773 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28774 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28775
28776 if (!use_xsave())
28777 return err;
28778
28779 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28780 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28781
28782 /*
28783 * Read the xstate_bv which we copied (directly from the cpu or
28784 * from the state in task struct) to the user buffers.
28785 */
28786 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28787 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28788
28789 /*
28790 * For legacy compatible, we always set FP/SSE bits in the bit
28791 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28792 */
28793 xstate_bv |= XSTATE_FPSSE;
28794
28795 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28796 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28797
28798 return err;
28799 }
28800 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28801 {
28802 int err;
28803
28804 + buf = (struct xsave_struct __user *)____m(buf);
28805 if (use_xsave())
28806 err = xsave_user(buf);
28807 else if (use_fxsr())
28808 @@ -314,6 +315,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28809 */
28810 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28811 {
28812 + buf = (void __user *)____m(buf);
28813 if (use_xsave()) {
28814 if ((unsigned long)buf % 64 || fx_only) {
28815 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28816 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28817 index 38a0afe..94421a9 100644
28818 --- a/arch/x86/kvm/cpuid.c
28819 +++ b/arch/x86/kvm/cpuid.c
28820 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28821 struct kvm_cpuid2 *cpuid,
28822 struct kvm_cpuid_entry2 __user *entries)
28823 {
28824 - int r;
28825 + int r, i;
28826
28827 r = -E2BIG;
28828 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28829 goto out;
28830 r = -EFAULT;
28831 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28832 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28833 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28834 goto out;
28835 + for (i = 0; i < cpuid->nent; ++i) {
28836 + struct kvm_cpuid_entry2 cpuid_entry;
28837 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28838 + goto out;
28839 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28840 + }
28841 vcpu->arch.cpuid_nent = cpuid->nent;
28842 kvm_apic_set_version(vcpu);
28843 kvm_x86_ops->cpuid_update(vcpu);
28844 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28845 struct kvm_cpuid2 *cpuid,
28846 struct kvm_cpuid_entry2 __user *entries)
28847 {
28848 - int r;
28849 + int r, i;
28850
28851 r = -E2BIG;
28852 if (cpuid->nent < vcpu->arch.cpuid_nent)
28853 goto out;
28854 r = -EFAULT;
28855 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28856 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28857 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28858 goto out;
28859 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28860 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28861 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28862 + goto out;
28863 + }
28864 return 0;
28865
28866 out:
28867 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28868 index 03954f7..48daa1a 100644
28869 --- a/arch/x86/kvm/emulate.c
28870 +++ b/arch/x86/kvm/emulate.c
28871 @@ -504,11 +504,6 @@ static void rsp_increment(struct x86_emulate_ctxt *ctxt, int inc)
28872 masked_increment(reg_rmw(ctxt, VCPU_REGS_RSP), stack_mask(ctxt), inc);
28873 }
28874
28875 -static inline void jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
28876 -{
28877 - register_address_increment(ctxt, &ctxt->_eip, rel);
28878 -}
28879 -
28880 static u32 desc_limit_scaled(struct desc_struct *desc)
28881 {
28882 u32 limit = get_desc_limit(desc);
28883 @@ -568,6 +563,38 @@ static int emulate_nm(struct x86_emulate_ctxt *ctxt)
28884 return emulate_exception(ctxt, NM_VECTOR, 0, false);
28885 }
28886
28887 +static inline int assign_eip_far(struct x86_emulate_ctxt *ctxt, ulong dst,
28888 + int cs_l)
28889 +{
28890 + switch (ctxt->op_bytes) {
28891 + case 2:
28892 + ctxt->_eip = (u16)dst;
28893 + break;
28894 + case 4:
28895 + ctxt->_eip = (u32)dst;
28896 + break;
28897 + case 8:
28898 + if ((cs_l && is_noncanonical_address(dst)) ||
28899 + (!cs_l && (dst & ~(u32)-1)))
28900 + return emulate_gp(ctxt, 0);
28901 + ctxt->_eip = dst;
28902 + break;
28903 + default:
28904 + WARN(1, "unsupported eip assignment size\n");
28905 + }
28906 + return X86EMUL_CONTINUE;
28907 +}
28908 +
28909 +static inline int assign_eip_near(struct x86_emulate_ctxt *ctxt, ulong dst)
28910 +{
28911 + return assign_eip_far(ctxt, dst, ctxt->mode == X86EMUL_MODE_PROT64);
28912 +}
28913 +
28914 +static inline int jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
28915 +{
28916 + return assign_eip_near(ctxt, ctxt->_eip + rel);
28917 +}
28918 +
28919 static u16 get_segment_selector(struct x86_emulate_ctxt *ctxt, unsigned seg)
28920 {
28921 u16 selector;
28922 @@ -750,8 +777,10 @@ static int __do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, int op_size)
28923 static __always_inline int do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt,
28924 unsigned size)
28925 {
28926 - if (unlikely(ctxt->fetch.end - ctxt->fetch.ptr < size))
28927 - return __do_insn_fetch_bytes(ctxt, size);
28928 + unsigned done_size = ctxt->fetch.end - ctxt->fetch.ptr;
28929 +
28930 + if (unlikely(done_size < size))
28931 + return __do_insn_fetch_bytes(ctxt, size - done_size);
28932 else
28933 return X86EMUL_CONTINUE;
28934 }
28935 @@ -1415,7 +1444,9 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
28936
28937 /* Does not support long mode */
28938 static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
28939 - u16 selector, int seg, u8 cpl, bool in_task_switch)
28940 + u16 selector, int seg, u8 cpl,
28941 + bool in_task_switch,
28942 + struct desc_struct *desc)
28943 {
28944 struct desc_struct seg_desc, old_desc;
28945 u8 dpl, rpl;
28946 @@ -1547,6 +1578,8 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
28947 }
28948 load:
28949 ctxt->ops->set_segment(ctxt, selector, &seg_desc, base3, seg);
28950 + if (desc)
28951 + *desc = seg_desc;
28952 return X86EMUL_CONTINUE;
28953 exception:
28954 emulate_exception(ctxt, err_vec, err_code, true);
28955 @@ -1557,7 +1590,7 @@ static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
28956 u16 selector, int seg)
28957 {
28958 u8 cpl = ctxt->ops->cpl(ctxt);
28959 - return __load_segment_descriptor(ctxt, selector, seg, cpl, false);
28960 + return __load_segment_descriptor(ctxt, selector, seg, cpl, false, NULL);
28961 }
28962
28963 static void write_register_operand(struct operand *op)
28964 @@ -1951,17 +1984,31 @@ static int em_iret(struct x86_emulate_ctxt *ctxt)
28965 static int em_jmp_far(struct x86_emulate_ctxt *ctxt)
28966 {
28967 int rc;
28968 - unsigned short sel;
28969 + unsigned short sel, old_sel;
28970 + struct desc_struct old_desc, new_desc;
28971 + const struct x86_emulate_ops *ops = ctxt->ops;
28972 + u8 cpl = ctxt->ops->cpl(ctxt);
28973 +
28974 + /* Assignment of RIP may only fail in 64-bit mode */
28975 + if (ctxt->mode == X86EMUL_MODE_PROT64)
28976 + ops->get_segment(ctxt, &old_sel, &old_desc, NULL,
28977 + VCPU_SREG_CS);
28978
28979 memcpy(&sel, ctxt->src.valptr + ctxt->op_bytes, 2);
28980
28981 - rc = load_segment_descriptor(ctxt, sel, VCPU_SREG_CS);
28982 + rc = __load_segment_descriptor(ctxt, sel, VCPU_SREG_CS, cpl, false,
28983 + &new_desc);
28984 if (rc != X86EMUL_CONTINUE)
28985 return rc;
28986
28987 - ctxt->_eip = 0;
28988 - memcpy(&ctxt->_eip, ctxt->src.valptr, ctxt->op_bytes);
28989 - return X86EMUL_CONTINUE;
28990 + rc = assign_eip_far(ctxt, ctxt->src.val, new_desc.l);
28991 + if (rc != X86EMUL_CONTINUE) {
28992 + WARN_ON(!ctxt->mode != X86EMUL_MODE_PROT64);
28993 + /* assigning eip failed; restore the old cs */
28994 + ops->set_segment(ctxt, old_sel, &old_desc, 0, VCPU_SREG_CS);
28995 + return rc;
28996 + }
28997 + return rc;
28998 }
28999
29000 static int em_grp45(struct x86_emulate_ctxt *ctxt)
29001 @@ -1972,13 +2019,15 @@ static int em_grp45(struct x86_emulate_ctxt *ctxt)
29002 case 2: /* call near abs */ {
29003 long int old_eip;
29004 old_eip = ctxt->_eip;
29005 - ctxt->_eip = ctxt->src.val;
29006 + rc = assign_eip_near(ctxt, ctxt->src.val);
29007 + if (rc != X86EMUL_CONTINUE)
29008 + break;
29009 ctxt->src.val = old_eip;
29010 rc = em_push(ctxt);
29011 break;
29012 }
29013 case 4: /* jmp abs */
29014 - ctxt->_eip = ctxt->src.val;
29015 + rc = assign_eip_near(ctxt, ctxt->src.val);
29016 break;
29017 case 5: /* jmp far */
29018 rc = em_jmp_far(ctxt);
29019 @@ -2013,30 +2062,47 @@ static int em_cmpxchg8b(struct x86_emulate_ctxt *ctxt)
29020
29021 static int em_ret(struct x86_emulate_ctxt *ctxt)
29022 {
29023 - ctxt->dst.type = OP_REG;
29024 - ctxt->dst.addr.reg = &ctxt->_eip;
29025 - ctxt->dst.bytes = ctxt->op_bytes;
29026 - return em_pop(ctxt);
29027 + int rc;
29028 + unsigned long eip;
29029 +
29030 + rc = emulate_pop(ctxt, &eip, ctxt->op_bytes);
29031 + if (rc != X86EMUL_CONTINUE)
29032 + return rc;
29033 +
29034 + return assign_eip_near(ctxt, eip);
29035 }
29036
29037 static int em_ret_far(struct x86_emulate_ctxt *ctxt)
29038 {
29039 int rc;
29040 - unsigned long cs;
29041 + unsigned long eip, cs;
29042 + u16 old_cs;
29043 int cpl = ctxt->ops->cpl(ctxt);
29044 + struct desc_struct old_desc, new_desc;
29045 + const struct x86_emulate_ops *ops = ctxt->ops;
29046
29047 - rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
29048 + if (ctxt->mode == X86EMUL_MODE_PROT64)
29049 + ops->get_segment(ctxt, &old_cs, &old_desc, NULL,
29050 + VCPU_SREG_CS);
29051 +
29052 + rc = emulate_pop(ctxt, &eip, ctxt->op_bytes);
29053 if (rc != X86EMUL_CONTINUE)
29054 return rc;
29055 - if (ctxt->op_bytes == 4)
29056 - ctxt->_eip = (u32)ctxt->_eip;
29057 rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
29058 if (rc != X86EMUL_CONTINUE)
29059 return rc;
29060 /* Outer-privilege level return is not implemented */
29061 if (ctxt->mode >= X86EMUL_MODE_PROT16 && (cs & 3) > cpl)
29062 return X86EMUL_UNHANDLEABLE;
29063 - rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
29064 + rc = __load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS, 0, false,
29065 + &new_desc);
29066 + if (rc != X86EMUL_CONTINUE)
29067 + return rc;
29068 + rc = assign_eip_far(ctxt, eip, new_desc.l);
29069 + if (rc != X86EMUL_CONTINUE) {
29070 + WARN_ON(!ctxt->mode != X86EMUL_MODE_PROT64);
29071 + ops->set_segment(ctxt, old_cs, &old_desc, 0, VCPU_SREG_CS);
29072 + }
29073 return rc;
29074 }
29075
29076 @@ -2297,7 +2363,7 @@ static int em_sysexit(struct x86_emulate_ctxt *ctxt)
29077 {
29078 const struct x86_emulate_ops *ops = ctxt->ops;
29079 struct desc_struct cs, ss;
29080 - u64 msr_data;
29081 + u64 msr_data, rcx, rdx;
29082 int usermode;
29083 u16 cs_sel = 0, ss_sel = 0;
29084
29085 @@ -2313,6 +2379,9 @@ static int em_sysexit(struct x86_emulate_ctxt *ctxt)
29086 else
29087 usermode = X86EMUL_MODE_PROT32;
29088
29089 + rcx = reg_read(ctxt, VCPU_REGS_RCX);
29090 + rdx = reg_read(ctxt, VCPU_REGS_RDX);
29091 +
29092 cs.dpl = 3;
29093 ss.dpl = 3;
29094 ops->get_msr(ctxt, MSR_IA32_SYSENTER_CS, &msr_data);
29095 @@ -2330,6 +2399,9 @@ static int em_sysexit(struct x86_emulate_ctxt *ctxt)
29096 ss_sel = cs_sel + 8;
29097 cs.d = 0;
29098 cs.l = 1;
29099 + if (is_noncanonical_address(rcx) ||
29100 + is_noncanonical_address(rdx))
29101 + return emulate_gp(ctxt, 0);
29102 break;
29103 }
29104 cs_sel |= SELECTOR_RPL_MASK;
29105 @@ -2338,8 +2410,8 @@ static int em_sysexit(struct x86_emulate_ctxt *ctxt)
29106 ops->set_segment(ctxt, cs_sel, &cs, 0, VCPU_SREG_CS);
29107 ops->set_segment(ctxt, ss_sel, &ss, 0, VCPU_SREG_SS);
29108
29109 - ctxt->_eip = reg_read(ctxt, VCPU_REGS_RDX);
29110 - *reg_write(ctxt, VCPU_REGS_RSP) = reg_read(ctxt, VCPU_REGS_RCX);
29111 + ctxt->_eip = rdx;
29112 + *reg_write(ctxt, VCPU_REGS_RSP) = rcx;
29113
29114 return X86EMUL_CONTINUE;
29115 }
29116 @@ -2457,19 +2529,24 @@ static int load_state_from_tss16(struct x86_emulate_ctxt *ctxt,
29117 * Now load segment descriptors. If fault happens at this stage
29118 * it is handled in a context of new task
29119 */
29120 - ret = __load_segment_descriptor(ctxt, tss->ldt, VCPU_SREG_LDTR, cpl, true);
29121 + ret = __load_segment_descriptor(ctxt, tss->ldt, VCPU_SREG_LDTR, cpl,
29122 + true, NULL);
29123 if (ret != X86EMUL_CONTINUE)
29124 return ret;
29125 - ret = __load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, cpl, true);
29126 + ret = __load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, cpl,
29127 + true, NULL);
29128 if (ret != X86EMUL_CONTINUE)
29129 return ret;
29130 - ret = __load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, cpl, true);
29131 + ret = __load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, cpl,
29132 + true, NULL);
29133 if (ret != X86EMUL_CONTINUE)
29134 return ret;
29135 - ret = __load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, cpl, true);
29136 + ret = __load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, cpl,
29137 + true, NULL);
29138 if (ret != X86EMUL_CONTINUE)
29139 return ret;
29140 - ret = __load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, cpl, true);
29141 + ret = __load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, cpl,
29142 + true, NULL);
29143 if (ret != X86EMUL_CONTINUE)
29144 return ret;
29145
29146 @@ -2594,25 +2671,32 @@ static int load_state_from_tss32(struct x86_emulate_ctxt *ctxt,
29147 * Now load segment descriptors. If fault happenes at this stage
29148 * it is handled in a context of new task
29149 */
29150 - ret = __load_segment_descriptor(ctxt, tss->ldt_selector, VCPU_SREG_LDTR, cpl, true);
29151 + ret = __load_segment_descriptor(ctxt, tss->ldt_selector, VCPU_SREG_LDTR,
29152 + cpl, true, NULL);
29153 if (ret != X86EMUL_CONTINUE)
29154 return ret;
29155 - ret = __load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, cpl, true);
29156 + ret = __load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, cpl,
29157 + true, NULL);
29158 if (ret != X86EMUL_CONTINUE)
29159 return ret;
29160 - ret = __load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, cpl, true);
29161 + ret = __load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, cpl,
29162 + true, NULL);
29163 if (ret != X86EMUL_CONTINUE)
29164 return ret;
29165 - ret = __load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, cpl, true);
29166 + ret = __load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, cpl,
29167 + true, NULL);
29168 if (ret != X86EMUL_CONTINUE)
29169 return ret;
29170 - ret = __load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, cpl, true);
29171 + ret = __load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, cpl,
29172 + true, NULL);
29173 if (ret != X86EMUL_CONTINUE)
29174 return ret;
29175 - ret = __load_segment_descriptor(ctxt, tss->fs, VCPU_SREG_FS, cpl, true);
29176 + ret = __load_segment_descriptor(ctxt, tss->fs, VCPU_SREG_FS, cpl,
29177 + true, NULL);
29178 if (ret != X86EMUL_CONTINUE)
29179 return ret;
29180 - ret = __load_segment_descriptor(ctxt, tss->gs, VCPU_SREG_GS, cpl, true);
29181 + ret = __load_segment_descriptor(ctxt, tss->gs, VCPU_SREG_GS, cpl,
29182 + true, NULL);
29183 if (ret != X86EMUL_CONTINUE)
29184 return ret;
29185
29186 @@ -2880,10 +2964,13 @@ static int em_aad(struct x86_emulate_ctxt *ctxt)
29187
29188 static int em_call(struct x86_emulate_ctxt *ctxt)
29189 {
29190 + int rc;
29191 long rel = ctxt->src.val;
29192
29193 ctxt->src.val = (unsigned long)ctxt->_eip;
29194 - jmp_rel(ctxt, rel);
29195 + rc = jmp_rel(ctxt, rel);
29196 + if (rc != X86EMUL_CONTINUE)
29197 + return rc;
29198 return em_push(ctxt);
29199 }
29200
29201 @@ -2892,34 +2979,50 @@ static int em_call_far(struct x86_emulate_ctxt *ctxt)
29202 u16 sel, old_cs;
29203 ulong old_eip;
29204 int rc;
29205 + struct desc_struct old_desc, new_desc;
29206 + const struct x86_emulate_ops *ops = ctxt->ops;
29207 + int cpl = ctxt->ops->cpl(ctxt);
29208
29209 - old_cs = get_segment_selector(ctxt, VCPU_SREG_CS);
29210 old_eip = ctxt->_eip;
29211 + ops->get_segment(ctxt, &old_cs, &old_desc, NULL, VCPU_SREG_CS);
29212
29213 memcpy(&sel, ctxt->src.valptr + ctxt->op_bytes, 2);
29214 - if (load_segment_descriptor(ctxt, sel, VCPU_SREG_CS))
29215 + rc = __load_segment_descriptor(ctxt, sel, VCPU_SREG_CS, cpl, false,
29216 + &new_desc);
29217 + if (rc != X86EMUL_CONTINUE)
29218 return X86EMUL_CONTINUE;
29219
29220 - ctxt->_eip = 0;
29221 - memcpy(&ctxt->_eip, ctxt->src.valptr, ctxt->op_bytes);
29222 + rc = assign_eip_far(ctxt, ctxt->src.val, new_desc.l);
29223 + if (rc != X86EMUL_CONTINUE)
29224 + goto fail;
29225
29226 ctxt->src.val = old_cs;
29227 rc = em_push(ctxt);
29228 if (rc != X86EMUL_CONTINUE)
29229 - return rc;
29230 + goto fail;
29231
29232 ctxt->src.val = old_eip;
29233 - return em_push(ctxt);
29234 + rc = em_push(ctxt);
29235 + /* If we failed, we tainted the memory, but the very least we should
29236 + restore cs */
29237 + if (rc != X86EMUL_CONTINUE)
29238 + goto fail;
29239 + return rc;
29240 +fail:
29241 + ops->set_segment(ctxt, old_cs, &old_desc, 0, VCPU_SREG_CS);
29242 + return rc;
29243 +
29244 }
29245
29246 static int em_ret_near_imm(struct x86_emulate_ctxt *ctxt)
29247 {
29248 int rc;
29249 + unsigned long eip;
29250
29251 - ctxt->dst.type = OP_REG;
29252 - ctxt->dst.addr.reg = &ctxt->_eip;
29253 - ctxt->dst.bytes = ctxt->op_bytes;
29254 - rc = emulate_pop(ctxt, &ctxt->dst.val, ctxt->op_bytes);
29255 + rc = emulate_pop(ctxt, &eip, ctxt->op_bytes);
29256 + if (rc != X86EMUL_CONTINUE)
29257 + return rc;
29258 + rc = assign_eip_near(ctxt, eip);
29259 if (rc != X86EMUL_CONTINUE)
29260 return rc;
29261 rsp_increment(ctxt, ctxt->src.val);
29262 @@ -3250,20 +3353,24 @@ static int em_lmsw(struct x86_emulate_ctxt *ctxt)
29263
29264 static int em_loop(struct x86_emulate_ctxt *ctxt)
29265 {
29266 + int rc = X86EMUL_CONTINUE;
29267 +
29268 register_address_increment(ctxt, reg_rmw(ctxt, VCPU_REGS_RCX), -1);
29269 if ((address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) != 0) &&
29270 (ctxt->b == 0xe2 || test_cc(ctxt->b ^ 0x5, ctxt->eflags)))
29271 - jmp_rel(ctxt, ctxt->src.val);
29272 + rc = jmp_rel(ctxt, ctxt->src.val);
29273
29274 - return X86EMUL_CONTINUE;
29275 + return rc;
29276 }
29277
29278 static int em_jcxz(struct x86_emulate_ctxt *ctxt)
29279 {
29280 + int rc = X86EMUL_CONTINUE;
29281 +
29282 if (address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) == 0)
29283 - jmp_rel(ctxt, ctxt->src.val);
29284 + rc = jmp_rel(ctxt, ctxt->src.val);
29285
29286 - return X86EMUL_CONTINUE;
29287 + return rc;
29288 }
29289
29290 static int em_in(struct x86_emulate_ctxt *ctxt)
29291 @@ -3351,6 +3458,12 @@ static int em_bswap(struct x86_emulate_ctxt *ctxt)
29292 return X86EMUL_CONTINUE;
29293 }
29294
29295 +static int em_clflush(struct x86_emulate_ctxt *ctxt)
29296 +{
29297 + /* emulating clflush regardless of cpuid */
29298 + return X86EMUL_CONTINUE;
29299 +}
29300 +
29301 static bool valid_cr(int nr)
29302 {
29303 switch (nr) {
29304 @@ -3683,6 +3796,16 @@ static const struct opcode group11[] = {
29305 X7(D(Undefined)),
29306 };
29307
29308 +static const struct gprefix pfx_0f_ae_7 = {
29309 + I(SrcMem | ByteOp, em_clflush), N, N, N,
29310 +};
29311 +
29312 +static const struct group_dual group15 = { {
29313 + N, N, N, N, N, N, N, GP(0, &pfx_0f_ae_7),
29314 +}, {
29315 + N, N, N, N, N, N, N, N,
29316 +} };
29317 +
29318 static const struct gprefix pfx_0f_6f_0f_7f = {
29319 I(Mmx, em_mov), I(Sse | Aligned, em_mov), N, I(Sse | Unaligned, em_mov),
29320 };
29321 @@ -3887,10 +4010,11 @@ static const struct opcode twobyte_table[256] = {
29322 N, I(ImplicitOps | EmulateOnUD, em_syscall),
29323 II(ImplicitOps | Priv, em_clts, clts), N,
29324 DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N,
29325 - N, D(ImplicitOps | ModRM), N, N,
29326 + N, D(ImplicitOps | ModRM | SrcMem | NoAccess), N, N,
29327 /* 0x10 - 0x1F */
29328 N, N, N, N, N, N, N, N,
29329 - D(ImplicitOps | ModRM), N, N, N, N, N, N, D(ImplicitOps | ModRM),
29330 + D(ImplicitOps | ModRM | SrcMem | NoAccess),
29331 + N, N, N, N, N, N, D(ImplicitOps | ModRM | SrcMem | NoAccess),
29332 /* 0x20 - 0x2F */
29333 DIP(ModRM | DstMem | Priv | Op3264 | NoMod, cr_read, check_cr_read),
29334 DIP(ModRM | DstMem | Priv | Op3264 | NoMod, dr_read, check_dr_read),
29335 @@ -3942,7 +4066,7 @@ static const struct opcode twobyte_table[256] = {
29336 F(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable, em_bts),
29337 F(DstMem | SrcReg | Src2ImmByte | ModRM, em_shrd),
29338 F(DstMem | SrcReg | Src2CL | ModRM, em_shrd),
29339 - D(ModRM), F(DstReg | SrcMem | ModRM, em_imul),
29340 + GD(0, &group15), F(DstReg | SrcMem | ModRM, em_imul),
29341 /* 0xB0 - 0xB7 */
29342 I2bv(DstMem | SrcReg | ModRM | Lock | PageTable, em_cmpxchg),
29343 I(DstReg | SrcMemFAddr | ModRM | Src2SS, em_lseg),
29344 @@ -4458,10 +4582,10 @@ done_prefixes:
29345 /* Decode and fetch the destination operand: register or memory. */
29346 rc = decode_operand(ctxt, &ctxt->dst, (ctxt->d >> DstShift) & OpMask);
29347
29348 -done:
29349 if (ctxt->rip_relative)
29350 ctxt->memopp->addr.mem.ea += ctxt->_eip;
29351
29352 +done:
29353 return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK;
29354 }
29355
29356 @@ -4711,7 +4835,7 @@ special_insn:
29357 break;
29358 case 0x70 ... 0x7f: /* jcc (short) */
29359 if (test_cc(ctxt->b, ctxt->eflags))
29360 - jmp_rel(ctxt, ctxt->src.val);
29361 + rc = jmp_rel(ctxt, ctxt->src.val);
29362 break;
29363 case 0x8d: /* lea r16/r32, m */
29364 ctxt->dst.val = ctxt->src.addr.mem.ea;
29365 @@ -4741,7 +4865,7 @@ special_insn:
29366 break;
29367 case 0xe9: /* jmp rel */
29368 case 0xeb: /* jmp rel short */
29369 - jmp_rel(ctxt, ctxt->src.val);
29370 + rc = jmp_rel(ctxt, ctxt->src.val);
29371 ctxt->dst.type = OP_NONE; /* Disable writeback. */
29372 break;
29373 case 0xf4: /* hlt */
29374 @@ -4864,13 +4988,11 @@ twobyte_insn:
29375 break;
29376 case 0x80 ... 0x8f: /* jnz rel, etc*/
29377 if (test_cc(ctxt->b, ctxt->eflags))
29378 - jmp_rel(ctxt, ctxt->src.val);
29379 + rc = jmp_rel(ctxt, ctxt->src.val);
29380 break;
29381 case 0x90 ... 0x9f: /* setcc r/m8 */
29382 ctxt->dst.val = test_cc(ctxt->b, ctxt->eflags);
29383 break;
29384 - case 0xae: /* clflush */
29385 - break;
29386 case 0xb6 ... 0xb7: /* movzx */
29387 ctxt->dst.bytes = ctxt->op_bytes;
29388 ctxt->dst.val = (ctxt->src.bytes == 1) ? (u8) ctxt->src.val
29389 diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
29390 index 518d864..298781d 100644
29391 --- a/arch/x86/kvm/i8254.c
29392 +++ b/arch/x86/kvm/i8254.c
29393 @@ -262,8 +262,10 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
29394 return;
29395
29396 timer = &pit->pit_state.timer;
29397 + mutex_lock(&pit->pit_state.lock);
29398 if (hrtimer_cancel(timer))
29399 hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
29400 + mutex_unlock(&pit->pit_state.lock);
29401 }
29402
29403 static void destroy_pit_timer(struct kvm_pit *pit)
29404 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29405 index 08e8a89..0e9183e 100644
29406 --- a/arch/x86/kvm/lapic.c
29407 +++ b/arch/x86/kvm/lapic.c
29408 @@ -55,7 +55,7 @@
29409 #define APIC_BUS_CYCLE_NS 1
29410
29411 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29412 -#define apic_debug(fmt, arg...)
29413 +#define apic_debug(fmt, arg...) do {} while (0)
29414
29415 #define APIC_LVT_NUM 6
29416 /* 14 is the version for Xeon and Pentium 8.4.8*/
29417 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29418 index 4107765..d9eb358 100644
29419 --- a/arch/x86/kvm/paging_tmpl.h
29420 +++ b/arch/x86/kvm/paging_tmpl.h
29421 @@ -331,7 +331,7 @@ retry_walk:
29422 if (unlikely(kvm_is_error_hva(host_addr)))
29423 goto error;
29424
29425 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29426 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29427 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29428 goto error;
29429 walker->ptep_user[walker->level - 1] = ptep_user;
29430 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29431 index ddf7427..fd84599 100644
29432 --- a/arch/x86/kvm/svm.c
29433 +++ b/arch/x86/kvm/svm.c
29434 @@ -3234,7 +3234,7 @@ static int wrmsr_interception(struct vcpu_svm *svm)
29435 msr.host_initiated = false;
29436
29437 svm->next_rip = kvm_rip_read(&svm->vcpu) + 2;
29438 - if (svm_set_msr(&svm->vcpu, &msr)) {
29439 + if (kvm_set_msr(&svm->vcpu, &msr)) {
29440 trace_kvm_msr_write_ex(ecx, data);
29441 kvm_inject_gp(&svm->vcpu, 0);
29442 } else {
29443 @@ -3534,9 +3534,9 @@ static int handle_exit(struct kvm_vcpu *vcpu)
29444
29445 if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
29446 || !svm_exit_handlers[exit_code]) {
29447 - kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
29448 - kvm_run->hw.hardware_exit_reason = exit_code;
29449 - return 0;
29450 + WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_code);
29451 + kvm_queue_exception(vcpu, UD_VECTOR);
29452 + return 1;
29453 }
29454
29455 return svm_exit_handlers[exit_code](svm);
29456 @@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29457 int cpu = raw_smp_processor_id();
29458
29459 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29460 +
29461 + pax_open_kernel();
29462 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29463 + pax_close_kernel();
29464 +
29465 load_TR_desc();
29466 }
29467
29468 @@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29469 #endif
29470 #endif
29471
29472 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29473 + __set_fs(current_thread_info()->addr_limit);
29474 +#endif
29475 +
29476 reload_tss(vcpu);
29477
29478 local_irq_disable();
29479 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29480 index bfe11cf..deb3959 100644
29481 --- a/arch/x86/kvm/vmx.c
29482 +++ b/arch/x86/kvm/vmx.c
29483 @@ -453,6 +453,7 @@ struct vcpu_vmx {
29484 int gs_ldt_reload_needed;
29485 int fs_reload_needed;
29486 u64 msr_host_bndcfgs;
29487 + unsigned long vmcs_host_cr4; /* May not match real cr4 */
29488 } host_state;
29489 struct {
29490 int vm86_active;
29491 @@ -1340,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29492 #endif
29493 }
29494
29495 -static void vmcs_clear_bits(unsigned long field, u32 mask)
29496 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29497 {
29498 vmcs_writel(field, vmcs_readl(field) & ~mask);
29499 }
29500
29501 -static void vmcs_set_bits(unsigned long field, u32 mask)
29502 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
29503 {
29504 vmcs_writel(field, vmcs_readl(field) | mask);
29505 }
29506 @@ -1605,7 +1606,11 @@ static void reload_tss(void)
29507 struct desc_struct *descs;
29508
29509 descs = (void *)gdt->address;
29510 +
29511 + pax_open_kernel();
29512 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29513 + pax_close_kernel();
29514 +
29515 load_TR_desc();
29516 }
29517
29518 @@ -1833,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29519 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29520 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29521
29522 +#ifdef CONFIG_PAX_PER_CPU_PGD
29523 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29524 +#endif
29525 +
29526 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29527 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29528 vmx->loaded_vmcs->cpu = cpu;
29529 @@ -2122,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29530 * reads and returns guest's timestamp counter "register"
29531 * guest_tsc = host_tsc + tsc_offset -- 21.3
29532 */
29533 -static u64 guest_read_tsc(void)
29534 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
29535 {
29536 u64 host_tsc, tsc_offset;
29537
29538 @@ -2631,12 +2640,15 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
29539 default:
29540 msr = find_msr_entry(vmx, msr_index);
29541 if (msr) {
29542 + u64 old_msr_data = msr->data;
29543 msr->data = data;
29544 if (msr - vmx->guest_msrs < vmx->save_nmsrs) {
29545 preempt_disable();
29546 - kvm_set_shared_msr(msr->index, msr->data,
29547 - msr->mask);
29548 + ret = kvm_set_shared_msr(msr->index, msr->data,
29549 + msr->mask);
29550 preempt_enable();
29551 + if (ret)
29552 + msr->data = old_msr_data;
29553 }
29554 break;
29555 }
29556 @@ -3110,8 +3122,11 @@ static __init int hardware_setup(void)
29557 if (!cpu_has_vmx_flexpriority())
29558 flexpriority_enabled = 0;
29559
29560 - if (!cpu_has_vmx_tpr_shadow())
29561 - kvm_x86_ops->update_cr8_intercept = NULL;
29562 + if (!cpu_has_vmx_tpr_shadow()) {
29563 + pax_open_kernel();
29564 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29565 + pax_close_kernel();
29566 + }
29567
29568 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29569 kvm_disable_largepages();
29570 @@ -3122,13 +3137,15 @@ static __init int hardware_setup(void)
29571 if (!cpu_has_vmx_apicv())
29572 enable_apicv = 0;
29573
29574 + pax_open_kernel();
29575 if (enable_apicv)
29576 - kvm_x86_ops->update_cr8_intercept = NULL;
29577 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29578 else {
29579 - kvm_x86_ops->hwapic_irr_update = NULL;
29580 - kvm_x86_ops->deliver_posted_interrupt = NULL;
29581 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29582 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29583 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29584 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29585 }
29586 + pax_close_kernel();
29587
29588 if (nested)
29589 nested_vmx_setup_ctls_msrs();
29590 @@ -4235,10 +4252,17 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29591 u32 low32, high32;
29592 unsigned long tmpl;
29593 struct desc_ptr dt;
29594 + unsigned long cr4;
29595
29596 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29597 - vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
29598 +#ifndef CONFIG_PAX_PER_CPU_PGD
29599 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29600 +#endif
29601 +
29602 + /* Save the most likely value for this task's CR4 in the VMCS. */
29603 + cr4 = read_cr4();
29604 + vmcs_writel(HOST_CR4, cr4); /* 22.2.3, 22.2.5 */
29605 + vmx->host_state.vmcs_host_cr4 = cr4;
29606
29607 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
29608 #ifdef CONFIG_X86_64
29609 @@ -4260,7 +4284,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29610 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29611 vmx->host_idt_base = dt.address;
29612
29613 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29614 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29615
29616 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29617 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29618 @@ -5257,7 +5281,7 @@ static int handle_wrmsr(struct kvm_vcpu *vcpu)
29619 msr.data = data;
29620 msr.index = ecx;
29621 msr.host_initiated = false;
29622 - if (vmx_set_msr(vcpu, &msr) != 0) {
29623 + if (kvm_set_msr(vcpu, &msr) != 0) {
29624 trace_kvm_msr_write_ex(ecx, data);
29625 kvm_inject_gp(vcpu, 0);
29626 return 1;
29627 @@ -6630,6 +6654,12 @@ static int handle_invept(struct kvm_vcpu *vcpu)
29628 return 1;
29629 }
29630
29631 +static int handle_invvpid(struct kvm_vcpu *vcpu)
29632 +{
29633 + kvm_queue_exception(vcpu, UD_VECTOR);
29634 + return 1;
29635 +}
29636 +
29637 /*
29638 * The exit handlers return 1 if the exit was handled fully and guest execution
29639 * may resume. Otherwise they set the kvm_run parameter to indicate what needs
29640 @@ -6675,6 +6705,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
29641 [EXIT_REASON_MWAIT_INSTRUCTION] = handle_mwait,
29642 [EXIT_REASON_MONITOR_INSTRUCTION] = handle_monitor,
29643 [EXIT_REASON_INVEPT] = handle_invept,
29644 + [EXIT_REASON_INVVPID] = handle_invvpid,
29645 };
29646
29647 static const int kvm_vmx_max_exit_handlers =
29648 @@ -6908,7 +6939,7 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu)
29649 case EXIT_REASON_VMPTRST: case EXIT_REASON_VMREAD:
29650 case EXIT_REASON_VMRESUME: case EXIT_REASON_VMWRITE:
29651 case EXIT_REASON_VMOFF: case EXIT_REASON_VMON:
29652 - case EXIT_REASON_INVEPT:
29653 + case EXIT_REASON_INVEPT: case EXIT_REASON_INVVPID:
29654 /*
29655 * VMX instructions trap unconditionally. This allows L1 to
29656 * emulate them for its L2 guest, i.e., allows 3-level nesting!
29657 @@ -7049,10 +7080,10 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
29658 && kvm_vmx_exit_handlers[exit_reason])
29659 return kvm_vmx_exit_handlers[exit_reason](vcpu);
29660 else {
29661 - vcpu->run->exit_reason = KVM_EXIT_UNKNOWN;
29662 - vcpu->run->hw.hardware_exit_reason = exit_reason;
29663 + WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason);
29664 + kvm_queue_exception(vcpu, UD_VECTOR);
29665 + return 1;
29666 }
29667 - return 0;
29668 }
29669
29670 static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
29671 @@ -7376,7 +7407,7 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
29672 static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29673 {
29674 struct vcpu_vmx *vmx = to_vmx(vcpu);
29675 - unsigned long debugctlmsr;
29676 + unsigned long debugctlmsr, cr4;
29677
29678 /* Record the guest's net vcpu time for enforced NMI injections. */
29679 if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked))
29680 @@ -7397,6 +7428,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29681 if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))
29682 vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);
29683
29684 + cr4 = read_cr4();
29685 + if (unlikely(cr4 != vmx->host_state.vmcs_host_cr4)) {
29686 + vmcs_writel(HOST_CR4, cr4);
29687 + vmx->host_state.vmcs_host_cr4 = cr4;
29688 + }
29689 +
29690 /* When single-stepping over STI and MOV SS, we must clear the
29691 * corresponding interruptibility bits in the guest state. Otherwise
29692 * vmentry fails as it then expects bit 14 (BS) in pending debug
29693 @@ -7453,6 +7490,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29694 "jmp 2f \n\t"
29695 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29696 "2: "
29697 +
29698 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29699 + "ljmp %[cs],$3f\n\t"
29700 + "3: "
29701 +#endif
29702 +
29703 /* Save guest registers, load host registers, keep flags */
29704 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29705 "pop %0 \n\t"
29706 @@ -7505,6 +7548,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29707 #endif
29708 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29709 [wordsize]"i"(sizeof(ulong))
29710 +
29711 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29712 + ,[cs]"i"(__KERNEL_CS)
29713 +#endif
29714 +
29715 : "cc", "memory"
29716 #ifdef CONFIG_X86_64
29717 , "rax", "rbx", "rdi", "rsi"
29718 @@ -7518,7 +7566,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29719 if (debugctlmsr)
29720 update_debugctlmsr(debugctlmsr);
29721
29722 -#ifndef CONFIG_X86_64
29723 +#ifdef CONFIG_X86_32
29724 /*
29725 * The sysexit path does not restore ds/es, so we must set them to
29726 * a reasonable value ourselves.
29727 @@ -7527,8 +7575,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29728 * may be executed in interrupt context, which saves and restore segments
29729 * around it, nullifying its effect.
29730 */
29731 - loadsegment(ds, __USER_DS);
29732 - loadsegment(es, __USER_DS);
29733 + loadsegment(ds, __KERNEL_DS);
29734 + loadsegment(es, __KERNEL_DS);
29735 + loadsegment(ss, __KERNEL_DS);
29736 +
29737 +#ifdef CONFIG_PAX_KERNEXEC
29738 + loadsegment(fs, __KERNEL_PERCPU);
29739 +#endif
29740 +
29741 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29742 + __set_fs(current_thread_info()->addr_limit);
29743 +#endif
29744 +
29745 #endif
29746
29747 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29748 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29749 index 8f1e22d..c23d3c5 100644
29750 --- a/arch/x86/kvm/x86.c
29751 +++ b/arch/x86/kvm/x86.c
29752 @@ -229,20 +229,25 @@ static void kvm_shared_msr_cpu_online(void)
29753 shared_msr_update(i, shared_msrs_global.msrs[i]);
29754 }
29755
29756 -void kvm_set_shared_msr(unsigned slot, u64 value, u64 mask)
29757 +int kvm_set_shared_msr(unsigned slot, u64 value, u64 mask)
29758 {
29759 unsigned int cpu = smp_processor_id();
29760 struct kvm_shared_msrs *smsr = per_cpu_ptr(shared_msrs, cpu);
29761 + int err;
29762
29763 if (((value ^ smsr->values[slot].curr) & mask) == 0)
29764 - return;
29765 + return 0;
29766 smsr->values[slot].curr = value;
29767 - wrmsrl(shared_msrs_global.msrs[slot], value);
29768 + err = wrmsrl_safe(shared_msrs_global.msrs[slot], value);
29769 + if (err)
29770 + return 1;
29771 +
29772 if (!smsr->registered) {
29773 smsr->urn.on_user_return = kvm_on_user_return;
29774 user_return_notifier_register(&smsr->urn);
29775 smsr->registered = true;
29776 }
29777 + return 0;
29778 }
29779 EXPORT_SYMBOL_GPL(kvm_set_shared_msr);
29780
29781 @@ -984,7 +989,6 @@ void kvm_enable_efer_bits(u64 mask)
29782 }
29783 EXPORT_SYMBOL_GPL(kvm_enable_efer_bits);
29784
29785 -
29786 /*
29787 * Writes msr value into into the appropriate "register".
29788 * Returns 0 on success, non-0 otherwise.
29789 @@ -992,8 +996,34 @@ EXPORT_SYMBOL_GPL(kvm_enable_efer_bits);
29790 */
29791 int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
29792 {
29793 + switch (msr->index) {
29794 + case MSR_FS_BASE:
29795 + case MSR_GS_BASE:
29796 + case MSR_KERNEL_GS_BASE:
29797 + case MSR_CSTAR:
29798 + case MSR_LSTAR:
29799 + if (is_noncanonical_address(msr->data))
29800 + return 1;
29801 + break;
29802 + case MSR_IA32_SYSENTER_EIP:
29803 + case MSR_IA32_SYSENTER_ESP:
29804 + /*
29805 + * IA32_SYSENTER_ESP and IA32_SYSENTER_EIP cause #GP if
29806 + * non-canonical address is written on Intel but not on
29807 + * AMD (which ignores the top 32-bits, because it does
29808 + * not implement 64-bit SYSENTER).
29809 + *
29810 + * 64-bit code should hence be able to write a non-canonical
29811 + * value on AMD. Making the address canonical ensures that
29812 + * vmentry does not fail on Intel after writing a non-canonical
29813 + * value, and that something deterministic happens if the guest
29814 + * invokes 64-bit SYSENTER.
29815 + */
29816 + msr->data = get_canonical(msr->data);
29817 + }
29818 return kvm_x86_ops->set_msr(vcpu, msr);
29819 }
29820 +EXPORT_SYMBOL_GPL(kvm_set_msr);
29821
29822 /*
29823 * Adapt set_msr() to msr_io()'s calling convention
29824 @@ -1827,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29825 {
29826 struct kvm *kvm = vcpu->kvm;
29827 int lm = is_long_mode(vcpu);
29828 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29829 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29830 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29831 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29832 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29833 : kvm->arch.xen_hvm_config.blob_size_32;
29834 u32 page_num = data & ~PAGE_MASK;
29835 @@ -2749,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29836 if (n < msr_list.nmsrs)
29837 goto out;
29838 r = -EFAULT;
29839 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29840 + goto out;
29841 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29842 num_msrs_to_save * sizeof(u32)))
29843 goto out;
29844 @@ -5609,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29845 };
29846 #endif
29847
29848 -int kvm_arch_init(void *opaque)
29849 +int kvm_arch_init(const void *opaque)
29850 {
29851 int r;
29852 struct kvm_x86_ops *ops = opaque;
29853 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29854 index aae9413..d11e829 100644
29855 --- a/arch/x86/lguest/boot.c
29856 +++ b/arch/x86/lguest/boot.c
29857 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29858 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29859 * Launcher to reboot us.
29860 */
29861 -static void lguest_restart(char *reason)
29862 +static __noreturn void lguest_restart(char *reason)
29863 {
29864 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29865 + BUG();
29866 }
29867
29868 /*G:050
29869 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29870 index 00933d5..3a64af9 100644
29871 --- a/arch/x86/lib/atomic64_386_32.S
29872 +++ b/arch/x86/lib/atomic64_386_32.S
29873 @@ -48,6 +48,10 @@ BEGIN(read)
29874 movl (v), %eax
29875 movl 4(v), %edx
29876 RET_ENDP
29877 +BEGIN(read_unchecked)
29878 + movl (v), %eax
29879 + movl 4(v), %edx
29880 +RET_ENDP
29881 #undef v
29882
29883 #define v %esi
29884 @@ -55,6 +59,10 @@ BEGIN(set)
29885 movl %ebx, (v)
29886 movl %ecx, 4(v)
29887 RET_ENDP
29888 +BEGIN(set_unchecked)
29889 + movl %ebx, (v)
29890 + movl %ecx, 4(v)
29891 +RET_ENDP
29892 #undef v
29893
29894 #define v %esi
29895 @@ -70,6 +78,20 @@ RET_ENDP
29896 BEGIN(add)
29897 addl %eax, (v)
29898 adcl %edx, 4(v)
29899 +
29900 +#ifdef CONFIG_PAX_REFCOUNT
29901 + jno 0f
29902 + subl %eax, (v)
29903 + sbbl %edx, 4(v)
29904 + int $4
29905 +0:
29906 + _ASM_EXTABLE(0b, 0b)
29907 +#endif
29908 +
29909 +RET_ENDP
29910 +BEGIN(add_unchecked)
29911 + addl %eax, (v)
29912 + adcl %edx, 4(v)
29913 RET_ENDP
29914 #undef v
29915
29916 @@ -77,6 +99,24 @@ RET_ENDP
29917 BEGIN(add_return)
29918 addl (v), %eax
29919 adcl 4(v), %edx
29920 +
29921 +#ifdef CONFIG_PAX_REFCOUNT
29922 + into
29923 +1234:
29924 + _ASM_EXTABLE(1234b, 2f)
29925 +#endif
29926 +
29927 + movl %eax, (v)
29928 + movl %edx, 4(v)
29929 +
29930 +#ifdef CONFIG_PAX_REFCOUNT
29931 +2:
29932 +#endif
29933 +
29934 +RET_ENDP
29935 +BEGIN(add_return_unchecked)
29936 + addl (v), %eax
29937 + adcl 4(v), %edx
29938 movl %eax, (v)
29939 movl %edx, 4(v)
29940 RET_ENDP
29941 @@ -86,6 +126,20 @@ RET_ENDP
29942 BEGIN(sub)
29943 subl %eax, (v)
29944 sbbl %edx, 4(v)
29945 +
29946 +#ifdef CONFIG_PAX_REFCOUNT
29947 + jno 0f
29948 + addl %eax, (v)
29949 + adcl %edx, 4(v)
29950 + int $4
29951 +0:
29952 + _ASM_EXTABLE(0b, 0b)
29953 +#endif
29954 +
29955 +RET_ENDP
29956 +BEGIN(sub_unchecked)
29957 + subl %eax, (v)
29958 + sbbl %edx, 4(v)
29959 RET_ENDP
29960 #undef v
29961
29962 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29963 sbbl $0, %edx
29964 addl (v), %eax
29965 adcl 4(v), %edx
29966 +
29967 +#ifdef CONFIG_PAX_REFCOUNT
29968 + into
29969 +1234:
29970 + _ASM_EXTABLE(1234b, 2f)
29971 +#endif
29972 +
29973 + movl %eax, (v)
29974 + movl %edx, 4(v)
29975 +
29976 +#ifdef CONFIG_PAX_REFCOUNT
29977 +2:
29978 +#endif
29979 +
29980 +RET_ENDP
29981 +BEGIN(sub_return_unchecked)
29982 + negl %edx
29983 + negl %eax
29984 + sbbl $0, %edx
29985 + addl (v), %eax
29986 + adcl 4(v), %edx
29987 movl %eax, (v)
29988 movl %edx, 4(v)
29989 RET_ENDP
29990 @@ -105,6 +180,20 @@ RET_ENDP
29991 BEGIN(inc)
29992 addl $1, (v)
29993 adcl $0, 4(v)
29994 +
29995 +#ifdef CONFIG_PAX_REFCOUNT
29996 + jno 0f
29997 + subl $1, (v)
29998 + sbbl $0, 4(v)
29999 + int $4
30000 +0:
30001 + _ASM_EXTABLE(0b, 0b)
30002 +#endif
30003 +
30004 +RET_ENDP
30005 +BEGIN(inc_unchecked)
30006 + addl $1, (v)
30007 + adcl $0, 4(v)
30008 RET_ENDP
30009 #undef v
30010
30011 @@ -114,6 +203,26 @@ BEGIN(inc_return)
30012 movl 4(v), %edx
30013 addl $1, %eax
30014 adcl $0, %edx
30015 +
30016 +#ifdef CONFIG_PAX_REFCOUNT
30017 + into
30018 +1234:
30019 + _ASM_EXTABLE(1234b, 2f)
30020 +#endif
30021 +
30022 + movl %eax, (v)
30023 + movl %edx, 4(v)
30024 +
30025 +#ifdef CONFIG_PAX_REFCOUNT
30026 +2:
30027 +#endif
30028 +
30029 +RET_ENDP
30030 +BEGIN(inc_return_unchecked)
30031 + movl (v), %eax
30032 + movl 4(v), %edx
30033 + addl $1, %eax
30034 + adcl $0, %edx
30035 movl %eax, (v)
30036 movl %edx, 4(v)
30037 RET_ENDP
30038 @@ -123,6 +232,20 @@ RET_ENDP
30039 BEGIN(dec)
30040 subl $1, (v)
30041 sbbl $0, 4(v)
30042 +
30043 +#ifdef CONFIG_PAX_REFCOUNT
30044 + jno 0f
30045 + addl $1, (v)
30046 + adcl $0, 4(v)
30047 + int $4
30048 +0:
30049 + _ASM_EXTABLE(0b, 0b)
30050 +#endif
30051 +
30052 +RET_ENDP
30053 +BEGIN(dec_unchecked)
30054 + subl $1, (v)
30055 + sbbl $0, 4(v)
30056 RET_ENDP
30057 #undef v
30058
30059 @@ -132,6 +255,26 @@ BEGIN(dec_return)
30060 movl 4(v), %edx
30061 subl $1, %eax
30062 sbbl $0, %edx
30063 +
30064 +#ifdef CONFIG_PAX_REFCOUNT
30065 + into
30066 +1234:
30067 + _ASM_EXTABLE(1234b, 2f)
30068 +#endif
30069 +
30070 + movl %eax, (v)
30071 + movl %edx, 4(v)
30072 +
30073 +#ifdef CONFIG_PAX_REFCOUNT
30074 +2:
30075 +#endif
30076 +
30077 +RET_ENDP
30078 +BEGIN(dec_return_unchecked)
30079 + movl (v), %eax
30080 + movl 4(v), %edx
30081 + subl $1, %eax
30082 + sbbl $0, %edx
30083 movl %eax, (v)
30084 movl %edx, 4(v)
30085 RET_ENDP
30086 @@ -143,6 +286,13 @@ BEGIN(add_unless)
30087 adcl %edx, %edi
30088 addl (v), %eax
30089 adcl 4(v), %edx
30090 +
30091 +#ifdef CONFIG_PAX_REFCOUNT
30092 + into
30093 +1234:
30094 + _ASM_EXTABLE(1234b, 2f)
30095 +#endif
30096 +
30097 cmpl %eax, %ecx
30098 je 3f
30099 1:
30100 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
30101 1:
30102 addl $1, %eax
30103 adcl $0, %edx
30104 +
30105 +#ifdef CONFIG_PAX_REFCOUNT
30106 + into
30107 +1234:
30108 + _ASM_EXTABLE(1234b, 2f)
30109 +#endif
30110 +
30111 movl %eax, (v)
30112 movl %edx, 4(v)
30113 movl $1, %eax
30114 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
30115 movl 4(v), %edx
30116 subl $1, %eax
30117 sbbl $0, %edx
30118 +
30119 +#ifdef CONFIG_PAX_REFCOUNT
30120 + into
30121 +1234:
30122 + _ASM_EXTABLE(1234b, 1f)
30123 +#endif
30124 +
30125 js 1f
30126 movl %eax, (v)
30127 movl %edx, 4(v)
30128 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
30129 index f5cc9eb..51fa319 100644
30130 --- a/arch/x86/lib/atomic64_cx8_32.S
30131 +++ b/arch/x86/lib/atomic64_cx8_32.S
30132 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
30133 CFI_STARTPROC
30134
30135 read64 %ecx
30136 + pax_force_retaddr
30137 ret
30138 CFI_ENDPROC
30139 ENDPROC(atomic64_read_cx8)
30140
30141 +ENTRY(atomic64_read_unchecked_cx8)
30142 + CFI_STARTPROC
30143 +
30144 + read64 %ecx
30145 + pax_force_retaddr
30146 + ret
30147 + CFI_ENDPROC
30148 +ENDPROC(atomic64_read_unchecked_cx8)
30149 +
30150 ENTRY(atomic64_set_cx8)
30151 CFI_STARTPROC
30152
30153 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
30154 cmpxchg8b (%esi)
30155 jne 1b
30156
30157 + pax_force_retaddr
30158 ret
30159 CFI_ENDPROC
30160 ENDPROC(atomic64_set_cx8)
30161
30162 +ENTRY(atomic64_set_unchecked_cx8)
30163 + CFI_STARTPROC
30164 +
30165 +1:
30166 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
30167 + * are atomic on 586 and newer */
30168 + cmpxchg8b (%esi)
30169 + jne 1b
30170 +
30171 + pax_force_retaddr
30172 + ret
30173 + CFI_ENDPROC
30174 +ENDPROC(atomic64_set_unchecked_cx8)
30175 +
30176 ENTRY(atomic64_xchg_cx8)
30177 CFI_STARTPROC
30178
30179 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
30180 cmpxchg8b (%esi)
30181 jne 1b
30182
30183 + pax_force_retaddr
30184 ret
30185 CFI_ENDPROC
30186 ENDPROC(atomic64_xchg_cx8)
30187
30188 -.macro addsub_return func ins insc
30189 -ENTRY(atomic64_\func\()_return_cx8)
30190 +.macro addsub_return func ins insc unchecked=""
30191 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30192 CFI_STARTPROC
30193 SAVE ebp
30194 SAVE ebx
30195 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
30196 movl %edx, %ecx
30197 \ins\()l %esi, %ebx
30198 \insc\()l %edi, %ecx
30199 +
30200 +.ifb \unchecked
30201 +#ifdef CONFIG_PAX_REFCOUNT
30202 + into
30203 +2:
30204 + _ASM_EXTABLE(2b, 3f)
30205 +#endif
30206 +.endif
30207 +
30208 LOCK_PREFIX
30209 cmpxchg8b (%ebp)
30210 jne 1b
30211 -
30212 -10:
30213 movl %ebx, %eax
30214 movl %ecx, %edx
30215 +
30216 +.ifb \unchecked
30217 +#ifdef CONFIG_PAX_REFCOUNT
30218 +3:
30219 +#endif
30220 +.endif
30221 +
30222 RESTORE edi
30223 RESTORE esi
30224 RESTORE ebx
30225 RESTORE ebp
30226 + pax_force_retaddr
30227 ret
30228 CFI_ENDPROC
30229 -ENDPROC(atomic64_\func\()_return_cx8)
30230 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30231 .endm
30232
30233 addsub_return add add adc
30234 addsub_return sub sub sbb
30235 +addsub_return add add adc _unchecked
30236 +addsub_return sub sub sbb _unchecked
30237
30238 -.macro incdec_return func ins insc
30239 -ENTRY(atomic64_\func\()_return_cx8)
30240 +.macro incdec_return func ins insc unchecked=""
30241 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30242 CFI_STARTPROC
30243 SAVE ebx
30244
30245 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
30246 movl %edx, %ecx
30247 \ins\()l $1, %ebx
30248 \insc\()l $0, %ecx
30249 +
30250 +.ifb \unchecked
30251 +#ifdef CONFIG_PAX_REFCOUNT
30252 + into
30253 +2:
30254 + _ASM_EXTABLE(2b, 3f)
30255 +#endif
30256 +.endif
30257 +
30258 LOCK_PREFIX
30259 cmpxchg8b (%esi)
30260 jne 1b
30261
30262 -10:
30263 movl %ebx, %eax
30264 movl %ecx, %edx
30265 +
30266 +.ifb \unchecked
30267 +#ifdef CONFIG_PAX_REFCOUNT
30268 +3:
30269 +#endif
30270 +.endif
30271 +
30272 RESTORE ebx
30273 + pax_force_retaddr
30274 ret
30275 CFI_ENDPROC
30276 -ENDPROC(atomic64_\func\()_return_cx8)
30277 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30278 .endm
30279
30280 incdec_return inc add adc
30281 incdec_return dec sub sbb
30282 +incdec_return inc add adc _unchecked
30283 +incdec_return dec sub sbb _unchecked
30284
30285 ENTRY(atomic64_dec_if_positive_cx8)
30286 CFI_STARTPROC
30287 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
30288 movl %edx, %ecx
30289 subl $1, %ebx
30290 sbb $0, %ecx
30291 +
30292 +#ifdef CONFIG_PAX_REFCOUNT
30293 + into
30294 +1234:
30295 + _ASM_EXTABLE(1234b, 2f)
30296 +#endif
30297 +
30298 js 2f
30299 LOCK_PREFIX
30300 cmpxchg8b (%esi)
30301 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30302 movl %ebx, %eax
30303 movl %ecx, %edx
30304 RESTORE ebx
30305 + pax_force_retaddr
30306 ret
30307 CFI_ENDPROC
30308 ENDPROC(atomic64_dec_if_positive_cx8)
30309 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30310 movl %edx, %ecx
30311 addl %ebp, %ebx
30312 adcl %edi, %ecx
30313 +
30314 +#ifdef CONFIG_PAX_REFCOUNT
30315 + into
30316 +1234:
30317 + _ASM_EXTABLE(1234b, 3f)
30318 +#endif
30319 +
30320 LOCK_PREFIX
30321 cmpxchg8b (%esi)
30322 jne 1b
30323 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30324 CFI_ADJUST_CFA_OFFSET -8
30325 RESTORE ebx
30326 RESTORE ebp
30327 + pax_force_retaddr
30328 ret
30329 4:
30330 cmpl %edx, 4(%esp)
30331 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30332 xorl %ecx, %ecx
30333 addl $1, %ebx
30334 adcl %edx, %ecx
30335 +
30336 +#ifdef CONFIG_PAX_REFCOUNT
30337 + into
30338 +1234:
30339 + _ASM_EXTABLE(1234b, 3f)
30340 +#endif
30341 +
30342 LOCK_PREFIX
30343 cmpxchg8b (%esi)
30344 jne 1b
30345 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30346 movl $1, %eax
30347 3:
30348 RESTORE ebx
30349 + pax_force_retaddr
30350 ret
30351 CFI_ENDPROC
30352 ENDPROC(atomic64_inc_not_zero_cx8)
30353 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30354 index e78b8eee..7e173a8 100644
30355 --- a/arch/x86/lib/checksum_32.S
30356 +++ b/arch/x86/lib/checksum_32.S
30357 @@ -29,7 +29,8 @@
30358 #include <asm/dwarf2.h>
30359 #include <asm/errno.h>
30360 #include <asm/asm.h>
30361 -
30362 +#include <asm/segment.h>
30363 +
30364 /*
30365 * computes a partial checksum, e.g. for TCP/UDP fragments
30366 */
30367 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30368
30369 #define ARGBASE 16
30370 #define FP 12
30371 -
30372 -ENTRY(csum_partial_copy_generic)
30373 +
30374 +ENTRY(csum_partial_copy_generic_to_user)
30375 CFI_STARTPROC
30376 +
30377 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30378 + pushl_cfi %gs
30379 + popl_cfi %es
30380 + jmp csum_partial_copy_generic
30381 +#endif
30382 +
30383 +ENTRY(csum_partial_copy_generic_from_user)
30384 +
30385 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30386 + pushl_cfi %gs
30387 + popl_cfi %ds
30388 +#endif
30389 +
30390 +ENTRY(csum_partial_copy_generic)
30391 subl $4,%esp
30392 CFI_ADJUST_CFA_OFFSET 4
30393 pushl_cfi %edi
30394 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30395 jmp 4f
30396 SRC(1: movw (%esi), %bx )
30397 addl $2, %esi
30398 -DST( movw %bx, (%edi) )
30399 +DST( movw %bx, %es:(%edi) )
30400 addl $2, %edi
30401 addw %bx, %ax
30402 adcl $0, %eax
30403 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30404 SRC(1: movl (%esi), %ebx )
30405 SRC( movl 4(%esi), %edx )
30406 adcl %ebx, %eax
30407 -DST( movl %ebx, (%edi) )
30408 +DST( movl %ebx, %es:(%edi) )
30409 adcl %edx, %eax
30410 -DST( movl %edx, 4(%edi) )
30411 +DST( movl %edx, %es:4(%edi) )
30412
30413 SRC( movl 8(%esi), %ebx )
30414 SRC( movl 12(%esi), %edx )
30415 adcl %ebx, %eax
30416 -DST( movl %ebx, 8(%edi) )
30417 +DST( movl %ebx, %es:8(%edi) )
30418 adcl %edx, %eax
30419 -DST( movl %edx, 12(%edi) )
30420 +DST( movl %edx, %es:12(%edi) )
30421
30422 SRC( movl 16(%esi), %ebx )
30423 SRC( movl 20(%esi), %edx )
30424 adcl %ebx, %eax
30425 -DST( movl %ebx, 16(%edi) )
30426 +DST( movl %ebx, %es:16(%edi) )
30427 adcl %edx, %eax
30428 -DST( movl %edx, 20(%edi) )
30429 +DST( movl %edx, %es:20(%edi) )
30430
30431 SRC( movl 24(%esi), %ebx )
30432 SRC( movl 28(%esi), %edx )
30433 adcl %ebx, %eax
30434 -DST( movl %ebx, 24(%edi) )
30435 +DST( movl %ebx, %es:24(%edi) )
30436 adcl %edx, %eax
30437 -DST( movl %edx, 28(%edi) )
30438 +DST( movl %edx, %es:28(%edi) )
30439
30440 lea 32(%esi), %esi
30441 lea 32(%edi), %edi
30442 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30443 shrl $2, %edx # This clears CF
30444 SRC(3: movl (%esi), %ebx )
30445 adcl %ebx, %eax
30446 -DST( movl %ebx, (%edi) )
30447 +DST( movl %ebx, %es:(%edi) )
30448 lea 4(%esi), %esi
30449 lea 4(%edi), %edi
30450 dec %edx
30451 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30452 jb 5f
30453 SRC( movw (%esi), %cx )
30454 leal 2(%esi), %esi
30455 -DST( movw %cx, (%edi) )
30456 +DST( movw %cx, %es:(%edi) )
30457 leal 2(%edi), %edi
30458 je 6f
30459 shll $16,%ecx
30460 SRC(5: movb (%esi), %cl )
30461 -DST( movb %cl, (%edi) )
30462 +DST( movb %cl, %es:(%edi) )
30463 6: addl %ecx, %eax
30464 adcl $0, %eax
30465 7:
30466 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30467
30468 6001:
30469 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30470 - movl $-EFAULT, (%ebx)
30471 + movl $-EFAULT, %ss:(%ebx)
30472
30473 # zero the complete destination - computing the rest
30474 # is too much work
30475 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30476
30477 6002:
30478 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30479 - movl $-EFAULT,(%ebx)
30480 + movl $-EFAULT,%ss:(%ebx)
30481 jmp 5000b
30482
30483 .previous
30484
30485 + pushl_cfi %ss
30486 + popl_cfi %ds
30487 + pushl_cfi %ss
30488 + popl_cfi %es
30489 popl_cfi %ebx
30490 CFI_RESTORE ebx
30491 popl_cfi %esi
30492 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30493 popl_cfi %ecx # equivalent to addl $4,%esp
30494 ret
30495 CFI_ENDPROC
30496 -ENDPROC(csum_partial_copy_generic)
30497 +ENDPROC(csum_partial_copy_generic_to_user)
30498
30499 #else
30500
30501 /* Version for PentiumII/PPro */
30502
30503 #define ROUND1(x) \
30504 + nop; nop; nop; \
30505 SRC(movl x(%esi), %ebx ) ; \
30506 addl %ebx, %eax ; \
30507 - DST(movl %ebx, x(%edi) ) ;
30508 + DST(movl %ebx, %es:x(%edi)) ;
30509
30510 #define ROUND(x) \
30511 + nop; nop; nop; \
30512 SRC(movl x(%esi), %ebx ) ; \
30513 adcl %ebx, %eax ; \
30514 - DST(movl %ebx, x(%edi) ) ;
30515 + DST(movl %ebx, %es:x(%edi)) ;
30516
30517 #define ARGBASE 12
30518 -
30519 -ENTRY(csum_partial_copy_generic)
30520 +
30521 +ENTRY(csum_partial_copy_generic_to_user)
30522 CFI_STARTPROC
30523 +
30524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30525 + pushl_cfi %gs
30526 + popl_cfi %es
30527 + jmp csum_partial_copy_generic
30528 +#endif
30529 +
30530 +ENTRY(csum_partial_copy_generic_from_user)
30531 +
30532 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30533 + pushl_cfi %gs
30534 + popl_cfi %ds
30535 +#endif
30536 +
30537 +ENTRY(csum_partial_copy_generic)
30538 pushl_cfi %ebx
30539 CFI_REL_OFFSET ebx, 0
30540 pushl_cfi %edi
30541 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30542 subl %ebx, %edi
30543 lea -1(%esi),%edx
30544 andl $-32,%edx
30545 - lea 3f(%ebx,%ebx), %ebx
30546 + lea 3f(%ebx,%ebx,2), %ebx
30547 testl %esi, %esi
30548 jmp *%ebx
30549 1: addl $64,%esi
30550 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30551 jb 5f
30552 SRC( movw (%esi), %dx )
30553 leal 2(%esi), %esi
30554 -DST( movw %dx, (%edi) )
30555 +DST( movw %dx, %es:(%edi) )
30556 leal 2(%edi), %edi
30557 je 6f
30558 shll $16,%edx
30559 5:
30560 SRC( movb (%esi), %dl )
30561 -DST( movb %dl, (%edi) )
30562 +DST( movb %dl, %es:(%edi) )
30563 6: addl %edx, %eax
30564 adcl $0, %eax
30565 7:
30566 .section .fixup, "ax"
30567 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30568 - movl $-EFAULT, (%ebx)
30569 + movl $-EFAULT, %ss:(%ebx)
30570 # zero the complete destination (computing the rest is too much work)
30571 movl ARGBASE+8(%esp),%edi # dst
30572 movl ARGBASE+12(%esp),%ecx # len
30573 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30574 rep; stosb
30575 jmp 7b
30576 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30577 - movl $-EFAULT, (%ebx)
30578 + movl $-EFAULT, %ss:(%ebx)
30579 jmp 7b
30580 .previous
30581
30582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30583 + pushl_cfi %ss
30584 + popl_cfi %ds
30585 + pushl_cfi %ss
30586 + popl_cfi %es
30587 +#endif
30588 +
30589 popl_cfi %esi
30590 CFI_RESTORE esi
30591 popl_cfi %edi
30592 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30593 CFI_RESTORE ebx
30594 ret
30595 CFI_ENDPROC
30596 -ENDPROC(csum_partial_copy_generic)
30597 +ENDPROC(csum_partial_copy_generic_to_user)
30598
30599 #undef ROUND
30600 #undef ROUND1
30601 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30602 index f2145cf..cea889d 100644
30603 --- a/arch/x86/lib/clear_page_64.S
30604 +++ b/arch/x86/lib/clear_page_64.S
30605 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30606 movl $4096/8,%ecx
30607 xorl %eax,%eax
30608 rep stosq
30609 + pax_force_retaddr
30610 ret
30611 CFI_ENDPROC
30612 ENDPROC(clear_page_c)
30613 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30614 movl $4096,%ecx
30615 xorl %eax,%eax
30616 rep stosb
30617 + pax_force_retaddr
30618 ret
30619 CFI_ENDPROC
30620 ENDPROC(clear_page_c_e)
30621 @@ -43,6 +45,7 @@ ENTRY(clear_page)
30622 leaq 64(%rdi),%rdi
30623 jnz .Lloop
30624 nop
30625 + pax_force_retaddr
30626 ret
30627 CFI_ENDPROC
30628 .Lclear_page_end:
30629 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
30630
30631 #include <asm/cpufeature.h>
30632
30633 - .section .altinstr_replacement,"ax"
30634 + .section .altinstr_replacement,"a"
30635 1: .byte 0xeb /* jmp <disp8> */
30636 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30637 2: .byte 0xeb /* jmp <disp8> */
30638 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30639 index 1e572c5..2a162cd 100644
30640 --- a/arch/x86/lib/cmpxchg16b_emu.S
30641 +++ b/arch/x86/lib/cmpxchg16b_emu.S
30642 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30643
30644 popf
30645 mov $1, %al
30646 + pax_force_retaddr
30647 ret
30648
30649 not_same:
30650 popf
30651 xor %al,%al
30652 + pax_force_retaddr
30653 ret
30654
30655 CFI_ENDPROC
30656 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30657 index 176cca6..e0d658e 100644
30658 --- a/arch/x86/lib/copy_page_64.S
30659 +++ b/arch/x86/lib/copy_page_64.S
30660 @@ -9,6 +9,7 @@ copy_page_rep:
30661 CFI_STARTPROC
30662 movl $4096/8, %ecx
30663 rep movsq
30664 + pax_force_retaddr
30665 ret
30666 CFI_ENDPROC
30667 ENDPROC(copy_page_rep)
30668 @@ -24,8 +25,8 @@ ENTRY(copy_page)
30669 CFI_ADJUST_CFA_OFFSET 2*8
30670 movq %rbx, (%rsp)
30671 CFI_REL_OFFSET rbx, 0
30672 - movq %r12, 1*8(%rsp)
30673 - CFI_REL_OFFSET r12, 1*8
30674 + movq %r13, 1*8(%rsp)
30675 + CFI_REL_OFFSET r13, 1*8
30676
30677 movl $(4096/64)-5, %ecx
30678 .p2align 4
30679 @@ -38,7 +39,7 @@ ENTRY(copy_page)
30680 movq 0x8*4(%rsi), %r9
30681 movq 0x8*5(%rsi), %r10
30682 movq 0x8*6(%rsi), %r11
30683 - movq 0x8*7(%rsi), %r12
30684 + movq 0x8*7(%rsi), %r13
30685
30686 prefetcht0 5*64(%rsi)
30687
30688 @@ -49,7 +50,7 @@ ENTRY(copy_page)
30689 movq %r9, 0x8*4(%rdi)
30690 movq %r10, 0x8*5(%rdi)
30691 movq %r11, 0x8*6(%rdi)
30692 - movq %r12, 0x8*7(%rdi)
30693 + movq %r13, 0x8*7(%rdi)
30694
30695 leaq 64 (%rsi), %rsi
30696 leaq 64 (%rdi), %rdi
30697 @@ -68,7 +69,7 @@ ENTRY(copy_page)
30698 movq 0x8*4(%rsi), %r9
30699 movq 0x8*5(%rsi), %r10
30700 movq 0x8*6(%rsi), %r11
30701 - movq 0x8*7(%rsi), %r12
30702 + movq 0x8*7(%rsi), %r13
30703
30704 movq %rax, 0x8*0(%rdi)
30705 movq %rbx, 0x8*1(%rdi)
30706 @@ -77,7 +78,7 @@ ENTRY(copy_page)
30707 movq %r9, 0x8*4(%rdi)
30708 movq %r10, 0x8*5(%rdi)
30709 movq %r11, 0x8*6(%rdi)
30710 - movq %r12, 0x8*7(%rdi)
30711 + movq %r13, 0x8*7(%rdi)
30712
30713 leaq 64(%rdi), %rdi
30714 leaq 64(%rsi), %rsi
30715 @@ -85,10 +86,11 @@ ENTRY(copy_page)
30716
30717 movq (%rsp), %rbx
30718 CFI_RESTORE rbx
30719 - movq 1*8(%rsp), %r12
30720 - CFI_RESTORE r12
30721 + movq 1*8(%rsp), %r13
30722 + CFI_RESTORE r13
30723 addq $2*8, %rsp
30724 CFI_ADJUST_CFA_OFFSET -2*8
30725 + pax_force_retaddr
30726 ret
30727 .Lcopy_page_end:
30728 CFI_ENDPROC
30729 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
30730
30731 #include <asm/cpufeature.h>
30732
30733 - .section .altinstr_replacement,"ax"
30734 + .section .altinstr_replacement,"a"
30735 1: .byte 0xeb /* jmp <disp8> */
30736 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30737 2:
30738 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30739 index dee945d..a84067b 100644
30740 --- a/arch/x86/lib/copy_user_64.S
30741 +++ b/arch/x86/lib/copy_user_64.S
30742 @@ -18,31 +18,7 @@
30743 #include <asm/alternative-asm.h>
30744 #include <asm/asm.h>
30745 #include <asm/smap.h>
30746 -
30747 -/*
30748 - * By placing feature2 after feature1 in altinstructions section, we logically
30749 - * implement:
30750 - * If CPU has feature2, jmp to alt2 is used
30751 - * else if CPU has feature1, jmp to alt1 is used
30752 - * else jmp to orig is used.
30753 - */
30754 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30755 -0:
30756 - .byte 0xe9 /* 32bit jump */
30757 - .long \orig-1f /* by default jump to orig */
30758 -1:
30759 - .section .altinstr_replacement,"ax"
30760 -2: .byte 0xe9 /* near jump with 32bit immediate */
30761 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30762 -3: .byte 0xe9 /* near jump with 32bit immediate */
30763 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30764 - .previous
30765 -
30766 - .section .altinstructions,"a"
30767 - altinstruction_entry 0b,2b,\feature1,5,5
30768 - altinstruction_entry 0b,3b,\feature2,5,5
30769 - .previous
30770 - .endm
30771 +#include <asm/pgtable.h>
30772
30773 .macro ALIGN_DESTINATION
30774 #ifdef FIX_ALIGNMENT
30775 @@ -70,52 +46,6 @@
30776 #endif
30777 .endm
30778
30779 -/* Standard copy_to_user with segment limit checking */
30780 -ENTRY(_copy_to_user)
30781 - CFI_STARTPROC
30782 - GET_THREAD_INFO(%rax)
30783 - movq %rdi,%rcx
30784 - addq %rdx,%rcx
30785 - jc bad_to_user
30786 - cmpq TI_addr_limit(%rax),%rcx
30787 - ja bad_to_user
30788 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30789 - copy_user_generic_unrolled,copy_user_generic_string, \
30790 - copy_user_enhanced_fast_string
30791 - CFI_ENDPROC
30792 -ENDPROC(_copy_to_user)
30793 -
30794 -/* Standard copy_from_user with segment limit checking */
30795 -ENTRY(_copy_from_user)
30796 - CFI_STARTPROC
30797 - GET_THREAD_INFO(%rax)
30798 - movq %rsi,%rcx
30799 - addq %rdx,%rcx
30800 - jc bad_from_user
30801 - cmpq TI_addr_limit(%rax),%rcx
30802 - ja bad_from_user
30803 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30804 - copy_user_generic_unrolled,copy_user_generic_string, \
30805 - copy_user_enhanced_fast_string
30806 - CFI_ENDPROC
30807 -ENDPROC(_copy_from_user)
30808 -
30809 - .section .fixup,"ax"
30810 - /* must zero dest */
30811 -ENTRY(bad_from_user)
30812 -bad_from_user:
30813 - CFI_STARTPROC
30814 - movl %edx,%ecx
30815 - xorl %eax,%eax
30816 - rep
30817 - stosb
30818 -bad_to_user:
30819 - movl %edx,%eax
30820 - ret
30821 - CFI_ENDPROC
30822 -ENDPROC(bad_from_user)
30823 - .previous
30824 -
30825 /*
30826 * copy_user_generic_unrolled - memory copy with exception handling.
30827 * This version is for CPUs like P4 that don't have efficient micro
30828 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30829 */
30830 ENTRY(copy_user_generic_unrolled)
30831 CFI_STARTPROC
30832 + ASM_PAX_OPEN_USERLAND
30833 ASM_STAC
30834 cmpl $8,%edx
30835 jb 20f /* less then 8 bytes, go to byte copy loop */
30836 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30837 jnz 21b
30838 23: xor %eax,%eax
30839 ASM_CLAC
30840 + ASM_PAX_CLOSE_USERLAND
30841 + pax_force_retaddr
30842 ret
30843
30844 .section .fixup,"ax"
30845 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30846 */
30847 ENTRY(copy_user_generic_string)
30848 CFI_STARTPROC
30849 + ASM_PAX_OPEN_USERLAND
30850 ASM_STAC
30851 cmpl $8,%edx
30852 jb 2f /* less than 8 bytes, go to byte copy loop */
30853 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30854 movsb
30855 xorl %eax,%eax
30856 ASM_CLAC
30857 + ASM_PAX_CLOSE_USERLAND
30858 + pax_force_retaddr
30859 ret
30860
30861 .section .fixup,"ax"
30862 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30863 */
30864 ENTRY(copy_user_enhanced_fast_string)
30865 CFI_STARTPROC
30866 + ASM_PAX_OPEN_USERLAND
30867 ASM_STAC
30868 movl %edx,%ecx
30869 1: rep
30870 movsb
30871 xorl %eax,%eax
30872 ASM_CLAC
30873 + ASM_PAX_CLOSE_USERLAND
30874 + pax_force_retaddr
30875 ret
30876
30877 .section .fixup,"ax"
30878 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30879 index 6a4f43c..c70fb52 100644
30880 --- a/arch/x86/lib/copy_user_nocache_64.S
30881 +++ b/arch/x86/lib/copy_user_nocache_64.S
30882 @@ -8,6 +8,7 @@
30883
30884 #include <linux/linkage.h>
30885 #include <asm/dwarf2.h>
30886 +#include <asm/alternative-asm.h>
30887
30888 #define FIX_ALIGNMENT 1
30889
30890 @@ -16,6 +17,7 @@
30891 #include <asm/thread_info.h>
30892 #include <asm/asm.h>
30893 #include <asm/smap.h>
30894 +#include <asm/pgtable.h>
30895
30896 .macro ALIGN_DESTINATION
30897 #ifdef FIX_ALIGNMENT
30898 @@ -49,6 +51,16 @@
30899 */
30900 ENTRY(__copy_user_nocache)
30901 CFI_STARTPROC
30902 +
30903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30904 + mov pax_user_shadow_base,%rcx
30905 + cmp %rcx,%rsi
30906 + jae 1f
30907 + add %rcx,%rsi
30908 +1:
30909 +#endif
30910 +
30911 + ASM_PAX_OPEN_USERLAND
30912 ASM_STAC
30913 cmpl $8,%edx
30914 jb 20f /* less then 8 bytes, go to byte copy loop */
30915 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30916 jnz 21b
30917 23: xorl %eax,%eax
30918 ASM_CLAC
30919 + ASM_PAX_CLOSE_USERLAND
30920 sfence
30921 + pax_force_retaddr
30922 ret
30923
30924 .section .fixup,"ax"
30925 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30926 index 2419d5f..fe52d0e 100644
30927 --- a/arch/x86/lib/csum-copy_64.S
30928 +++ b/arch/x86/lib/csum-copy_64.S
30929 @@ -9,6 +9,7 @@
30930 #include <asm/dwarf2.h>
30931 #include <asm/errno.h>
30932 #include <asm/asm.h>
30933 +#include <asm/alternative-asm.h>
30934
30935 /*
30936 * Checksum copy with exception handling.
30937 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30938 CFI_ADJUST_CFA_OFFSET 7*8
30939 movq %rbx, 2*8(%rsp)
30940 CFI_REL_OFFSET rbx, 2*8
30941 - movq %r12, 3*8(%rsp)
30942 - CFI_REL_OFFSET r12, 3*8
30943 + movq %r15, 3*8(%rsp)
30944 + CFI_REL_OFFSET r15, 3*8
30945 movq %r14, 4*8(%rsp)
30946 CFI_REL_OFFSET r14, 4*8
30947 movq %r13, 5*8(%rsp)
30948 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30949 movl %edx, %ecx
30950
30951 xorl %r9d, %r9d
30952 - movq %rcx, %r12
30953 + movq %rcx, %r15
30954
30955 - shrq $6, %r12
30956 + shrq $6, %r15
30957 jz .Lhandle_tail /* < 64 */
30958
30959 clc
30960
30961 /* main loop. clear in 64 byte blocks */
30962 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30963 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30964 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30965 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30966 .p2align 4
30967 .Lloop:
30968 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30969 adcq %r14, %rax
30970 adcq %r13, %rax
30971
30972 - decl %r12d
30973 + decl %r15d
30974
30975 dest
30976 movq %rbx, (%rsi)
30977 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30978 .Lende:
30979 movq 2*8(%rsp), %rbx
30980 CFI_RESTORE rbx
30981 - movq 3*8(%rsp), %r12
30982 - CFI_RESTORE r12
30983 + movq 3*8(%rsp), %r15
30984 + CFI_RESTORE r15
30985 movq 4*8(%rsp), %r14
30986 CFI_RESTORE r14
30987 movq 5*8(%rsp), %r13
30988 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30989 CFI_RESTORE rbp
30990 addq $7*8, %rsp
30991 CFI_ADJUST_CFA_OFFSET -7*8
30992 + pax_force_retaddr
30993 ret
30994 CFI_RESTORE_STATE
30995
30996 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30997 index 7609e0e..b449b98 100644
30998 --- a/arch/x86/lib/csum-wrappers_64.c
30999 +++ b/arch/x86/lib/csum-wrappers_64.c
31000 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
31001 len -= 2;
31002 }
31003 }
31004 + pax_open_userland();
31005 stac();
31006 - isum = csum_partial_copy_generic((__force const void *)src,
31007 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
31008 dst, len, isum, errp, NULL);
31009 clac();
31010 + pax_close_userland();
31011 if (unlikely(*errp))
31012 goto out_err;
31013
31014 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
31015 }
31016
31017 *errp = 0;
31018 + pax_open_userland();
31019 stac();
31020 - ret = csum_partial_copy_generic(src, (void __force *)dst,
31021 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
31022 len, isum, NULL, errp);
31023 clac();
31024 + pax_close_userland();
31025 return ret;
31026 }
31027 EXPORT_SYMBOL(csum_partial_copy_to_user);
31028 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
31029 index a451235..1daa956 100644
31030 --- a/arch/x86/lib/getuser.S
31031 +++ b/arch/x86/lib/getuser.S
31032 @@ -33,17 +33,40 @@
31033 #include <asm/thread_info.h>
31034 #include <asm/asm.h>
31035 #include <asm/smap.h>
31036 +#include <asm/segment.h>
31037 +#include <asm/pgtable.h>
31038 +#include <asm/alternative-asm.h>
31039 +
31040 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31041 +#define __copyuser_seg gs;
31042 +#else
31043 +#define __copyuser_seg
31044 +#endif
31045
31046 .text
31047 ENTRY(__get_user_1)
31048 CFI_STARTPROC
31049 +
31050 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31051 GET_THREAD_INFO(%_ASM_DX)
31052 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31053 jae bad_get_user
31054 ASM_STAC
31055 -1: movzbl (%_ASM_AX),%edx
31056 +
31057 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31058 + mov pax_user_shadow_base,%_ASM_DX
31059 + cmp %_ASM_DX,%_ASM_AX
31060 + jae 1234f
31061 + add %_ASM_DX,%_ASM_AX
31062 +1234:
31063 +#endif
31064 +
31065 +#endif
31066 +
31067 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
31068 xor %eax,%eax
31069 ASM_CLAC
31070 + pax_force_retaddr
31071 ret
31072 CFI_ENDPROC
31073 ENDPROC(__get_user_1)
31074 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
31075 ENTRY(__get_user_2)
31076 CFI_STARTPROC
31077 add $1,%_ASM_AX
31078 +
31079 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31080 jc bad_get_user
31081 GET_THREAD_INFO(%_ASM_DX)
31082 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31083 jae bad_get_user
31084 ASM_STAC
31085 -2: movzwl -1(%_ASM_AX),%edx
31086 +
31087 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31088 + mov pax_user_shadow_base,%_ASM_DX
31089 + cmp %_ASM_DX,%_ASM_AX
31090 + jae 1234f
31091 + add %_ASM_DX,%_ASM_AX
31092 +1234:
31093 +#endif
31094 +
31095 +#endif
31096 +
31097 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
31098 xor %eax,%eax
31099 ASM_CLAC
31100 + pax_force_retaddr
31101 ret
31102 CFI_ENDPROC
31103 ENDPROC(__get_user_2)
31104 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
31105 ENTRY(__get_user_4)
31106 CFI_STARTPROC
31107 add $3,%_ASM_AX
31108 +
31109 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31110 jc bad_get_user
31111 GET_THREAD_INFO(%_ASM_DX)
31112 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31113 jae bad_get_user
31114 ASM_STAC
31115 -3: movl -3(%_ASM_AX),%edx
31116 +
31117 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31118 + mov pax_user_shadow_base,%_ASM_DX
31119 + cmp %_ASM_DX,%_ASM_AX
31120 + jae 1234f
31121 + add %_ASM_DX,%_ASM_AX
31122 +1234:
31123 +#endif
31124 +
31125 +#endif
31126 +
31127 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
31128 xor %eax,%eax
31129 ASM_CLAC
31130 + pax_force_retaddr
31131 ret
31132 CFI_ENDPROC
31133 ENDPROC(__get_user_4)
31134 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
31135 GET_THREAD_INFO(%_ASM_DX)
31136 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31137 jae bad_get_user
31138 +
31139 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31140 + mov pax_user_shadow_base,%_ASM_DX
31141 + cmp %_ASM_DX,%_ASM_AX
31142 + jae 1234f
31143 + add %_ASM_DX,%_ASM_AX
31144 +1234:
31145 +#endif
31146 +
31147 ASM_STAC
31148 4: movq -7(%_ASM_AX),%rdx
31149 xor %eax,%eax
31150 ASM_CLAC
31151 + pax_force_retaddr
31152 ret
31153 #else
31154 add $7,%_ASM_AX
31155 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
31156 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31157 jae bad_get_user_8
31158 ASM_STAC
31159 -4: movl -7(%_ASM_AX),%edx
31160 -5: movl -3(%_ASM_AX),%ecx
31161 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
31162 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
31163 xor %eax,%eax
31164 ASM_CLAC
31165 + pax_force_retaddr
31166 ret
31167 #endif
31168 CFI_ENDPROC
31169 @@ -113,6 +175,7 @@ bad_get_user:
31170 xor %edx,%edx
31171 mov $(-EFAULT),%_ASM_AX
31172 ASM_CLAC
31173 + pax_force_retaddr
31174 ret
31175 CFI_ENDPROC
31176 END(bad_get_user)
31177 @@ -124,6 +187,7 @@ bad_get_user_8:
31178 xor %ecx,%ecx
31179 mov $(-EFAULT),%_ASM_AX
31180 ASM_CLAC
31181 + pax_force_retaddr
31182 ret
31183 CFI_ENDPROC
31184 END(bad_get_user_8)
31185 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
31186 index 54fcffe..7be149e 100644
31187 --- a/arch/x86/lib/insn.c
31188 +++ b/arch/x86/lib/insn.c
31189 @@ -20,8 +20,10 @@
31190
31191 #ifdef __KERNEL__
31192 #include <linux/string.h>
31193 +#include <asm/pgtable_types.h>
31194 #else
31195 #include <string.h>
31196 +#define ktla_ktva(addr) addr
31197 #endif
31198 #include <asm/inat.h>
31199 #include <asm/insn.h>
31200 @@ -53,8 +55,8 @@
31201 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
31202 {
31203 memset(insn, 0, sizeof(*insn));
31204 - insn->kaddr = kaddr;
31205 - insn->next_byte = kaddr;
31206 + insn->kaddr = ktla_ktva(kaddr);
31207 + insn->next_byte = ktla_ktva(kaddr);
31208 insn->x86_64 = x86_64 ? 1 : 0;
31209 insn->opnd_bytes = 4;
31210 if (x86_64)
31211 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
31212 index 05a95e7..326f2fa 100644
31213 --- a/arch/x86/lib/iomap_copy_64.S
31214 +++ b/arch/x86/lib/iomap_copy_64.S
31215 @@ -17,6 +17,7 @@
31216
31217 #include <linux/linkage.h>
31218 #include <asm/dwarf2.h>
31219 +#include <asm/alternative-asm.h>
31220
31221 /*
31222 * override generic version in lib/iomap_copy.c
31223 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
31224 CFI_STARTPROC
31225 movl %edx,%ecx
31226 rep movsd
31227 + pax_force_retaddr
31228 ret
31229 CFI_ENDPROC
31230 ENDPROC(__iowrite32_copy)
31231 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
31232 index 56313a3..0db417e 100644
31233 --- a/arch/x86/lib/memcpy_64.S
31234 +++ b/arch/x86/lib/memcpy_64.S
31235 @@ -24,7 +24,7 @@
31236 * This gets patched over the unrolled variant (below) via the
31237 * alternative instructions framework:
31238 */
31239 - .section .altinstr_replacement, "ax", @progbits
31240 + .section .altinstr_replacement, "a", @progbits
31241 .Lmemcpy_c:
31242 movq %rdi, %rax
31243 movq %rdx, %rcx
31244 @@ -33,6 +33,7 @@
31245 rep movsq
31246 movl %edx, %ecx
31247 rep movsb
31248 + pax_force_retaddr
31249 ret
31250 .Lmemcpy_e:
31251 .previous
31252 @@ -44,11 +45,12 @@
31253 * This gets patched over the unrolled variant (below) via the
31254 * alternative instructions framework:
31255 */
31256 - .section .altinstr_replacement, "ax", @progbits
31257 + .section .altinstr_replacement, "a", @progbits
31258 .Lmemcpy_c_e:
31259 movq %rdi, %rax
31260 movq %rdx, %rcx
31261 rep movsb
31262 + pax_force_retaddr
31263 ret
31264 .Lmemcpy_e_e:
31265 .previous
31266 @@ -136,6 +138,7 @@ ENTRY(memcpy)
31267 movq %r9, 1*8(%rdi)
31268 movq %r10, -2*8(%rdi, %rdx)
31269 movq %r11, -1*8(%rdi, %rdx)
31270 + pax_force_retaddr
31271 retq
31272 .p2align 4
31273 .Lless_16bytes:
31274 @@ -148,6 +151,7 @@ ENTRY(memcpy)
31275 movq -1*8(%rsi, %rdx), %r9
31276 movq %r8, 0*8(%rdi)
31277 movq %r9, -1*8(%rdi, %rdx)
31278 + pax_force_retaddr
31279 retq
31280 .p2align 4
31281 .Lless_8bytes:
31282 @@ -161,6 +165,7 @@ ENTRY(memcpy)
31283 movl -4(%rsi, %rdx), %r8d
31284 movl %ecx, (%rdi)
31285 movl %r8d, -4(%rdi, %rdx)
31286 + pax_force_retaddr
31287 retq
31288 .p2align 4
31289 .Lless_3bytes:
31290 @@ -179,6 +184,7 @@ ENTRY(memcpy)
31291 movb %cl, (%rdi)
31292
31293 .Lend:
31294 + pax_force_retaddr
31295 retq
31296 CFI_ENDPROC
31297 ENDPROC(memcpy)
31298 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
31299 index 65268a6..dd1de11 100644
31300 --- a/arch/x86/lib/memmove_64.S
31301 +++ b/arch/x86/lib/memmove_64.S
31302 @@ -202,14 +202,16 @@ ENTRY(memmove)
31303 movb (%rsi), %r11b
31304 movb %r11b, (%rdi)
31305 13:
31306 + pax_force_retaddr
31307 retq
31308 CFI_ENDPROC
31309
31310 - .section .altinstr_replacement,"ax"
31311 + .section .altinstr_replacement,"a"
31312 .Lmemmove_begin_forward_efs:
31313 /* Forward moving data. */
31314 movq %rdx, %rcx
31315 rep movsb
31316 + pax_force_retaddr
31317 retq
31318 .Lmemmove_end_forward_efs:
31319 .previous
31320 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31321 index 2dcb380..2eb79fe 100644
31322 --- a/arch/x86/lib/memset_64.S
31323 +++ b/arch/x86/lib/memset_64.S
31324 @@ -16,7 +16,7 @@
31325 *
31326 * rax original destination
31327 */
31328 - .section .altinstr_replacement, "ax", @progbits
31329 + .section .altinstr_replacement, "a", @progbits
31330 .Lmemset_c:
31331 movq %rdi,%r9
31332 movq %rdx,%rcx
31333 @@ -30,6 +30,7 @@
31334 movl %edx,%ecx
31335 rep stosb
31336 movq %r9,%rax
31337 + pax_force_retaddr
31338 ret
31339 .Lmemset_e:
31340 .previous
31341 @@ -45,13 +46,14 @@
31342 *
31343 * rax original destination
31344 */
31345 - .section .altinstr_replacement, "ax", @progbits
31346 + .section .altinstr_replacement, "a", @progbits
31347 .Lmemset_c_e:
31348 movq %rdi,%r9
31349 movb %sil,%al
31350 movq %rdx,%rcx
31351 rep stosb
31352 movq %r9,%rax
31353 + pax_force_retaddr
31354 ret
31355 .Lmemset_e_e:
31356 .previous
31357 @@ -118,6 +120,7 @@ ENTRY(__memset)
31358
31359 .Lende:
31360 movq %r10,%rax
31361 + pax_force_retaddr
31362 ret
31363
31364 CFI_RESTORE_STATE
31365 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31366 index c9f2d9b..e7fd2c0 100644
31367 --- a/arch/x86/lib/mmx_32.c
31368 +++ b/arch/x86/lib/mmx_32.c
31369 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31370 {
31371 void *p;
31372 int i;
31373 + unsigned long cr0;
31374
31375 if (unlikely(in_interrupt()))
31376 return __memcpy(to, from, len);
31377 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31378 kernel_fpu_begin();
31379
31380 __asm__ __volatile__ (
31381 - "1: prefetch (%0)\n" /* This set is 28 bytes */
31382 - " prefetch 64(%0)\n"
31383 - " prefetch 128(%0)\n"
31384 - " prefetch 192(%0)\n"
31385 - " prefetch 256(%0)\n"
31386 + "1: prefetch (%1)\n" /* This set is 28 bytes */
31387 + " prefetch 64(%1)\n"
31388 + " prefetch 128(%1)\n"
31389 + " prefetch 192(%1)\n"
31390 + " prefetch 256(%1)\n"
31391 "2: \n"
31392 ".section .fixup, \"ax\"\n"
31393 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31394 + "3: \n"
31395 +
31396 +#ifdef CONFIG_PAX_KERNEXEC
31397 + " movl %%cr0, %0\n"
31398 + " movl %0, %%eax\n"
31399 + " andl $0xFFFEFFFF, %%eax\n"
31400 + " movl %%eax, %%cr0\n"
31401 +#endif
31402 +
31403 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31404 +
31405 +#ifdef CONFIG_PAX_KERNEXEC
31406 + " movl %0, %%cr0\n"
31407 +#endif
31408 +
31409 " jmp 2b\n"
31410 ".previous\n"
31411 _ASM_EXTABLE(1b, 3b)
31412 - : : "r" (from));
31413 + : "=&r" (cr0) : "r" (from) : "ax");
31414
31415 for ( ; i > 5; i--) {
31416 __asm__ __volatile__ (
31417 - "1: prefetch 320(%0)\n"
31418 - "2: movq (%0), %%mm0\n"
31419 - " movq 8(%0), %%mm1\n"
31420 - " movq 16(%0), %%mm2\n"
31421 - " movq 24(%0), %%mm3\n"
31422 - " movq %%mm0, (%1)\n"
31423 - " movq %%mm1, 8(%1)\n"
31424 - " movq %%mm2, 16(%1)\n"
31425 - " movq %%mm3, 24(%1)\n"
31426 - " movq 32(%0), %%mm0\n"
31427 - " movq 40(%0), %%mm1\n"
31428 - " movq 48(%0), %%mm2\n"
31429 - " movq 56(%0), %%mm3\n"
31430 - " movq %%mm0, 32(%1)\n"
31431 - " movq %%mm1, 40(%1)\n"
31432 - " movq %%mm2, 48(%1)\n"
31433 - " movq %%mm3, 56(%1)\n"
31434 + "1: prefetch 320(%1)\n"
31435 + "2: movq (%1), %%mm0\n"
31436 + " movq 8(%1), %%mm1\n"
31437 + " movq 16(%1), %%mm2\n"
31438 + " movq 24(%1), %%mm3\n"
31439 + " movq %%mm0, (%2)\n"
31440 + " movq %%mm1, 8(%2)\n"
31441 + " movq %%mm2, 16(%2)\n"
31442 + " movq %%mm3, 24(%2)\n"
31443 + " movq 32(%1), %%mm0\n"
31444 + " movq 40(%1), %%mm1\n"
31445 + " movq 48(%1), %%mm2\n"
31446 + " movq 56(%1), %%mm3\n"
31447 + " movq %%mm0, 32(%2)\n"
31448 + " movq %%mm1, 40(%2)\n"
31449 + " movq %%mm2, 48(%2)\n"
31450 + " movq %%mm3, 56(%2)\n"
31451 ".section .fixup, \"ax\"\n"
31452 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31453 + "3:\n"
31454 +
31455 +#ifdef CONFIG_PAX_KERNEXEC
31456 + " movl %%cr0, %0\n"
31457 + " movl %0, %%eax\n"
31458 + " andl $0xFFFEFFFF, %%eax\n"
31459 + " movl %%eax, %%cr0\n"
31460 +#endif
31461 +
31462 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31463 +
31464 +#ifdef CONFIG_PAX_KERNEXEC
31465 + " movl %0, %%cr0\n"
31466 +#endif
31467 +
31468 " jmp 2b\n"
31469 ".previous\n"
31470 _ASM_EXTABLE(1b, 3b)
31471 - : : "r" (from), "r" (to) : "memory");
31472 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31473
31474 from += 64;
31475 to += 64;
31476 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31477 static void fast_copy_page(void *to, void *from)
31478 {
31479 int i;
31480 + unsigned long cr0;
31481
31482 kernel_fpu_begin();
31483
31484 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31485 * but that is for later. -AV
31486 */
31487 __asm__ __volatile__(
31488 - "1: prefetch (%0)\n"
31489 - " prefetch 64(%0)\n"
31490 - " prefetch 128(%0)\n"
31491 - " prefetch 192(%0)\n"
31492 - " prefetch 256(%0)\n"
31493 + "1: prefetch (%1)\n"
31494 + " prefetch 64(%1)\n"
31495 + " prefetch 128(%1)\n"
31496 + " prefetch 192(%1)\n"
31497 + " prefetch 256(%1)\n"
31498 "2: \n"
31499 ".section .fixup, \"ax\"\n"
31500 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31501 + "3: \n"
31502 +
31503 +#ifdef CONFIG_PAX_KERNEXEC
31504 + " movl %%cr0, %0\n"
31505 + " movl %0, %%eax\n"
31506 + " andl $0xFFFEFFFF, %%eax\n"
31507 + " movl %%eax, %%cr0\n"
31508 +#endif
31509 +
31510 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31511 +
31512 +#ifdef CONFIG_PAX_KERNEXEC
31513 + " movl %0, %%cr0\n"
31514 +#endif
31515 +
31516 " jmp 2b\n"
31517 ".previous\n"
31518 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31519 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31520
31521 for (i = 0; i < (4096-320)/64; i++) {
31522 __asm__ __volatile__ (
31523 - "1: prefetch 320(%0)\n"
31524 - "2: movq (%0), %%mm0\n"
31525 - " movntq %%mm0, (%1)\n"
31526 - " movq 8(%0), %%mm1\n"
31527 - " movntq %%mm1, 8(%1)\n"
31528 - " movq 16(%0), %%mm2\n"
31529 - " movntq %%mm2, 16(%1)\n"
31530 - " movq 24(%0), %%mm3\n"
31531 - " movntq %%mm3, 24(%1)\n"
31532 - " movq 32(%0), %%mm4\n"
31533 - " movntq %%mm4, 32(%1)\n"
31534 - " movq 40(%0), %%mm5\n"
31535 - " movntq %%mm5, 40(%1)\n"
31536 - " movq 48(%0), %%mm6\n"
31537 - " movntq %%mm6, 48(%1)\n"
31538 - " movq 56(%0), %%mm7\n"
31539 - " movntq %%mm7, 56(%1)\n"
31540 + "1: prefetch 320(%1)\n"
31541 + "2: movq (%1), %%mm0\n"
31542 + " movntq %%mm0, (%2)\n"
31543 + " movq 8(%1), %%mm1\n"
31544 + " movntq %%mm1, 8(%2)\n"
31545 + " movq 16(%1), %%mm2\n"
31546 + " movntq %%mm2, 16(%2)\n"
31547 + " movq 24(%1), %%mm3\n"
31548 + " movntq %%mm3, 24(%2)\n"
31549 + " movq 32(%1), %%mm4\n"
31550 + " movntq %%mm4, 32(%2)\n"
31551 + " movq 40(%1), %%mm5\n"
31552 + " movntq %%mm5, 40(%2)\n"
31553 + " movq 48(%1), %%mm6\n"
31554 + " movntq %%mm6, 48(%2)\n"
31555 + " movq 56(%1), %%mm7\n"
31556 + " movntq %%mm7, 56(%2)\n"
31557 ".section .fixup, \"ax\"\n"
31558 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31559 + "3:\n"
31560 +
31561 +#ifdef CONFIG_PAX_KERNEXEC
31562 + " movl %%cr0, %0\n"
31563 + " movl %0, %%eax\n"
31564 + " andl $0xFFFEFFFF, %%eax\n"
31565 + " movl %%eax, %%cr0\n"
31566 +#endif
31567 +
31568 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31569 +
31570 +#ifdef CONFIG_PAX_KERNEXEC
31571 + " movl %0, %%cr0\n"
31572 +#endif
31573 +
31574 " jmp 2b\n"
31575 ".previous\n"
31576 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31577 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31578
31579 from += 64;
31580 to += 64;
31581 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31582 static void fast_copy_page(void *to, void *from)
31583 {
31584 int i;
31585 + unsigned long cr0;
31586
31587 kernel_fpu_begin();
31588
31589 __asm__ __volatile__ (
31590 - "1: prefetch (%0)\n"
31591 - " prefetch 64(%0)\n"
31592 - " prefetch 128(%0)\n"
31593 - " prefetch 192(%0)\n"
31594 - " prefetch 256(%0)\n"
31595 + "1: prefetch (%1)\n"
31596 + " prefetch 64(%1)\n"
31597 + " prefetch 128(%1)\n"
31598 + " prefetch 192(%1)\n"
31599 + " prefetch 256(%1)\n"
31600 "2: \n"
31601 ".section .fixup, \"ax\"\n"
31602 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31603 + "3: \n"
31604 +
31605 +#ifdef CONFIG_PAX_KERNEXEC
31606 + " movl %%cr0, %0\n"
31607 + " movl %0, %%eax\n"
31608 + " andl $0xFFFEFFFF, %%eax\n"
31609 + " movl %%eax, %%cr0\n"
31610 +#endif
31611 +
31612 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31613 +
31614 +#ifdef CONFIG_PAX_KERNEXEC
31615 + " movl %0, %%cr0\n"
31616 +#endif
31617 +
31618 " jmp 2b\n"
31619 ".previous\n"
31620 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31621 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31622
31623 for (i = 0; i < 4096/64; i++) {
31624 __asm__ __volatile__ (
31625 - "1: prefetch 320(%0)\n"
31626 - "2: movq (%0), %%mm0\n"
31627 - " movq 8(%0), %%mm1\n"
31628 - " movq 16(%0), %%mm2\n"
31629 - " movq 24(%0), %%mm3\n"
31630 - " movq %%mm0, (%1)\n"
31631 - " movq %%mm1, 8(%1)\n"
31632 - " movq %%mm2, 16(%1)\n"
31633 - " movq %%mm3, 24(%1)\n"
31634 - " movq 32(%0), %%mm0\n"
31635 - " movq 40(%0), %%mm1\n"
31636 - " movq 48(%0), %%mm2\n"
31637 - " movq 56(%0), %%mm3\n"
31638 - " movq %%mm0, 32(%1)\n"
31639 - " movq %%mm1, 40(%1)\n"
31640 - " movq %%mm2, 48(%1)\n"
31641 - " movq %%mm3, 56(%1)\n"
31642 + "1: prefetch 320(%1)\n"
31643 + "2: movq (%1), %%mm0\n"
31644 + " movq 8(%1), %%mm1\n"
31645 + " movq 16(%1), %%mm2\n"
31646 + " movq 24(%1), %%mm3\n"
31647 + " movq %%mm0, (%2)\n"
31648 + " movq %%mm1, 8(%2)\n"
31649 + " movq %%mm2, 16(%2)\n"
31650 + " movq %%mm3, 24(%2)\n"
31651 + " movq 32(%1), %%mm0\n"
31652 + " movq 40(%1), %%mm1\n"
31653 + " movq 48(%1), %%mm2\n"
31654 + " movq 56(%1), %%mm3\n"
31655 + " movq %%mm0, 32(%2)\n"
31656 + " movq %%mm1, 40(%2)\n"
31657 + " movq %%mm2, 48(%2)\n"
31658 + " movq %%mm3, 56(%2)\n"
31659 ".section .fixup, \"ax\"\n"
31660 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31661 + "3:\n"
31662 +
31663 +#ifdef CONFIG_PAX_KERNEXEC
31664 + " movl %%cr0, %0\n"
31665 + " movl %0, %%eax\n"
31666 + " andl $0xFFFEFFFF, %%eax\n"
31667 + " movl %%eax, %%cr0\n"
31668 +#endif
31669 +
31670 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31671 +
31672 +#ifdef CONFIG_PAX_KERNEXEC
31673 + " movl %0, %%cr0\n"
31674 +#endif
31675 +
31676 " jmp 2b\n"
31677 ".previous\n"
31678 _ASM_EXTABLE(1b, 3b)
31679 - : : "r" (from), "r" (to) : "memory");
31680 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31681
31682 from += 64;
31683 to += 64;
31684 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31685 index f6d13ee..d789440 100644
31686 --- a/arch/x86/lib/msr-reg.S
31687 +++ b/arch/x86/lib/msr-reg.S
31688 @@ -3,6 +3,7 @@
31689 #include <asm/dwarf2.h>
31690 #include <asm/asm.h>
31691 #include <asm/msr.h>
31692 +#include <asm/alternative-asm.h>
31693
31694 #ifdef CONFIG_X86_64
31695 /*
31696 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31697 movl %edi, 28(%r10)
31698 popq_cfi %rbp
31699 popq_cfi %rbx
31700 + pax_force_retaddr
31701 ret
31702 3:
31703 CFI_RESTORE_STATE
31704 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31705 index fc6ba17..d4d989d 100644
31706 --- a/arch/x86/lib/putuser.S
31707 +++ b/arch/x86/lib/putuser.S
31708 @@ -16,7 +16,9 @@
31709 #include <asm/errno.h>
31710 #include <asm/asm.h>
31711 #include <asm/smap.h>
31712 -
31713 +#include <asm/segment.h>
31714 +#include <asm/pgtable.h>
31715 +#include <asm/alternative-asm.h>
31716
31717 /*
31718 * __put_user_X
31719 @@ -30,57 +32,125 @@
31720 * as they get called from within inline assembly.
31721 */
31722
31723 -#define ENTER CFI_STARTPROC ; \
31724 - GET_THREAD_INFO(%_ASM_BX)
31725 -#define EXIT ASM_CLAC ; \
31726 - ret ; \
31727 +#define ENTER CFI_STARTPROC
31728 +#define EXIT ASM_CLAC ; \
31729 + pax_force_retaddr ; \
31730 + ret ; \
31731 CFI_ENDPROC
31732
31733 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31734 +#define _DEST %_ASM_CX,%_ASM_BX
31735 +#else
31736 +#define _DEST %_ASM_CX
31737 +#endif
31738 +
31739 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31740 +#define __copyuser_seg gs;
31741 +#else
31742 +#define __copyuser_seg
31743 +#endif
31744 +
31745 .text
31746 ENTRY(__put_user_1)
31747 ENTER
31748 +
31749 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31750 + GET_THREAD_INFO(%_ASM_BX)
31751 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31752 jae bad_put_user
31753 ASM_STAC
31754 -1: movb %al,(%_ASM_CX)
31755 +
31756 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31757 + mov pax_user_shadow_base,%_ASM_BX
31758 + cmp %_ASM_BX,%_ASM_CX
31759 + jb 1234f
31760 + xor %ebx,%ebx
31761 +1234:
31762 +#endif
31763 +
31764 +#endif
31765 +
31766 +1: __copyuser_seg movb %al,(_DEST)
31767 xor %eax,%eax
31768 EXIT
31769 ENDPROC(__put_user_1)
31770
31771 ENTRY(__put_user_2)
31772 ENTER
31773 +
31774 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31775 + GET_THREAD_INFO(%_ASM_BX)
31776 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31777 sub $1,%_ASM_BX
31778 cmp %_ASM_BX,%_ASM_CX
31779 jae bad_put_user
31780 ASM_STAC
31781 -2: movw %ax,(%_ASM_CX)
31782 +
31783 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31784 + mov pax_user_shadow_base,%_ASM_BX
31785 + cmp %_ASM_BX,%_ASM_CX
31786 + jb 1234f
31787 + xor %ebx,%ebx
31788 +1234:
31789 +#endif
31790 +
31791 +#endif
31792 +
31793 +2: __copyuser_seg movw %ax,(_DEST)
31794 xor %eax,%eax
31795 EXIT
31796 ENDPROC(__put_user_2)
31797
31798 ENTRY(__put_user_4)
31799 ENTER
31800 +
31801 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31802 + GET_THREAD_INFO(%_ASM_BX)
31803 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31804 sub $3,%_ASM_BX
31805 cmp %_ASM_BX,%_ASM_CX
31806 jae bad_put_user
31807 ASM_STAC
31808 -3: movl %eax,(%_ASM_CX)
31809 +
31810 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31811 + mov pax_user_shadow_base,%_ASM_BX
31812 + cmp %_ASM_BX,%_ASM_CX
31813 + jb 1234f
31814 + xor %ebx,%ebx
31815 +1234:
31816 +#endif
31817 +
31818 +#endif
31819 +
31820 +3: __copyuser_seg movl %eax,(_DEST)
31821 xor %eax,%eax
31822 EXIT
31823 ENDPROC(__put_user_4)
31824
31825 ENTRY(__put_user_8)
31826 ENTER
31827 +
31828 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31829 + GET_THREAD_INFO(%_ASM_BX)
31830 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31831 sub $7,%_ASM_BX
31832 cmp %_ASM_BX,%_ASM_CX
31833 jae bad_put_user
31834 ASM_STAC
31835 -4: mov %_ASM_AX,(%_ASM_CX)
31836 +
31837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31838 + mov pax_user_shadow_base,%_ASM_BX
31839 + cmp %_ASM_BX,%_ASM_CX
31840 + jb 1234f
31841 + xor %ebx,%ebx
31842 +1234:
31843 +#endif
31844 +
31845 +#endif
31846 +
31847 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31848 #ifdef CONFIG_X86_32
31849 -5: movl %edx,4(%_ASM_CX)
31850 +5: __copyuser_seg movl %edx,4(_DEST)
31851 #endif
31852 xor %eax,%eax
31853 EXIT
31854 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31855 index 1cad221..de671ee 100644
31856 --- a/arch/x86/lib/rwlock.S
31857 +++ b/arch/x86/lib/rwlock.S
31858 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31859 FRAME
31860 0: LOCK_PREFIX
31861 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31862 +
31863 +#ifdef CONFIG_PAX_REFCOUNT
31864 + jno 1234f
31865 + LOCK_PREFIX
31866 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31867 + int $4
31868 +1234:
31869 + _ASM_EXTABLE(1234b, 1234b)
31870 +#endif
31871 +
31872 1: rep; nop
31873 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31874 jne 1b
31875 LOCK_PREFIX
31876 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31877 +
31878 +#ifdef CONFIG_PAX_REFCOUNT
31879 + jno 1234f
31880 + LOCK_PREFIX
31881 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31882 + int $4
31883 +1234:
31884 + _ASM_EXTABLE(1234b, 1234b)
31885 +#endif
31886 +
31887 jnz 0b
31888 ENDFRAME
31889 + pax_force_retaddr
31890 ret
31891 CFI_ENDPROC
31892 END(__write_lock_failed)
31893 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31894 FRAME
31895 0: LOCK_PREFIX
31896 READ_LOCK_SIZE(inc) (%__lock_ptr)
31897 +
31898 +#ifdef CONFIG_PAX_REFCOUNT
31899 + jno 1234f
31900 + LOCK_PREFIX
31901 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31902 + int $4
31903 +1234:
31904 + _ASM_EXTABLE(1234b, 1234b)
31905 +#endif
31906 +
31907 1: rep; nop
31908 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31909 js 1b
31910 LOCK_PREFIX
31911 READ_LOCK_SIZE(dec) (%__lock_ptr)
31912 +
31913 +#ifdef CONFIG_PAX_REFCOUNT
31914 + jno 1234f
31915 + LOCK_PREFIX
31916 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31917 + int $4
31918 +1234:
31919 + _ASM_EXTABLE(1234b, 1234b)
31920 +#endif
31921 +
31922 js 0b
31923 ENDFRAME
31924 + pax_force_retaddr
31925 ret
31926 CFI_ENDPROC
31927 END(__read_lock_failed)
31928 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31929 index 5dff5f0..cadebf4 100644
31930 --- a/arch/x86/lib/rwsem.S
31931 +++ b/arch/x86/lib/rwsem.S
31932 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31933 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31934 CFI_RESTORE __ASM_REG(dx)
31935 restore_common_regs
31936 + pax_force_retaddr
31937 ret
31938 CFI_ENDPROC
31939 ENDPROC(call_rwsem_down_read_failed)
31940 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31941 movq %rax,%rdi
31942 call rwsem_down_write_failed
31943 restore_common_regs
31944 + pax_force_retaddr
31945 ret
31946 CFI_ENDPROC
31947 ENDPROC(call_rwsem_down_write_failed)
31948 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31949 movq %rax,%rdi
31950 call rwsem_wake
31951 restore_common_regs
31952 -1: ret
31953 +1: pax_force_retaddr
31954 + ret
31955 CFI_ENDPROC
31956 ENDPROC(call_rwsem_wake)
31957
31958 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31959 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31960 CFI_RESTORE __ASM_REG(dx)
31961 restore_common_regs
31962 + pax_force_retaddr
31963 ret
31964 CFI_ENDPROC
31965 ENDPROC(call_rwsem_downgrade_wake)
31966 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31967 index 92d9fea..b2762c8 100644
31968 --- a/arch/x86/lib/thunk_64.S
31969 +++ b/arch/x86/lib/thunk_64.S
31970 @@ -9,6 +9,7 @@
31971 #include <asm/dwarf2.h>
31972 #include <asm/calling.h>
31973 #include <asm/asm.h>
31974 +#include <asm/alternative-asm.h>
31975
31976 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31977 .macro THUNK name, func, put_ret_addr_in_rdi=0
31978 @@ -16,11 +17,11 @@
31979 \name:
31980 CFI_STARTPROC
31981
31982 - /* this one pushes 9 elems, the next one would be %rIP */
31983 - SAVE_ARGS
31984 + /* this one pushes 15+1 elems, the next one would be %rIP */
31985 + SAVE_ARGS 8
31986
31987 .if \put_ret_addr_in_rdi
31988 - movq_cfi_restore 9*8, rdi
31989 + movq_cfi_restore RIP, rdi
31990 .endif
31991
31992 call \func
31993 @@ -40,9 +41,10 @@
31994
31995 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31996 CFI_STARTPROC
31997 - SAVE_ARGS
31998 + SAVE_ARGS 8
31999 restore:
32000 - RESTORE_ARGS
32001 + RESTORE_ARGS 1,8
32002 + pax_force_retaddr
32003 ret
32004 CFI_ENDPROC
32005 _ASM_NOKPROBE(restore)
32006 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
32007 index e2f5e21..4b22130 100644
32008 --- a/arch/x86/lib/usercopy_32.c
32009 +++ b/arch/x86/lib/usercopy_32.c
32010 @@ -42,11 +42,13 @@ do { \
32011 int __d0; \
32012 might_fault(); \
32013 __asm__ __volatile__( \
32014 + __COPYUSER_SET_ES \
32015 ASM_STAC "\n" \
32016 "0: rep; stosl\n" \
32017 " movl %2,%0\n" \
32018 "1: rep; stosb\n" \
32019 "2: " ASM_CLAC "\n" \
32020 + __COPYUSER_RESTORE_ES \
32021 ".section .fixup,\"ax\"\n" \
32022 "3: lea 0(%2,%0,4),%0\n" \
32023 " jmp 2b\n" \
32024 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
32025
32026 #ifdef CONFIG_X86_INTEL_USERCOPY
32027 static unsigned long
32028 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
32029 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
32030 {
32031 int d0, d1;
32032 __asm__ __volatile__(
32033 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
32034 " .align 2,0x90\n"
32035 "3: movl 0(%4), %%eax\n"
32036 "4: movl 4(%4), %%edx\n"
32037 - "5: movl %%eax, 0(%3)\n"
32038 - "6: movl %%edx, 4(%3)\n"
32039 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
32040 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
32041 "7: movl 8(%4), %%eax\n"
32042 "8: movl 12(%4),%%edx\n"
32043 - "9: movl %%eax, 8(%3)\n"
32044 - "10: movl %%edx, 12(%3)\n"
32045 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
32046 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
32047 "11: movl 16(%4), %%eax\n"
32048 "12: movl 20(%4), %%edx\n"
32049 - "13: movl %%eax, 16(%3)\n"
32050 - "14: movl %%edx, 20(%3)\n"
32051 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
32052 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
32053 "15: movl 24(%4), %%eax\n"
32054 "16: movl 28(%4), %%edx\n"
32055 - "17: movl %%eax, 24(%3)\n"
32056 - "18: movl %%edx, 28(%3)\n"
32057 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
32058 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
32059 "19: movl 32(%4), %%eax\n"
32060 "20: movl 36(%4), %%edx\n"
32061 - "21: movl %%eax, 32(%3)\n"
32062 - "22: movl %%edx, 36(%3)\n"
32063 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
32064 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
32065 "23: movl 40(%4), %%eax\n"
32066 "24: movl 44(%4), %%edx\n"
32067 - "25: movl %%eax, 40(%3)\n"
32068 - "26: movl %%edx, 44(%3)\n"
32069 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
32070 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
32071 "27: movl 48(%4), %%eax\n"
32072 "28: movl 52(%4), %%edx\n"
32073 - "29: movl %%eax, 48(%3)\n"
32074 - "30: movl %%edx, 52(%3)\n"
32075 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
32076 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
32077 "31: movl 56(%4), %%eax\n"
32078 "32: movl 60(%4), %%edx\n"
32079 - "33: movl %%eax, 56(%3)\n"
32080 - "34: movl %%edx, 60(%3)\n"
32081 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
32082 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
32083 " addl $-64, %0\n"
32084 " addl $64, %4\n"
32085 " addl $64, %3\n"
32086 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
32087 " shrl $2, %0\n"
32088 " andl $3, %%eax\n"
32089 " cld\n"
32090 + __COPYUSER_SET_ES
32091 "99: rep; movsl\n"
32092 "36: movl %%eax, %0\n"
32093 "37: rep; movsb\n"
32094 "100:\n"
32095 + __COPYUSER_RESTORE_ES
32096 + ".section .fixup,\"ax\"\n"
32097 + "101: lea 0(%%eax,%0,4),%0\n"
32098 + " jmp 100b\n"
32099 + ".previous\n"
32100 + _ASM_EXTABLE(1b,100b)
32101 + _ASM_EXTABLE(2b,100b)
32102 + _ASM_EXTABLE(3b,100b)
32103 + _ASM_EXTABLE(4b,100b)
32104 + _ASM_EXTABLE(5b,100b)
32105 + _ASM_EXTABLE(6b,100b)
32106 + _ASM_EXTABLE(7b,100b)
32107 + _ASM_EXTABLE(8b,100b)
32108 + _ASM_EXTABLE(9b,100b)
32109 + _ASM_EXTABLE(10b,100b)
32110 + _ASM_EXTABLE(11b,100b)
32111 + _ASM_EXTABLE(12b,100b)
32112 + _ASM_EXTABLE(13b,100b)
32113 + _ASM_EXTABLE(14b,100b)
32114 + _ASM_EXTABLE(15b,100b)
32115 + _ASM_EXTABLE(16b,100b)
32116 + _ASM_EXTABLE(17b,100b)
32117 + _ASM_EXTABLE(18b,100b)
32118 + _ASM_EXTABLE(19b,100b)
32119 + _ASM_EXTABLE(20b,100b)
32120 + _ASM_EXTABLE(21b,100b)
32121 + _ASM_EXTABLE(22b,100b)
32122 + _ASM_EXTABLE(23b,100b)
32123 + _ASM_EXTABLE(24b,100b)
32124 + _ASM_EXTABLE(25b,100b)
32125 + _ASM_EXTABLE(26b,100b)
32126 + _ASM_EXTABLE(27b,100b)
32127 + _ASM_EXTABLE(28b,100b)
32128 + _ASM_EXTABLE(29b,100b)
32129 + _ASM_EXTABLE(30b,100b)
32130 + _ASM_EXTABLE(31b,100b)
32131 + _ASM_EXTABLE(32b,100b)
32132 + _ASM_EXTABLE(33b,100b)
32133 + _ASM_EXTABLE(34b,100b)
32134 + _ASM_EXTABLE(35b,100b)
32135 + _ASM_EXTABLE(36b,100b)
32136 + _ASM_EXTABLE(37b,100b)
32137 + _ASM_EXTABLE(99b,101b)
32138 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
32139 + : "1"(to), "2"(from), "0"(size)
32140 + : "eax", "edx", "memory");
32141 + return size;
32142 +}
32143 +
32144 +static unsigned long
32145 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
32146 +{
32147 + int d0, d1;
32148 + __asm__ __volatile__(
32149 + " .align 2,0x90\n"
32150 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
32151 + " cmpl $67, %0\n"
32152 + " jbe 3f\n"
32153 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
32154 + " .align 2,0x90\n"
32155 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
32156 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
32157 + "5: movl %%eax, 0(%3)\n"
32158 + "6: movl %%edx, 4(%3)\n"
32159 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
32160 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
32161 + "9: movl %%eax, 8(%3)\n"
32162 + "10: movl %%edx, 12(%3)\n"
32163 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
32164 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
32165 + "13: movl %%eax, 16(%3)\n"
32166 + "14: movl %%edx, 20(%3)\n"
32167 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
32168 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
32169 + "17: movl %%eax, 24(%3)\n"
32170 + "18: movl %%edx, 28(%3)\n"
32171 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
32172 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
32173 + "21: movl %%eax, 32(%3)\n"
32174 + "22: movl %%edx, 36(%3)\n"
32175 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
32176 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
32177 + "25: movl %%eax, 40(%3)\n"
32178 + "26: movl %%edx, 44(%3)\n"
32179 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
32180 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
32181 + "29: movl %%eax, 48(%3)\n"
32182 + "30: movl %%edx, 52(%3)\n"
32183 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
32184 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
32185 + "33: movl %%eax, 56(%3)\n"
32186 + "34: movl %%edx, 60(%3)\n"
32187 + " addl $-64, %0\n"
32188 + " addl $64, %4\n"
32189 + " addl $64, %3\n"
32190 + " cmpl $63, %0\n"
32191 + " ja 1b\n"
32192 + "35: movl %0, %%eax\n"
32193 + " shrl $2, %0\n"
32194 + " andl $3, %%eax\n"
32195 + " cld\n"
32196 + "99: rep; "__copyuser_seg" movsl\n"
32197 + "36: movl %%eax, %0\n"
32198 + "37: rep; "__copyuser_seg" movsb\n"
32199 + "100:\n"
32200 ".section .fixup,\"ax\"\n"
32201 "101: lea 0(%%eax,%0,4),%0\n"
32202 " jmp 100b\n"
32203 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32204 int d0, d1;
32205 __asm__ __volatile__(
32206 " .align 2,0x90\n"
32207 - "0: movl 32(%4), %%eax\n"
32208 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32209 " cmpl $67, %0\n"
32210 " jbe 2f\n"
32211 - "1: movl 64(%4), %%eax\n"
32212 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32213 " .align 2,0x90\n"
32214 - "2: movl 0(%4), %%eax\n"
32215 - "21: movl 4(%4), %%edx\n"
32216 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32217 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32218 " movl %%eax, 0(%3)\n"
32219 " movl %%edx, 4(%3)\n"
32220 - "3: movl 8(%4), %%eax\n"
32221 - "31: movl 12(%4),%%edx\n"
32222 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32223 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32224 " movl %%eax, 8(%3)\n"
32225 " movl %%edx, 12(%3)\n"
32226 - "4: movl 16(%4), %%eax\n"
32227 - "41: movl 20(%4), %%edx\n"
32228 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32229 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32230 " movl %%eax, 16(%3)\n"
32231 " movl %%edx, 20(%3)\n"
32232 - "10: movl 24(%4), %%eax\n"
32233 - "51: movl 28(%4), %%edx\n"
32234 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32235 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32236 " movl %%eax, 24(%3)\n"
32237 " movl %%edx, 28(%3)\n"
32238 - "11: movl 32(%4), %%eax\n"
32239 - "61: movl 36(%4), %%edx\n"
32240 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32241 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32242 " movl %%eax, 32(%3)\n"
32243 " movl %%edx, 36(%3)\n"
32244 - "12: movl 40(%4), %%eax\n"
32245 - "71: movl 44(%4), %%edx\n"
32246 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32247 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32248 " movl %%eax, 40(%3)\n"
32249 " movl %%edx, 44(%3)\n"
32250 - "13: movl 48(%4), %%eax\n"
32251 - "81: movl 52(%4), %%edx\n"
32252 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32253 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32254 " movl %%eax, 48(%3)\n"
32255 " movl %%edx, 52(%3)\n"
32256 - "14: movl 56(%4), %%eax\n"
32257 - "91: movl 60(%4), %%edx\n"
32258 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32259 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32260 " movl %%eax, 56(%3)\n"
32261 " movl %%edx, 60(%3)\n"
32262 " addl $-64, %0\n"
32263 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32264 " shrl $2, %0\n"
32265 " andl $3, %%eax\n"
32266 " cld\n"
32267 - "6: rep; movsl\n"
32268 + "6: rep; "__copyuser_seg" movsl\n"
32269 " movl %%eax,%0\n"
32270 - "7: rep; movsb\n"
32271 + "7: rep; "__copyuser_seg" movsb\n"
32272 "8:\n"
32273 ".section .fixup,\"ax\"\n"
32274 "9: lea 0(%%eax,%0,4),%0\n"
32275 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32276
32277 __asm__ __volatile__(
32278 " .align 2,0x90\n"
32279 - "0: movl 32(%4), %%eax\n"
32280 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32281 " cmpl $67, %0\n"
32282 " jbe 2f\n"
32283 - "1: movl 64(%4), %%eax\n"
32284 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32285 " .align 2,0x90\n"
32286 - "2: movl 0(%4), %%eax\n"
32287 - "21: movl 4(%4), %%edx\n"
32288 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32289 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32290 " movnti %%eax, 0(%3)\n"
32291 " movnti %%edx, 4(%3)\n"
32292 - "3: movl 8(%4), %%eax\n"
32293 - "31: movl 12(%4),%%edx\n"
32294 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32295 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32296 " movnti %%eax, 8(%3)\n"
32297 " movnti %%edx, 12(%3)\n"
32298 - "4: movl 16(%4), %%eax\n"
32299 - "41: movl 20(%4), %%edx\n"
32300 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32301 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32302 " movnti %%eax, 16(%3)\n"
32303 " movnti %%edx, 20(%3)\n"
32304 - "10: movl 24(%4), %%eax\n"
32305 - "51: movl 28(%4), %%edx\n"
32306 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32307 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32308 " movnti %%eax, 24(%3)\n"
32309 " movnti %%edx, 28(%3)\n"
32310 - "11: movl 32(%4), %%eax\n"
32311 - "61: movl 36(%4), %%edx\n"
32312 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32313 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32314 " movnti %%eax, 32(%3)\n"
32315 " movnti %%edx, 36(%3)\n"
32316 - "12: movl 40(%4), %%eax\n"
32317 - "71: movl 44(%4), %%edx\n"
32318 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32319 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32320 " movnti %%eax, 40(%3)\n"
32321 " movnti %%edx, 44(%3)\n"
32322 - "13: movl 48(%4), %%eax\n"
32323 - "81: movl 52(%4), %%edx\n"
32324 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32325 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32326 " movnti %%eax, 48(%3)\n"
32327 " movnti %%edx, 52(%3)\n"
32328 - "14: movl 56(%4), %%eax\n"
32329 - "91: movl 60(%4), %%edx\n"
32330 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32331 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32332 " movnti %%eax, 56(%3)\n"
32333 " movnti %%edx, 60(%3)\n"
32334 " addl $-64, %0\n"
32335 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32336 " shrl $2, %0\n"
32337 " andl $3, %%eax\n"
32338 " cld\n"
32339 - "6: rep; movsl\n"
32340 + "6: rep; "__copyuser_seg" movsl\n"
32341 " movl %%eax,%0\n"
32342 - "7: rep; movsb\n"
32343 + "7: rep; "__copyuser_seg" movsb\n"
32344 "8:\n"
32345 ".section .fixup,\"ax\"\n"
32346 "9: lea 0(%%eax,%0,4),%0\n"
32347 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32348
32349 __asm__ __volatile__(
32350 " .align 2,0x90\n"
32351 - "0: movl 32(%4), %%eax\n"
32352 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32353 " cmpl $67, %0\n"
32354 " jbe 2f\n"
32355 - "1: movl 64(%4), %%eax\n"
32356 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32357 " .align 2,0x90\n"
32358 - "2: movl 0(%4), %%eax\n"
32359 - "21: movl 4(%4), %%edx\n"
32360 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32361 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32362 " movnti %%eax, 0(%3)\n"
32363 " movnti %%edx, 4(%3)\n"
32364 - "3: movl 8(%4), %%eax\n"
32365 - "31: movl 12(%4),%%edx\n"
32366 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32367 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32368 " movnti %%eax, 8(%3)\n"
32369 " movnti %%edx, 12(%3)\n"
32370 - "4: movl 16(%4), %%eax\n"
32371 - "41: movl 20(%4), %%edx\n"
32372 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32373 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32374 " movnti %%eax, 16(%3)\n"
32375 " movnti %%edx, 20(%3)\n"
32376 - "10: movl 24(%4), %%eax\n"
32377 - "51: movl 28(%4), %%edx\n"
32378 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32379 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32380 " movnti %%eax, 24(%3)\n"
32381 " movnti %%edx, 28(%3)\n"
32382 - "11: movl 32(%4), %%eax\n"
32383 - "61: movl 36(%4), %%edx\n"
32384 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32385 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32386 " movnti %%eax, 32(%3)\n"
32387 " movnti %%edx, 36(%3)\n"
32388 - "12: movl 40(%4), %%eax\n"
32389 - "71: movl 44(%4), %%edx\n"
32390 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32391 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32392 " movnti %%eax, 40(%3)\n"
32393 " movnti %%edx, 44(%3)\n"
32394 - "13: movl 48(%4), %%eax\n"
32395 - "81: movl 52(%4), %%edx\n"
32396 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32397 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32398 " movnti %%eax, 48(%3)\n"
32399 " movnti %%edx, 52(%3)\n"
32400 - "14: movl 56(%4), %%eax\n"
32401 - "91: movl 60(%4), %%edx\n"
32402 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32403 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32404 " movnti %%eax, 56(%3)\n"
32405 " movnti %%edx, 60(%3)\n"
32406 " addl $-64, %0\n"
32407 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32408 " shrl $2, %0\n"
32409 " andl $3, %%eax\n"
32410 " cld\n"
32411 - "6: rep; movsl\n"
32412 + "6: rep; "__copyuser_seg" movsl\n"
32413 " movl %%eax,%0\n"
32414 - "7: rep; movsb\n"
32415 + "7: rep; "__copyuser_seg" movsb\n"
32416 "8:\n"
32417 ".section .fixup,\"ax\"\n"
32418 "9: lea 0(%%eax,%0,4),%0\n"
32419 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32420 */
32421 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32422 unsigned long size);
32423 -unsigned long __copy_user_intel(void __user *to, const void *from,
32424 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32425 + unsigned long size);
32426 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32427 unsigned long size);
32428 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32429 const void __user *from, unsigned long size);
32430 #endif /* CONFIG_X86_INTEL_USERCOPY */
32431
32432 /* Generic arbitrary sized copy. */
32433 -#define __copy_user(to, from, size) \
32434 +#define __copy_user(to, from, size, prefix, set, restore) \
32435 do { \
32436 int __d0, __d1, __d2; \
32437 __asm__ __volatile__( \
32438 + set \
32439 " cmp $7,%0\n" \
32440 " jbe 1f\n" \
32441 " movl %1,%0\n" \
32442 " negl %0\n" \
32443 " andl $7,%0\n" \
32444 " subl %0,%3\n" \
32445 - "4: rep; movsb\n" \
32446 + "4: rep; "prefix"movsb\n" \
32447 " movl %3,%0\n" \
32448 " shrl $2,%0\n" \
32449 " andl $3,%3\n" \
32450 " .align 2,0x90\n" \
32451 - "0: rep; movsl\n" \
32452 + "0: rep; "prefix"movsl\n" \
32453 " movl %3,%0\n" \
32454 - "1: rep; movsb\n" \
32455 + "1: rep; "prefix"movsb\n" \
32456 "2:\n" \
32457 + restore \
32458 ".section .fixup,\"ax\"\n" \
32459 "5: addl %3,%0\n" \
32460 " jmp 2b\n" \
32461 @@ -538,14 +650,14 @@ do { \
32462 " negl %0\n" \
32463 " andl $7,%0\n" \
32464 " subl %0,%3\n" \
32465 - "4: rep; movsb\n" \
32466 + "4: rep; "__copyuser_seg"movsb\n" \
32467 " movl %3,%0\n" \
32468 " shrl $2,%0\n" \
32469 " andl $3,%3\n" \
32470 " .align 2,0x90\n" \
32471 - "0: rep; movsl\n" \
32472 + "0: rep; "__copyuser_seg"movsl\n" \
32473 " movl %3,%0\n" \
32474 - "1: rep; movsb\n" \
32475 + "1: rep; "__copyuser_seg"movsb\n" \
32476 "2:\n" \
32477 ".section .fixup,\"ax\"\n" \
32478 "5: addl %3,%0\n" \
32479 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32480 {
32481 stac();
32482 if (movsl_is_ok(to, from, n))
32483 - __copy_user(to, from, n);
32484 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32485 else
32486 - n = __copy_user_intel(to, from, n);
32487 + n = __generic_copy_to_user_intel(to, from, n);
32488 clac();
32489 return n;
32490 }
32491 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32492 {
32493 stac();
32494 if (movsl_is_ok(to, from, n))
32495 - __copy_user(to, from, n);
32496 + __copy_user(to, from, n, __copyuser_seg, "", "");
32497 else
32498 - n = __copy_user_intel((void __user *)to,
32499 - (const void *)from, n);
32500 + n = __generic_copy_from_user_intel(to, from, n);
32501 clac();
32502 return n;
32503 }
32504 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32505 if (n > 64 && cpu_has_xmm2)
32506 n = __copy_user_intel_nocache(to, from, n);
32507 else
32508 - __copy_user(to, from, n);
32509 + __copy_user(to, from, n, __copyuser_seg, "", "");
32510 #else
32511 - __copy_user(to, from, n);
32512 + __copy_user(to, from, n, __copyuser_seg, "", "");
32513 #endif
32514 clac();
32515 return n;
32516 }
32517 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32518
32519 -/**
32520 - * copy_to_user: - Copy a block of data into user space.
32521 - * @to: Destination address, in user space.
32522 - * @from: Source address, in kernel space.
32523 - * @n: Number of bytes to copy.
32524 - *
32525 - * Context: User context only. This function may sleep.
32526 - *
32527 - * Copy data from kernel space to user space.
32528 - *
32529 - * Returns number of bytes that could not be copied.
32530 - * On success, this will be zero.
32531 - */
32532 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32534 +void __set_fs(mm_segment_t x)
32535 {
32536 - if (access_ok(VERIFY_WRITE, to, n))
32537 - n = __copy_to_user(to, from, n);
32538 - return n;
32539 + switch (x.seg) {
32540 + case 0:
32541 + loadsegment(gs, 0);
32542 + break;
32543 + case TASK_SIZE_MAX:
32544 + loadsegment(gs, __USER_DS);
32545 + break;
32546 + case -1UL:
32547 + loadsegment(gs, __KERNEL_DS);
32548 + break;
32549 + default:
32550 + BUG();
32551 + }
32552 }
32553 -EXPORT_SYMBOL(_copy_to_user);
32554 +EXPORT_SYMBOL(__set_fs);
32555
32556 -/**
32557 - * copy_from_user: - Copy a block of data from user space.
32558 - * @to: Destination address, in kernel space.
32559 - * @from: Source address, in user space.
32560 - * @n: Number of bytes to copy.
32561 - *
32562 - * Context: User context only. This function may sleep.
32563 - *
32564 - * Copy data from user space to kernel space.
32565 - *
32566 - * Returns number of bytes that could not be copied.
32567 - * On success, this will be zero.
32568 - *
32569 - * If some data could not be copied, this function will pad the copied
32570 - * data to the requested size using zero bytes.
32571 - */
32572 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32573 +void set_fs(mm_segment_t x)
32574 {
32575 - if (access_ok(VERIFY_READ, from, n))
32576 - n = __copy_from_user(to, from, n);
32577 - else
32578 - memset(to, 0, n);
32579 - return n;
32580 + current_thread_info()->addr_limit = x;
32581 + __set_fs(x);
32582 }
32583 -EXPORT_SYMBOL(_copy_from_user);
32584 +EXPORT_SYMBOL(set_fs);
32585 +#endif
32586 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32587 index c905e89..01ab928 100644
32588 --- a/arch/x86/lib/usercopy_64.c
32589 +++ b/arch/x86/lib/usercopy_64.c
32590 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32591 might_fault();
32592 /* no memory constraint because it doesn't change any memory gcc knows
32593 about */
32594 + pax_open_userland();
32595 stac();
32596 asm volatile(
32597 " testq %[size8],%[size8]\n"
32598 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32599 _ASM_EXTABLE(0b,3b)
32600 _ASM_EXTABLE(1b,2b)
32601 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32602 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32603 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32604 [zero] "r" (0UL), [eight] "r" (8UL));
32605 clac();
32606 + pax_close_userland();
32607 return size;
32608 }
32609 EXPORT_SYMBOL(__clear_user);
32610 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32611 }
32612 EXPORT_SYMBOL(clear_user);
32613
32614 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32615 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32616 {
32617 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32618 - return copy_user_generic((__force void *)to, (__force void *)from, len);
32619 - }
32620 - return len;
32621 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32622 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32623 + return len;
32624 }
32625 EXPORT_SYMBOL(copy_in_user);
32626
32627 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32628 * it is not necessary to optimize tail handling.
32629 */
32630 __visible unsigned long
32631 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32632 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32633 {
32634 char c;
32635 unsigned zero_len;
32636
32637 + clac();
32638 + pax_close_userland();
32639 for (; len; --len, to++) {
32640 if (__get_user_nocheck(c, from++, sizeof(char)))
32641 break;
32642 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32643 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32644 if (__put_user_nocheck(c, to++, sizeof(char)))
32645 break;
32646 - clac();
32647 return len;
32648 }
32649 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32650 index 6a19ad9..1c48f9a 100644
32651 --- a/arch/x86/mm/Makefile
32652 +++ b/arch/x86/mm/Makefile
32653 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32654 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32655
32656 obj-$(CONFIG_MEMTEST) += memtest.o
32657 +
32658 +quote:="
32659 +obj-$(CONFIG_X86_64) += uderef_64.o
32660 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32661 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32662 index 903ec1e..c4166b2 100644
32663 --- a/arch/x86/mm/extable.c
32664 +++ b/arch/x86/mm/extable.c
32665 @@ -6,12 +6,24 @@
32666 static inline unsigned long
32667 ex_insn_addr(const struct exception_table_entry *x)
32668 {
32669 - return (unsigned long)&x->insn + x->insn;
32670 + unsigned long reloc = 0;
32671 +
32672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32673 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32674 +#endif
32675 +
32676 + return (unsigned long)&x->insn + x->insn + reloc;
32677 }
32678 static inline unsigned long
32679 ex_fixup_addr(const struct exception_table_entry *x)
32680 {
32681 - return (unsigned long)&x->fixup + x->fixup;
32682 + unsigned long reloc = 0;
32683 +
32684 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32685 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32686 +#endif
32687 +
32688 + return (unsigned long)&x->fixup + x->fixup + reloc;
32689 }
32690
32691 int fixup_exception(struct pt_regs *regs)
32692 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32693 unsigned long new_ip;
32694
32695 #ifdef CONFIG_PNPBIOS
32696 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32697 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32698 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32699 extern u32 pnp_bios_is_utter_crap;
32700 pnp_bios_is_utter_crap = 1;
32701 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32702 i += 4;
32703 p->fixup -= i;
32704 i += 4;
32705 +
32706 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32707 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32708 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32709 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32710 +#endif
32711 +
32712 }
32713 }
32714
32715 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32716 index a241946..d7a04cf 100644
32717 --- a/arch/x86/mm/fault.c
32718 +++ b/arch/x86/mm/fault.c
32719 @@ -14,12 +14,19 @@
32720 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32721 #include <linux/prefetch.h> /* prefetchw */
32722 #include <linux/context_tracking.h> /* exception_enter(), ... */
32723 +#include <linux/unistd.h>
32724 +#include <linux/compiler.h>
32725
32726 #include <asm/traps.h> /* dotraplinkage, ... */
32727 #include <asm/pgalloc.h> /* pgd_*(), ... */
32728 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32729 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32730 #include <asm/vsyscall.h> /* emulate_vsyscall */
32731 +#include <asm/tlbflush.h>
32732 +
32733 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32734 +#include <asm/stacktrace.h>
32735 +#endif
32736
32737 #define CREATE_TRACE_POINTS
32738 #include <asm/trace/exceptions.h>
32739 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32740 int ret = 0;
32741
32742 /* kprobe_running() needs smp_processor_id() */
32743 - if (kprobes_built_in() && !user_mode_vm(regs)) {
32744 + if (kprobes_built_in() && !user_mode(regs)) {
32745 preempt_disable();
32746 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32747 ret = 1;
32748 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32749 return !instr_lo || (instr_lo>>1) == 1;
32750 case 0x00:
32751 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32752 - if (probe_kernel_address(instr, opcode))
32753 + if (user_mode(regs)) {
32754 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32755 + return 0;
32756 + } else if (probe_kernel_address(instr, opcode))
32757 return 0;
32758
32759 *prefetch = (instr_lo == 0xF) &&
32760 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32761 while (instr < max_instr) {
32762 unsigned char opcode;
32763
32764 - if (probe_kernel_address(instr, opcode))
32765 + if (user_mode(regs)) {
32766 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32767 + break;
32768 + } else if (probe_kernel_address(instr, opcode))
32769 break;
32770
32771 instr++;
32772 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32773 force_sig_info(si_signo, &info, tsk);
32774 }
32775
32776 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32777 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32778 +#endif
32779 +
32780 +#ifdef CONFIG_PAX_EMUTRAMP
32781 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32782 +#endif
32783 +
32784 +#ifdef CONFIG_PAX_PAGEEXEC
32785 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32786 +{
32787 + pgd_t *pgd;
32788 + pud_t *pud;
32789 + pmd_t *pmd;
32790 +
32791 + pgd = pgd_offset(mm, address);
32792 + if (!pgd_present(*pgd))
32793 + return NULL;
32794 + pud = pud_offset(pgd, address);
32795 + if (!pud_present(*pud))
32796 + return NULL;
32797 + pmd = pmd_offset(pud, address);
32798 + if (!pmd_present(*pmd))
32799 + return NULL;
32800 + return pmd;
32801 +}
32802 +#endif
32803 +
32804 DEFINE_SPINLOCK(pgd_lock);
32805 LIST_HEAD(pgd_list);
32806
32807 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32808 for (address = VMALLOC_START & PMD_MASK;
32809 address >= TASK_SIZE && address < FIXADDR_TOP;
32810 address += PMD_SIZE) {
32811 +
32812 +#ifdef CONFIG_PAX_PER_CPU_PGD
32813 + unsigned long cpu;
32814 +#else
32815 struct page *page;
32816 +#endif
32817
32818 spin_lock(&pgd_lock);
32819 +
32820 +#ifdef CONFIG_PAX_PER_CPU_PGD
32821 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32822 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32823 + pmd_t *ret;
32824 +
32825 + ret = vmalloc_sync_one(pgd, address);
32826 + if (!ret)
32827 + break;
32828 + pgd = get_cpu_pgd(cpu, kernel);
32829 +#else
32830 list_for_each_entry(page, &pgd_list, lru) {
32831 + pgd_t *pgd;
32832 spinlock_t *pgt_lock;
32833 pmd_t *ret;
32834
32835 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32836 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32837
32838 spin_lock(pgt_lock);
32839 - ret = vmalloc_sync_one(page_address(page), address);
32840 + pgd = page_address(page);
32841 +#endif
32842 +
32843 + ret = vmalloc_sync_one(pgd, address);
32844 +
32845 +#ifndef CONFIG_PAX_PER_CPU_PGD
32846 spin_unlock(pgt_lock);
32847 +#endif
32848
32849 if (!ret)
32850 break;
32851 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32852 * an interrupt in the middle of a task switch..
32853 */
32854 pgd_paddr = read_cr3();
32855 +
32856 +#ifdef CONFIG_PAX_PER_CPU_PGD
32857 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32858 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32859 +#endif
32860 +
32861 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32862 if (!pmd_k)
32863 return -1;
32864 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32865 * happen within a race in page table update. In the later
32866 * case just flush:
32867 */
32868 - pgd = pgd_offset(current->active_mm, address);
32869 +
32870 pgd_ref = pgd_offset_k(address);
32871 if (pgd_none(*pgd_ref))
32872 return -1;
32873
32874 +#ifdef CONFIG_PAX_PER_CPU_PGD
32875 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32876 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32877 + if (pgd_none(*pgd)) {
32878 + set_pgd(pgd, *pgd_ref);
32879 + arch_flush_lazy_mmu_mode();
32880 + } else {
32881 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32882 + }
32883 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32884 +#else
32885 + pgd = pgd_offset(current->active_mm, address);
32886 +#endif
32887 +
32888 if (pgd_none(*pgd)) {
32889 set_pgd(pgd, *pgd_ref);
32890 arch_flush_lazy_mmu_mode();
32891 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32892 static int is_errata100(struct pt_regs *regs, unsigned long address)
32893 {
32894 #ifdef CONFIG_X86_64
32895 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32896 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32897 return 1;
32898 #endif
32899 return 0;
32900 @@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32901 }
32902
32903 static const char nx_warning[] = KERN_CRIT
32904 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32905 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32906 static const char smep_warning[] = KERN_CRIT
32907 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32908 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32909
32910 static void
32911 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32912 @@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32913 if (!oops_may_print())
32914 return;
32915
32916 - if (error_code & PF_INSTR) {
32917 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32918 unsigned int level;
32919 pgd_t *pgd;
32920 pte_t *pte;
32921 @@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32922 pte = lookup_address_in_pgd(pgd, address, &level);
32923
32924 if (pte && pte_present(*pte) && !pte_exec(*pte))
32925 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32926 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32927 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32928 (pgd_flags(*pgd) & _PAGE_USER) &&
32929 (read_cr4() & X86_CR4_SMEP))
32930 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32931 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32932 }
32933
32934 +#ifdef CONFIG_PAX_KERNEXEC
32935 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32936 + if (current->signal->curr_ip)
32937 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32938 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32939 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32940 + else
32941 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32942 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32943 + }
32944 +#endif
32945 +
32946 printk(KERN_ALERT "BUG: unable to handle kernel ");
32947 if (address < PAGE_SIZE)
32948 printk(KERN_CONT "NULL pointer dereference");
32949 @@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32950 return;
32951 }
32952 #endif
32953 +
32954 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32955 + if (pax_is_fetch_fault(regs, error_code, address)) {
32956 +
32957 +#ifdef CONFIG_PAX_EMUTRAMP
32958 + switch (pax_handle_fetch_fault(regs)) {
32959 + case 2:
32960 + return;
32961 + }
32962 +#endif
32963 +
32964 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32965 + do_group_exit(SIGKILL);
32966 + }
32967 +#endif
32968 +
32969 /* Kernel addresses are always protection faults: */
32970 if (address >= TASK_SIZE)
32971 error_code |= PF_PROT;
32972 @@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32973 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32974 printk(KERN_ERR
32975 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32976 - tsk->comm, tsk->pid, address);
32977 + tsk->comm, task_pid_nr(tsk), address);
32978 code = BUS_MCEERR_AR;
32979 }
32980 #endif
32981 @@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32982 return 1;
32983 }
32984
32985 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32986 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32987 +{
32988 + pte_t *pte;
32989 + pmd_t *pmd;
32990 + spinlock_t *ptl;
32991 + unsigned char pte_mask;
32992 +
32993 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32994 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32995 + return 0;
32996 +
32997 + /* PaX: it's our fault, let's handle it if we can */
32998 +
32999 + /* PaX: take a look at read faults before acquiring any locks */
33000 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
33001 + /* instruction fetch attempt from a protected page in user mode */
33002 + up_read(&mm->mmap_sem);
33003 +
33004 +#ifdef CONFIG_PAX_EMUTRAMP
33005 + switch (pax_handle_fetch_fault(regs)) {
33006 + case 2:
33007 + return 1;
33008 + }
33009 +#endif
33010 +
33011 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
33012 + do_group_exit(SIGKILL);
33013 + }
33014 +
33015 + pmd = pax_get_pmd(mm, address);
33016 + if (unlikely(!pmd))
33017 + return 0;
33018 +
33019 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
33020 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
33021 + pte_unmap_unlock(pte, ptl);
33022 + return 0;
33023 + }
33024 +
33025 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
33026 + /* write attempt to a protected page in user mode */
33027 + pte_unmap_unlock(pte, ptl);
33028 + return 0;
33029 + }
33030 +
33031 +#ifdef CONFIG_SMP
33032 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
33033 +#else
33034 + if (likely(address > get_limit(regs->cs)))
33035 +#endif
33036 + {
33037 + set_pte(pte, pte_mkread(*pte));
33038 + __flush_tlb_one(address);
33039 + pte_unmap_unlock(pte, ptl);
33040 + up_read(&mm->mmap_sem);
33041 + return 1;
33042 + }
33043 +
33044 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
33045 +
33046 + /*
33047 + * PaX: fill DTLB with user rights and retry
33048 + */
33049 + __asm__ __volatile__ (
33050 + "orb %2,(%1)\n"
33051 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
33052 +/*
33053 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
33054 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
33055 + * page fault when examined during a TLB load attempt. this is true not only
33056 + * for PTEs holding a non-present entry but also present entries that will
33057 + * raise a page fault (such as those set up by PaX, or the copy-on-write
33058 + * mechanism). in effect it means that we do *not* need to flush the TLBs
33059 + * for our target pages since their PTEs are simply not in the TLBs at all.
33060 +
33061 + * the best thing in omitting it is that we gain around 15-20% speed in the
33062 + * fast path of the page fault handler and can get rid of tracing since we
33063 + * can no longer flush unintended entries.
33064 + */
33065 + "invlpg (%0)\n"
33066 +#endif
33067 + __copyuser_seg"testb $0,(%0)\n"
33068 + "xorb %3,(%1)\n"
33069 + :
33070 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
33071 + : "memory", "cc");
33072 + pte_unmap_unlock(pte, ptl);
33073 + up_read(&mm->mmap_sem);
33074 + return 1;
33075 +}
33076 +#endif
33077 +
33078 /*
33079 * Handle a spurious fault caused by a stale TLB entry.
33080 *
33081 @@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
33082 static inline int
33083 access_error(unsigned long error_code, struct vm_area_struct *vma)
33084 {
33085 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
33086 + return 1;
33087 +
33088 if (error_code & PF_WRITE) {
33089 /* write, present and write, not present: */
33090 if (unlikely(!(vma->vm_flags & VM_WRITE)))
33091 @@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
33092 if (error_code & PF_USER)
33093 return false;
33094
33095 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
33096 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
33097 return false;
33098
33099 return true;
33100 @@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
33101 tsk = current;
33102 mm = tsk->mm;
33103
33104 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33105 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
33106 + if (!search_exception_tables(regs->ip)) {
33107 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
33108 + bad_area_nosemaphore(regs, error_code, address);
33109 + return;
33110 + }
33111 + if (address < pax_user_shadow_base) {
33112 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
33113 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
33114 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
33115 + } else
33116 + address -= pax_user_shadow_base;
33117 + }
33118 +#endif
33119 +
33120 /*
33121 * Detect and handle instructions that would cause a page fault for
33122 * both a tracked kernel page and a userspace page.
33123 @@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
33124 * User-mode registers count as a user access even for any
33125 * potential system fault or CPU buglet:
33126 */
33127 - if (user_mode_vm(regs)) {
33128 + if (user_mode(regs)) {
33129 local_irq_enable();
33130 error_code |= PF_USER;
33131 flags |= FAULT_FLAG_USER;
33132 @@ -1177,6 +1401,11 @@ retry:
33133 might_sleep();
33134 }
33135
33136 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
33137 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
33138 + return;
33139 +#endif
33140 +
33141 vma = find_vma(mm, address);
33142 if (unlikely(!vma)) {
33143 bad_area(regs, error_code, address);
33144 @@ -1188,18 +1417,24 @@ retry:
33145 bad_area(regs, error_code, address);
33146 return;
33147 }
33148 - if (error_code & PF_USER) {
33149 - /*
33150 - * Accessing the stack below %sp is always a bug.
33151 - * The large cushion allows instructions like enter
33152 - * and pusha to work. ("enter $65535, $31" pushes
33153 - * 32 pointers and then decrements %sp by 65535.)
33154 - */
33155 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
33156 - bad_area(regs, error_code, address);
33157 - return;
33158 - }
33159 + /*
33160 + * Accessing the stack below %sp is always a bug.
33161 + * The large cushion allows instructions like enter
33162 + * and pusha to work. ("enter $65535, $31" pushes
33163 + * 32 pointers and then decrements %sp by 65535.)
33164 + */
33165 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
33166 + bad_area(regs, error_code, address);
33167 + return;
33168 }
33169 +
33170 +#ifdef CONFIG_PAX_SEGMEXEC
33171 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
33172 + bad_area(regs, error_code, address);
33173 + return;
33174 + }
33175 +#endif
33176 +
33177 if (unlikely(expand_stack(vma, address))) {
33178 bad_area(regs, error_code, address);
33179 return;
33180 @@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
33181 }
33182 NOKPROBE_SYMBOL(trace_do_page_fault);
33183 #endif /* CONFIG_TRACING */
33184 +
33185 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33186 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
33187 +{
33188 + struct mm_struct *mm = current->mm;
33189 + unsigned long ip = regs->ip;
33190 +
33191 + if (v8086_mode(regs))
33192 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
33193 +
33194 +#ifdef CONFIG_PAX_PAGEEXEC
33195 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
33196 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
33197 + return true;
33198 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
33199 + return true;
33200 + return false;
33201 + }
33202 +#endif
33203 +
33204 +#ifdef CONFIG_PAX_SEGMEXEC
33205 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
33206 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
33207 + return true;
33208 + return false;
33209 + }
33210 +#endif
33211 +
33212 + return false;
33213 +}
33214 +#endif
33215 +
33216 +#ifdef CONFIG_PAX_EMUTRAMP
33217 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
33218 +{
33219 + int err;
33220 +
33221 + do { /* PaX: libffi trampoline emulation */
33222 + unsigned char mov, jmp;
33223 + unsigned int addr1, addr2;
33224 +
33225 +#ifdef CONFIG_X86_64
33226 + if ((regs->ip + 9) >> 32)
33227 + break;
33228 +#endif
33229 +
33230 + err = get_user(mov, (unsigned char __user *)regs->ip);
33231 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33232 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33233 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33234 +
33235 + if (err)
33236 + break;
33237 +
33238 + if (mov == 0xB8 && jmp == 0xE9) {
33239 + regs->ax = addr1;
33240 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33241 + return 2;
33242 + }
33243 + } while (0);
33244 +
33245 + do { /* PaX: gcc trampoline emulation #1 */
33246 + unsigned char mov1, mov2;
33247 + unsigned short jmp;
33248 + unsigned int addr1, addr2;
33249 +
33250 +#ifdef CONFIG_X86_64
33251 + if ((regs->ip + 11) >> 32)
33252 + break;
33253 +#endif
33254 +
33255 + err = get_user(mov1, (unsigned char __user *)regs->ip);
33256 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33257 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
33258 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33259 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
33260 +
33261 + if (err)
33262 + break;
33263 +
33264 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
33265 + regs->cx = addr1;
33266 + regs->ax = addr2;
33267 + regs->ip = addr2;
33268 + return 2;
33269 + }
33270 + } while (0);
33271 +
33272 + do { /* PaX: gcc trampoline emulation #2 */
33273 + unsigned char mov, jmp;
33274 + unsigned int addr1, addr2;
33275 +
33276 +#ifdef CONFIG_X86_64
33277 + if ((regs->ip + 9) >> 32)
33278 + break;
33279 +#endif
33280 +
33281 + err = get_user(mov, (unsigned char __user *)regs->ip);
33282 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33283 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33284 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33285 +
33286 + if (err)
33287 + break;
33288 +
33289 + if (mov == 0xB9 && jmp == 0xE9) {
33290 + regs->cx = addr1;
33291 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33292 + return 2;
33293 + }
33294 + } while (0);
33295 +
33296 + return 1; /* PaX in action */
33297 +}
33298 +
33299 +#ifdef CONFIG_X86_64
33300 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
33301 +{
33302 + int err;
33303 +
33304 + do { /* PaX: libffi trampoline emulation */
33305 + unsigned short mov1, mov2, jmp1;
33306 + unsigned char stcclc, jmp2;
33307 + unsigned long addr1, addr2;
33308 +
33309 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33310 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33311 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33312 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33313 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33314 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33315 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33316 +
33317 + if (err)
33318 + break;
33319 +
33320 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33321 + regs->r11 = addr1;
33322 + regs->r10 = addr2;
33323 + if (stcclc == 0xF8)
33324 + regs->flags &= ~X86_EFLAGS_CF;
33325 + else
33326 + regs->flags |= X86_EFLAGS_CF;
33327 + regs->ip = addr1;
33328 + return 2;
33329 + }
33330 + } while (0);
33331 +
33332 + do { /* PaX: gcc trampoline emulation #1 */
33333 + unsigned short mov1, mov2, jmp1;
33334 + unsigned char jmp2;
33335 + unsigned int addr1;
33336 + unsigned long addr2;
33337 +
33338 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33339 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33340 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33341 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33342 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33343 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33344 +
33345 + if (err)
33346 + break;
33347 +
33348 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33349 + regs->r11 = addr1;
33350 + regs->r10 = addr2;
33351 + regs->ip = addr1;
33352 + return 2;
33353 + }
33354 + } while (0);
33355 +
33356 + do { /* PaX: gcc trampoline emulation #2 */
33357 + unsigned short mov1, mov2, jmp1;
33358 + unsigned char jmp2;
33359 + unsigned long addr1, addr2;
33360 +
33361 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33362 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33363 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33364 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33365 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33366 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33367 +
33368 + if (err)
33369 + break;
33370 +
33371 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33372 + regs->r11 = addr1;
33373 + regs->r10 = addr2;
33374 + regs->ip = addr1;
33375 + return 2;
33376 + }
33377 + } while (0);
33378 +
33379 + return 1; /* PaX in action */
33380 +}
33381 +#endif
33382 +
33383 +/*
33384 + * PaX: decide what to do with offenders (regs->ip = fault address)
33385 + *
33386 + * returns 1 when task should be killed
33387 + * 2 when gcc trampoline was detected
33388 + */
33389 +static int pax_handle_fetch_fault(struct pt_regs *regs)
33390 +{
33391 + if (v8086_mode(regs))
33392 + return 1;
33393 +
33394 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33395 + return 1;
33396 +
33397 +#ifdef CONFIG_X86_32
33398 + return pax_handle_fetch_fault_32(regs);
33399 +#else
33400 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33401 + return pax_handle_fetch_fault_32(regs);
33402 + else
33403 + return pax_handle_fetch_fault_64(regs);
33404 +#endif
33405 +}
33406 +#endif
33407 +
33408 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33409 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33410 +{
33411 + long i;
33412 +
33413 + printk(KERN_ERR "PAX: bytes at PC: ");
33414 + for (i = 0; i < 20; i++) {
33415 + unsigned char c;
33416 + if (get_user(c, (unsigned char __force_user *)pc+i))
33417 + printk(KERN_CONT "?? ");
33418 + else
33419 + printk(KERN_CONT "%02x ", c);
33420 + }
33421 + printk("\n");
33422 +
33423 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33424 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
33425 + unsigned long c;
33426 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
33427 +#ifdef CONFIG_X86_32
33428 + printk(KERN_CONT "???????? ");
33429 +#else
33430 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33431 + printk(KERN_CONT "???????? ???????? ");
33432 + else
33433 + printk(KERN_CONT "???????????????? ");
33434 +#endif
33435 + } else {
33436 +#ifdef CONFIG_X86_64
33437 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33438 + printk(KERN_CONT "%08x ", (unsigned int)c);
33439 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33440 + } else
33441 +#endif
33442 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33443 + }
33444 + }
33445 + printk("\n");
33446 +}
33447 +#endif
33448 +
33449 +/**
33450 + * probe_kernel_write(): safely attempt to write to a location
33451 + * @dst: address to write to
33452 + * @src: pointer to the data that shall be written
33453 + * @size: size of the data chunk
33454 + *
33455 + * Safely write to address @dst from the buffer at @src. If a kernel fault
33456 + * happens, handle that and return -EFAULT.
33457 + */
33458 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33459 +{
33460 + long ret;
33461 + mm_segment_t old_fs = get_fs();
33462 +
33463 + set_fs(KERNEL_DS);
33464 + pagefault_disable();
33465 + pax_open_kernel();
33466 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33467 + pax_close_kernel();
33468 + pagefault_enable();
33469 + set_fs(old_fs);
33470 +
33471 + return ret ? -EFAULT : 0;
33472 +}
33473 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33474 index 207d9aef..69030980 100644
33475 --- a/arch/x86/mm/gup.c
33476 +++ b/arch/x86/mm/gup.c
33477 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33478 addr = start;
33479 len = (unsigned long) nr_pages << PAGE_SHIFT;
33480 end = start + len;
33481 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33482 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33483 (void __user *)start, len)))
33484 return 0;
33485
33486 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33487 goto slow_irqon;
33488 #endif
33489
33490 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33491 + (void __user *)start, len)))
33492 + return 0;
33493 +
33494 /*
33495 * XXX: batch / limit 'nr', to avoid large irq off latency
33496 * needs some instrumenting to determine the common sizes used by
33497 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33498 index 4500142..53a363c 100644
33499 --- a/arch/x86/mm/highmem_32.c
33500 +++ b/arch/x86/mm/highmem_32.c
33501 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33502 idx = type + KM_TYPE_NR*smp_processor_id();
33503 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33504 BUG_ON(!pte_none(*(kmap_pte-idx)));
33505 +
33506 + pax_open_kernel();
33507 set_pte(kmap_pte-idx, mk_pte(page, prot));
33508 + pax_close_kernel();
33509 +
33510 arch_flush_lazy_mmu_mode();
33511
33512 return (void *)vaddr;
33513 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33514 index 8b977eb..4732c33 100644
33515 --- a/arch/x86/mm/hugetlbpage.c
33516 +++ b/arch/x86/mm/hugetlbpage.c
33517 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33518 #ifdef CONFIG_HUGETLB_PAGE
33519 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33520 unsigned long addr, unsigned long len,
33521 - unsigned long pgoff, unsigned long flags)
33522 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33523 {
33524 struct hstate *h = hstate_file(file);
33525 struct vm_unmapped_area_info info;
33526 -
33527 +
33528 info.flags = 0;
33529 info.length = len;
33530 info.low_limit = current->mm->mmap_legacy_base;
33531 info.high_limit = TASK_SIZE;
33532 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33533 info.align_offset = 0;
33534 + info.threadstack_offset = offset;
33535 return vm_unmapped_area(&info);
33536 }
33537
33538 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33539 unsigned long addr0, unsigned long len,
33540 - unsigned long pgoff, unsigned long flags)
33541 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33542 {
33543 struct hstate *h = hstate_file(file);
33544 struct vm_unmapped_area_info info;
33545 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33546 info.high_limit = current->mm->mmap_base;
33547 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33548 info.align_offset = 0;
33549 + info.threadstack_offset = offset;
33550 addr = vm_unmapped_area(&info);
33551
33552 /*
33553 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33554 VM_BUG_ON(addr != -ENOMEM);
33555 info.flags = 0;
33556 info.low_limit = TASK_UNMAPPED_BASE;
33557 +
33558 +#ifdef CONFIG_PAX_RANDMMAP
33559 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33560 + info.low_limit += current->mm->delta_mmap;
33561 +#endif
33562 +
33563 info.high_limit = TASK_SIZE;
33564 addr = vm_unmapped_area(&info);
33565 }
33566 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33567 struct hstate *h = hstate_file(file);
33568 struct mm_struct *mm = current->mm;
33569 struct vm_area_struct *vma;
33570 + unsigned long pax_task_size = TASK_SIZE;
33571 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33572
33573 if (len & ~huge_page_mask(h))
33574 return -EINVAL;
33575 - if (len > TASK_SIZE)
33576 +
33577 +#ifdef CONFIG_PAX_SEGMEXEC
33578 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33579 + pax_task_size = SEGMEXEC_TASK_SIZE;
33580 +#endif
33581 +
33582 + pax_task_size -= PAGE_SIZE;
33583 +
33584 + if (len > pax_task_size)
33585 return -ENOMEM;
33586
33587 if (flags & MAP_FIXED) {
33588 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33589 return addr;
33590 }
33591
33592 +#ifdef CONFIG_PAX_RANDMMAP
33593 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33594 +#endif
33595 +
33596 if (addr) {
33597 addr = ALIGN(addr, huge_page_size(h));
33598 vma = find_vma(mm, addr);
33599 - if (TASK_SIZE - len >= addr &&
33600 - (!vma || addr + len <= vma->vm_start))
33601 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33602 return addr;
33603 }
33604 if (mm->get_unmapped_area == arch_get_unmapped_area)
33605 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33606 - pgoff, flags);
33607 + pgoff, flags, offset);
33608 else
33609 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33610 - pgoff, flags);
33611 + pgoff, flags, offset);
33612 }
33613 #endif /* CONFIG_HUGETLB_PAGE */
33614
33615 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33616 index 66dba36..f8082ec 100644
33617 --- a/arch/x86/mm/init.c
33618 +++ b/arch/x86/mm/init.c
33619 @@ -4,6 +4,7 @@
33620 #include <linux/swap.h>
33621 #include <linux/memblock.h>
33622 #include <linux/bootmem.h> /* for max_low_pfn */
33623 +#include <linux/tboot.h>
33624
33625 #include <asm/cacheflush.h>
33626 #include <asm/e820.h>
33627 @@ -17,6 +18,8 @@
33628 #include <asm/proto.h>
33629 #include <asm/dma.h> /* for MAX_DMA_PFN */
33630 #include <asm/microcode.h>
33631 +#include <asm/desc.h>
33632 +#include <asm/bios_ebda.h>
33633
33634 /*
33635 * We need to define the tracepoints somewhere, and tlb.c
33636 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33637 early_ioremap_page_table_range_init();
33638 #endif
33639
33640 +#ifdef CONFIG_PAX_PER_CPU_PGD
33641 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33642 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33643 + KERNEL_PGD_PTRS);
33644 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33645 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33646 + KERNEL_PGD_PTRS);
33647 + load_cr3(get_cpu_pgd(0, kernel));
33648 +#else
33649 load_cr3(swapper_pg_dir);
33650 +#endif
33651 +
33652 __flush_tlb_all();
33653
33654 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33655 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33656 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33657 * mmio resources as well as potential bios/acpi data regions.
33658 */
33659 +
33660 +#ifdef CONFIG_GRKERNSEC_KMEM
33661 +static unsigned int ebda_start __read_only;
33662 +static unsigned int ebda_end __read_only;
33663 +#endif
33664 +
33665 int devmem_is_allowed(unsigned long pagenr)
33666 {
33667 - if (pagenr < 256)
33668 +#ifdef CONFIG_GRKERNSEC_KMEM
33669 + /* allow BDA */
33670 + if (!pagenr)
33671 return 1;
33672 + /* allow EBDA */
33673 + if (pagenr >= ebda_start && pagenr < ebda_end)
33674 + return 1;
33675 + /* if tboot is in use, allow access to its hardcoded serial log range */
33676 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33677 + return 1;
33678 +#else
33679 + if (!pagenr)
33680 + return 1;
33681 +#ifdef CONFIG_VM86
33682 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33683 + return 1;
33684 +#endif
33685 +#endif
33686 +
33687 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33688 + return 1;
33689 +#ifdef CONFIG_GRKERNSEC_KMEM
33690 + /* throw out everything else below 1MB */
33691 + if (pagenr <= 256)
33692 + return 0;
33693 +#endif
33694 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33695 return 0;
33696 if (!page_is_ram(pagenr))
33697 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33698 #endif
33699 }
33700
33701 +#ifdef CONFIG_GRKERNSEC_KMEM
33702 +static inline void gr_init_ebda(void)
33703 +{
33704 + unsigned int ebda_addr;
33705 + unsigned int ebda_size = 0;
33706 +
33707 + ebda_addr = get_bios_ebda();
33708 + if (ebda_addr) {
33709 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33710 + ebda_size <<= 10;
33711 + }
33712 + if (ebda_addr && ebda_size) {
33713 + ebda_start = ebda_addr >> PAGE_SHIFT;
33714 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33715 + } else {
33716 + ebda_start = 0x9f000 >> PAGE_SHIFT;
33717 + ebda_end = 0xa0000 >> PAGE_SHIFT;
33718 + }
33719 +}
33720 +#else
33721 +static inline void gr_init_ebda(void) { }
33722 +#endif
33723 +
33724 void free_initmem(void)
33725 {
33726 +#ifdef CONFIG_PAX_KERNEXEC
33727 +#ifdef CONFIG_X86_32
33728 + /* PaX: limit KERNEL_CS to actual size */
33729 + unsigned long addr, limit;
33730 + struct desc_struct d;
33731 + int cpu;
33732 +#else
33733 + pgd_t *pgd;
33734 + pud_t *pud;
33735 + pmd_t *pmd;
33736 + unsigned long addr, end;
33737 +#endif
33738 +#endif
33739 +
33740 + gr_init_ebda();
33741 +
33742 +#ifdef CONFIG_PAX_KERNEXEC
33743 +#ifdef CONFIG_X86_32
33744 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33745 + limit = (limit - 1UL) >> PAGE_SHIFT;
33746 +
33747 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33748 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33749 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33750 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33751 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33752 + }
33753 +
33754 + /* PaX: make KERNEL_CS read-only */
33755 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33756 + if (!paravirt_enabled())
33757 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33758 +/*
33759 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33760 + pgd = pgd_offset_k(addr);
33761 + pud = pud_offset(pgd, addr);
33762 + pmd = pmd_offset(pud, addr);
33763 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33764 + }
33765 +*/
33766 +#ifdef CONFIG_X86_PAE
33767 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33768 +/*
33769 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33770 + pgd = pgd_offset_k(addr);
33771 + pud = pud_offset(pgd, addr);
33772 + pmd = pmd_offset(pud, addr);
33773 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33774 + }
33775 +*/
33776 +#endif
33777 +
33778 +#ifdef CONFIG_MODULES
33779 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33780 +#endif
33781 +
33782 +#else
33783 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33784 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33785 + pgd = pgd_offset_k(addr);
33786 + pud = pud_offset(pgd, addr);
33787 + pmd = pmd_offset(pud, addr);
33788 + if (!pmd_present(*pmd))
33789 + continue;
33790 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33791 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33792 + else
33793 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33794 + }
33795 +
33796 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33797 + end = addr + KERNEL_IMAGE_SIZE;
33798 + for (; addr < end; addr += PMD_SIZE) {
33799 + pgd = pgd_offset_k(addr);
33800 + pud = pud_offset(pgd, addr);
33801 + pmd = pmd_offset(pud, addr);
33802 + if (!pmd_present(*pmd))
33803 + continue;
33804 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33805 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33806 + }
33807 +#endif
33808 +
33809 + flush_tlb_all();
33810 +#endif
33811 +
33812 free_init_pages("unused kernel",
33813 (unsigned long)(&__init_begin),
33814 (unsigned long)(&__init_end));
33815 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33816 index 7d05565..bfc5338 100644
33817 --- a/arch/x86/mm/init_32.c
33818 +++ b/arch/x86/mm/init_32.c
33819 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33820 bool __read_mostly __vmalloc_start_set = false;
33821
33822 /*
33823 - * Creates a middle page table and puts a pointer to it in the
33824 - * given global directory entry. This only returns the gd entry
33825 - * in non-PAE compilation mode, since the middle layer is folded.
33826 - */
33827 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33828 -{
33829 - pud_t *pud;
33830 - pmd_t *pmd_table;
33831 -
33832 -#ifdef CONFIG_X86_PAE
33833 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33834 - pmd_table = (pmd_t *)alloc_low_page();
33835 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33836 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33837 - pud = pud_offset(pgd, 0);
33838 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33839 -
33840 - return pmd_table;
33841 - }
33842 -#endif
33843 - pud = pud_offset(pgd, 0);
33844 - pmd_table = pmd_offset(pud, 0);
33845 -
33846 - return pmd_table;
33847 -}
33848 -
33849 -/*
33850 * Create a page table and place a pointer to it in a middle page
33851 * directory entry:
33852 */
33853 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33854 pte_t *page_table = (pte_t *)alloc_low_page();
33855
33856 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33857 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33858 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33859 +#else
33860 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33861 +#endif
33862 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33863 }
33864
33865 return pte_offset_kernel(pmd, 0);
33866 }
33867
33868 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33869 +{
33870 + pud_t *pud;
33871 + pmd_t *pmd_table;
33872 +
33873 + pud = pud_offset(pgd, 0);
33874 + pmd_table = pmd_offset(pud, 0);
33875 +
33876 + return pmd_table;
33877 +}
33878 +
33879 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33880 {
33881 int pgd_idx = pgd_index(vaddr);
33882 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33883 int pgd_idx, pmd_idx;
33884 unsigned long vaddr;
33885 pgd_t *pgd;
33886 + pud_t *pud;
33887 pmd_t *pmd;
33888 pte_t *pte = NULL;
33889 unsigned long count = page_table_range_init_count(start, end);
33890 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33891 pgd = pgd_base + pgd_idx;
33892
33893 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33894 - pmd = one_md_table_init(pgd);
33895 - pmd = pmd + pmd_index(vaddr);
33896 + pud = pud_offset(pgd, vaddr);
33897 + pmd = pmd_offset(pud, vaddr);
33898 +
33899 +#ifdef CONFIG_X86_PAE
33900 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33901 +#endif
33902 +
33903 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33904 pmd++, pmd_idx++) {
33905 pte = page_table_kmap_check(one_page_table_init(pmd),
33906 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33907 }
33908 }
33909
33910 -static inline int is_kernel_text(unsigned long addr)
33911 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33912 {
33913 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33914 - return 1;
33915 - return 0;
33916 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33917 + end <= ktla_ktva((unsigned long)_stext)) &&
33918 + (start >= ktla_ktva((unsigned long)_einittext) ||
33919 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33920 +
33921 +#ifdef CONFIG_ACPI_SLEEP
33922 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33923 +#endif
33924 +
33925 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33926 + return 0;
33927 + return 1;
33928 }
33929
33930 /*
33931 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33932 unsigned long last_map_addr = end;
33933 unsigned long start_pfn, end_pfn;
33934 pgd_t *pgd_base = swapper_pg_dir;
33935 - int pgd_idx, pmd_idx, pte_ofs;
33936 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33937 unsigned long pfn;
33938 pgd_t *pgd;
33939 + pud_t *pud;
33940 pmd_t *pmd;
33941 pte_t *pte;
33942 unsigned pages_2m, pages_4k;
33943 @@ -291,8 +295,13 @@ repeat:
33944 pfn = start_pfn;
33945 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33946 pgd = pgd_base + pgd_idx;
33947 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33948 - pmd = one_md_table_init(pgd);
33949 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33950 + pud = pud_offset(pgd, 0);
33951 + pmd = pmd_offset(pud, 0);
33952 +
33953 +#ifdef CONFIG_X86_PAE
33954 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33955 +#endif
33956
33957 if (pfn >= end_pfn)
33958 continue;
33959 @@ -304,14 +313,13 @@ repeat:
33960 #endif
33961 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33962 pmd++, pmd_idx++) {
33963 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33964 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33965
33966 /*
33967 * Map with big pages if possible, otherwise
33968 * create normal page tables:
33969 */
33970 if (use_pse) {
33971 - unsigned int addr2;
33972 pgprot_t prot = PAGE_KERNEL_LARGE;
33973 /*
33974 * first pass will use the same initial
33975 @@ -322,11 +330,7 @@ repeat:
33976 _PAGE_PSE);
33977
33978 pfn &= PMD_MASK >> PAGE_SHIFT;
33979 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33980 - PAGE_OFFSET + PAGE_SIZE-1;
33981 -
33982 - if (is_kernel_text(addr) ||
33983 - is_kernel_text(addr2))
33984 + if (is_kernel_text(address, address + PMD_SIZE))
33985 prot = PAGE_KERNEL_LARGE_EXEC;
33986
33987 pages_2m++;
33988 @@ -343,7 +347,7 @@ repeat:
33989 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33990 pte += pte_ofs;
33991 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33992 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33993 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33994 pgprot_t prot = PAGE_KERNEL;
33995 /*
33996 * first pass will use the same initial
33997 @@ -351,7 +355,7 @@ repeat:
33998 */
33999 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
34000
34001 - if (is_kernel_text(addr))
34002 + if (is_kernel_text(address, address + PAGE_SIZE))
34003 prot = PAGE_KERNEL_EXEC;
34004
34005 pages_4k++;
34006 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
34007
34008 pud = pud_offset(pgd, va);
34009 pmd = pmd_offset(pud, va);
34010 - if (!pmd_present(*pmd))
34011 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
34012 break;
34013
34014 /* should not be large page here */
34015 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
34016
34017 static void __init pagetable_init(void)
34018 {
34019 - pgd_t *pgd_base = swapper_pg_dir;
34020 -
34021 - permanent_kmaps_init(pgd_base);
34022 + permanent_kmaps_init(swapper_pg_dir);
34023 }
34024
34025 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
34026 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
34027 EXPORT_SYMBOL_GPL(__supported_pte_mask);
34028
34029 /* user-defined highmem size */
34030 @@ -787,10 +789,10 @@ void __init mem_init(void)
34031 ((unsigned long)&__init_end -
34032 (unsigned long)&__init_begin) >> 10,
34033
34034 - (unsigned long)&_etext, (unsigned long)&_edata,
34035 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
34036 + (unsigned long)&_sdata, (unsigned long)&_edata,
34037 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
34038
34039 - (unsigned long)&_text, (unsigned long)&_etext,
34040 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
34041 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
34042
34043 /*
34044 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
34045 if (!kernel_set_to_readonly)
34046 return;
34047
34048 + start = ktla_ktva(start);
34049 pr_debug("Set kernel text: %lx - %lx for read write\n",
34050 start, start+size);
34051
34052 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
34053 if (!kernel_set_to_readonly)
34054 return;
34055
34056 + start = ktla_ktva(start);
34057 pr_debug("Set kernel text: %lx - %lx for read only\n",
34058 start, start+size);
34059
34060 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
34061 unsigned long start = PFN_ALIGN(_text);
34062 unsigned long size = PFN_ALIGN(_etext) - start;
34063
34064 + start = ktla_ktva(start);
34065 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
34066 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
34067 size >> 10);
34068 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
34069 index 5621c47..5e17b7390 100644
34070 --- a/arch/x86/mm/init_64.c
34071 +++ b/arch/x86/mm/init_64.c
34072 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
34073 * around without checking the pgd every time.
34074 */
34075
34076 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
34077 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
34078 EXPORT_SYMBOL_GPL(__supported_pte_mask);
34079
34080 int force_personality32;
34081 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34082
34083 for (address = start; address <= end; address += PGDIR_SIZE) {
34084 const pgd_t *pgd_ref = pgd_offset_k(address);
34085 +
34086 +#ifdef CONFIG_PAX_PER_CPU_PGD
34087 + unsigned long cpu;
34088 +#else
34089 struct page *page;
34090 +#endif
34091
34092 if (pgd_none(*pgd_ref))
34093 continue;
34094
34095 spin_lock(&pgd_lock);
34096 +
34097 +#ifdef CONFIG_PAX_PER_CPU_PGD
34098 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34099 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
34100 +
34101 + if (pgd_none(*pgd))
34102 + set_pgd(pgd, *pgd_ref);
34103 + else
34104 + BUG_ON(pgd_page_vaddr(*pgd)
34105 + != pgd_page_vaddr(*pgd_ref));
34106 + pgd = pgd_offset_cpu(cpu, kernel, address);
34107 +#else
34108 list_for_each_entry(page, &pgd_list, lru) {
34109 pgd_t *pgd;
34110 spinlock_t *pgt_lock;
34111 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34112 /* the pgt_lock only for Xen */
34113 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
34114 spin_lock(pgt_lock);
34115 +#endif
34116
34117 if (pgd_none(*pgd))
34118 set_pgd(pgd, *pgd_ref);
34119 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34120 BUG_ON(pgd_page_vaddr(*pgd)
34121 != pgd_page_vaddr(*pgd_ref));
34122
34123 +#ifndef CONFIG_PAX_PER_CPU_PGD
34124 spin_unlock(pgt_lock);
34125 +#endif
34126 +
34127 }
34128 spin_unlock(&pgd_lock);
34129 }
34130 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
34131 {
34132 if (pgd_none(*pgd)) {
34133 pud_t *pud = (pud_t *)spp_getpage();
34134 - pgd_populate(&init_mm, pgd, pud);
34135 + pgd_populate_kernel(&init_mm, pgd, pud);
34136 if (pud != pud_offset(pgd, 0))
34137 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
34138 pud, pud_offset(pgd, 0));
34139 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
34140 {
34141 if (pud_none(*pud)) {
34142 pmd_t *pmd = (pmd_t *) spp_getpage();
34143 - pud_populate(&init_mm, pud, pmd);
34144 + pud_populate_kernel(&init_mm, pud, pmd);
34145 if (pmd != pmd_offset(pud, 0))
34146 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
34147 pmd, pmd_offset(pud, 0));
34148 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
34149 pmd = fill_pmd(pud, vaddr);
34150 pte = fill_pte(pmd, vaddr);
34151
34152 + pax_open_kernel();
34153 set_pte(pte, new_pte);
34154 + pax_close_kernel();
34155
34156 /*
34157 * It's enough to flush this one mapping.
34158 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
34159 pgd = pgd_offset_k((unsigned long)__va(phys));
34160 if (pgd_none(*pgd)) {
34161 pud = (pud_t *) spp_getpage();
34162 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
34163 - _PAGE_USER));
34164 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
34165 }
34166 pud = pud_offset(pgd, (unsigned long)__va(phys));
34167 if (pud_none(*pud)) {
34168 pmd = (pmd_t *) spp_getpage();
34169 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
34170 - _PAGE_USER));
34171 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
34172 }
34173 pmd = pmd_offset(pud, phys);
34174 BUG_ON(!pmd_none(*pmd));
34175 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
34176 prot);
34177
34178 spin_lock(&init_mm.page_table_lock);
34179 - pud_populate(&init_mm, pud, pmd);
34180 + pud_populate_kernel(&init_mm, pud, pmd);
34181 spin_unlock(&init_mm.page_table_lock);
34182 }
34183 __flush_tlb_all();
34184 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
34185 page_size_mask);
34186
34187 spin_lock(&init_mm.page_table_lock);
34188 - pgd_populate(&init_mm, pgd, pud);
34189 + pgd_populate_kernel(&init_mm, pgd, pud);
34190 spin_unlock(&init_mm.page_table_lock);
34191 pgd_changed = true;
34192 }
34193 @@ -1196,8 +1217,8 @@ static struct vm_operations_struct gate_vma_ops = {
34194 static struct vm_area_struct gate_vma = {
34195 .vm_start = VSYSCALL_ADDR,
34196 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
34197 - .vm_page_prot = PAGE_READONLY_EXEC,
34198 - .vm_flags = VM_READ | VM_EXEC,
34199 + .vm_page_prot = PAGE_READONLY,
34200 + .vm_flags = VM_READ,
34201 .vm_ops = &gate_vma_ops,
34202 };
34203
34204 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
34205 index 7b179b49..6bd17777 100644
34206 --- a/arch/x86/mm/iomap_32.c
34207 +++ b/arch/x86/mm/iomap_32.c
34208 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
34209 type = kmap_atomic_idx_push();
34210 idx = type + KM_TYPE_NR * smp_processor_id();
34211 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
34212 +
34213 + pax_open_kernel();
34214 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
34215 + pax_close_kernel();
34216 +
34217 arch_flush_lazy_mmu_mode();
34218
34219 return (void *)vaddr;
34220 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
34221 index baff1da..2816ef4 100644
34222 --- a/arch/x86/mm/ioremap.c
34223 +++ b/arch/x86/mm/ioremap.c
34224 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
34225 unsigned long i;
34226
34227 for (i = 0; i < nr_pages; ++i)
34228 - if (pfn_valid(start_pfn + i) &&
34229 - !PageReserved(pfn_to_page(start_pfn + i)))
34230 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
34231 + !PageReserved(pfn_to_page(start_pfn + i))))
34232 return 1;
34233
34234 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
34235 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
34236 *
34237 * Caller must ensure there is only one unmapping for the same pointer.
34238 */
34239 -void iounmap(volatile void __iomem *addr)
34240 +void iounmap(const volatile void __iomem *addr)
34241 {
34242 struct vm_struct *p, *o;
34243
34244 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34245
34246 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
34247 if (page_is_ram(start >> PAGE_SHIFT))
34248 +#ifdef CONFIG_HIGHMEM
34249 + if ((start >> PAGE_SHIFT) < max_low_pfn)
34250 +#endif
34251 return __va(phys);
34252
34253 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
34254 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34255 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
34256 {
34257 if (page_is_ram(phys >> PAGE_SHIFT))
34258 +#ifdef CONFIG_HIGHMEM
34259 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
34260 +#endif
34261 return;
34262
34263 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
34264 return;
34265 }
34266
34267 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
34268 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
34269
34270 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
34271 {
34272 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
34273 early_ioremap_setup();
34274
34275 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
34276 - memset(bm_pte, 0, sizeof(bm_pte));
34277 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
34278 + pmd_populate_user(&init_mm, pmd, bm_pte);
34279
34280 /*
34281 * The boot-ioremap range spans multiple pmds, for which
34282 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
34283 index dd89a13..d77bdcc 100644
34284 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
34285 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
34286 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
34287 * memory (e.g. tracked pages)? For now, we need this to avoid
34288 * invoking kmemcheck for PnP BIOS calls.
34289 */
34290 - if (regs->flags & X86_VM_MASK)
34291 + if (v8086_mode(regs))
34292 return false;
34293 - if (regs->cs != __KERNEL_CS)
34294 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
34295 return false;
34296
34297 pte = kmemcheck_pte_lookup(address);
34298 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
34299 index 919b912..9267313 100644
34300 --- a/arch/x86/mm/mmap.c
34301 +++ b/arch/x86/mm/mmap.c
34302 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34303 * Leave an at least ~128 MB hole with possible stack randomization.
34304 */
34305 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34306 -#define MAX_GAP (TASK_SIZE/6*5)
34307 +#define MAX_GAP (pax_task_size/6*5)
34308
34309 static int mmap_is_legacy(void)
34310 {
34311 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34312 return rnd << PAGE_SHIFT;
34313 }
34314
34315 -static unsigned long mmap_base(void)
34316 +static unsigned long mmap_base(struct mm_struct *mm)
34317 {
34318 unsigned long gap = rlimit(RLIMIT_STACK);
34319 + unsigned long pax_task_size = TASK_SIZE;
34320 +
34321 +#ifdef CONFIG_PAX_SEGMEXEC
34322 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34323 + pax_task_size = SEGMEXEC_TASK_SIZE;
34324 +#endif
34325
34326 if (gap < MIN_GAP)
34327 gap = MIN_GAP;
34328 else if (gap > MAX_GAP)
34329 gap = MAX_GAP;
34330
34331 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34332 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34333 }
34334
34335 /*
34336 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34337 * does, but not when emulating X86_32
34338 */
34339 -static unsigned long mmap_legacy_base(void)
34340 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
34341 {
34342 - if (mmap_is_ia32())
34343 + if (mmap_is_ia32()) {
34344 +
34345 +#ifdef CONFIG_PAX_SEGMEXEC
34346 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34347 + return SEGMEXEC_TASK_UNMAPPED_BASE;
34348 + else
34349 +#endif
34350 +
34351 return TASK_UNMAPPED_BASE;
34352 - else
34353 + } else
34354 return TASK_UNMAPPED_BASE + mmap_rnd();
34355 }
34356
34357 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34358 */
34359 void arch_pick_mmap_layout(struct mm_struct *mm)
34360 {
34361 - mm->mmap_legacy_base = mmap_legacy_base();
34362 - mm->mmap_base = mmap_base();
34363 + mm->mmap_legacy_base = mmap_legacy_base(mm);
34364 + mm->mmap_base = mmap_base(mm);
34365 +
34366 +#ifdef CONFIG_PAX_RANDMMAP
34367 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
34368 + mm->mmap_legacy_base += mm->delta_mmap;
34369 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34370 + }
34371 +#endif
34372
34373 if (mmap_is_legacy()) {
34374 mm->mmap_base = mm->mmap_legacy_base;
34375 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34376 index 0057a7a..95c7edd 100644
34377 --- a/arch/x86/mm/mmio-mod.c
34378 +++ b/arch/x86/mm/mmio-mod.c
34379 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34380 break;
34381 default:
34382 {
34383 - unsigned char *ip = (unsigned char *)instptr;
34384 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34385 my_trace->opcode = MMIO_UNKNOWN_OP;
34386 my_trace->width = 0;
34387 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34388 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34389 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34390 void __iomem *addr)
34391 {
34392 - static atomic_t next_id;
34393 + static atomic_unchecked_t next_id;
34394 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34395 /* These are page-unaligned. */
34396 struct mmiotrace_map map = {
34397 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34398 .private = trace
34399 },
34400 .phys = offset,
34401 - .id = atomic_inc_return(&next_id)
34402 + .id = atomic_inc_return_unchecked(&next_id)
34403 };
34404 map.map_id = trace->id;
34405
34406 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34407 ioremap_trace_core(offset, size, addr);
34408 }
34409
34410 -static void iounmap_trace_core(volatile void __iomem *addr)
34411 +static void iounmap_trace_core(const volatile void __iomem *addr)
34412 {
34413 struct mmiotrace_map map = {
34414 .phys = 0,
34415 @@ -328,7 +328,7 @@ not_enabled:
34416 }
34417 }
34418
34419 -void mmiotrace_iounmap(volatile void __iomem *addr)
34420 +void mmiotrace_iounmap(const volatile void __iomem *addr)
34421 {
34422 might_sleep();
34423 if (is_enabled()) /* recheck and proper locking in *_core() */
34424 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34425 index a32b706..efb308b 100644
34426 --- a/arch/x86/mm/numa.c
34427 +++ b/arch/x86/mm/numa.c
34428 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34429 return true;
34430 }
34431
34432 -static int __init numa_register_memblks(struct numa_meminfo *mi)
34433 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34434 {
34435 unsigned long uninitialized_var(pfn_align);
34436 int i, nid;
34437 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34438 index ae242a7..1c7998f 100644
34439 --- a/arch/x86/mm/pageattr.c
34440 +++ b/arch/x86/mm/pageattr.c
34441 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34442 */
34443 #ifdef CONFIG_PCI_BIOS
34444 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34445 - pgprot_val(forbidden) |= _PAGE_NX;
34446 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34447 #endif
34448
34449 /*
34450 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34451 * Does not cover __inittext since that is gone later on. On
34452 * 64bit we do not enforce !NX on the low mapping
34453 */
34454 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
34455 - pgprot_val(forbidden) |= _PAGE_NX;
34456 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34457 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34458
34459 +#ifdef CONFIG_DEBUG_RODATA
34460 /*
34461 * The .rodata section needs to be read-only. Using the pfn
34462 * catches all aliases.
34463 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34464 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34465 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34466 pgprot_val(forbidden) |= _PAGE_RW;
34467 +#endif
34468
34469 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34470 /*
34471 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34472 }
34473 #endif
34474
34475 +#ifdef CONFIG_PAX_KERNEXEC
34476 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34477 + pgprot_val(forbidden) |= _PAGE_RW;
34478 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34479 + }
34480 +#endif
34481 +
34482 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34483
34484 return prot;
34485 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34486 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34487 {
34488 /* change init_mm */
34489 + pax_open_kernel();
34490 set_pte_atomic(kpte, pte);
34491 +
34492 #ifdef CONFIG_X86_32
34493 if (!SHARED_KERNEL_PMD) {
34494 +
34495 +#ifdef CONFIG_PAX_PER_CPU_PGD
34496 + unsigned long cpu;
34497 +#else
34498 struct page *page;
34499 +#endif
34500
34501 +#ifdef CONFIG_PAX_PER_CPU_PGD
34502 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34503 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34504 +#else
34505 list_for_each_entry(page, &pgd_list, lru) {
34506 - pgd_t *pgd;
34507 + pgd_t *pgd = (pgd_t *)page_address(page);
34508 +#endif
34509 +
34510 pud_t *pud;
34511 pmd_t *pmd;
34512
34513 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
34514 + pgd += pgd_index(address);
34515 pud = pud_offset(pgd, address);
34516 pmd = pmd_offset(pud, address);
34517 set_pte_atomic((pte_t *)pmd, pte);
34518 }
34519 }
34520 #endif
34521 + pax_close_kernel();
34522 }
34523
34524 static int
34525 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34526 index 6574388..87e9bef 100644
34527 --- a/arch/x86/mm/pat.c
34528 +++ b/arch/x86/mm/pat.c
34529 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34530
34531 if (!entry) {
34532 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34533 - current->comm, current->pid, start, end - 1);
34534 + current->comm, task_pid_nr(current), start, end - 1);
34535 return -EINVAL;
34536 }
34537
34538 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34539
34540 while (cursor < to) {
34541 if (!devmem_is_allowed(pfn)) {
34542 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34543 - current->comm, from, to - 1);
34544 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34545 + current->comm, from, to - 1, cursor);
34546 return 0;
34547 }
34548 cursor += PAGE_SIZE;
34549 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34550 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34551 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34552 "for [mem %#010Lx-%#010Lx]\n",
34553 - current->comm, current->pid,
34554 + current->comm, task_pid_nr(current),
34555 cattr_name(flags),
34556 base, (unsigned long long)(base + size-1));
34557 return -EINVAL;
34558 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34559 flags = lookup_memtype(paddr);
34560 if (want_flags != flags) {
34561 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34562 - current->comm, current->pid,
34563 + current->comm, task_pid_nr(current),
34564 cattr_name(want_flags),
34565 (unsigned long long)paddr,
34566 (unsigned long long)(paddr + size - 1),
34567 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34568 free_memtype(paddr, paddr + size);
34569 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34570 " for [mem %#010Lx-%#010Lx], got %s\n",
34571 - current->comm, current->pid,
34572 + current->comm, task_pid_nr(current),
34573 cattr_name(want_flags),
34574 (unsigned long long)paddr,
34575 (unsigned long long)(paddr + size - 1),
34576 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34577 index 415f6c4..d319983 100644
34578 --- a/arch/x86/mm/pat_rbtree.c
34579 +++ b/arch/x86/mm/pat_rbtree.c
34580 @@ -160,7 +160,7 @@ success:
34581
34582 failure:
34583 printk(KERN_INFO "%s:%d conflicting memory types "
34584 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34585 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34586 end, cattr_name(found_type), cattr_name(match->type));
34587 return -EBUSY;
34588 }
34589 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34590 index 9f0614d..92ae64a 100644
34591 --- a/arch/x86/mm/pf_in.c
34592 +++ b/arch/x86/mm/pf_in.c
34593 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34594 int i;
34595 enum reason_type rv = OTHERS;
34596
34597 - p = (unsigned char *)ins_addr;
34598 + p = (unsigned char *)ktla_ktva(ins_addr);
34599 p += skip_prefix(p, &prf);
34600 p += get_opcode(p, &opcode);
34601
34602 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34603 struct prefix_bits prf;
34604 int i;
34605
34606 - p = (unsigned char *)ins_addr;
34607 + p = (unsigned char *)ktla_ktva(ins_addr);
34608 p += skip_prefix(p, &prf);
34609 p += get_opcode(p, &opcode);
34610
34611 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34612 struct prefix_bits prf;
34613 int i;
34614
34615 - p = (unsigned char *)ins_addr;
34616 + p = (unsigned char *)ktla_ktva(ins_addr);
34617 p += skip_prefix(p, &prf);
34618 p += get_opcode(p, &opcode);
34619
34620 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34621 struct prefix_bits prf;
34622 int i;
34623
34624 - p = (unsigned char *)ins_addr;
34625 + p = (unsigned char *)ktla_ktva(ins_addr);
34626 p += skip_prefix(p, &prf);
34627 p += get_opcode(p, &opcode);
34628 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34629 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34630 struct prefix_bits prf;
34631 int i;
34632
34633 - p = (unsigned char *)ins_addr;
34634 + p = (unsigned char *)ktla_ktva(ins_addr);
34635 p += skip_prefix(p, &prf);
34636 p += get_opcode(p, &opcode);
34637 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34638 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34639 index 6fb6927..4fc13c0 100644
34640 --- a/arch/x86/mm/pgtable.c
34641 +++ b/arch/x86/mm/pgtable.c
34642 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34643 list_del(&page->lru);
34644 }
34645
34646 -#define UNSHARED_PTRS_PER_PGD \
34647 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34648 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34649 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34650
34651 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34652 +{
34653 + unsigned int count = USER_PGD_PTRS;
34654
34655 + if (!pax_user_shadow_base)
34656 + return;
34657 +
34658 + while (count--)
34659 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34660 +}
34661 +#endif
34662 +
34663 +#ifdef CONFIG_PAX_PER_CPU_PGD
34664 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34665 +{
34666 + unsigned int count = USER_PGD_PTRS;
34667 +
34668 + while (count--) {
34669 + pgd_t pgd;
34670 +
34671 +#ifdef CONFIG_X86_64
34672 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34673 +#else
34674 + pgd = *src++;
34675 +#endif
34676 +
34677 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34678 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34679 +#endif
34680 +
34681 + *dst++ = pgd;
34682 + }
34683 +
34684 +}
34685 +#endif
34686 +
34687 +#ifdef CONFIG_X86_64
34688 +#define pxd_t pud_t
34689 +#define pyd_t pgd_t
34690 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34691 +#define pgtable_pxd_page_ctor(page) true
34692 +#define pgtable_pxd_page_dtor(page)
34693 +#define pxd_free(mm, pud) pud_free((mm), (pud))
34694 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34695 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
34696 +#define PYD_SIZE PGDIR_SIZE
34697 +#else
34698 +#define pxd_t pmd_t
34699 +#define pyd_t pud_t
34700 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34701 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34702 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34703 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
34704 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34705 +#define pyd_offset(mm, address) pud_offset((mm), (address))
34706 +#define PYD_SIZE PUD_SIZE
34707 +#endif
34708 +
34709 +#ifdef CONFIG_PAX_PER_CPU_PGD
34710 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34711 +static inline void pgd_dtor(pgd_t *pgd) {}
34712 +#else
34713 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34714 {
34715 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34716 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34717 pgd_list_del(pgd);
34718 spin_unlock(&pgd_lock);
34719 }
34720 +#endif
34721
34722 /*
34723 * List of all pgd's needed for non-PAE so it can invalidate entries
34724 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34725 * -- nyc
34726 */
34727
34728 -#ifdef CONFIG_X86_PAE
34729 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34730 /*
34731 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34732 * updating the top-level pagetable entries to guarantee the
34733 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34734 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34735 * and initialize the kernel pmds here.
34736 */
34737 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34738 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34739
34740 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34741 {
34742 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34743 */
34744 flush_tlb_mm(mm);
34745 }
34746 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34747 +#define PREALLOCATED_PXDS USER_PGD_PTRS
34748 #else /* !CONFIG_X86_PAE */
34749
34750 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34751 -#define PREALLOCATED_PMDS 0
34752 +#define PREALLOCATED_PXDS 0
34753
34754 #endif /* CONFIG_X86_PAE */
34755
34756 -static void free_pmds(pmd_t *pmds[])
34757 +static void free_pxds(pxd_t *pxds[])
34758 {
34759 int i;
34760
34761 - for(i = 0; i < PREALLOCATED_PMDS; i++)
34762 - if (pmds[i]) {
34763 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34764 - free_page((unsigned long)pmds[i]);
34765 + for(i = 0; i < PREALLOCATED_PXDS; i++)
34766 + if (pxds[i]) {
34767 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34768 + free_page((unsigned long)pxds[i]);
34769 }
34770 }
34771
34772 -static int preallocate_pmds(pmd_t *pmds[])
34773 +static int preallocate_pxds(pxd_t *pxds[])
34774 {
34775 int i;
34776 bool failed = false;
34777
34778 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34779 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34780 - if (!pmd)
34781 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34782 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34783 + if (!pxd)
34784 failed = true;
34785 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34786 - free_page((unsigned long)pmd);
34787 - pmd = NULL;
34788 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34789 + free_page((unsigned long)pxd);
34790 + pxd = NULL;
34791 failed = true;
34792 }
34793 - pmds[i] = pmd;
34794 + pxds[i] = pxd;
34795 }
34796
34797 if (failed) {
34798 - free_pmds(pmds);
34799 + free_pxds(pxds);
34800 return -ENOMEM;
34801 }
34802
34803 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34804 * preallocate which never got a corresponding vma will need to be
34805 * freed manually.
34806 */
34807 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34808 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34809 {
34810 int i;
34811
34812 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34813 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34814 pgd_t pgd = pgdp[i];
34815
34816 if (pgd_val(pgd) != 0) {
34817 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34818 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34819
34820 - pgdp[i] = native_make_pgd(0);
34821 + set_pgd(pgdp + i, native_make_pgd(0));
34822
34823 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34824 - pmd_free(mm, pmd);
34825 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34826 + pxd_free(mm, pxd);
34827 }
34828 }
34829 }
34830
34831 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34832 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34833 {
34834 - pud_t *pud;
34835 + pyd_t *pyd;
34836 int i;
34837
34838 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34839 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34840 return;
34841
34842 - pud = pud_offset(pgd, 0);
34843 -
34844 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34845 - pmd_t *pmd = pmds[i];
34846 +#ifdef CONFIG_X86_64
34847 + pyd = pyd_offset(mm, 0L);
34848 +#else
34849 + pyd = pyd_offset(pgd, 0L);
34850 +#endif
34851
34852 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34853 + pxd_t *pxd = pxds[i];
34854 if (i >= KERNEL_PGD_BOUNDARY)
34855 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34856 - sizeof(pmd_t) * PTRS_PER_PMD);
34857 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34858 + sizeof(pxd_t) * PTRS_PER_PMD);
34859
34860 - pud_populate(mm, pud, pmd);
34861 + pyd_populate(mm, pyd, pxd);
34862 }
34863 }
34864
34865 pgd_t *pgd_alloc(struct mm_struct *mm)
34866 {
34867 pgd_t *pgd;
34868 - pmd_t *pmds[PREALLOCATED_PMDS];
34869 + pxd_t *pxds[PREALLOCATED_PXDS];
34870
34871 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34872
34873 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34874
34875 mm->pgd = pgd;
34876
34877 - if (preallocate_pmds(pmds) != 0)
34878 + if (preallocate_pxds(pxds) != 0)
34879 goto out_free_pgd;
34880
34881 if (paravirt_pgd_alloc(mm) != 0)
34882 - goto out_free_pmds;
34883 + goto out_free_pxds;
34884
34885 /*
34886 * Make sure that pre-populating the pmds is atomic with
34887 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34888 spin_lock(&pgd_lock);
34889
34890 pgd_ctor(mm, pgd);
34891 - pgd_prepopulate_pmd(mm, pgd, pmds);
34892 + pgd_prepopulate_pxd(mm, pgd, pxds);
34893
34894 spin_unlock(&pgd_lock);
34895
34896 return pgd;
34897
34898 -out_free_pmds:
34899 - free_pmds(pmds);
34900 +out_free_pxds:
34901 + free_pxds(pxds);
34902 out_free_pgd:
34903 free_page((unsigned long)pgd);
34904 out:
34905 @@ -313,7 +380,7 @@ out:
34906
34907 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34908 {
34909 - pgd_mop_up_pmds(mm, pgd);
34910 + pgd_mop_up_pxds(mm, pgd);
34911 pgd_dtor(pgd);
34912 paravirt_pgd_free(mm, pgd);
34913 free_page((unsigned long)pgd);
34914 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34915 index 4dd8cf6..f9d143e 100644
34916 --- a/arch/x86/mm/pgtable_32.c
34917 +++ b/arch/x86/mm/pgtable_32.c
34918 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34919 return;
34920 }
34921 pte = pte_offset_kernel(pmd, vaddr);
34922 +
34923 + pax_open_kernel();
34924 if (pte_val(pteval))
34925 set_pte_at(&init_mm, vaddr, pte, pteval);
34926 else
34927 pte_clear(&init_mm, vaddr, pte);
34928 + pax_close_kernel();
34929
34930 /*
34931 * It's enough to flush this one mapping.
34932 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34933 index e666cbb..61788c45 100644
34934 --- a/arch/x86/mm/physaddr.c
34935 +++ b/arch/x86/mm/physaddr.c
34936 @@ -10,7 +10,7 @@
34937 #ifdef CONFIG_X86_64
34938
34939 #ifdef CONFIG_DEBUG_VIRTUAL
34940 -unsigned long __phys_addr(unsigned long x)
34941 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34942 {
34943 unsigned long y = x - __START_KERNEL_map;
34944
34945 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34946 #else
34947
34948 #ifdef CONFIG_DEBUG_VIRTUAL
34949 -unsigned long __phys_addr(unsigned long x)
34950 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34951 {
34952 unsigned long phys_addr = x - PAGE_OFFSET;
34953 /* VMALLOC_* aren't constants */
34954 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34955 index 90555bf..f5f1828 100644
34956 --- a/arch/x86/mm/setup_nx.c
34957 +++ b/arch/x86/mm/setup_nx.c
34958 @@ -5,8 +5,10 @@
34959 #include <asm/pgtable.h>
34960 #include <asm/proto.h>
34961
34962 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34963 static int disable_nx;
34964
34965 +#ifndef CONFIG_PAX_PAGEEXEC
34966 /*
34967 * noexec = on|off
34968 *
34969 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34970 return 0;
34971 }
34972 early_param("noexec", noexec_setup);
34973 +#endif
34974 +
34975 +#endif
34976
34977 void x86_configure_nx(void)
34978 {
34979 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34980 if (cpu_has_nx && !disable_nx)
34981 __supported_pte_mask |= _PAGE_NX;
34982 else
34983 +#endif
34984 __supported_pte_mask &= ~_PAGE_NX;
34985 }
34986
34987 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34988 index ee61c36..e6fedeb 100644
34989 --- a/arch/x86/mm/tlb.c
34990 +++ b/arch/x86/mm/tlb.c
34991 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34992 BUG();
34993 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34994 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34995 +
34996 +#ifndef CONFIG_PAX_PER_CPU_PGD
34997 load_cr3(swapper_pg_dir);
34998 +#endif
34999 +
35000 /*
35001 * This gets called in the idle path where RCU
35002 * functions differently. Tracing normally
35003 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
35004 new file mode 100644
35005 index 0000000..dace51c
35006 --- /dev/null
35007 +++ b/arch/x86/mm/uderef_64.c
35008 @@ -0,0 +1,37 @@
35009 +#include <linux/mm.h>
35010 +#include <asm/pgtable.h>
35011 +#include <asm/uaccess.h>
35012 +
35013 +#ifdef CONFIG_PAX_MEMORY_UDEREF
35014 +/* PaX: due to the special call convention these functions must
35015 + * - remain leaf functions under all configurations,
35016 + * - never be called directly, only dereferenced from the wrappers.
35017 + */
35018 +void __pax_open_userland(void)
35019 +{
35020 + unsigned int cpu;
35021 +
35022 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
35023 + return;
35024 +
35025 + cpu = raw_get_cpu();
35026 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
35027 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
35028 + raw_put_cpu_no_resched();
35029 +}
35030 +EXPORT_SYMBOL(__pax_open_userland);
35031 +
35032 +void __pax_close_userland(void)
35033 +{
35034 + unsigned int cpu;
35035 +
35036 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
35037 + return;
35038 +
35039 + cpu = raw_get_cpu();
35040 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
35041 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
35042 + raw_put_cpu_no_resched();
35043 +}
35044 +EXPORT_SYMBOL(__pax_close_userland);
35045 +#endif
35046 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
35047 index 6440221..f84b5c7 100644
35048 --- a/arch/x86/net/bpf_jit.S
35049 +++ b/arch/x86/net/bpf_jit.S
35050 @@ -9,6 +9,7 @@
35051 */
35052 #include <linux/linkage.h>
35053 #include <asm/dwarf2.h>
35054 +#include <asm/alternative-asm.h>
35055
35056 /*
35057 * Calling convention :
35058 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
35059 jle bpf_slow_path_word
35060 mov (SKBDATA,%rsi),%eax
35061 bswap %eax /* ntohl() */
35062 + pax_force_retaddr
35063 ret
35064
35065 sk_load_half:
35066 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
35067 jle bpf_slow_path_half
35068 movzwl (SKBDATA,%rsi),%eax
35069 rol $8,%ax # ntohs()
35070 + pax_force_retaddr
35071 ret
35072
35073 sk_load_byte:
35074 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
35075 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
35076 jle bpf_slow_path_byte
35077 movzbl (SKBDATA,%rsi),%eax
35078 + pax_force_retaddr
35079 ret
35080
35081 /* rsi contains offset and can be scratched */
35082 @@ -90,6 +94,7 @@ bpf_slow_path_word:
35083 js bpf_error
35084 mov - MAX_BPF_STACK + 32(%rbp),%eax
35085 bswap %eax
35086 + pax_force_retaddr
35087 ret
35088
35089 bpf_slow_path_half:
35090 @@ -98,12 +103,14 @@ bpf_slow_path_half:
35091 mov - MAX_BPF_STACK + 32(%rbp),%ax
35092 rol $8,%ax
35093 movzwl %ax,%eax
35094 + pax_force_retaddr
35095 ret
35096
35097 bpf_slow_path_byte:
35098 bpf_slow_path_common(1)
35099 js bpf_error
35100 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
35101 + pax_force_retaddr
35102 ret
35103
35104 #define sk_negative_common(SIZE) \
35105 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
35106 sk_negative_common(4)
35107 mov (%rax), %eax
35108 bswap %eax
35109 + pax_force_retaddr
35110 ret
35111
35112 bpf_slow_path_half_neg:
35113 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
35114 mov (%rax),%ax
35115 rol $8,%ax
35116 movzwl %ax,%eax
35117 + pax_force_retaddr
35118 ret
35119
35120 bpf_slow_path_byte_neg:
35121 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
35122 .globl sk_load_byte_negative_offset
35123 sk_negative_common(1)
35124 movzbl (%rax), %eax
35125 + pax_force_retaddr
35126 ret
35127
35128 bpf_error:
35129 @@ -156,4 +166,5 @@ bpf_error:
35130 mov - MAX_BPF_STACK + 16(%rbp),%r14
35131 mov - MAX_BPF_STACK + 24(%rbp),%r15
35132 leaveq
35133 + pax_force_retaddr
35134 ret
35135 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
35136 index 5c8cb80..728d0cd 100644
35137 --- a/arch/x86/net/bpf_jit_comp.c
35138 +++ b/arch/x86/net/bpf_jit_comp.c
35139 @@ -15,7 +15,11 @@
35140 #include <linux/if_vlan.h>
35141 #include <linux/random.h>
35142
35143 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
35144 +int bpf_jit_enable __read_only;
35145 +#else
35146 int bpf_jit_enable __read_mostly;
35147 +#endif
35148
35149 /*
35150 * assembly code in arch/x86/net/bpf_jit.S
35151 @@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
35152 #define CHOOSE_LOAD_FUNC(K, func) \
35153 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
35154
35155 -struct bpf_binary_header {
35156 - unsigned int pages;
35157 - /* Note : for security reasons, bpf code will follow a randomly
35158 - * sized amount of int3 instructions
35159 - */
35160 - u8 image[];
35161 -};
35162 -
35163 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
35164 +/* Note : for security reasons, bpf code will follow a randomly
35165 + * sized amount of int3 instructions
35166 + */
35167 +static u8 *bpf_alloc_binary(unsigned int proglen,
35168 u8 **image_ptr)
35169 {
35170 unsigned int sz, hole;
35171 - struct bpf_binary_header *header;
35172 + u8 *header;
35173
35174 /* Most of BPF filters are really small,
35175 * but if some of them fill a page, allow at least
35176 * 128 extra bytes to insert a random section of int3
35177 */
35178 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
35179 - header = module_alloc(sz);
35180 + sz = round_up(proglen + 128, PAGE_SIZE);
35181 + header = module_alloc_exec(sz);
35182 if (!header)
35183 return NULL;
35184
35185 + pax_open_kernel();
35186 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
35187 + pax_close_kernel();
35188
35189 - header->pages = sz / PAGE_SIZE;
35190 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
35191 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
35192
35193 /* insert a random number of int3 instructions before BPF code */
35194 - *image_ptr = &header->image[prandom_u32() % hole];
35195 + *image_ptr = &header[prandom_u32() % hole];
35196 return header;
35197 }
35198
35199 @@ -853,7 +853,9 @@ common_load: ctx->seen_ld_abs = true;
35200 pr_err("bpf_jit_compile fatal error\n");
35201 return -EFAULT;
35202 }
35203 + pax_open_kernel();
35204 memcpy(image + proglen, temp, ilen);
35205 + pax_close_kernel();
35206 }
35207 proglen += ilen;
35208 addrs[i] = proglen;
35209 @@ -868,7 +870,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
35210
35211 void bpf_int_jit_compile(struct bpf_prog *prog)
35212 {
35213 - struct bpf_binary_header *header = NULL;
35214 + u8 *header = NULL;
35215 int proglen, oldproglen = 0;
35216 struct jit_context ctx = {};
35217 u8 *image = NULL;
35218 @@ -900,7 +902,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35219 if (proglen <= 0) {
35220 image = NULL;
35221 if (header)
35222 - module_free(NULL, header);
35223 + module_free_exec(NULL, image);
35224 goto out;
35225 }
35226 if (image) {
35227 @@ -922,7 +924,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35228
35229 if (image) {
35230 bpf_flush_icache(header, image + proglen);
35231 - set_memory_ro((unsigned long)header, header->pages);
35232 prog->bpf_func = (void *)image;
35233 prog->jited = 1;
35234 }
35235 @@ -930,23 +931,16 @@ out:
35236 kfree(addrs);
35237 }
35238
35239 -static void bpf_jit_free_deferred(struct work_struct *work)
35240 -{
35241 - struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
35242 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35243 - struct bpf_binary_header *header = (void *)addr;
35244 -
35245 - set_memory_rw(addr, header->pages);
35246 - module_free(NULL, header);
35247 - kfree(fp);
35248 -}
35249 -
35250 void bpf_jit_free(struct bpf_prog *fp)
35251 {
35252 - if (fp->jited) {
35253 - INIT_WORK(&fp->work, bpf_jit_free_deferred);
35254 - schedule_work(&fp->work);
35255 - } else {
35256 - kfree(fp);
35257 - }
35258 + unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35259 +
35260 + if (!fp->jited)
35261 + goto free_filter;
35262 +
35263 + set_memory_rw(addr, 1);
35264 + module_free_exec(NULL, (void *)addr);
35265 +
35266 +free_filter:
35267 + bpf_prog_unlock_free(fp);
35268 }
35269 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
35270 index 5d04be5..2beeaa2 100644
35271 --- a/arch/x86/oprofile/backtrace.c
35272 +++ b/arch/x86/oprofile/backtrace.c
35273 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
35274 struct stack_frame_ia32 *fp;
35275 unsigned long bytes;
35276
35277 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35278 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35279 if (bytes != 0)
35280 return NULL;
35281
35282 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
35283 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
35284
35285 oprofile_add_trace(bufhead[0].return_address);
35286
35287 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
35288 struct stack_frame bufhead[2];
35289 unsigned long bytes;
35290
35291 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35292 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35293 if (bytes != 0)
35294 return NULL;
35295
35296 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
35297 {
35298 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
35299
35300 - if (!user_mode_vm(regs)) {
35301 + if (!user_mode(regs)) {
35302 unsigned long stack = kernel_stack_pointer(regs);
35303 if (depth)
35304 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35305 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35306 index 379e8bd..6386e09 100644
35307 --- a/arch/x86/oprofile/nmi_int.c
35308 +++ b/arch/x86/oprofile/nmi_int.c
35309 @@ -23,6 +23,7 @@
35310 #include <asm/nmi.h>
35311 #include <asm/msr.h>
35312 #include <asm/apic.h>
35313 +#include <asm/pgtable.h>
35314
35315 #include "op_counter.h"
35316 #include "op_x86_model.h"
35317 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35318 if (ret)
35319 return ret;
35320
35321 - if (!model->num_virt_counters)
35322 - model->num_virt_counters = model->num_counters;
35323 + if (!model->num_virt_counters) {
35324 + pax_open_kernel();
35325 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
35326 + pax_close_kernel();
35327 + }
35328
35329 mux_init(ops);
35330
35331 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35332 index 50d86c0..7985318 100644
35333 --- a/arch/x86/oprofile/op_model_amd.c
35334 +++ b/arch/x86/oprofile/op_model_amd.c
35335 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35336 num_counters = AMD64_NUM_COUNTERS;
35337 }
35338
35339 - op_amd_spec.num_counters = num_counters;
35340 - op_amd_spec.num_controls = num_counters;
35341 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35342 + pax_open_kernel();
35343 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35344 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35345 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35346 + pax_close_kernel();
35347
35348 return 0;
35349 }
35350 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35351 index d90528e..0127e2b 100644
35352 --- a/arch/x86/oprofile/op_model_ppro.c
35353 +++ b/arch/x86/oprofile/op_model_ppro.c
35354 @@ -19,6 +19,7 @@
35355 #include <asm/msr.h>
35356 #include <asm/apic.h>
35357 #include <asm/nmi.h>
35358 +#include <asm/pgtable.h>
35359
35360 #include "op_x86_model.h"
35361 #include "op_counter.h"
35362 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35363
35364 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35365
35366 - op_arch_perfmon_spec.num_counters = num_counters;
35367 - op_arch_perfmon_spec.num_controls = num_counters;
35368 + pax_open_kernel();
35369 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35370 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35371 + pax_close_kernel();
35372 }
35373
35374 static int arch_perfmon_init(struct oprofile_operations *ignore)
35375 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35376 index 71e8a67..6a313bb 100644
35377 --- a/arch/x86/oprofile/op_x86_model.h
35378 +++ b/arch/x86/oprofile/op_x86_model.h
35379 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
35380 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35381 struct op_msrs const * const msrs);
35382 #endif
35383 -};
35384 +} __do_const;
35385
35386 struct op_counter_config;
35387
35388 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35389 index b9958c3..24229ab 100644
35390 --- a/arch/x86/pci/intel_mid_pci.c
35391 +++ b/arch/x86/pci/intel_mid_pci.c
35392 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35393 pci_mmcfg_late_init();
35394 pcibios_enable_irq = intel_mid_pci_irq_enable;
35395 pcibios_disable_irq = intel_mid_pci_irq_disable;
35396 - pci_root_ops = intel_mid_pci_ops;
35397 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35398 pci_soc_mode = 1;
35399 /* Continue with standard init */
35400 return 1;
35401 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35402 index eb500c2..eab9e70 100644
35403 --- a/arch/x86/pci/irq.c
35404 +++ b/arch/x86/pci/irq.c
35405 @@ -51,7 +51,7 @@ struct irq_router {
35406 struct irq_router_handler {
35407 u16 vendor;
35408 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35409 -};
35410 +} __do_const;
35411
35412 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35413 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35414 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35415 return 0;
35416 }
35417
35418 -static __initdata struct irq_router_handler pirq_routers[] = {
35419 +static __initconst const struct irq_router_handler pirq_routers[] = {
35420 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35421 { PCI_VENDOR_ID_AL, ali_router_probe },
35422 { PCI_VENDOR_ID_ITE, ite_router_probe },
35423 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35424 static void __init pirq_find_router(struct irq_router *r)
35425 {
35426 struct irq_routing_table *rt = pirq_table;
35427 - struct irq_router_handler *h;
35428 + const struct irq_router_handler *h;
35429
35430 #ifdef CONFIG_PCI_BIOS
35431 if (!rt->signature) {
35432 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35433 return 0;
35434 }
35435
35436 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35437 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35438 {
35439 .callback = fix_broken_hp_bios_irq9,
35440 .ident = "HP Pavilion N5400 Series Laptop",
35441 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35442 index c77b24a..c979855 100644
35443 --- a/arch/x86/pci/pcbios.c
35444 +++ b/arch/x86/pci/pcbios.c
35445 @@ -79,7 +79,7 @@ union bios32 {
35446 static struct {
35447 unsigned long address;
35448 unsigned short segment;
35449 -} bios32_indirect = { 0, __KERNEL_CS };
35450 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35451
35452 /*
35453 * Returns the entry point for the given service, NULL on error
35454 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35455 unsigned long length; /* %ecx */
35456 unsigned long entry; /* %edx */
35457 unsigned long flags;
35458 + struct desc_struct d, *gdt;
35459
35460 local_irq_save(flags);
35461 - __asm__("lcall *(%%edi); cld"
35462 +
35463 + gdt = get_cpu_gdt_table(smp_processor_id());
35464 +
35465 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35466 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35467 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35468 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35469 +
35470 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35471 : "=a" (return_code),
35472 "=b" (address),
35473 "=c" (length),
35474 "=d" (entry)
35475 : "0" (service),
35476 "1" (0),
35477 - "D" (&bios32_indirect));
35478 + "D" (&bios32_indirect),
35479 + "r"(__PCIBIOS_DS)
35480 + : "memory");
35481 +
35482 + pax_open_kernel();
35483 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35484 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35485 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35486 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35487 + pax_close_kernel();
35488 +
35489 local_irq_restore(flags);
35490
35491 switch (return_code) {
35492 - case 0:
35493 - return address + entry;
35494 - case 0x80: /* Not present */
35495 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35496 - return 0;
35497 - default: /* Shouldn't happen */
35498 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35499 - service, return_code);
35500 + case 0: {
35501 + int cpu;
35502 + unsigned char flags;
35503 +
35504 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35505 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35506 + printk(KERN_WARNING "bios32_service: not valid\n");
35507 return 0;
35508 + }
35509 + address = address + PAGE_OFFSET;
35510 + length += 16UL; /* some BIOSs underreport this... */
35511 + flags = 4;
35512 + if (length >= 64*1024*1024) {
35513 + length >>= PAGE_SHIFT;
35514 + flags |= 8;
35515 + }
35516 +
35517 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35518 + gdt = get_cpu_gdt_table(cpu);
35519 + pack_descriptor(&d, address, length, 0x9b, flags);
35520 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35521 + pack_descriptor(&d, address, length, 0x93, flags);
35522 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35523 + }
35524 + return entry;
35525 + }
35526 + case 0x80: /* Not present */
35527 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35528 + return 0;
35529 + default: /* Shouldn't happen */
35530 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35531 + service, return_code);
35532 + return 0;
35533 }
35534 }
35535
35536 static struct {
35537 unsigned long address;
35538 unsigned short segment;
35539 -} pci_indirect = { 0, __KERNEL_CS };
35540 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35541
35542 -static int pci_bios_present;
35543 +static int pci_bios_present __read_only;
35544
35545 static int check_pcibios(void)
35546 {
35547 @@ -131,11 +174,13 @@ static int check_pcibios(void)
35548 unsigned long flags, pcibios_entry;
35549
35550 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35551 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35552 + pci_indirect.address = pcibios_entry;
35553
35554 local_irq_save(flags);
35555 - __asm__(
35556 - "lcall *(%%edi); cld\n\t"
35557 + __asm__("movw %w6, %%ds\n\t"
35558 + "lcall *%%ss:(%%edi); cld\n\t"
35559 + "push %%ss\n\t"
35560 + "pop %%ds\n\t"
35561 "jc 1f\n\t"
35562 "xor %%ah, %%ah\n"
35563 "1:"
35564 @@ -144,7 +189,8 @@ static int check_pcibios(void)
35565 "=b" (ebx),
35566 "=c" (ecx)
35567 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35568 - "D" (&pci_indirect)
35569 + "D" (&pci_indirect),
35570 + "r" (__PCIBIOS_DS)
35571 : "memory");
35572 local_irq_restore(flags);
35573
35574 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35575
35576 switch (len) {
35577 case 1:
35578 - __asm__("lcall *(%%esi); cld\n\t"
35579 + __asm__("movw %w6, %%ds\n\t"
35580 + "lcall *%%ss:(%%esi); cld\n\t"
35581 + "push %%ss\n\t"
35582 + "pop %%ds\n\t"
35583 "jc 1f\n\t"
35584 "xor %%ah, %%ah\n"
35585 "1:"
35586 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35587 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35588 "b" (bx),
35589 "D" ((long)reg),
35590 - "S" (&pci_indirect));
35591 + "S" (&pci_indirect),
35592 + "r" (__PCIBIOS_DS));
35593 /*
35594 * Zero-extend the result beyond 8 bits, do not trust the
35595 * BIOS having done it:
35596 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35597 *value &= 0xff;
35598 break;
35599 case 2:
35600 - __asm__("lcall *(%%esi); cld\n\t"
35601 + __asm__("movw %w6, %%ds\n\t"
35602 + "lcall *%%ss:(%%esi); cld\n\t"
35603 + "push %%ss\n\t"
35604 + "pop %%ds\n\t"
35605 "jc 1f\n\t"
35606 "xor %%ah, %%ah\n"
35607 "1:"
35608 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35609 : "1" (PCIBIOS_READ_CONFIG_WORD),
35610 "b" (bx),
35611 "D" ((long)reg),
35612 - "S" (&pci_indirect));
35613 + "S" (&pci_indirect),
35614 + "r" (__PCIBIOS_DS));
35615 /*
35616 * Zero-extend the result beyond 16 bits, do not trust the
35617 * BIOS having done it:
35618 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35619 *value &= 0xffff;
35620 break;
35621 case 4:
35622 - __asm__("lcall *(%%esi); cld\n\t"
35623 + __asm__("movw %w6, %%ds\n\t"
35624 + "lcall *%%ss:(%%esi); cld\n\t"
35625 + "push %%ss\n\t"
35626 + "pop %%ds\n\t"
35627 "jc 1f\n\t"
35628 "xor %%ah, %%ah\n"
35629 "1:"
35630 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35631 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35632 "b" (bx),
35633 "D" ((long)reg),
35634 - "S" (&pci_indirect));
35635 + "S" (&pci_indirect),
35636 + "r" (__PCIBIOS_DS));
35637 break;
35638 }
35639
35640 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35641
35642 switch (len) {
35643 case 1:
35644 - __asm__("lcall *(%%esi); cld\n\t"
35645 + __asm__("movw %w6, %%ds\n\t"
35646 + "lcall *%%ss:(%%esi); cld\n\t"
35647 + "push %%ss\n\t"
35648 + "pop %%ds\n\t"
35649 "jc 1f\n\t"
35650 "xor %%ah, %%ah\n"
35651 "1:"
35652 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35653 "c" (value),
35654 "b" (bx),
35655 "D" ((long)reg),
35656 - "S" (&pci_indirect));
35657 + "S" (&pci_indirect),
35658 + "r" (__PCIBIOS_DS));
35659 break;
35660 case 2:
35661 - __asm__("lcall *(%%esi); cld\n\t"
35662 + __asm__("movw %w6, %%ds\n\t"
35663 + "lcall *%%ss:(%%esi); cld\n\t"
35664 + "push %%ss\n\t"
35665 + "pop %%ds\n\t"
35666 "jc 1f\n\t"
35667 "xor %%ah, %%ah\n"
35668 "1:"
35669 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35670 "c" (value),
35671 "b" (bx),
35672 "D" ((long)reg),
35673 - "S" (&pci_indirect));
35674 + "S" (&pci_indirect),
35675 + "r" (__PCIBIOS_DS));
35676 break;
35677 case 4:
35678 - __asm__("lcall *(%%esi); cld\n\t"
35679 + __asm__("movw %w6, %%ds\n\t"
35680 + "lcall *%%ss:(%%esi); cld\n\t"
35681 + "push %%ss\n\t"
35682 + "pop %%ds\n\t"
35683 "jc 1f\n\t"
35684 "xor %%ah, %%ah\n"
35685 "1:"
35686 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35687 "c" (value),
35688 "b" (bx),
35689 "D" ((long)reg),
35690 - "S" (&pci_indirect));
35691 + "S" (&pci_indirect),
35692 + "r" (__PCIBIOS_DS));
35693 break;
35694 }
35695
35696 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35697
35698 DBG("PCI: Fetching IRQ routing table... ");
35699 __asm__("push %%es\n\t"
35700 + "movw %w8, %%ds\n\t"
35701 "push %%ds\n\t"
35702 "pop %%es\n\t"
35703 - "lcall *(%%esi); cld\n\t"
35704 + "lcall *%%ss:(%%esi); cld\n\t"
35705 "pop %%es\n\t"
35706 + "push %%ss\n\t"
35707 + "pop %%ds\n"
35708 "jc 1f\n\t"
35709 "xor %%ah, %%ah\n"
35710 "1:"
35711 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35712 "1" (0),
35713 "D" ((long) &opt),
35714 "S" (&pci_indirect),
35715 - "m" (opt)
35716 + "m" (opt),
35717 + "r" (__PCIBIOS_DS)
35718 : "memory");
35719 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35720 if (ret & 0xff00)
35721 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35722 {
35723 int ret;
35724
35725 - __asm__("lcall *(%%esi); cld\n\t"
35726 + __asm__("movw %w5, %%ds\n\t"
35727 + "lcall *%%ss:(%%esi); cld\n\t"
35728 + "push %%ss\n\t"
35729 + "pop %%ds\n"
35730 "jc 1f\n\t"
35731 "xor %%ah, %%ah\n"
35732 "1:"
35733 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35734 : "0" (PCIBIOS_SET_PCI_HW_INT),
35735 "b" ((dev->bus->number << 8) | dev->devfn),
35736 "c" ((irq << 8) | (pin + 10)),
35737 - "S" (&pci_indirect));
35738 + "S" (&pci_indirect),
35739 + "r" (__PCIBIOS_DS));
35740 return !(ret & 0xff00);
35741 }
35742 EXPORT_SYMBOL(pcibios_set_irq_routing);
35743 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35744 index 9ee3491..872192f 100644
35745 --- a/arch/x86/platform/efi/efi_32.c
35746 +++ b/arch/x86/platform/efi/efi_32.c
35747 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35748 {
35749 struct desc_ptr gdt_descr;
35750
35751 +#ifdef CONFIG_PAX_KERNEXEC
35752 + struct desc_struct d;
35753 +#endif
35754 +
35755 local_irq_save(efi_rt_eflags);
35756
35757 load_cr3(initial_page_table);
35758 __flush_tlb_all();
35759
35760 +#ifdef CONFIG_PAX_KERNEXEC
35761 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35762 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35763 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35764 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35765 +#endif
35766 +
35767 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35768 gdt_descr.size = GDT_SIZE - 1;
35769 load_gdt(&gdt_descr);
35770 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35771 {
35772 struct desc_ptr gdt_descr;
35773
35774 +#ifdef CONFIG_PAX_KERNEXEC
35775 + struct desc_struct d;
35776 +
35777 + memset(&d, 0, sizeof d);
35778 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35779 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35780 +#endif
35781 +
35782 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35783 gdt_descr.size = GDT_SIZE - 1;
35784 load_gdt(&gdt_descr);
35785
35786 +#ifdef CONFIG_PAX_PER_CPU_PGD
35787 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35788 +#else
35789 load_cr3(swapper_pg_dir);
35790 +#endif
35791 +
35792 __flush_tlb_all();
35793
35794 local_irq_restore(efi_rt_eflags);
35795 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35796 index 290d397..e09d270 100644
35797 --- a/arch/x86/platform/efi/efi_64.c
35798 +++ b/arch/x86/platform/efi/efi_64.c
35799 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35800 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35801 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35802 }
35803 +
35804 +#ifdef CONFIG_PAX_PER_CPU_PGD
35805 + load_cr3(swapper_pg_dir);
35806 +#endif
35807 +
35808 __flush_tlb_all();
35809 }
35810
35811 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35812 for (pgd = 0; pgd < n_pgds; pgd++)
35813 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35814 kfree(save_pgd);
35815 +
35816 +#ifdef CONFIG_PAX_PER_CPU_PGD
35817 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35818 +#endif
35819 +
35820 __flush_tlb_all();
35821 local_irq_restore(efi_flags);
35822 early_code_mapping_set_exec(0);
35823 @@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35824 unsigned npages;
35825 pgd_t *pgd;
35826
35827 - if (efi_enabled(EFI_OLD_MEMMAP))
35828 + if (efi_enabled(EFI_OLD_MEMMAP)) {
35829 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35830 + * able to execute the EFI services.
35831 + */
35832 + if (__supported_pte_mask & _PAGE_NX) {
35833 + unsigned long addr = (unsigned long) __va(0);
35834 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35835 +
35836 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35837 +#ifdef CONFIG_PAX_PER_CPU_PGD
35838 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35839 +#endif
35840 + set_pgd(pgd_offset_k(addr), pe);
35841 + }
35842 +
35843 return 0;
35844 + }
35845
35846 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35847 pgd = __va(efi_scratch.efi_pgt);
35848 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35849 index fbe66e6..eae5e38 100644
35850 --- a/arch/x86/platform/efi/efi_stub_32.S
35851 +++ b/arch/x86/platform/efi/efi_stub_32.S
35852 @@ -6,7 +6,9 @@
35853 */
35854
35855 #include <linux/linkage.h>
35856 +#include <linux/init.h>
35857 #include <asm/page_types.h>
35858 +#include <asm/segment.h>
35859
35860 /*
35861 * efi_call_phys(void *, ...) is a function with variable parameters.
35862 @@ -20,7 +22,7 @@
35863 * service functions will comply with gcc calling convention, too.
35864 */
35865
35866 -.text
35867 +__INIT
35868 ENTRY(efi_call_phys)
35869 /*
35870 * 0. The function can only be called in Linux kernel. So CS has been
35871 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35872 * The mapping of lower virtual memory has been created in prelog and
35873 * epilog.
35874 */
35875 - movl $1f, %edx
35876 - subl $__PAGE_OFFSET, %edx
35877 - jmp *%edx
35878 +#ifdef CONFIG_PAX_KERNEXEC
35879 + movl $(__KERNEXEC_EFI_DS), %edx
35880 + mov %edx, %ds
35881 + mov %edx, %es
35882 + mov %edx, %ss
35883 + addl $2f,(1f)
35884 + ljmp *(1f)
35885 +
35886 +__INITDATA
35887 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35888 +.previous
35889 +
35890 +2:
35891 + subl $2b,(1b)
35892 +#else
35893 + jmp 1f-__PAGE_OFFSET
35894 1:
35895 +#endif
35896
35897 /*
35898 * 2. Now on the top of stack is the return
35899 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35900 * parameter 2, ..., param n. To make things easy, we save the return
35901 * address of efi_call_phys in a global variable.
35902 */
35903 - popl %edx
35904 - movl %edx, saved_return_addr
35905 - /* get the function pointer into ECX*/
35906 - popl %ecx
35907 - movl %ecx, efi_rt_function_ptr
35908 - movl $2f, %edx
35909 - subl $__PAGE_OFFSET, %edx
35910 - pushl %edx
35911 + popl (saved_return_addr)
35912 + popl (efi_rt_function_ptr)
35913
35914 /*
35915 * 3. Clear PG bit in %CR0.
35916 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35917 /*
35918 * 5. Call the physical function.
35919 */
35920 - jmp *%ecx
35921 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35922
35923 -2:
35924 /*
35925 * 6. After EFI runtime service returns, control will return to
35926 * following instruction. We'd better readjust stack pointer first.
35927 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35928 movl %cr0, %edx
35929 orl $0x80000000, %edx
35930 movl %edx, %cr0
35931 - jmp 1f
35932 -1:
35933 +
35934 /*
35935 * 8. Now restore the virtual mode from flat mode by
35936 * adding EIP with PAGE_OFFSET.
35937 */
35938 - movl $1f, %edx
35939 - jmp *%edx
35940 +#ifdef CONFIG_PAX_KERNEXEC
35941 + movl $(__KERNEL_DS), %edx
35942 + mov %edx, %ds
35943 + mov %edx, %es
35944 + mov %edx, %ss
35945 + ljmp $(__KERNEL_CS),$1f
35946 +#else
35947 + jmp 1f+__PAGE_OFFSET
35948 +#endif
35949 1:
35950
35951 /*
35952 * 9. Balance the stack. And because EAX contain the return value,
35953 * we'd better not clobber it.
35954 */
35955 - leal efi_rt_function_ptr, %edx
35956 - movl (%edx), %ecx
35957 - pushl %ecx
35958 + pushl (efi_rt_function_ptr)
35959
35960 /*
35961 - * 10. Push the saved return address onto the stack and return.
35962 + * 10. Return to the saved return address.
35963 */
35964 - leal saved_return_addr, %edx
35965 - movl (%edx), %ecx
35966 - pushl %ecx
35967 - ret
35968 + jmpl *(saved_return_addr)
35969 ENDPROC(efi_call_phys)
35970 .previous
35971
35972 -.data
35973 +__INITDATA
35974 saved_return_addr:
35975 .long 0
35976 efi_rt_function_ptr:
35977 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35978 index 5fcda72..cd4dc41 100644
35979 --- a/arch/x86/platform/efi/efi_stub_64.S
35980 +++ b/arch/x86/platform/efi/efi_stub_64.S
35981 @@ -11,6 +11,7 @@
35982 #include <asm/msr.h>
35983 #include <asm/processor-flags.h>
35984 #include <asm/page_types.h>
35985 +#include <asm/alternative-asm.h>
35986
35987 #define SAVE_XMM \
35988 mov %rsp, %rax; \
35989 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35990 RESTORE_PGT
35991 addq $48, %rsp
35992 RESTORE_XMM
35993 + pax_force_retaddr 0, 1
35994 ret
35995 ENDPROC(efi_call)
35996
35997 @@ -245,8 +247,8 @@ efi_gdt64:
35998 .long 0 /* Filled out by user */
35999 .word 0
36000 .quad 0x0000000000000000 /* NULL descriptor */
36001 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
36002 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
36003 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
36004 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
36005 .quad 0x0080890000000000 /* TS descriptor */
36006 .quad 0x0000000000000000 /* TS continued */
36007 efi_gdt64_end:
36008 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
36009 index 1bbedc4..eb795b5 100644
36010 --- a/arch/x86/platform/intel-mid/intel-mid.c
36011 +++ b/arch/x86/platform/intel-mid/intel-mid.c
36012 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
36013 {
36014 };
36015
36016 -static void intel_mid_reboot(void)
36017 +static void __noreturn intel_mid_reboot(void)
36018 {
36019 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36020 + BUG();
36021 }
36022
36023 static unsigned long __init intel_mid_calibrate_tsc(void)
36024 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36025 index 46aa25c..59a68ed 100644
36026 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36027 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36028 @@ -10,10 +10,9 @@
36029 */
36030
36031
36032 -/* __attribute__((weak)) makes these declarations overridable */
36033 /* For every CPU addition a new get_<cpuname>_ops interface needs
36034 * to be added.
36035 */
36036 -extern void *get_penwell_ops(void) __attribute__((weak));
36037 -extern void *get_cloverview_ops(void) __attribute__((weak));
36038 -extern void *get_tangier_ops(void) __attribute__((weak));
36039 +extern const void *get_penwell_ops(void);
36040 +extern const void *get_cloverview_ops(void);
36041 +extern const void *get_tangier_ops(void);
36042 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
36043 index 23381d2..8ddc10e 100644
36044 --- a/arch/x86/platform/intel-mid/mfld.c
36045 +++ b/arch/x86/platform/intel-mid/mfld.c
36046 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
36047 pm_power_off = mfld_power_off;
36048 }
36049
36050 -void *get_penwell_ops(void)
36051 +const void *get_penwell_ops(void)
36052 {
36053 return &penwell_ops;
36054 }
36055
36056 -void *get_cloverview_ops(void)
36057 +const void *get_cloverview_ops(void)
36058 {
36059 return &penwell_ops;
36060 }
36061 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
36062 index aaca917..66eadbc 100644
36063 --- a/arch/x86/platform/intel-mid/mrfl.c
36064 +++ b/arch/x86/platform/intel-mid/mrfl.c
36065 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
36066 .arch_setup = tangier_arch_setup,
36067 };
36068
36069 -void *get_tangier_ops(void)
36070 +const void *get_tangier_ops(void)
36071 {
36072 return &tangier_ops;
36073 }
36074 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36075 index d6ee929..3637cb5 100644
36076 --- a/arch/x86/platform/olpc/olpc_dt.c
36077 +++ b/arch/x86/platform/olpc/olpc_dt.c
36078 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36079 return res;
36080 }
36081
36082 -static struct of_pdt_ops prom_olpc_ops __initdata = {
36083 +static struct of_pdt_ops prom_olpc_ops __initconst = {
36084 .nextprop = olpc_dt_nextprop,
36085 .getproplen = olpc_dt_getproplen,
36086 .getproperty = olpc_dt_getproperty,
36087 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36088 index 6ec7910..ecdbb11 100644
36089 --- a/arch/x86/power/cpu.c
36090 +++ b/arch/x86/power/cpu.c
36091 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
36092 static void fix_processor_context(void)
36093 {
36094 int cpu = smp_processor_id();
36095 - struct tss_struct *t = &per_cpu(init_tss, cpu);
36096 -#ifdef CONFIG_X86_64
36097 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
36098 - tss_desc tss;
36099 -#endif
36100 + struct tss_struct *t = init_tss + cpu;
36101 +
36102 set_tss_desc(cpu, t); /*
36103 * This just modifies memory; should not be
36104 * necessary. But... This is necessary, because
36105 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
36106 */
36107
36108 #ifdef CONFIG_X86_64
36109 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36110 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36111 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36112 -
36113 syscall_init(); /* This sets MSR_*STAR and related */
36114 #endif
36115 load_TR_desc(); /* This does ltr */
36116 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36117 index bad628a..a102610 100644
36118 --- a/arch/x86/realmode/init.c
36119 +++ b/arch/x86/realmode/init.c
36120 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36121 __va(real_mode_header->trampoline_header);
36122
36123 #ifdef CONFIG_X86_32
36124 - trampoline_header->start = __pa_symbol(startup_32_smp);
36125 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36126 +
36127 +#ifdef CONFIG_PAX_KERNEXEC
36128 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36129 +#endif
36130 +
36131 + trampoline_header->boot_cs = __BOOT_CS;
36132 trampoline_header->gdt_limit = __BOOT_DS + 7;
36133 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36134 #else
36135 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36136 *trampoline_cr4_features = read_cr4();
36137
36138 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36139 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36140 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36141 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36142 #endif
36143 }
36144 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36145 index 7c0d7be..d24dc88 100644
36146 --- a/arch/x86/realmode/rm/Makefile
36147 +++ b/arch/x86/realmode/rm/Makefile
36148 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36149
36150 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36151 -I$(srctree)/arch/x86/boot
36152 +ifdef CONSTIFY_PLUGIN
36153 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36154 +endif
36155 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36156 GCOV_PROFILE := n
36157 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36158 index a28221d..93c40f1 100644
36159 --- a/arch/x86/realmode/rm/header.S
36160 +++ b/arch/x86/realmode/rm/header.S
36161 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36162 #endif
36163 /* APM/BIOS reboot */
36164 .long pa_machine_real_restart_asm
36165 -#ifdef CONFIG_X86_64
36166 +#ifdef CONFIG_X86_32
36167 + .long __KERNEL_CS
36168 +#else
36169 .long __KERNEL32_CS
36170 #endif
36171 END(real_mode_header)
36172 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36173 index 48ddd76..c26749f 100644
36174 --- a/arch/x86/realmode/rm/trampoline_32.S
36175 +++ b/arch/x86/realmode/rm/trampoline_32.S
36176 @@ -24,6 +24,12 @@
36177 #include <asm/page_types.h>
36178 #include "realmode.h"
36179
36180 +#ifdef CONFIG_PAX_KERNEXEC
36181 +#define ta(X) (X)
36182 +#else
36183 +#define ta(X) (pa_ ## X)
36184 +#endif
36185 +
36186 .text
36187 .code16
36188
36189 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36190
36191 cli # We should be safe anyway
36192
36193 - movl tr_start, %eax # where we need to go
36194 -
36195 movl $0xA5A5A5A5, trampoline_status
36196 # write marker for master knows we're running
36197
36198 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
36199 movw $1, %dx # protected mode (PE) bit
36200 lmsw %dx # into protected mode
36201
36202 - ljmpl $__BOOT_CS, $pa_startup_32
36203 + ljmpl *(trampoline_header)
36204
36205 .section ".text32","ax"
36206 .code32
36207 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
36208 .balign 8
36209 GLOBAL(trampoline_header)
36210 tr_start: .space 4
36211 - tr_gdt_pad: .space 2
36212 + tr_boot_cs: .space 2
36213 tr_gdt: .space 6
36214 END(trampoline_header)
36215
36216 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
36217 index dac7b20..72dbaca 100644
36218 --- a/arch/x86/realmode/rm/trampoline_64.S
36219 +++ b/arch/x86/realmode/rm/trampoline_64.S
36220 @@ -93,6 +93,7 @@ ENTRY(startup_32)
36221 movl %edx, %gs
36222
36223 movl pa_tr_cr4, %eax
36224 + andl $~X86_CR4_PCIDE, %eax
36225 movl %eax, %cr4 # Enable PAE mode
36226
36227 # Setup trampoline 4 level pagetables
36228 @@ -106,7 +107,7 @@ ENTRY(startup_32)
36229 wrmsr
36230
36231 # Enable paging and in turn activate Long Mode
36232 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36233 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
36234 movl %eax, %cr0
36235
36236 /*
36237 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36238 index 9e7e147..25a4158 100644
36239 --- a/arch/x86/realmode/rm/wakeup_asm.S
36240 +++ b/arch/x86/realmode/rm/wakeup_asm.S
36241 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36242 lgdtl pmode_gdt
36243
36244 /* This really couldn't... */
36245 - movl pmode_entry, %eax
36246 movl pmode_cr0, %ecx
36247 movl %ecx, %cr0
36248 - ljmpl $__KERNEL_CS, $pa_startup_32
36249 - /* -> jmp *%eax in trampoline_32.S */
36250 +
36251 + ljmpl *pmode_entry
36252 #else
36253 jmp trampoline_start
36254 #endif
36255 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36256 index 604a37e..e49702a 100644
36257 --- a/arch/x86/tools/Makefile
36258 +++ b/arch/x86/tools/Makefile
36259 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36260
36261 $(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
36262
36263 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
36264 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
36265 hostprogs-y += relocs
36266 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
36267 PHONY += relocs
36268 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
36269 index bbb1d22..e505211 100644
36270 --- a/arch/x86/tools/relocs.c
36271 +++ b/arch/x86/tools/relocs.c
36272 @@ -1,5 +1,7 @@
36273 /* This is included from relocs_32/64.c */
36274
36275 +#include "../../../include/generated/autoconf.h"
36276 +
36277 #define ElfW(type) _ElfW(ELF_BITS, type)
36278 #define _ElfW(bits, type) __ElfW(bits, type)
36279 #define __ElfW(bits, type) Elf##bits##_##type
36280 @@ -11,6 +13,7 @@
36281 #define Elf_Sym ElfW(Sym)
36282
36283 static Elf_Ehdr ehdr;
36284 +static Elf_Phdr *phdr;
36285
36286 struct relocs {
36287 uint32_t *offset;
36288 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
36289 }
36290 }
36291
36292 +static void read_phdrs(FILE *fp)
36293 +{
36294 + unsigned int i;
36295 +
36296 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
36297 + if (!phdr) {
36298 + die("Unable to allocate %d program headers\n",
36299 + ehdr.e_phnum);
36300 + }
36301 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
36302 + die("Seek to %d failed: %s\n",
36303 + ehdr.e_phoff, strerror(errno));
36304 + }
36305 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36306 + die("Cannot read ELF program headers: %s\n",
36307 + strerror(errno));
36308 + }
36309 + for(i = 0; i < ehdr.e_phnum; i++) {
36310 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36311 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36312 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36313 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36314 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36315 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36316 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36317 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36318 + }
36319 +
36320 +}
36321 +
36322 static void read_shdrs(FILE *fp)
36323 {
36324 - int i;
36325 + unsigned int i;
36326 Elf_Shdr shdr;
36327
36328 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36329 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36330
36331 static void read_strtabs(FILE *fp)
36332 {
36333 - int i;
36334 + unsigned int i;
36335 for (i = 0; i < ehdr.e_shnum; i++) {
36336 struct section *sec = &secs[i];
36337 if (sec->shdr.sh_type != SHT_STRTAB) {
36338 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36339
36340 static void read_symtabs(FILE *fp)
36341 {
36342 - int i,j;
36343 + unsigned int i,j;
36344 for (i = 0; i < ehdr.e_shnum; i++) {
36345 struct section *sec = &secs[i];
36346 if (sec->shdr.sh_type != SHT_SYMTAB) {
36347 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36348 }
36349
36350
36351 -static void read_relocs(FILE *fp)
36352 +static void read_relocs(FILE *fp, int use_real_mode)
36353 {
36354 - int i,j;
36355 + unsigned int i,j;
36356 + uint32_t base;
36357 +
36358 for (i = 0; i < ehdr.e_shnum; i++) {
36359 struct section *sec = &secs[i];
36360 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36361 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36362 die("Cannot read symbol table: %s\n",
36363 strerror(errno));
36364 }
36365 + base = 0;
36366 +
36367 +#ifdef CONFIG_X86_32
36368 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36369 + if (phdr[j].p_type != PT_LOAD )
36370 + continue;
36371 + 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)
36372 + continue;
36373 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36374 + break;
36375 + }
36376 +#endif
36377 +
36378 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36379 Elf_Rel *rel = &sec->reltab[j];
36380 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36381 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36382 rel->r_info = elf_xword_to_cpu(rel->r_info);
36383 #if (SHT_REL_TYPE == SHT_RELA)
36384 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36385 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36386
36387 static void print_absolute_symbols(void)
36388 {
36389 - int i;
36390 + unsigned int i;
36391 const char *format;
36392
36393 if (ELF_BITS == 64)
36394 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36395 for (i = 0; i < ehdr.e_shnum; i++) {
36396 struct section *sec = &secs[i];
36397 char *sym_strtab;
36398 - int j;
36399 + unsigned int j;
36400
36401 if (sec->shdr.sh_type != SHT_SYMTAB) {
36402 continue;
36403 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36404
36405 static void print_absolute_relocs(void)
36406 {
36407 - int i, printed = 0;
36408 + unsigned int i, printed = 0;
36409 const char *format;
36410
36411 if (ELF_BITS == 64)
36412 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36413 struct section *sec_applies, *sec_symtab;
36414 char *sym_strtab;
36415 Elf_Sym *sh_symtab;
36416 - int j;
36417 + unsigned int j;
36418 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36419 continue;
36420 }
36421 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36422 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36423 Elf_Sym *sym, const char *symname))
36424 {
36425 - int i;
36426 + unsigned int i;
36427 /* Walk through the relocations */
36428 for (i = 0; i < ehdr.e_shnum; i++) {
36429 char *sym_strtab;
36430 Elf_Sym *sh_symtab;
36431 struct section *sec_applies, *sec_symtab;
36432 - int j;
36433 + unsigned int j;
36434 struct section *sec = &secs[i];
36435
36436 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36437 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36438 {
36439 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36440 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36441 + char *sym_strtab = sec->link->link->strtab;
36442 +
36443 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36444 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36445 + return 0;
36446 +
36447 +#ifdef CONFIG_PAX_KERNEXEC
36448 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36449 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36450 + return 0;
36451 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36452 + return 0;
36453 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36454 + return 0;
36455 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36456 + return 0;
36457 +#endif
36458
36459 switch (r_type) {
36460 case R_386_NONE:
36461 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36462
36463 static void emit_relocs(int as_text, int use_real_mode)
36464 {
36465 - int i;
36466 + unsigned int i;
36467 int (*write_reloc)(uint32_t, FILE *) = write32;
36468 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36469 const char *symname);
36470 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36471 {
36472 regex_init(use_real_mode);
36473 read_ehdr(fp);
36474 + read_phdrs(fp);
36475 read_shdrs(fp);
36476 read_strtabs(fp);
36477 read_symtabs(fp);
36478 - read_relocs(fp);
36479 + read_relocs(fp, use_real_mode);
36480 if (ELF_BITS == 64)
36481 percpu_init();
36482 if (show_absolute_syms) {
36483 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36484 index f40281e..92728c9 100644
36485 --- a/arch/x86/um/mem_32.c
36486 +++ b/arch/x86/um/mem_32.c
36487 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36488 gate_vma.vm_start = FIXADDR_USER_START;
36489 gate_vma.vm_end = FIXADDR_USER_END;
36490 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36491 - gate_vma.vm_page_prot = __P101;
36492 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36493
36494 return 0;
36495 }
36496 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36497 index 80ffa5b..a33bd15 100644
36498 --- a/arch/x86/um/tls_32.c
36499 +++ b/arch/x86/um/tls_32.c
36500 @@ -260,7 +260,7 @@ out:
36501 if (unlikely(task == current &&
36502 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36503 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36504 - "without flushed TLS.", current->pid);
36505 + "without flushed TLS.", task_pid_nr(current));
36506 }
36507
36508 return 0;
36509 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36510 index 5a4affe..9e2d522 100644
36511 --- a/arch/x86/vdso/Makefile
36512 +++ b/arch/x86/vdso/Makefile
36513 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36514 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36515 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36516
36517 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36518 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36519 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36520 GCOV_PROFILE := n
36521
36522 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36523 index e904c27..b9eaa03 100644
36524 --- a/arch/x86/vdso/vdso32-setup.c
36525 +++ b/arch/x86/vdso/vdso32-setup.c
36526 @@ -14,6 +14,7 @@
36527 #include <asm/cpufeature.h>
36528 #include <asm/processor.h>
36529 #include <asm/vdso.h>
36530 +#include <asm/mman.h>
36531
36532 #ifdef CONFIG_COMPAT_VDSO
36533 #define VDSO_DEFAULT 0
36534 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36535 index 970463b..da82d3e 100644
36536 --- a/arch/x86/vdso/vma.c
36537 +++ b/arch/x86/vdso/vma.c
36538 @@ -16,10 +16,9 @@
36539 #include <asm/vdso.h>
36540 #include <asm/page.h>
36541 #include <asm/hpet.h>
36542 +#include <asm/mman.h>
36543
36544 #if defined(CONFIG_X86_64)
36545 -unsigned int __read_mostly vdso64_enabled = 1;
36546 -
36547 extern unsigned short vdso_sync_cpuid;
36548 #endif
36549
36550 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36551 .pages = no_pages,
36552 };
36553
36554 +#ifdef CONFIG_PAX_RANDMMAP
36555 + if (mm->pax_flags & MF_PAX_RANDMMAP)
36556 + calculate_addr = false;
36557 +#endif
36558 +
36559 if (calculate_addr) {
36560 addr = vdso_addr(current->mm->start_stack,
36561 image->size - image->sym_vvar_start);
36562 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36563 down_write(&mm->mmap_sem);
36564
36565 addr = get_unmapped_area(NULL, addr,
36566 - image->size - image->sym_vvar_start, 0, 0);
36567 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36568 if (IS_ERR_VALUE(addr)) {
36569 ret = addr;
36570 goto up_fail;
36571 }
36572
36573 text_start = addr - image->sym_vvar_start;
36574 - current->mm->context.vdso = (void __user *)text_start;
36575 + mm->context.vdso = text_start;
36576
36577 /*
36578 * MAYWRITE to allow gdb to COW and set breakpoints
36579 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36580 hpet_address >> PAGE_SHIFT,
36581 PAGE_SIZE,
36582 pgprot_noncached(PAGE_READONLY));
36583 -
36584 - if (ret)
36585 - goto up_fail;
36586 }
36587 #endif
36588
36589 up_fail:
36590 if (ret)
36591 - current->mm->context.vdso = NULL;
36592 + current->mm->context.vdso = 0;
36593
36594 up_write(&mm->mmap_sem);
36595 return ret;
36596 @@ -191,8 +192,8 @@ static int load_vdso32(void)
36597
36598 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36599 current_thread_info()->sysenter_return =
36600 - current->mm->context.vdso +
36601 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36602 + (void __force_user *)(current->mm->context.vdso +
36603 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36604
36605 return 0;
36606 }
36607 @@ -201,9 +202,6 @@ static int load_vdso32(void)
36608 #ifdef CONFIG_X86_64
36609 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36610 {
36611 - if (!vdso64_enabled)
36612 - return 0;
36613 -
36614 return map_vdso(&vdso_image_64, true);
36615 }
36616
36617 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36618 int uses_interp)
36619 {
36620 #ifdef CONFIG_X86_X32_ABI
36621 - if (test_thread_flag(TIF_X32)) {
36622 - if (!vdso64_enabled)
36623 - return 0;
36624 -
36625 + if (test_thread_flag(TIF_X32))
36626 return map_vdso(&vdso_image_x32, true);
36627 - }
36628 #endif
36629
36630 return load_vdso32();
36631 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36632 return load_vdso32();
36633 }
36634 #endif
36635 -
36636 -#ifdef CONFIG_X86_64
36637 -static __init int vdso_setup(char *s)
36638 -{
36639 - vdso64_enabled = simple_strtoul(s, NULL, 0);
36640 - return 0;
36641 -}
36642 -__setup("vdso=", vdso_setup);
36643 -#endif
36644 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36645 index e88fda8..76ce7ce 100644
36646 --- a/arch/x86/xen/Kconfig
36647 +++ b/arch/x86/xen/Kconfig
36648 @@ -9,6 +9,7 @@ config XEN
36649 select XEN_HAVE_PVMMU
36650 depends on X86_64 || (X86_32 && X86_PAE)
36651 depends on X86_TSC
36652 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36653 help
36654 This is the Linux Xen port. Enabling this will allow the
36655 kernel to boot in a paravirtualized environment under the
36656 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36657 index c0cb11f..bed56ff 100644
36658 --- a/arch/x86/xen/enlighten.c
36659 +++ b/arch/x86/xen/enlighten.c
36660 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36661
36662 struct shared_info xen_dummy_shared_info;
36663
36664 -void *xen_initial_gdt;
36665 -
36666 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36667 __read_mostly int xen_have_vector_callback;
36668 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36669 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36670 {
36671 unsigned long va = dtr->address;
36672 unsigned int size = dtr->size + 1;
36673 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36674 - unsigned long frames[pages];
36675 + unsigned long frames[65536 / PAGE_SIZE];
36676 int f;
36677
36678 /*
36679 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36680 {
36681 unsigned long va = dtr->address;
36682 unsigned int size = dtr->size + 1;
36683 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36684 - unsigned long frames[pages];
36685 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36686 int f;
36687
36688 /*
36689 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36690 * 8-byte entries, or 16 4k pages..
36691 */
36692
36693 - BUG_ON(size > 65536);
36694 + BUG_ON(size > GDT_SIZE);
36695 BUG_ON(va & ~PAGE_MASK);
36696
36697 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36698 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36699 return 0;
36700 }
36701
36702 -static void set_xen_basic_apic_ops(void)
36703 +static void __init set_xen_basic_apic_ops(void)
36704 {
36705 apic->read = xen_apic_read;
36706 apic->write = xen_apic_write;
36707 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36708 #endif
36709 };
36710
36711 -static void xen_reboot(int reason)
36712 +static __noreturn void xen_reboot(int reason)
36713 {
36714 struct sched_shutdown r = { .reason = reason };
36715
36716 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36717 - BUG();
36718 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36719 + BUG();
36720 }
36721
36722 -static void xen_restart(char *msg)
36723 +static __noreturn void xen_restart(char *msg)
36724 {
36725 xen_reboot(SHUTDOWN_reboot);
36726 }
36727
36728 -static void xen_emergency_restart(void)
36729 +static __noreturn void xen_emergency_restart(void)
36730 {
36731 xen_reboot(SHUTDOWN_reboot);
36732 }
36733
36734 -static void xen_machine_halt(void)
36735 +static __noreturn void xen_machine_halt(void)
36736 {
36737 xen_reboot(SHUTDOWN_poweroff);
36738 }
36739
36740 -static void xen_machine_power_off(void)
36741 +static __noreturn void xen_machine_power_off(void)
36742 {
36743 if (pm_power_off)
36744 pm_power_off();
36745 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36746 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36747
36748 /* Work out if we support NX */
36749 - x86_configure_nx();
36750 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36751 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36752 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36753 + unsigned l, h;
36754 +
36755 + __supported_pte_mask |= _PAGE_NX;
36756 + rdmsr(MSR_EFER, l, h);
36757 + l |= EFER_NX;
36758 + wrmsr(MSR_EFER, l, h);
36759 + }
36760 +#endif
36761
36762 /* Get mfn list */
36763 xen_build_dynamic_phys_to_machine();
36764 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36765
36766 machine_ops = xen_machine_ops;
36767
36768 - /*
36769 - * The only reliable way to retain the initial address of the
36770 - * percpu gdt_page is to remember it here, so we can go and
36771 - * mark it RW later, when the initial percpu area is freed.
36772 - */
36773 - xen_initial_gdt = &per_cpu(gdt_page, 0);
36774 -
36775 xen_smp_init();
36776
36777 #ifdef CONFIG_ACPI_NUMA
36778 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36779 index 16fb009..02b7801 100644
36780 --- a/arch/x86/xen/mmu.c
36781 +++ b/arch/x86/xen/mmu.c
36782 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36783 return val;
36784 }
36785
36786 -static pteval_t pte_pfn_to_mfn(pteval_t val)
36787 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36788 {
36789 if (val & _PAGE_PRESENT) {
36790 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36791 @@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36792 * L3_k[511] -> level2_fixmap_pgt */
36793 convert_pfn_mfn(level3_kernel_pgt);
36794
36795 + convert_pfn_mfn(level3_vmalloc_start_pgt);
36796 + convert_pfn_mfn(level3_vmalloc_end_pgt);
36797 + convert_pfn_mfn(level3_vmemmap_pgt);
36798 /* L3_k[511][506] -> level1_fixmap_pgt */
36799 + /* L3_k[511][507] -> level1_vsyscall_pgt */
36800 convert_pfn_mfn(level2_fixmap_pgt);
36801 }
36802 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36803 @@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36804 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36805 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36806 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36807 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36808 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36809 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36810 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36811 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36812 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36813 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36814 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36815 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36816 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36817
36818 /* Pin down new L4 */
36819 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36820 @@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36821 pv_mmu_ops.set_pud = xen_set_pud;
36822 #if PAGETABLE_LEVELS == 4
36823 pv_mmu_ops.set_pgd = xen_set_pgd;
36824 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36825 #endif
36826
36827 /* This will work as long as patching hasn't happened yet
36828 @@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36829 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36830 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36831 .set_pgd = xen_set_pgd_hyper,
36832 + .set_pgd_batched = xen_set_pgd_hyper,
36833
36834 .alloc_pud = xen_alloc_pmd_init,
36835 .release_pud = xen_release_pmd_init,
36836 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36837 index 7005974..54fb05f 100644
36838 --- a/arch/x86/xen/smp.c
36839 +++ b/arch/x86/xen/smp.c
36840 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36841
36842 if (xen_pv_domain()) {
36843 if (!xen_feature(XENFEAT_writable_page_tables))
36844 - /* We've switched to the "real" per-cpu gdt, so make
36845 - * sure the old memory can be recycled. */
36846 - make_lowmem_page_readwrite(xen_initial_gdt);
36847 -
36848 #ifdef CONFIG_X86_32
36849 /*
36850 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36851 * expects __USER_DS
36852 */
36853 - loadsegment(ds, __USER_DS);
36854 - loadsegment(es, __USER_DS);
36855 + loadsegment(ds, __KERNEL_DS);
36856 + loadsegment(es, __KERNEL_DS);
36857 #endif
36858
36859 xen_filter_cpu_maps();
36860 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36861 #ifdef CONFIG_X86_32
36862 /* Note: PVH is not yet supported on x86_32. */
36863 ctxt->user_regs.fs = __KERNEL_PERCPU;
36864 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36865 + savesegment(gs, ctxt->user_regs.gs);
36866 #endif
36867 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36868
36869 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36870 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36871 ctxt->flags = VGCF_IN_KERNEL;
36872 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36873 - ctxt->user_regs.ds = __USER_DS;
36874 - ctxt->user_regs.es = __USER_DS;
36875 + ctxt->user_regs.ds = __KERNEL_DS;
36876 + ctxt->user_regs.es = __KERNEL_DS;
36877 ctxt->user_regs.ss = __KERNEL_DS;
36878
36879 xen_copy_trap_info(ctxt->trap_ctxt);
36880 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36881 int rc;
36882
36883 per_cpu(current_task, cpu) = idle;
36884 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36885 #ifdef CONFIG_X86_32
36886 irq_ctx_init(cpu);
36887 #else
36888 clear_tsk_thread_flag(idle, TIF_FORK);
36889 #endif
36890 - per_cpu(kernel_stack, cpu) =
36891 - (unsigned long)task_stack_page(idle) -
36892 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36893 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36894
36895 xen_setup_runstate_info(cpu);
36896 xen_setup_timer(cpu);
36897 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36898
36899 void __init xen_smp_init(void)
36900 {
36901 - smp_ops = xen_smp_ops;
36902 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36903 xen_fill_possible_map();
36904 }
36905
36906 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36907 index fd92a64..1f72641 100644
36908 --- a/arch/x86/xen/xen-asm_32.S
36909 +++ b/arch/x86/xen/xen-asm_32.S
36910 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
36911 pushw %fs
36912 movl $(__KERNEL_PERCPU), %eax
36913 movl %eax, %fs
36914 - movl %fs:xen_vcpu, %eax
36915 + mov PER_CPU_VAR(xen_vcpu), %eax
36916 POP_FS
36917 #else
36918 movl %ss:xen_vcpu, %eax
36919 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36920 index 485b695..fda3e7c 100644
36921 --- a/arch/x86/xen/xen-head.S
36922 +++ b/arch/x86/xen/xen-head.S
36923 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36924 #ifdef CONFIG_X86_32
36925 mov %esi,xen_start_info
36926 mov $init_thread_union+THREAD_SIZE,%esp
36927 +#ifdef CONFIG_SMP
36928 + movl $cpu_gdt_table,%edi
36929 + movl $__per_cpu_load,%eax
36930 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36931 + rorl $16,%eax
36932 + movb %al,__KERNEL_PERCPU + 4(%edi)
36933 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36934 + movl $__per_cpu_end - 1,%eax
36935 + subl $__per_cpu_start,%eax
36936 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36937 +#endif
36938 #else
36939 mov %rsi,xen_start_info
36940 mov $init_thread_union+THREAD_SIZE,%rsp
36941 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36942 index 28c7e0b..2acfec7 100644
36943 --- a/arch/x86/xen/xen-ops.h
36944 +++ b/arch/x86/xen/xen-ops.h
36945 @@ -10,8 +10,6 @@
36946 extern const char xen_hypervisor_callback[];
36947 extern const char xen_failsafe_callback[];
36948
36949 -extern void *xen_initial_gdt;
36950 -
36951 struct trap_info;
36952 void xen_copy_trap_info(struct trap_info *traps);
36953
36954 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36955 index 525bd3d..ef888b1 100644
36956 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36957 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36958 @@ -119,9 +119,9 @@
36959 ----------------------------------------------------------------------*/
36960
36961 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36962 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36963 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36964 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36965 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36966
36967 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36968 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36969 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36970 index 2f33760..835e50a 100644
36971 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36972 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36973 @@ -11,6 +11,7 @@
36974 #ifndef _XTENSA_CORE_H
36975 #define _XTENSA_CORE_H
36976
36977 +#include <linux/const.h>
36978
36979 /****************************************************************************
36980 Parameters Useful for Any Code, USER or PRIVILEGED
36981 @@ -112,9 +113,9 @@
36982 ----------------------------------------------------------------------*/
36983
36984 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36985 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36986 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36987 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36988 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36989
36990 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36991 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36992 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36993 index af00795..2bb8105 100644
36994 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36995 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36996 @@ -11,6 +11,7 @@
36997 #ifndef _XTENSA_CORE_CONFIGURATION_H
36998 #define _XTENSA_CORE_CONFIGURATION_H
36999
37000 +#include <linux/const.h>
37001
37002 /****************************************************************************
37003 Parameters Useful for Any Code, USER or PRIVILEGED
37004 @@ -118,9 +119,9 @@
37005 ----------------------------------------------------------------------*/
37006
37007 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37008 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37009 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37010 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37011 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37012
37013 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
37014 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
37015 diff --git a/block/bio.c b/block/bio.c
37016 index 3e6331d..f970433 100644
37017 --- a/block/bio.c
37018 +++ b/block/bio.c
37019 @@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37020 /*
37021 * Overflow, abort
37022 */
37023 - if (end < start)
37024 + if (end < start || end - start > INT_MAX - nr_pages)
37025 return ERR_PTR(-EINVAL);
37026
37027 nr_pages += end - start;
37028 @@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37029 /*
37030 * Overflow, abort
37031 */
37032 - if (end < start)
37033 + if (end < start || end - start > INT_MAX - nr_pages)
37034 return ERR_PTR(-EINVAL);
37035
37036 nr_pages += end - start;
37037 @@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37038 const int read = bio_data_dir(bio) == READ;
37039 struct bio_map_data *bmd = bio->bi_private;
37040 int i;
37041 - char *p = bmd->sgvecs[0].iov_base;
37042 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37043
37044 bio_for_each_segment_all(bvec, bio, i) {
37045 char *addr = page_address(bvec->bv_page);
37046 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37047 index e17da94..e01cce1 100644
37048 --- a/block/blk-cgroup.c
37049 +++ b/block/blk-cgroup.c
37050 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37051 static struct cgroup_subsys_state *
37052 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37053 {
37054 - static atomic64_t id_seq = ATOMIC64_INIT(0);
37055 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37056 struct blkcg *blkcg;
37057
37058 if (!parent_css) {
37059 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37060
37061 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37062 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37063 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37064 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37065 done:
37066 spin_lock_init(&blkcg->lock);
37067 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37068 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37069 index 0736729..2ec3b48 100644
37070 --- a/block/blk-iopoll.c
37071 +++ b/block/blk-iopoll.c
37072 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37073 }
37074 EXPORT_SYMBOL(blk_iopoll_complete);
37075
37076 -static void blk_iopoll_softirq(struct softirq_action *h)
37077 +static __latent_entropy void blk_iopoll_softirq(void)
37078 {
37079 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37080 int rearm = 0, budget = blk_iopoll_budget;
37081 diff --git a/block/blk-map.c b/block/blk-map.c
37082 index f890d43..97b0482 100644
37083 --- a/block/blk-map.c
37084 +++ b/block/blk-map.c
37085 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37086 if (!len || !kbuf)
37087 return -EINVAL;
37088
37089 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37090 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37091 if (do_copy)
37092 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37093 else
37094 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37095 index 53b1737..08177d2e 100644
37096 --- a/block/blk-softirq.c
37097 +++ b/block/blk-softirq.c
37098 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37099 * Softirq action handler - move entries to local list and loop over them
37100 * while passing them to the queue registered handler.
37101 */
37102 -static void blk_done_softirq(struct softirq_action *h)
37103 +static __latent_entropy void blk_done_softirq(void)
37104 {
37105 struct list_head *cpu_list, local_list;
37106
37107 diff --git a/block/bsg.c b/block/bsg.c
37108 index ff46add..c4ba8ee 100644
37109 --- a/block/bsg.c
37110 +++ b/block/bsg.c
37111 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37112 struct sg_io_v4 *hdr, struct bsg_device *bd,
37113 fmode_t has_write_perm)
37114 {
37115 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37116 + unsigned char *cmdptr;
37117 +
37118 if (hdr->request_len > BLK_MAX_CDB) {
37119 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37120 if (!rq->cmd)
37121 return -ENOMEM;
37122 - }
37123 + cmdptr = rq->cmd;
37124 + } else
37125 + cmdptr = tmpcmd;
37126
37127 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37128 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37129 hdr->request_len))
37130 return -EFAULT;
37131
37132 + if (cmdptr != rq->cmd)
37133 + memcpy(rq->cmd, cmdptr, hdr->request_len);
37134 +
37135 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37136 if (blk_verify_command(rq->cmd, has_write_perm))
37137 return -EPERM;
37138 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37139 index 18b282c..050dbe5 100644
37140 --- a/block/compat_ioctl.c
37141 +++ b/block/compat_ioctl.c
37142 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37143 cgc = compat_alloc_user_space(sizeof(*cgc));
37144 cgc32 = compat_ptr(arg);
37145
37146 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37147 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37148 get_user(data, &cgc32->buffer) ||
37149 put_user(compat_ptr(data), &cgc->buffer) ||
37150 copy_in_user(&cgc->buflen, &cgc32->buflen,
37151 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37152 err |= __get_user(f->spec1, &uf->spec1);
37153 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37154 err |= __get_user(name, &uf->name);
37155 - f->name = compat_ptr(name);
37156 + f->name = (void __force_kernel *)compat_ptr(name);
37157 if (err) {
37158 err = -EFAULT;
37159 goto out;
37160 diff --git a/block/genhd.c b/block/genhd.c
37161 index e6723bd..703e4ac 100644
37162 --- a/block/genhd.c
37163 +++ b/block/genhd.c
37164 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37165
37166 /*
37167 * Register device numbers dev..(dev+range-1)
37168 - * range must be nonzero
37169 + * Noop if @range is zero.
37170 * The hash chain is sorted on range, so that subranges can override.
37171 */
37172 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37173 struct kobject *(*probe)(dev_t, int *, void *),
37174 int (*lock)(dev_t, void *), void *data)
37175 {
37176 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
37177 + if (range)
37178 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
37179 }
37180
37181 EXPORT_SYMBOL(blk_register_region);
37182
37183 +/* undo blk_register_region(), noop if @range is zero */
37184 void blk_unregister_region(dev_t devt, unsigned long range)
37185 {
37186 - kobj_unmap(bdev_map, devt, range);
37187 + if (range)
37188 + kobj_unmap(bdev_map, devt, range);
37189 }
37190
37191 EXPORT_SYMBOL(blk_unregister_region);
37192 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37193 index 56d08fd..2e07090 100644
37194 --- a/block/partitions/efi.c
37195 +++ b/block/partitions/efi.c
37196 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37197 if (!gpt)
37198 return NULL;
37199
37200 + if (!le32_to_cpu(gpt->num_partition_entries))
37201 + return NULL;
37202 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
37203 + if (!pte)
37204 + return NULL;
37205 +
37206 count = le32_to_cpu(gpt->num_partition_entries) *
37207 le32_to_cpu(gpt->sizeof_partition_entry);
37208 - if (!count)
37209 - return NULL;
37210 - pte = kmalloc(count, GFP_KERNEL);
37211 - if (!pte)
37212 - return NULL;
37213 -
37214 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
37215 (u8 *) pte, count) < count) {
37216 kfree(pte);
37217 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
37218 index 9b8eaec..c20279a 100644
37219 --- a/block/scsi_ioctl.c
37220 +++ b/block/scsi_ioctl.c
37221 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
37222 return put_user(0, p);
37223 }
37224
37225 -static int sg_get_timeout(struct request_queue *q)
37226 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
37227 {
37228 return jiffies_to_clock_t(q->sg_timeout);
37229 }
37230 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
37231 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37232 struct sg_io_hdr *hdr, fmode_t mode)
37233 {
37234 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37235 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37236 + unsigned char *cmdptr;
37237 +
37238 + if (rq->cmd != rq->__cmd)
37239 + cmdptr = rq->cmd;
37240 + else
37241 + cmdptr = tmpcmd;
37242 +
37243 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37244 return -EFAULT;
37245 +
37246 + if (cmdptr != rq->cmd)
37247 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37248 +
37249 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37250 return -EPERM;
37251
37252 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37253 int err;
37254 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37255 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37256 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37257 + unsigned char *cmdptr;
37258
37259 if (!sic)
37260 return -EINVAL;
37261 @@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37262 */
37263 err = -EFAULT;
37264 rq->cmd_len = cmdlen;
37265 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
37266 +
37267 + if (rq->cmd != rq->__cmd)
37268 + cmdptr = rq->cmd;
37269 + else
37270 + cmdptr = tmpcmd;
37271 +
37272 + if (copy_from_user(cmdptr, sic->data, cmdlen))
37273 goto error;
37274
37275 + if (rq->cmd != cmdptr)
37276 + memcpy(rq->cmd, cmdptr, cmdlen);
37277 +
37278 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
37279 goto error;
37280
37281 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
37282 index e592c90..c566114 100644
37283 --- a/crypto/cryptd.c
37284 +++ b/crypto/cryptd.c
37285 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
37286
37287 struct cryptd_blkcipher_request_ctx {
37288 crypto_completion_t complete;
37289 -};
37290 +} __no_const;
37291
37292 struct cryptd_hash_ctx {
37293 struct crypto_shash *child;
37294 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
37295
37296 struct cryptd_aead_request_ctx {
37297 crypto_completion_t complete;
37298 -};
37299 +} __no_const;
37300
37301 static void cryptd_queue_worker(struct work_struct *work);
37302
37303 diff --git a/crypto/cts.c b/crypto/cts.c
37304 index 042223f..133f087 100644
37305 --- a/crypto/cts.c
37306 +++ b/crypto/cts.c
37307 @@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37308 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37309 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37310 /* 6. Decrypt En to create Pn-1 */
37311 - memset(iv, 0, sizeof(iv));
37312 + memzero_explicit(iv, sizeof(iv));
37313 +
37314 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37315 sg_set_buf(&sgdst[0], d, bsize);
37316 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37317 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37318 index 309d345..1632720 100644
37319 --- a/crypto/pcrypt.c
37320 +++ b/crypto/pcrypt.c
37321 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37322 int ret;
37323
37324 pinst->kobj.kset = pcrypt_kset;
37325 - ret = kobject_add(&pinst->kobj, NULL, name);
37326 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37327 if (!ret)
37328 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37329
37330 diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37331 index 4279480..7bb0474 100644
37332 --- a/crypto/sha1_generic.c
37333 +++ b/crypto/sha1_generic.c
37334 @@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37335 src = data + done;
37336 } while (done + SHA1_BLOCK_SIZE <= len);
37337
37338 - memset(temp, 0, sizeof(temp));
37339 + memzero_explicit(temp, sizeof(temp));
37340 partial = 0;
37341 }
37342 memcpy(sctx->buffer + partial, src, len - done);
37343 diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37344 index 5433667..32c5e5e 100644
37345 --- a/crypto/sha256_generic.c
37346 +++ b/crypto/sha256_generic.c
37347 @@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37348
37349 /* clear any sensitive info... */
37350 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37351 - memset(W, 0, 64 * sizeof(u32));
37352 + memzero_explicit(W, 64 * sizeof(u32));
37353 }
37354
37355 -
37356 static int sha224_init(struct shash_desc *desc)
37357 {
37358 struct sha256_state *sctx = shash_desc_ctx(desc);
37359 @@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37360 sha256_final(desc, D);
37361
37362 memcpy(hash, D, SHA224_DIGEST_SIZE);
37363 - memset(D, 0, SHA256_DIGEST_SIZE);
37364 + memzero_explicit(D, SHA256_DIGEST_SIZE);
37365
37366 return 0;
37367 }
37368 diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37369 index 6ed124f..04d295a 100644
37370 --- a/crypto/sha512_generic.c
37371 +++ b/crypto/sha512_generic.c
37372 @@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37373 sha512_final(desc, D);
37374
37375 memcpy(hash, D, 48);
37376 - memset(D, 0, 64);
37377 + memzero_explicit(D, 64);
37378
37379 return 0;
37380 }
37381 diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37382 index 8740355..3c7af0d 100644
37383 --- a/crypto/tgr192.c
37384 +++ b/crypto/tgr192.c
37385 @@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37386
37387 tgr192_final(desc, D);
37388 memcpy(out, D, TGR160_DIGEST_SIZE);
37389 - memset(D, 0, TGR192_DIGEST_SIZE);
37390 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37391
37392 return 0;
37393 }
37394 @@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37395
37396 tgr192_final(desc, D);
37397 memcpy(out, D, TGR128_DIGEST_SIZE);
37398 - memset(D, 0, TGR192_DIGEST_SIZE);
37399 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37400
37401 return 0;
37402 }
37403 diff --git a/crypto/vmac.c b/crypto/vmac.c
37404 index 2eb11a3..d84c24b 100644
37405 --- a/crypto/vmac.c
37406 +++ b/crypto/vmac.c
37407 @@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37408 }
37409 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37410 memcpy(out, &mac, sizeof(vmac_t));
37411 - memset(&mac, 0, sizeof(vmac_t));
37412 + memzero_explicit(&mac, sizeof(vmac_t));
37413 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37414 ctx->partial_size = 0;
37415 return 0;
37416 diff --git a/crypto/wp512.c b/crypto/wp512.c
37417 index 180f1d6..ec64e77 100644
37418 --- a/crypto/wp512.c
37419 +++ b/crypto/wp512.c
37420 @@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37421 u8 D[64];
37422
37423 wp512_final(desc, D);
37424 - memcpy (out, D, WP384_DIGEST_SIZE);
37425 - memset (D, 0, WP512_DIGEST_SIZE);
37426 + memcpy(out, D, WP384_DIGEST_SIZE);
37427 + memzero_explicit(D, WP512_DIGEST_SIZE);
37428
37429 return 0;
37430 }
37431 @@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37432 u8 D[64];
37433
37434 wp512_final(desc, D);
37435 - memcpy (out, D, WP256_DIGEST_SIZE);
37436 - memset (D, 0, WP512_DIGEST_SIZE);
37437 + memcpy(out, D, WP256_DIGEST_SIZE);
37438 + memzero_explicit(D, WP512_DIGEST_SIZE);
37439
37440 return 0;
37441 }
37442 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37443 index 6921c7f..78e1af7 100644
37444 --- a/drivers/acpi/acpica/hwxfsleep.c
37445 +++ b/drivers/acpi/acpica/hwxfsleep.c
37446 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37447 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37448
37449 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37450 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37451 - acpi_hw_extended_sleep},
37452 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37453 - acpi_hw_extended_wake_prep},
37454 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37455 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37456 + .extended_function = acpi_hw_extended_sleep},
37457 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37458 + .extended_function = acpi_hw_extended_wake_prep},
37459 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37460 + .extended_function = acpi_hw_extended_wake}
37461 };
37462
37463 /*
37464 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37465 index 16129c7..8b675cd 100644
37466 --- a/drivers/acpi/apei/apei-internal.h
37467 +++ b/drivers/acpi/apei/apei-internal.h
37468 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37469 struct apei_exec_ins_type {
37470 u32 flags;
37471 apei_exec_ins_func_t run;
37472 -};
37473 +} __do_const;
37474
37475 struct apei_exec_context {
37476 u32 ip;
37477 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37478 index fc5f780..e5ac91a 100644
37479 --- a/drivers/acpi/apei/ghes.c
37480 +++ b/drivers/acpi/apei/ghes.c
37481 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37482 const struct acpi_hest_generic *generic,
37483 const struct acpi_hest_generic_status *estatus)
37484 {
37485 - static atomic_t seqno;
37486 + static atomic_unchecked_t seqno;
37487 unsigned int curr_seqno;
37488 char pfx_seq[64];
37489
37490 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37491 else
37492 pfx = KERN_ERR;
37493 }
37494 - curr_seqno = atomic_inc_return(&seqno);
37495 + curr_seqno = atomic_inc_return_unchecked(&seqno);
37496 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37497 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37498 pfx_seq, generic->header.source_id);
37499 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37500 index a83e3c6..c3d617f 100644
37501 --- a/drivers/acpi/bgrt.c
37502 +++ b/drivers/acpi/bgrt.c
37503 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37504 if (!bgrt_image)
37505 return -ENODEV;
37506
37507 - bin_attr_image.private = bgrt_image;
37508 - bin_attr_image.size = bgrt_image_size;
37509 + pax_open_kernel();
37510 + *(void **)&bin_attr_image.private = bgrt_image;
37511 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
37512 + pax_close_kernel();
37513
37514 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37515 if (!bgrt_kobj)
37516 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37517 index 36eb42e..3b2f47e 100644
37518 --- a/drivers/acpi/blacklist.c
37519 +++ b/drivers/acpi/blacklist.c
37520 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37521 u32 is_critical_error;
37522 };
37523
37524 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37525 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37526
37527 /*
37528 * POLICY: If *anything* doesn't work, put it on the blacklist.
37529 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37530 return 0;
37531 }
37532
37533 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37534 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37535 {
37536 .callback = dmi_disable_osi_vista,
37537 .ident = "Fujitsu Siemens",
37538 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37539 index c68e724..e863008 100644
37540 --- a/drivers/acpi/custom_method.c
37541 +++ b/drivers/acpi/custom_method.c
37542 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37543 struct acpi_table_header table;
37544 acpi_status status;
37545
37546 +#ifdef CONFIG_GRKERNSEC_KMEM
37547 + return -EPERM;
37548 +#endif
37549 +
37550 if (!(*ppos)) {
37551 /* parse the table header to get the table length */
37552 if (count <= sizeof(struct acpi_table_header))
37553 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37554 index 17f9ec5..d9a455e 100644
37555 --- a/drivers/acpi/processor_idle.c
37556 +++ b/drivers/acpi/processor_idle.c
37557 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37558 {
37559 int i, count = CPUIDLE_DRIVER_STATE_START;
37560 struct acpi_processor_cx *cx;
37561 - struct cpuidle_state *state;
37562 + cpuidle_state_no_const *state;
37563 struct cpuidle_driver *drv = &acpi_idle_driver;
37564
37565 if (!pr->flags.power_setup_done)
37566 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37567 index 38cb978..352c761 100644
37568 --- a/drivers/acpi/sysfs.c
37569 +++ b/drivers/acpi/sysfs.c
37570 @@ -423,11 +423,11 @@ static u32 num_counters;
37571 static struct attribute **all_attrs;
37572 static u32 acpi_gpe_count;
37573
37574 -static struct attribute_group interrupt_stats_attr_group = {
37575 +static attribute_group_no_const interrupt_stats_attr_group = {
37576 .name = "interrupts",
37577 };
37578
37579 -static struct kobj_attribute *counter_attrs;
37580 +static kobj_attribute_no_const *counter_attrs;
37581
37582 static void delete_gpe_attr_array(void)
37583 {
37584 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37585 index b784e9d..a69a049 100644
37586 --- a/drivers/ata/libahci.c
37587 +++ b/drivers/ata/libahci.c
37588 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37589 }
37590 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37591
37592 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37593 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37594 struct ata_taskfile *tf, int is_cmd, u16 flags,
37595 unsigned long timeout_msec)
37596 {
37597 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37598 index 6f67490..f951ead 100644
37599 --- a/drivers/ata/libata-core.c
37600 +++ b/drivers/ata/libata-core.c
37601 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37602 static void ata_dev_xfermask(struct ata_device *dev);
37603 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37604
37605 -atomic_t ata_print_id = ATOMIC_INIT(0);
37606 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37607
37608 struct ata_force_param {
37609 const char *name;
37610 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37611 struct ata_port *ap;
37612 unsigned int tag;
37613
37614 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37615 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37616 ap = qc->ap;
37617
37618 qc->flags = 0;
37619 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37620 struct ata_port *ap;
37621 struct ata_link *link;
37622
37623 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37624 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37625 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37626 ap = qc->ap;
37627 link = qc->dev->link;
37628 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37629 return;
37630
37631 spin_lock(&lock);
37632 + pax_open_kernel();
37633
37634 for (cur = ops->inherits; cur; cur = cur->inherits) {
37635 void **inherit = (void **)cur;
37636 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37637 if (IS_ERR(*pp))
37638 *pp = NULL;
37639
37640 - ops->inherits = NULL;
37641 + *(struct ata_port_operations **)&ops->inherits = NULL;
37642
37643 + pax_close_kernel();
37644 spin_unlock(&lock);
37645 }
37646
37647 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37648
37649 /* give ports names and add SCSI hosts */
37650 for (i = 0; i < host->n_ports; i++) {
37651 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37652 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37653 host->ports[i]->local_port_no = i + 1;
37654 }
37655
37656 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37657 index 0586f66..1a8f74a 100644
37658 --- a/drivers/ata/libata-scsi.c
37659 +++ b/drivers/ata/libata-scsi.c
37660 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37661
37662 if (rc)
37663 return rc;
37664 - ap->print_id = atomic_inc_return(&ata_print_id);
37665 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37666 return 0;
37667 }
37668 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37669 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37670 index 5f4e0cc..ff2c347 100644
37671 --- a/drivers/ata/libata.h
37672 +++ b/drivers/ata/libata.h
37673 @@ -53,7 +53,7 @@ enum {
37674 ATA_DNXFER_QUIET = (1 << 31),
37675 };
37676
37677 -extern atomic_t ata_print_id;
37678 +extern atomic_unchecked_t ata_print_id;
37679 extern int atapi_passthru16;
37680 extern int libata_fua;
37681 extern int libata_noacpi;
37682 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37683 index 4edb1a8..84e1658 100644
37684 --- a/drivers/ata/pata_arasan_cf.c
37685 +++ b/drivers/ata/pata_arasan_cf.c
37686 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37687 /* Handle platform specific quirks */
37688 if (quirk) {
37689 if (quirk & CF_BROKEN_PIO) {
37690 - ap->ops->set_piomode = NULL;
37691 + pax_open_kernel();
37692 + *(void **)&ap->ops->set_piomode = NULL;
37693 + pax_close_kernel();
37694 ap->pio_mask = 0;
37695 }
37696 if (quirk & CF_BROKEN_MWDMA)
37697 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37698 index f9b983a..887b9d8 100644
37699 --- a/drivers/atm/adummy.c
37700 +++ b/drivers/atm/adummy.c
37701 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37702 vcc->pop(vcc, skb);
37703 else
37704 dev_kfree_skb_any(skb);
37705 - atomic_inc(&vcc->stats->tx);
37706 + atomic_inc_unchecked(&vcc->stats->tx);
37707
37708 return 0;
37709 }
37710 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37711 index f1a9198..f466a4a 100644
37712 --- a/drivers/atm/ambassador.c
37713 +++ b/drivers/atm/ambassador.c
37714 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37715 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37716
37717 // VC layer stats
37718 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37719 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37720
37721 // free the descriptor
37722 kfree (tx_descr);
37723 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37724 dump_skb ("<<<", vc, skb);
37725
37726 // VC layer stats
37727 - atomic_inc(&atm_vcc->stats->rx);
37728 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37729 __net_timestamp(skb);
37730 // end of our responsibility
37731 atm_vcc->push (atm_vcc, skb);
37732 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37733 } else {
37734 PRINTK (KERN_INFO, "dropped over-size frame");
37735 // should we count this?
37736 - atomic_inc(&atm_vcc->stats->rx_drop);
37737 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37738 }
37739
37740 } else {
37741 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37742 }
37743
37744 if (check_area (skb->data, skb->len)) {
37745 - atomic_inc(&atm_vcc->stats->tx_err);
37746 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37747 return -ENOMEM; // ?
37748 }
37749
37750 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37751 index 480fa6f..947067c 100644
37752 --- a/drivers/atm/atmtcp.c
37753 +++ b/drivers/atm/atmtcp.c
37754 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37755 if (vcc->pop) vcc->pop(vcc,skb);
37756 else dev_kfree_skb(skb);
37757 if (dev_data) return 0;
37758 - atomic_inc(&vcc->stats->tx_err);
37759 + atomic_inc_unchecked(&vcc->stats->tx_err);
37760 return -ENOLINK;
37761 }
37762 size = skb->len+sizeof(struct atmtcp_hdr);
37763 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37764 if (!new_skb) {
37765 if (vcc->pop) vcc->pop(vcc,skb);
37766 else dev_kfree_skb(skb);
37767 - atomic_inc(&vcc->stats->tx_err);
37768 + atomic_inc_unchecked(&vcc->stats->tx_err);
37769 return -ENOBUFS;
37770 }
37771 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37772 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37773 if (vcc->pop) vcc->pop(vcc,skb);
37774 else dev_kfree_skb(skb);
37775 out_vcc->push(out_vcc,new_skb);
37776 - atomic_inc(&vcc->stats->tx);
37777 - atomic_inc(&out_vcc->stats->rx);
37778 + atomic_inc_unchecked(&vcc->stats->tx);
37779 + atomic_inc_unchecked(&out_vcc->stats->rx);
37780 return 0;
37781 }
37782
37783 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37784 read_unlock(&vcc_sklist_lock);
37785 if (!out_vcc) {
37786 result = -EUNATCH;
37787 - atomic_inc(&vcc->stats->tx_err);
37788 + atomic_inc_unchecked(&vcc->stats->tx_err);
37789 goto done;
37790 }
37791 skb_pull(skb,sizeof(struct atmtcp_hdr));
37792 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37793 __net_timestamp(new_skb);
37794 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37795 out_vcc->push(out_vcc,new_skb);
37796 - atomic_inc(&vcc->stats->tx);
37797 - atomic_inc(&out_vcc->stats->rx);
37798 + atomic_inc_unchecked(&vcc->stats->tx);
37799 + atomic_inc_unchecked(&out_vcc->stats->rx);
37800 done:
37801 if (vcc->pop) vcc->pop(vcc,skb);
37802 else dev_kfree_skb(skb);
37803 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37804 index d65975a..0b87e20 100644
37805 --- a/drivers/atm/eni.c
37806 +++ b/drivers/atm/eni.c
37807 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37808 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37809 vcc->dev->number);
37810 length = 0;
37811 - atomic_inc(&vcc->stats->rx_err);
37812 + atomic_inc_unchecked(&vcc->stats->rx_err);
37813 }
37814 else {
37815 length = ATM_CELL_SIZE-1; /* no HEC */
37816 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37817 size);
37818 }
37819 eff = length = 0;
37820 - atomic_inc(&vcc->stats->rx_err);
37821 + atomic_inc_unchecked(&vcc->stats->rx_err);
37822 }
37823 else {
37824 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37825 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37826 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37827 vcc->dev->number,vcc->vci,length,size << 2,descr);
37828 length = eff = 0;
37829 - atomic_inc(&vcc->stats->rx_err);
37830 + atomic_inc_unchecked(&vcc->stats->rx_err);
37831 }
37832 }
37833 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37834 @@ -767,7 +767,7 @@ rx_dequeued++;
37835 vcc->push(vcc,skb);
37836 pushed++;
37837 }
37838 - atomic_inc(&vcc->stats->rx);
37839 + atomic_inc_unchecked(&vcc->stats->rx);
37840 }
37841 wake_up(&eni_dev->rx_wait);
37842 }
37843 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37844 PCI_DMA_TODEVICE);
37845 if (vcc->pop) vcc->pop(vcc,skb);
37846 else dev_kfree_skb_irq(skb);
37847 - atomic_inc(&vcc->stats->tx);
37848 + atomic_inc_unchecked(&vcc->stats->tx);
37849 wake_up(&eni_dev->tx_wait);
37850 dma_complete++;
37851 }
37852 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37853 index 82f2ae0..f205c02 100644
37854 --- a/drivers/atm/firestream.c
37855 +++ b/drivers/atm/firestream.c
37856 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37857 }
37858 }
37859
37860 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37861 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37862
37863 fs_dprintk (FS_DEBUG_TXMEM, "i");
37864 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37865 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37866 #endif
37867 skb_put (skb, qe->p1 & 0xffff);
37868 ATM_SKB(skb)->vcc = atm_vcc;
37869 - atomic_inc(&atm_vcc->stats->rx);
37870 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37871 __net_timestamp(skb);
37872 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37873 atm_vcc->push (atm_vcc, skb);
37874 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37875 kfree (pe);
37876 }
37877 if (atm_vcc)
37878 - atomic_inc(&atm_vcc->stats->rx_drop);
37879 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37880 break;
37881 case 0x1f: /* Reassembly abort: no buffers. */
37882 /* Silently increment error counter. */
37883 if (atm_vcc)
37884 - atomic_inc(&atm_vcc->stats->rx_drop);
37885 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37886 break;
37887 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37888 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37889 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37890 index d4725fc..2d4ea65 100644
37891 --- a/drivers/atm/fore200e.c
37892 +++ b/drivers/atm/fore200e.c
37893 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37894 #endif
37895 /* check error condition */
37896 if (*entry->status & STATUS_ERROR)
37897 - atomic_inc(&vcc->stats->tx_err);
37898 + atomic_inc_unchecked(&vcc->stats->tx_err);
37899 else
37900 - atomic_inc(&vcc->stats->tx);
37901 + atomic_inc_unchecked(&vcc->stats->tx);
37902 }
37903 }
37904
37905 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37906 if (skb == NULL) {
37907 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37908
37909 - atomic_inc(&vcc->stats->rx_drop);
37910 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37911 return -ENOMEM;
37912 }
37913
37914 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37915
37916 dev_kfree_skb_any(skb);
37917
37918 - atomic_inc(&vcc->stats->rx_drop);
37919 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37920 return -ENOMEM;
37921 }
37922
37923 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37924
37925 vcc->push(vcc, skb);
37926 - atomic_inc(&vcc->stats->rx);
37927 + atomic_inc_unchecked(&vcc->stats->rx);
37928
37929 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37930
37931 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37932 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37933 fore200e->atm_dev->number,
37934 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37935 - atomic_inc(&vcc->stats->rx_err);
37936 + atomic_inc_unchecked(&vcc->stats->rx_err);
37937 }
37938 }
37939
37940 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37941 goto retry_here;
37942 }
37943
37944 - atomic_inc(&vcc->stats->tx_err);
37945 + atomic_inc_unchecked(&vcc->stats->tx_err);
37946
37947 fore200e->tx_sat++;
37948 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37949 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37950 index c39702b..785b73b 100644
37951 --- a/drivers/atm/he.c
37952 +++ b/drivers/atm/he.c
37953 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37954
37955 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37956 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37957 - atomic_inc(&vcc->stats->rx_drop);
37958 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37959 goto return_host_buffers;
37960 }
37961
37962 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37963 RBRQ_LEN_ERR(he_dev->rbrq_head)
37964 ? "LEN_ERR" : "",
37965 vcc->vpi, vcc->vci);
37966 - atomic_inc(&vcc->stats->rx_err);
37967 + atomic_inc_unchecked(&vcc->stats->rx_err);
37968 goto return_host_buffers;
37969 }
37970
37971 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37972 vcc->push(vcc, skb);
37973 spin_lock(&he_dev->global_lock);
37974
37975 - atomic_inc(&vcc->stats->rx);
37976 + atomic_inc_unchecked(&vcc->stats->rx);
37977
37978 return_host_buffers:
37979 ++pdus_assembled;
37980 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37981 tpd->vcc->pop(tpd->vcc, tpd->skb);
37982 else
37983 dev_kfree_skb_any(tpd->skb);
37984 - atomic_inc(&tpd->vcc->stats->tx_err);
37985 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37986 }
37987 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37988 return;
37989 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37990 vcc->pop(vcc, skb);
37991 else
37992 dev_kfree_skb_any(skb);
37993 - atomic_inc(&vcc->stats->tx_err);
37994 + atomic_inc_unchecked(&vcc->stats->tx_err);
37995 return -EINVAL;
37996 }
37997
37998 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37999 vcc->pop(vcc, skb);
38000 else
38001 dev_kfree_skb_any(skb);
38002 - atomic_inc(&vcc->stats->tx_err);
38003 + atomic_inc_unchecked(&vcc->stats->tx_err);
38004 return -EINVAL;
38005 }
38006 #endif
38007 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38008 vcc->pop(vcc, skb);
38009 else
38010 dev_kfree_skb_any(skb);
38011 - atomic_inc(&vcc->stats->tx_err);
38012 + atomic_inc_unchecked(&vcc->stats->tx_err);
38013 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38014 return -ENOMEM;
38015 }
38016 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38017 vcc->pop(vcc, skb);
38018 else
38019 dev_kfree_skb_any(skb);
38020 - atomic_inc(&vcc->stats->tx_err);
38021 + atomic_inc_unchecked(&vcc->stats->tx_err);
38022 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38023 return -ENOMEM;
38024 }
38025 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38026 __enqueue_tpd(he_dev, tpd, cid);
38027 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38028
38029 - atomic_inc(&vcc->stats->tx);
38030 + atomic_inc_unchecked(&vcc->stats->tx);
38031
38032 return 0;
38033 }
38034 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38035 index 1dc0519..1aadaf7 100644
38036 --- a/drivers/atm/horizon.c
38037 +++ b/drivers/atm/horizon.c
38038 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38039 {
38040 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38041 // VC layer stats
38042 - atomic_inc(&vcc->stats->rx);
38043 + atomic_inc_unchecked(&vcc->stats->rx);
38044 __net_timestamp(skb);
38045 // end of our responsibility
38046 vcc->push (vcc, skb);
38047 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38048 dev->tx_iovec = NULL;
38049
38050 // VC layer stats
38051 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38052 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38053
38054 // free the skb
38055 hrz_kfree_skb (skb);
38056 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38057 index 2b24ed0..b3d6acc 100644
38058 --- a/drivers/atm/idt77252.c
38059 +++ b/drivers/atm/idt77252.c
38060 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38061 else
38062 dev_kfree_skb(skb);
38063
38064 - atomic_inc(&vcc->stats->tx);
38065 + atomic_inc_unchecked(&vcc->stats->tx);
38066 }
38067
38068 atomic_dec(&scq->used);
38069 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38070 if ((sb = dev_alloc_skb(64)) == NULL) {
38071 printk("%s: Can't allocate buffers for aal0.\n",
38072 card->name);
38073 - atomic_add(i, &vcc->stats->rx_drop);
38074 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38075 break;
38076 }
38077 if (!atm_charge(vcc, sb->truesize)) {
38078 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38079 card->name);
38080 - atomic_add(i - 1, &vcc->stats->rx_drop);
38081 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38082 dev_kfree_skb(sb);
38083 break;
38084 }
38085 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38086 ATM_SKB(sb)->vcc = vcc;
38087 __net_timestamp(sb);
38088 vcc->push(vcc, sb);
38089 - atomic_inc(&vcc->stats->rx);
38090 + atomic_inc_unchecked(&vcc->stats->rx);
38091
38092 cell += ATM_CELL_PAYLOAD;
38093 }
38094 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38095 "(CDC: %08x)\n",
38096 card->name, len, rpp->len, readl(SAR_REG_CDC));
38097 recycle_rx_pool_skb(card, rpp);
38098 - atomic_inc(&vcc->stats->rx_err);
38099 + atomic_inc_unchecked(&vcc->stats->rx_err);
38100 return;
38101 }
38102 if (stat & SAR_RSQE_CRC) {
38103 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38104 recycle_rx_pool_skb(card, rpp);
38105 - atomic_inc(&vcc->stats->rx_err);
38106 + atomic_inc_unchecked(&vcc->stats->rx_err);
38107 return;
38108 }
38109 if (skb_queue_len(&rpp->queue) > 1) {
38110 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38111 RXPRINTK("%s: Can't alloc RX skb.\n",
38112 card->name);
38113 recycle_rx_pool_skb(card, rpp);
38114 - atomic_inc(&vcc->stats->rx_err);
38115 + atomic_inc_unchecked(&vcc->stats->rx_err);
38116 return;
38117 }
38118 if (!atm_charge(vcc, skb->truesize)) {
38119 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38120 __net_timestamp(skb);
38121
38122 vcc->push(vcc, skb);
38123 - atomic_inc(&vcc->stats->rx);
38124 + atomic_inc_unchecked(&vcc->stats->rx);
38125
38126 return;
38127 }
38128 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38129 __net_timestamp(skb);
38130
38131 vcc->push(vcc, skb);
38132 - atomic_inc(&vcc->stats->rx);
38133 + atomic_inc_unchecked(&vcc->stats->rx);
38134
38135 if (skb->truesize > SAR_FB_SIZE_3)
38136 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38137 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38138 if (vcc->qos.aal != ATM_AAL0) {
38139 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38140 card->name, vpi, vci);
38141 - atomic_inc(&vcc->stats->rx_drop);
38142 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38143 goto drop;
38144 }
38145
38146 if ((sb = dev_alloc_skb(64)) == NULL) {
38147 printk("%s: Can't allocate buffers for AAL0.\n",
38148 card->name);
38149 - atomic_inc(&vcc->stats->rx_err);
38150 + atomic_inc_unchecked(&vcc->stats->rx_err);
38151 goto drop;
38152 }
38153
38154 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38155 ATM_SKB(sb)->vcc = vcc;
38156 __net_timestamp(sb);
38157 vcc->push(vcc, sb);
38158 - atomic_inc(&vcc->stats->rx);
38159 + atomic_inc_unchecked(&vcc->stats->rx);
38160
38161 drop:
38162 skb_pull(queue, 64);
38163 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38164
38165 if (vc == NULL) {
38166 printk("%s: NULL connection in send().\n", card->name);
38167 - atomic_inc(&vcc->stats->tx_err);
38168 + atomic_inc_unchecked(&vcc->stats->tx_err);
38169 dev_kfree_skb(skb);
38170 return -EINVAL;
38171 }
38172 if (!test_bit(VCF_TX, &vc->flags)) {
38173 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38174 - atomic_inc(&vcc->stats->tx_err);
38175 + atomic_inc_unchecked(&vcc->stats->tx_err);
38176 dev_kfree_skb(skb);
38177 return -EINVAL;
38178 }
38179 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38180 break;
38181 default:
38182 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38183 - atomic_inc(&vcc->stats->tx_err);
38184 + atomic_inc_unchecked(&vcc->stats->tx_err);
38185 dev_kfree_skb(skb);
38186 return -EINVAL;
38187 }
38188
38189 if (skb_shinfo(skb)->nr_frags != 0) {
38190 printk("%s: No scatter-gather yet.\n", card->name);
38191 - atomic_inc(&vcc->stats->tx_err);
38192 + atomic_inc_unchecked(&vcc->stats->tx_err);
38193 dev_kfree_skb(skb);
38194 return -EINVAL;
38195 }
38196 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38197
38198 err = queue_skb(card, vc, skb, oam);
38199 if (err) {
38200 - atomic_inc(&vcc->stats->tx_err);
38201 + atomic_inc_unchecked(&vcc->stats->tx_err);
38202 dev_kfree_skb(skb);
38203 return err;
38204 }
38205 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38206 skb = dev_alloc_skb(64);
38207 if (!skb) {
38208 printk("%s: Out of memory in send_oam().\n", card->name);
38209 - atomic_inc(&vcc->stats->tx_err);
38210 + atomic_inc_unchecked(&vcc->stats->tx_err);
38211 return -ENOMEM;
38212 }
38213 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38214 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38215 index 4217f29..88f547a 100644
38216 --- a/drivers/atm/iphase.c
38217 +++ b/drivers/atm/iphase.c
38218 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38219 status = (u_short) (buf_desc_ptr->desc_mode);
38220 if (status & (RX_CER | RX_PTE | RX_OFL))
38221 {
38222 - atomic_inc(&vcc->stats->rx_err);
38223 + atomic_inc_unchecked(&vcc->stats->rx_err);
38224 IF_ERR(printk("IA: bad packet, dropping it");)
38225 if (status & RX_CER) {
38226 IF_ERR(printk(" cause: packet CRC error\n");)
38227 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38228 len = dma_addr - buf_addr;
38229 if (len > iadev->rx_buf_sz) {
38230 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38231 - atomic_inc(&vcc->stats->rx_err);
38232 + atomic_inc_unchecked(&vcc->stats->rx_err);
38233 goto out_free_desc;
38234 }
38235
38236 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38237 ia_vcc = INPH_IA_VCC(vcc);
38238 if (ia_vcc == NULL)
38239 {
38240 - atomic_inc(&vcc->stats->rx_err);
38241 + atomic_inc_unchecked(&vcc->stats->rx_err);
38242 atm_return(vcc, skb->truesize);
38243 dev_kfree_skb_any(skb);
38244 goto INCR_DLE;
38245 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38246 if ((length > iadev->rx_buf_sz) || (length >
38247 (skb->len - sizeof(struct cpcs_trailer))))
38248 {
38249 - atomic_inc(&vcc->stats->rx_err);
38250 + atomic_inc_unchecked(&vcc->stats->rx_err);
38251 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38252 length, skb->len);)
38253 atm_return(vcc, skb->truesize);
38254 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38255
38256 IF_RX(printk("rx_dle_intr: skb push");)
38257 vcc->push(vcc,skb);
38258 - atomic_inc(&vcc->stats->rx);
38259 + atomic_inc_unchecked(&vcc->stats->rx);
38260 iadev->rx_pkt_cnt++;
38261 }
38262 INCR_DLE:
38263 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38264 {
38265 struct k_sonet_stats *stats;
38266 stats = &PRIV(_ia_dev[board])->sonet_stats;
38267 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38268 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38269 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38270 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38271 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38272 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38273 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38274 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38275 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38276 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38277 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38278 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38279 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38280 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38281 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38282 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38283 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38284 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38285 }
38286 ia_cmds.status = 0;
38287 break;
38288 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38289 if ((desc == 0) || (desc > iadev->num_tx_desc))
38290 {
38291 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38292 - atomic_inc(&vcc->stats->tx);
38293 + atomic_inc_unchecked(&vcc->stats->tx);
38294 if (vcc->pop)
38295 vcc->pop(vcc, skb);
38296 else
38297 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38298 ATM_DESC(skb) = vcc->vci;
38299 skb_queue_tail(&iadev->tx_dma_q, skb);
38300
38301 - atomic_inc(&vcc->stats->tx);
38302 + atomic_inc_unchecked(&vcc->stats->tx);
38303 iadev->tx_pkt_cnt++;
38304 /* Increment transaction counter */
38305 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38306
38307 #if 0
38308 /* add flow control logic */
38309 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38310 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38311 if (iavcc->vc_desc_cnt > 10) {
38312 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38313 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38314 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38315 index fa7d7019..1e404c7 100644
38316 --- a/drivers/atm/lanai.c
38317 +++ b/drivers/atm/lanai.c
38318 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38319 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38320 lanai_endtx(lanai, lvcc);
38321 lanai_free_skb(lvcc->tx.atmvcc, skb);
38322 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38323 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38324 }
38325
38326 /* Try to fill the buffer - don't call unless there is backlog */
38327 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38328 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38329 __net_timestamp(skb);
38330 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38331 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38332 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38333 out:
38334 lvcc->rx.buf.ptr = end;
38335 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38336 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38337 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38338 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38339 lanai->stats.service_rxnotaal5++;
38340 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38341 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38342 return 0;
38343 }
38344 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38345 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38346 int bytes;
38347 read_unlock(&vcc_sklist_lock);
38348 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38349 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38350 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38351 lvcc->stats.x.aal5.service_trash++;
38352 bytes = (SERVICE_GET_END(s) * 16) -
38353 (((unsigned long) lvcc->rx.buf.ptr) -
38354 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38355 }
38356 if (s & SERVICE_STREAM) {
38357 read_unlock(&vcc_sklist_lock);
38358 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38359 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38360 lvcc->stats.x.aal5.service_stream++;
38361 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38362 "PDU on VCI %d!\n", lanai->number, vci);
38363 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38364 return 0;
38365 }
38366 DPRINTK("got rx crc error on vci %d\n", vci);
38367 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38368 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38369 lvcc->stats.x.aal5.service_rxcrc++;
38370 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38371 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38372 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38373 index 9988ac9..7c52585 100644
38374 --- a/drivers/atm/nicstar.c
38375 +++ b/drivers/atm/nicstar.c
38376 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38377 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38378 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38379 card->index);
38380 - atomic_inc(&vcc->stats->tx_err);
38381 + atomic_inc_unchecked(&vcc->stats->tx_err);
38382 dev_kfree_skb_any(skb);
38383 return -EINVAL;
38384 }
38385 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38386 if (!vc->tx) {
38387 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38388 card->index);
38389 - atomic_inc(&vcc->stats->tx_err);
38390 + atomic_inc_unchecked(&vcc->stats->tx_err);
38391 dev_kfree_skb_any(skb);
38392 return -EINVAL;
38393 }
38394 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38395 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38396 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38397 card->index);
38398 - atomic_inc(&vcc->stats->tx_err);
38399 + atomic_inc_unchecked(&vcc->stats->tx_err);
38400 dev_kfree_skb_any(skb);
38401 return -EINVAL;
38402 }
38403
38404 if (skb_shinfo(skb)->nr_frags != 0) {
38405 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38406 - atomic_inc(&vcc->stats->tx_err);
38407 + atomic_inc_unchecked(&vcc->stats->tx_err);
38408 dev_kfree_skb_any(skb);
38409 return -EINVAL;
38410 }
38411 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38412 }
38413
38414 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38415 - atomic_inc(&vcc->stats->tx_err);
38416 + atomic_inc_unchecked(&vcc->stats->tx_err);
38417 dev_kfree_skb_any(skb);
38418 return -EIO;
38419 }
38420 - atomic_inc(&vcc->stats->tx);
38421 + atomic_inc_unchecked(&vcc->stats->tx);
38422
38423 return 0;
38424 }
38425 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38426 printk
38427 ("nicstar%d: Can't allocate buffers for aal0.\n",
38428 card->index);
38429 - atomic_add(i, &vcc->stats->rx_drop);
38430 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38431 break;
38432 }
38433 if (!atm_charge(vcc, sb->truesize)) {
38434 RXPRINTK
38435 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38436 card->index);
38437 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38438 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38439 dev_kfree_skb_any(sb);
38440 break;
38441 }
38442 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38443 ATM_SKB(sb)->vcc = vcc;
38444 __net_timestamp(sb);
38445 vcc->push(vcc, sb);
38446 - atomic_inc(&vcc->stats->rx);
38447 + atomic_inc_unchecked(&vcc->stats->rx);
38448 cell += ATM_CELL_PAYLOAD;
38449 }
38450
38451 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38452 if (iovb == NULL) {
38453 printk("nicstar%d: Out of iovec buffers.\n",
38454 card->index);
38455 - atomic_inc(&vcc->stats->rx_drop);
38456 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38457 recycle_rx_buf(card, skb);
38458 return;
38459 }
38460 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38461 small or large buffer itself. */
38462 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38463 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38464 - atomic_inc(&vcc->stats->rx_err);
38465 + atomic_inc_unchecked(&vcc->stats->rx_err);
38466 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38467 NS_MAX_IOVECS);
38468 NS_PRV_IOVCNT(iovb) = 0;
38469 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38470 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38471 card->index);
38472 which_list(card, skb);
38473 - atomic_inc(&vcc->stats->rx_err);
38474 + atomic_inc_unchecked(&vcc->stats->rx_err);
38475 recycle_rx_buf(card, skb);
38476 vc->rx_iov = NULL;
38477 recycle_iov_buf(card, iovb);
38478 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38479 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38480 card->index);
38481 which_list(card, skb);
38482 - atomic_inc(&vcc->stats->rx_err);
38483 + atomic_inc_unchecked(&vcc->stats->rx_err);
38484 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38485 NS_PRV_IOVCNT(iovb));
38486 vc->rx_iov = NULL;
38487 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38488 printk(" - PDU size mismatch.\n");
38489 else
38490 printk(".\n");
38491 - atomic_inc(&vcc->stats->rx_err);
38492 + atomic_inc_unchecked(&vcc->stats->rx_err);
38493 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38494 NS_PRV_IOVCNT(iovb));
38495 vc->rx_iov = NULL;
38496 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38497 /* skb points to a small buffer */
38498 if (!atm_charge(vcc, skb->truesize)) {
38499 push_rxbufs(card, skb);
38500 - atomic_inc(&vcc->stats->rx_drop);
38501 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38502 } else {
38503 skb_put(skb, len);
38504 dequeue_sm_buf(card, skb);
38505 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38506 ATM_SKB(skb)->vcc = vcc;
38507 __net_timestamp(skb);
38508 vcc->push(vcc, skb);
38509 - atomic_inc(&vcc->stats->rx);
38510 + atomic_inc_unchecked(&vcc->stats->rx);
38511 }
38512 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38513 struct sk_buff *sb;
38514 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38515 if (len <= NS_SMBUFSIZE) {
38516 if (!atm_charge(vcc, sb->truesize)) {
38517 push_rxbufs(card, sb);
38518 - atomic_inc(&vcc->stats->rx_drop);
38519 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38520 } else {
38521 skb_put(sb, len);
38522 dequeue_sm_buf(card, sb);
38523 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38524 ATM_SKB(sb)->vcc = vcc;
38525 __net_timestamp(sb);
38526 vcc->push(vcc, sb);
38527 - atomic_inc(&vcc->stats->rx);
38528 + atomic_inc_unchecked(&vcc->stats->rx);
38529 }
38530
38531 push_rxbufs(card, skb);
38532 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38533
38534 if (!atm_charge(vcc, skb->truesize)) {
38535 push_rxbufs(card, skb);
38536 - atomic_inc(&vcc->stats->rx_drop);
38537 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38538 } else {
38539 dequeue_lg_buf(card, skb);
38540 #ifdef NS_USE_DESTRUCTORS
38541 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38542 ATM_SKB(skb)->vcc = vcc;
38543 __net_timestamp(skb);
38544 vcc->push(vcc, skb);
38545 - atomic_inc(&vcc->stats->rx);
38546 + atomic_inc_unchecked(&vcc->stats->rx);
38547 }
38548
38549 push_rxbufs(card, sb);
38550 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38551 printk
38552 ("nicstar%d: Out of huge buffers.\n",
38553 card->index);
38554 - atomic_inc(&vcc->stats->rx_drop);
38555 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38556 recycle_iovec_rx_bufs(card,
38557 (struct iovec *)
38558 iovb->data,
38559 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38560 card->hbpool.count++;
38561 } else
38562 dev_kfree_skb_any(hb);
38563 - atomic_inc(&vcc->stats->rx_drop);
38564 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38565 } else {
38566 /* Copy the small buffer to the huge buffer */
38567 sb = (struct sk_buff *)iov->iov_base;
38568 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38569 #endif /* NS_USE_DESTRUCTORS */
38570 __net_timestamp(hb);
38571 vcc->push(vcc, hb);
38572 - atomic_inc(&vcc->stats->rx);
38573 + atomic_inc_unchecked(&vcc->stats->rx);
38574 }
38575 }
38576
38577 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38578 index 7652e8d..db45069 100644
38579 --- a/drivers/atm/solos-pci.c
38580 +++ b/drivers/atm/solos-pci.c
38581 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38582 }
38583 atm_charge(vcc, skb->truesize);
38584 vcc->push(vcc, skb);
38585 - atomic_inc(&vcc->stats->rx);
38586 + atomic_inc_unchecked(&vcc->stats->rx);
38587 break;
38588
38589 case PKT_STATUS:
38590 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38591 vcc = SKB_CB(oldskb)->vcc;
38592
38593 if (vcc) {
38594 - atomic_inc(&vcc->stats->tx);
38595 + atomic_inc_unchecked(&vcc->stats->tx);
38596 solos_pop(vcc, oldskb);
38597 } else {
38598 dev_kfree_skb_irq(oldskb);
38599 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38600 index 0215934..ce9f5b1 100644
38601 --- a/drivers/atm/suni.c
38602 +++ b/drivers/atm/suni.c
38603 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38604
38605
38606 #define ADD_LIMITED(s,v) \
38607 - atomic_add((v),&stats->s); \
38608 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38609 + atomic_add_unchecked((v),&stats->s); \
38610 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38611
38612
38613 static void suni_hz(unsigned long from_timer)
38614 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38615 index 5120a96..e2572bd 100644
38616 --- a/drivers/atm/uPD98402.c
38617 +++ b/drivers/atm/uPD98402.c
38618 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38619 struct sonet_stats tmp;
38620 int error = 0;
38621
38622 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38623 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38624 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38625 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38626 if (zero && !error) {
38627 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38628
38629
38630 #define ADD_LIMITED(s,v) \
38631 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38632 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38633 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38634 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38635 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38636 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38637
38638
38639 static void stat_event(struct atm_dev *dev)
38640 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38641 if (reason & uPD98402_INT_PFM) stat_event(dev);
38642 if (reason & uPD98402_INT_PCO) {
38643 (void) GET(PCOCR); /* clear interrupt cause */
38644 - atomic_add(GET(HECCT),
38645 + atomic_add_unchecked(GET(HECCT),
38646 &PRIV(dev)->sonet_stats.uncorr_hcs);
38647 }
38648 if ((reason & uPD98402_INT_RFO) &&
38649 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38650 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38651 uPD98402_INT_LOS),PIMR); /* enable them */
38652 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38653 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38654 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38655 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38656 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38657 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38658 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38659 return 0;
38660 }
38661
38662 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38663 index 969c3c2..9b72956 100644
38664 --- a/drivers/atm/zatm.c
38665 +++ b/drivers/atm/zatm.c
38666 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38667 }
38668 if (!size) {
38669 dev_kfree_skb_irq(skb);
38670 - if (vcc) atomic_inc(&vcc->stats->rx_err);
38671 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38672 continue;
38673 }
38674 if (!atm_charge(vcc,skb->truesize)) {
38675 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38676 skb->len = size;
38677 ATM_SKB(skb)->vcc = vcc;
38678 vcc->push(vcc,skb);
38679 - atomic_inc(&vcc->stats->rx);
38680 + atomic_inc_unchecked(&vcc->stats->rx);
38681 }
38682 zout(pos & 0xffff,MTA(mbx));
38683 #if 0 /* probably a stupid idea */
38684 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38685 skb_queue_head(&zatm_vcc->backlog,skb);
38686 break;
38687 }
38688 - atomic_inc(&vcc->stats->tx);
38689 + atomic_inc_unchecked(&vcc->stats->tx);
38690 wake_up(&zatm_vcc->tx_wait);
38691 }
38692
38693 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38694 index 83e910a..b224a73 100644
38695 --- a/drivers/base/bus.c
38696 +++ b/drivers/base/bus.c
38697 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38698 return -EINVAL;
38699
38700 mutex_lock(&subsys->p->mutex);
38701 - list_add_tail(&sif->node, &subsys->p->interfaces);
38702 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38703 if (sif->add_dev) {
38704 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38705 while ((dev = subsys_dev_iter_next(&iter)))
38706 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38707 subsys = sif->subsys;
38708
38709 mutex_lock(&subsys->p->mutex);
38710 - list_del_init(&sif->node);
38711 + pax_list_del_init((struct list_head *)&sif->node);
38712 if (sif->remove_dev) {
38713 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38714 while ((dev = subsys_dev_iter_next(&iter)))
38715 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38716 index 25798db..15f130e 100644
38717 --- a/drivers/base/devtmpfs.c
38718 +++ b/drivers/base/devtmpfs.c
38719 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38720 if (!thread)
38721 return 0;
38722
38723 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38724 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38725 if (err)
38726 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38727 else
38728 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38729 *err = sys_unshare(CLONE_NEWNS);
38730 if (*err)
38731 goto out;
38732 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38733 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38734 if (*err)
38735 goto out;
38736 - sys_chdir("/.."); /* will traverse into overmounted root */
38737 - sys_chroot(".");
38738 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38739 + sys_chroot((char __force_user *)".");
38740 complete(&setup_done);
38741 while (1) {
38742 spin_lock(&req_lock);
38743 diff --git a/drivers/base/node.c b/drivers/base/node.c
38744 index d51c49c..28908df 100644
38745 --- a/drivers/base/node.c
38746 +++ b/drivers/base/node.c
38747 @@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38748 struct node_attr {
38749 struct device_attribute attr;
38750 enum node_states state;
38751 -};
38752 +} __do_const;
38753
38754 static ssize_t show_node_state(struct device *dev,
38755 struct device_attribute *attr, char *buf)
38756 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38757 index eee55c1..b8c9393 100644
38758 --- a/drivers/base/power/domain.c
38759 +++ b/drivers/base/power/domain.c
38760 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38761
38762 if (dev->power.subsys_data->domain_data) {
38763 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38764 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
38765 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38766 if (clear_td)
38767 - gpd_data->td = (struct gpd_timing_data){ 0 };
38768 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38769
38770 if (--gpd_data->refcount == 0) {
38771 dev->power.subsys_data->domain_data = NULL;
38772 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38773 {
38774 struct cpuidle_driver *cpuidle_drv;
38775 struct gpd_cpu_data *cpu_data;
38776 - struct cpuidle_state *idle_state;
38777 + cpuidle_state_no_const *idle_state;
38778 int ret = 0;
38779
38780 if (IS_ERR_OR_NULL(genpd) || state < 0)
38781 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38782 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38783 {
38784 struct gpd_cpu_data *cpu_data;
38785 - struct cpuidle_state *idle_state;
38786 + cpuidle_state_no_const *idle_state;
38787 int ret = 0;
38788
38789 if (IS_ERR_OR_NULL(genpd))
38790 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38791 index 95b181d1..c4f0e19 100644
38792 --- a/drivers/base/power/sysfs.c
38793 +++ b/drivers/base/power/sysfs.c
38794 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38795 return -EIO;
38796 }
38797 }
38798 - return sprintf(buf, p);
38799 + return sprintf(buf, "%s", p);
38800 }
38801
38802 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38803 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38804 index eb1bd2e..2667d3a 100644
38805 --- a/drivers/base/power/wakeup.c
38806 +++ b/drivers/base/power/wakeup.c
38807 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38808 * They need to be modified together atomically, so it's better to use one
38809 * atomic variable to hold them both.
38810 */
38811 -static atomic_t combined_event_count = ATOMIC_INIT(0);
38812 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38813
38814 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38815 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38816
38817 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38818 {
38819 - unsigned int comb = atomic_read(&combined_event_count);
38820 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
38821
38822 *cnt = (comb >> IN_PROGRESS_BITS);
38823 *inpr = comb & MAX_IN_PROGRESS;
38824 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38825 ws->start_prevent_time = ws->last_time;
38826
38827 /* Increment the counter of events in progress. */
38828 - cec = atomic_inc_return(&combined_event_count);
38829 + cec = atomic_inc_return_unchecked(&combined_event_count);
38830
38831 trace_wakeup_source_activate(ws->name, cec);
38832 }
38833 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38834 * Increment the counter of registered wakeup events and decrement the
38835 * couter of wakeup events in progress simultaneously.
38836 */
38837 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38838 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38839 trace_wakeup_source_deactivate(ws->name, cec);
38840
38841 split_counters(&cnt, &inpr);
38842 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38843 index dbb8350..4762f4c 100644
38844 --- a/drivers/base/syscore.c
38845 +++ b/drivers/base/syscore.c
38846 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38847 void register_syscore_ops(struct syscore_ops *ops)
38848 {
38849 mutex_lock(&syscore_ops_lock);
38850 - list_add_tail(&ops->node, &syscore_ops_list);
38851 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38852 mutex_unlock(&syscore_ops_lock);
38853 }
38854 EXPORT_SYMBOL_GPL(register_syscore_ops);
38855 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38856 void unregister_syscore_ops(struct syscore_ops *ops)
38857 {
38858 mutex_lock(&syscore_ops_lock);
38859 - list_del(&ops->node);
38860 + pax_list_del((struct list_head *)&ops->node);
38861 mutex_unlock(&syscore_ops_lock);
38862 }
38863 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38864 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38865 index ff20f19..018f1da 100644
38866 --- a/drivers/block/cciss.c
38867 +++ b/drivers/block/cciss.c
38868 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38869 while (!list_empty(&h->reqQ)) {
38870 c = list_entry(h->reqQ.next, CommandList_struct, list);
38871 /* can't do anything if fifo is full */
38872 - if ((h->access.fifo_full(h))) {
38873 + if ((h->access->fifo_full(h))) {
38874 dev_warn(&h->pdev->dev, "fifo full\n");
38875 break;
38876 }
38877 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38878 h->Qdepth--;
38879
38880 /* Tell the controller execute command */
38881 - h->access.submit_command(h, c);
38882 + h->access->submit_command(h, c);
38883
38884 /* Put job onto the completed Q */
38885 addQ(&h->cmpQ, c);
38886 @@ -3444,17 +3444,17 @@ startio:
38887
38888 static inline unsigned long get_next_completion(ctlr_info_t *h)
38889 {
38890 - return h->access.command_completed(h);
38891 + return h->access->command_completed(h);
38892 }
38893
38894 static inline int interrupt_pending(ctlr_info_t *h)
38895 {
38896 - return h->access.intr_pending(h);
38897 + return h->access->intr_pending(h);
38898 }
38899
38900 static inline long interrupt_not_for_us(ctlr_info_t *h)
38901 {
38902 - return ((h->access.intr_pending(h) == 0) ||
38903 + return ((h->access->intr_pending(h) == 0) ||
38904 (h->interrupts_enabled == 0));
38905 }
38906
38907 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38908 u32 a;
38909
38910 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38911 - return h->access.command_completed(h);
38912 + return h->access->command_completed(h);
38913
38914 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38915 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38916 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38917 trans_support & CFGTBL_Trans_use_short_tags);
38918
38919 /* Change the access methods to the performant access methods */
38920 - h->access = SA5_performant_access;
38921 + h->access = &SA5_performant_access;
38922 h->transMethod = CFGTBL_Trans_Performant;
38923
38924 return;
38925 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38926 if (prod_index < 0)
38927 return -ENODEV;
38928 h->product_name = products[prod_index].product_name;
38929 - h->access = *(products[prod_index].access);
38930 + h->access = products[prod_index].access;
38931
38932 if (cciss_board_disabled(h)) {
38933 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38934 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38935 }
38936
38937 /* make sure the board interrupts are off */
38938 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38939 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38940 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38941 if (rc)
38942 goto clean2;
38943 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38944 * fake ones to scoop up any residual completions.
38945 */
38946 spin_lock_irqsave(&h->lock, flags);
38947 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38948 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38949 spin_unlock_irqrestore(&h->lock, flags);
38950 free_irq(h->intr[h->intr_mode], h);
38951 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38952 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38953 dev_info(&h->pdev->dev, "Board READY.\n");
38954 dev_info(&h->pdev->dev,
38955 "Waiting for stale completions to drain.\n");
38956 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38957 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38958 msleep(10000);
38959 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38960 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38961
38962 rc = controller_reset_failed(h->cfgtable);
38963 if (rc)
38964 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38965 cciss_scsi_setup(h);
38966
38967 /* Turn the interrupts on so we can service requests */
38968 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38969 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38970
38971 /* Get the firmware version */
38972 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38973 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38974 kfree(flush_buf);
38975 if (return_code != IO_OK)
38976 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38977 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38978 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38979 free_irq(h->intr[h->intr_mode], h);
38980 }
38981
38982 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38983 index 7fda30e..2f27946 100644
38984 --- a/drivers/block/cciss.h
38985 +++ b/drivers/block/cciss.h
38986 @@ -101,7 +101,7 @@ struct ctlr_info
38987 /* information about each logical volume */
38988 drive_info_struct *drv[CISS_MAX_LUN];
38989
38990 - struct access_method access;
38991 + struct access_method *access;
38992
38993 /* queue and queue Info */
38994 struct list_head reqQ;
38995 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38996 }
38997
38998 static struct access_method SA5_access = {
38999 - SA5_submit_command,
39000 - SA5_intr_mask,
39001 - SA5_fifo_full,
39002 - SA5_intr_pending,
39003 - SA5_completed,
39004 + .submit_command = SA5_submit_command,
39005 + .set_intr_mask = SA5_intr_mask,
39006 + .fifo_full = SA5_fifo_full,
39007 + .intr_pending = SA5_intr_pending,
39008 + .command_completed = SA5_completed,
39009 };
39010
39011 static struct access_method SA5B_access = {
39012 - SA5_submit_command,
39013 - SA5B_intr_mask,
39014 - SA5_fifo_full,
39015 - SA5B_intr_pending,
39016 - SA5_completed,
39017 + .submit_command = SA5_submit_command,
39018 + .set_intr_mask = SA5B_intr_mask,
39019 + .fifo_full = SA5_fifo_full,
39020 + .intr_pending = SA5B_intr_pending,
39021 + .command_completed = SA5_completed,
39022 };
39023
39024 static struct access_method SA5_performant_access = {
39025 - SA5_submit_command,
39026 - SA5_performant_intr_mask,
39027 - SA5_fifo_full,
39028 - SA5_performant_intr_pending,
39029 - SA5_performant_completed,
39030 + .submit_command = SA5_submit_command,
39031 + .set_intr_mask = SA5_performant_intr_mask,
39032 + .fifo_full = SA5_fifo_full,
39033 + .intr_pending = SA5_performant_intr_pending,
39034 + .command_completed = SA5_performant_completed,
39035 };
39036
39037 struct board_type {
39038 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39039 index 2b94403..fd6ad1f 100644
39040 --- a/drivers/block/cpqarray.c
39041 +++ b/drivers/block/cpqarray.c
39042 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39043 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39044 goto Enomem4;
39045 }
39046 - hba[i]->access.set_intr_mask(hba[i], 0);
39047 + hba[i]->access->set_intr_mask(hba[i], 0);
39048 if (request_irq(hba[i]->intr, do_ida_intr,
39049 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39050 {
39051 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39052 add_timer(&hba[i]->timer);
39053
39054 /* Enable IRQ now that spinlock and rate limit timer are set up */
39055 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39056 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39057
39058 for(j=0; j<NWD; j++) {
39059 struct gendisk *disk = ida_gendisk[i][j];
39060 @@ -694,7 +694,7 @@ DBGINFO(
39061 for(i=0; i<NR_PRODUCTS; i++) {
39062 if (board_id == products[i].board_id) {
39063 c->product_name = products[i].product_name;
39064 - c->access = *(products[i].access);
39065 + c->access = products[i].access;
39066 break;
39067 }
39068 }
39069 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39070 hba[ctlr]->intr = intr;
39071 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39072 hba[ctlr]->product_name = products[j].product_name;
39073 - hba[ctlr]->access = *(products[j].access);
39074 + hba[ctlr]->access = products[j].access;
39075 hba[ctlr]->ctlr = ctlr;
39076 hba[ctlr]->board_id = board_id;
39077 hba[ctlr]->pci_dev = NULL; /* not PCI */
39078 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39079
39080 while((c = h->reqQ) != NULL) {
39081 /* Can't do anything if we're busy */
39082 - if (h->access.fifo_full(h) == 0)
39083 + if (h->access->fifo_full(h) == 0)
39084 return;
39085
39086 /* Get the first entry from the request Q */
39087 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39088 h->Qdepth--;
39089
39090 /* Tell the controller to do our bidding */
39091 - h->access.submit_command(h, c);
39092 + h->access->submit_command(h, c);
39093
39094 /* Get onto the completion Q */
39095 addQ(&h->cmpQ, c);
39096 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39097 unsigned long flags;
39098 __u32 a,a1;
39099
39100 - istat = h->access.intr_pending(h);
39101 + istat = h->access->intr_pending(h);
39102 /* Is this interrupt for us? */
39103 if (istat == 0)
39104 return IRQ_NONE;
39105 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39106 */
39107 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39108 if (istat & FIFO_NOT_EMPTY) {
39109 - while((a = h->access.command_completed(h))) {
39110 + while((a = h->access->command_completed(h))) {
39111 a1 = a; a &= ~3;
39112 if ((c = h->cmpQ) == NULL)
39113 {
39114 @@ -1448,11 +1448,11 @@ static int sendcmd(
39115 /*
39116 * Disable interrupt
39117 */
39118 - info_p->access.set_intr_mask(info_p, 0);
39119 + info_p->access->set_intr_mask(info_p, 0);
39120 /* Make sure there is room in the command FIFO */
39121 /* Actually it should be completely empty at this time. */
39122 for (i = 200000; i > 0; i--) {
39123 - temp = info_p->access.fifo_full(info_p);
39124 + temp = info_p->access->fifo_full(info_p);
39125 if (temp != 0) {
39126 break;
39127 }
39128 @@ -1465,7 +1465,7 @@ DBG(
39129 /*
39130 * Send the cmd
39131 */
39132 - info_p->access.submit_command(info_p, c);
39133 + info_p->access->submit_command(info_p, c);
39134 complete = pollcomplete(ctlr);
39135
39136 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39137 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39138 * we check the new geometry. Then turn interrupts back on when
39139 * we're done.
39140 */
39141 - host->access.set_intr_mask(host, 0);
39142 + host->access->set_intr_mask(host, 0);
39143 getgeometry(ctlr);
39144 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39145 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39146
39147 for(i=0; i<NWD; i++) {
39148 struct gendisk *disk = ida_gendisk[ctlr][i];
39149 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39150 /* Wait (up to 2 seconds) for a command to complete */
39151
39152 for (i = 200000; i > 0; i--) {
39153 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
39154 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
39155 if (done == 0) {
39156 udelay(10); /* a short fixed delay */
39157 } else
39158 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39159 index be73e9d..7fbf140 100644
39160 --- a/drivers/block/cpqarray.h
39161 +++ b/drivers/block/cpqarray.h
39162 @@ -99,7 +99,7 @@ struct ctlr_info {
39163 drv_info_t drv[NWD];
39164 struct proc_dir_entry *proc;
39165
39166 - struct access_method access;
39167 + struct access_method *access;
39168
39169 cmdlist_t *reqQ;
39170 cmdlist_t *cmpQ;
39171 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
39172 index 426c97a..8c58607 100644
39173 --- a/drivers/block/drbd/drbd_bitmap.c
39174 +++ b/drivers/block/drbd/drbd_bitmap.c
39175 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
39176 submit_bio(rw, bio);
39177 /* this should not count as user activity and cause the
39178 * resync to throttle -- see drbd_rs_should_slow_down(). */
39179 - atomic_add(len >> 9, &device->rs_sect_ev);
39180 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
39181 }
39182 }
39183
39184 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39185 index 1a00001..c0d4253 100644
39186 --- a/drivers/block/drbd/drbd_int.h
39187 +++ b/drivers/block/drbd/drbd_int.h
39188 @@ -387,7 +387,7 @@ struct drbd_epoch {
39189 struct drbd_connection *connection;
39190 struct list_head list;
39191 unsigned int barrier_nr;
39192 - atomic_t epoch_size; /* increased on every request added. */
39193 + atomic_unchecked_t epoch_size; /* increased on every request added. */
39194 atomic_t active; /* increased on every req. added, and dec on every finished. */
39195 unsigned long flags;
39196 };
39197 @@ -948,7 +948,7 @@ struct drbd_device {
39198 unsigned int al_tr_number;
39199 int al_tr_cycle;
39200 wait_queue_head_t seq_wait;
39201 - atomic_t packet_seq;
39202 + atomic_unchecked_t packet_seq;
39203 unsigned int peer_seq;
39204 spinlock_t peer_seq_lock;
39205 unsigned long comm_bm_set; /* communicated number of set bits. */
39206 @@ -957,8 +957,8 @@ struct drbd_device {
39207 struct mutex own_state_mutex;
39208 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
39209 char congestion_reason; /* Why we where congested... */
39210 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
39211 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
39212 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
39213 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
39214 int rs_last_sect_ev; /* counter to compare with */
39215 int rs_last_events; /* counter of read or write "events" (unit sectors)
39216 * on the lower level device when we last looked. */
39217 @@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39218 char __user *uoptval;
39219 int err;
39220
39221 - uoptval = (char __user __force *)optval;
39222 + uoptval = (char __force_user *)optval;
39223
39224 set_fs(KERNEL_DS);
39225 if (level == SOL_SOCKET)
39226 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39227 index 89c497c..9c736ae 100644
39228 --- a/drivers/block/drbd/drbd_interval.c
39229 +++ b/drivers/block/drbd/drbd_interval.c
39230 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39231 }
39232
39233 static const struct rb_augment_callbacks augment_callbacks = {
39234 - augment_propagate,
39235 - augment_copy,
39236 - augment_rotate,
39237 + .propagate = augment_propagate,
39238 + .copy = augment_copy,
39239 + .rotate = augment_rotate,
39240 };
39241
39242 /**
39243 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39244 index 9b465bb..00034ecf 100644
39245 --- a/drivers/block/drbd/drbd_main.c
39246 +++ b/drivers/block/drbd/drbd_main.c
39247 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39248 p->sector = sector;
39249 p->block_id = block_id;
39250 p->blksize = blksize;
39251 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39252 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39253 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39254 }
39255
39256 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39257 return -EIO;
39258 p->sector = cpu_to_be64(req->i.sector);
39259 p->block_id = (unsigned long)req;
39260 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39261 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39262 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39263 if (device->state.conn >= C_SYNC_SOURCE &&
39264 device->state.conn <= C_PAUSED_SYNC_T)
39265 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
39266 atomic_set(&device->unacked_cnt, 0);
39267 atomic_set(&device->local_cnt, 0);
39268 atomic_set(&device->pp_in_use_by_net, 0);
39269 - atomic_set(&device->rs_sect_in, 0);
39270 - atomic_set(&device->rs_sect_ev, 0);
39271 + atomic_set_unchecked(&device->rs_sect_in, 0);
39272 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39273 atomic_set(&device->ap_in_flight, 0);
39274 atomic_set(&device->md_io.in_use, 0);
39275
39276 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
39277 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39278 struct drbd_resource *resource = connection->resource;
39279
39280 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39281 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39282 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39283 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39284 kfree(connection->current_epoch);
39285
39286 idr_destroy(&connection->peer_devices);
39287 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39288 index 1cd47df..57c53c0 100644
39289 --- a/drivers/block/drbd/drbd_nl.c
39290 +++ b/drivers/block/drbd/drbd_nl.c
39291 @@ -3645,13 +3645,13 @@ finish:
39292
39293 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39294 {
39295 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39296 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39297 struct sk_buff *msg;
39298 struct drbd_genlmsghdr *d_out;
39299 unsigned seq;
39300 int err = -ENOMEM;
39301
39302 - seq = atomic_inc_return(&drbd_genl_seq);
39303 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39304 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39305 if (!msg)
39306 goto failed;
39307 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39308 index 9342b8d..b6a6825 100644
39309 --- a/drivers/block/drbd/drbd_receiver.c
39310 +++ b/drivers/block/drbd/drbd_receiver.c
39311 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39312 struct drbd_device *device = peer_device->device;
39313 int err;
39314
39315 - atomic_set(&device->packet_seq, 0);
39316 + atomic_set_unchecked(&device->packet_seq, 0);
39317 device->peer_seq = 0;
39318
39319 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39320 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39321 do {
39322 next_epoch = NULL;
39323
39324 - epoch_size = atomic_read(&epoch->epoch_size);
39325 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39326
39327 switch (ev & ~EV_CLEANUP) {
39328 case EV_PUT:
39329 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39330 rv = FE_DESTROYED;
39331 } else {
39332 epoch->flags = 0;
39333 - atomic_set(&epoch->epoch_size, 0);
39334 + atomic_set_unchecked(&epoch->epoch_size, 0);
39335 /* atomic_set(&epoch->active, 0); is already zero */
39336 if (rv == FE_STILL_LIVE)
39337 rv = FE_RECYCLED;
39338 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39339 conn_wait_active_ee_empty(connection);
39340 drbd_flush(connection);
39341
39342 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39343 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39344 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39345 if (epoch)
39346 break;
39347 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39348 }
39349
39350 epoch->flags = 0;
39351 - atomic_set(&epoch->epoch_size, 0);
39352 + atomic_set_unchecked(&epoch->epoch_size, 0);
39353 atomic_set(&epoch->active, 0);
39354
39355 spin_lock(&connection->epoch_lock);
39356 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39357 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39358 list_add(&epoch->list, &connection->current_epoch->list);
39359 connection->current_epoch = epoch;
39360 connection->epochs++;
39361 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39362 list_add_tail(&peer_req->w.list, &device->sync_ee);
39363 spin_unlock_irq(&device->resource->req_lock);
39364
39365 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
39366 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39367 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39368 return 0;
39369
39370 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39371 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39372 }
39373
39374 - atomic_add(pi->size >> 9, &device->rs_sect_in);
39375 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39376
39377 return err;
39378 }
39379 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39380
39381 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39382 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39383 - atomic_inc(&connection->current_epoch->epoch_size);
39384 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39385 err2 = drbd_drain_block(peer_device, pi->size);
39386 if (!err)
39387 err = err2;
39388 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39389
39390 spin_lock(&connection->epoch_lock);
39391 peer_req->epoch = connection->current_epoch;
39392 - atomic_inc(&peer_req->epoch->epoch_size);
39393 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39394 atomic_inc(&peer_req->epoch->active);
39395 spin_unlock(&connection->epoch_lock);
39396
39397 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39398
39399 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39400 (int)part_stat_read(&disk->part0, sectors[1]) -
39401 - atomic_read(&device->rs_sect_ev);
39402 + atomic_read_unchecked(&device->rs_sect_ev);
39403
39404 if (atomic_read(&device->ap_actlog_cnt)
39405 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39406 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39407 device->use_csums = true;
39408 } else if (pi->cmd == P_OV_REPLY) {
39409 /* track progress, we may need to throttle */
39410 - atomic_add(size >> 9, &device->rs_sect_in);
39411 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39412 peer_req->w.cb = w_e_end_ov_reply;
39413 dec_rs_pending(device);
39414 /* drbd_rs_begin_io done when we sent this request,
39415 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39416 goto out_free_e;
39417
39418 submit_for_resync:
39419 - atomic_add(size >> 9, &device->rs_sect_ev);
39420 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39421
39422 submit:
39423 update_receiver_timing_details(connection, drbd_submit_peer_request);
39424 @@ -4564,7 +4564,7 @@ struct data_cmd {
39425 int expect_payload;
39426 size_t pkt_size;
39427 int (*fn)(struct drbd_connection *, struct packet_info *);
39428 -};
39429 +} __do_const;
39430
39431 static struct data_cmd drbd_cmd_handler[] = {
39432 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39433 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39434 if (!list_empty(&connection->current_epoch->list))
39435 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39436 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39437 - atomic_set(&connection->current_epoch->epoch_size, 0);
39438 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39439 connection->send.seen_any_write_yet = false;
39440
39441 drbd_info(connection, "Connection closed\n");
39442 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39443 put_ldev(device);
39444 }
39445 dec_rs_pending(device);
39446 - atomic_add(blksize >> 9, &device->rs_sect_in);
39447 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39448
39449 return 0;
39450 }
39451 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39452 struct asender_cmd {
39453 size_t pkt_size;
39454 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39455 -};
39456 +} __do_const;
39457
39458 static struct asender_cmd asender_tbl[] = {
39459 [P_PING] = { 0, got_Ping },
39460 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39461 index 50776b3..1477c3f 100644
39462 --- a/drivers/block/drbd/drbd_worker.c
39463 +++ b/drivers/block/drbd/drbd_worker.c
39464 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39465 list_add_tail(&peer_req->w.list, &device->read_ee);
39466 spin_unlock_irq(&device->resource->req_lock);
39467
39468 - atomic_add(size >> 9, &device->rs_sect_ev);
39469 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39470 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39471 return 0;
39472
39473 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39474 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39475 int number, mxb;
39476
39477 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
39478 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39479 device->rs_in_flight -= sect_in;
39480
39481 rcu_read_lock();
39482 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39483 {
39484 struct fifo_buffer *plan;
39485
39486 - atomic_set(&device->rs_sect_in, 0);
39487 - atomic_set(&device->rs_sect_ev, 0);
39488 + atomic_set_unchecked(&device->rs_sect_in, 0);
39489 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39490 device->rs_in_flight = 0;
39491
39492 /* Updating the RCU protected object in place is necessary since
39493 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39494 index 6cb1beb..bf490f7 100644
39495 --- a/drivers/block/loop.c
39496 +++ b/drivers/block/loop.c
39497 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39498
39499 file_start_write(file);
39500 set_fs(get_ds());
39501 - bw = file->f_op->write(file, buf, len, &pos);
39502 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39503 set_fs(old_fs);
39504 file_end_write(file);
39505 if (likely(bw == len))
39506 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39507 index 02351e2..a9ea617 100644
39508 --- a/drivers/block/nvme-core.c
39509 +++ b/drivers/block/nvme-core.c
39510 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39511 static struct task_struct *nvme_thread;
39512 static struct workqueue_struct *nvme_workq;
39513 static wait_queue_head_t nvme_kthread_wait;
39514 -static struct notifier_block nvme_nb;
39515
39516 static void nvme_reset_failed_dev(struct work_struct *ws);
39517
39518 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39519 .err_handler = &nvme_err_handler,
39520 };
39521
39522 +static struct notifier_block nvme_nb = {
39523 + .notifier_call = &nvme_cpu_notify,
39524 +};
39525 +
39526 static int __init nvme_init(void)
39527 {
39528 int result;
39529 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39530 else if (result > 0)
39531 nvme_major = result;
39532
39533 - nvme_nb.notifier_call = &nvme_cpu_notify;
39534 result = register_hotcpu_notifier(&nvme_nb);
39535 if (result)
39536 goto unregister_blkdev;
39537 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39538 index 758ac44..58087fd 100644
39539 --- a/drivers/block/pktcdvd.c
39540 +++ b/drivers/block/pktcdvd.c
39541 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39542
39543 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39544 {
39545 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39546 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39547 }
39548
39549 /*
39550 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39551 return -EROFS;
39552 }
39553 pd->settings.fp = ti.fp;
39554 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39555 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39556
39557 if (ti.nwa_v) {
39558 pd->nwa = be32_to_cpu(ti.next_writable);
39559 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39560 index e5565fb..71be10b4 100644
39561 --- a/drivers/block/smart1,2.h
39562 +++ b/drivers/block/smart1,2.h
39563 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39564 }
39565
39566 static struct access_method smart4_access = {
39567 - smart4_submit_command,
39568 - smart4_intr_mask,
39569 - smart4_fifo_full,
39570 - smart4_intr_pending,
39571 - smart4_completed,
39572 + .submit_command = smart4_submit_command,
39573 + .set_intr_mask = smart4_intr_mask,
39574 + .fifo_full = smart4_fifo_full,
39575 + .intr_pending = smart4_intr_pending,
39576 + .command_completed = smart4_completed,
39577 };
39578
39579 /*
39580 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39581 }
39582
39583 static struct access_method smart2_access = {
39584 - smart2_submit_command,
39585 - smart2_intr_mask,
39586 - smart2_fifo_full,
39587 - smart2_intr_pending,
39588 - smart2_completed,
39589 + .submit_command = smart2_submit_command,
39590 + .set_intr_mask = smart2_intr_mask,
39591 + .fifo_full = smart2_fifo_full,
39592 + .intr_pending = smart2_intr_pending,
39593 + .command_completed = smart2_completed,
39594 };
39595
39596 /*
39597 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39598 }
39599
39600 static struct access_method smart2e_access = {
39601 - smart2e_submit_command,
39602 - smart2e_intr_mask,
39603 - smart2e_fifo_full,
39604 - smart2e_intr_pending,
39605 - smart2e_completed,
39606 + .submit_command = smart2e_submit_command,
39607 + .set_intr_mask = smart2e_intr_mask,
39608 + .fifo_full = smart2e_fifo_full,
39609 + .intr_pending = smart2e_intr_pending,
39610 + .command_completed = smart2e_completed,
39611 };
39612
39613 /*
39614 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39615 }
39616
39617 static struct access_method smart1_access = {
39618 - smart1_submit_command,
39619 - smart1_intr_mask,
39620 - smart1_fifo_full,
39621 - smart1_intr_pending,
39622 - smart1_completed,
39623 + .submit_command = smart1_submit_command,
39624 + .set_intr_mask = smart1_intr_mask,
39625 + .fifo_full = smart1_fifo_full,
39626 + .intr_pending = smart1_intr_pending,
39627 + .command_completed = smart1_completed,
39628 };
39629 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39630 index f038dba..bb74c08 100644
39631 --- a/drivers/bluetooth/btwilink.c
39632 +++ b/drivers/bluetooth/btwilink.c
39633 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39634
39635 static int bt_ti_probe(struct platform_device *pdev)
39636 {
39637 - static struct ti_st *hst;
39638 + struct ti_st *hst;
39639 struct hci_dev *hdev;
39640 int err;
39641
39642 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39643 index 898b84b..86f74b9 100644
39644 --- a/drivers/cdrom/cdrom.c
39645 +++ b/drivers/cdrom/cdrom.c
39646 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39647 ENSURE(reset, CDC_RESET);
39648 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39649 cdi->mc_flags = 0;
39650 - cdo->n_minors = 0;
39651 cdi->options = CDO_USE_FFLAGS;
39652
39653 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39654 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39655 else
39656 cdi->cdda_method = CDDA_OLD;
39657
39658 - if (!cdo->generic_packet)
39659 - cdo->generic_packet = cdrom_dummy_generic_packet;
39660 + if (!cdo->generic_packet) {
39661 + pax_open_kernel();
39662 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39663 + pax_close_kernel();
39664 + }
39665
39666 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39667 mutex_lock(&cdrom_mutex);
39668 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39669 if (cdi->exit)
39670 cdi->exit(cdi);
39671
39672 - cdi->ops->n_minors--;
39673 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39674 }
39675
39676 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39677 */
39678 nr = nframes;
39679 do {
39680 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39681 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39682 if (cgc.buffer)
39683 break;
39684
39685 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39686 struct cdrom_device_info *cdi;
39687 int ret;
39688
39689 - ret = scnprintf(info + *pos, max_size - *pos, header);
39690 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39691 if (!ret)
39692 return 1;
39693
39694 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39695 index 584bc31..e64a12c 100644
39696 --- a/drivers/cdrom/gdrom.c
39697 +++ b/drivers/cdrom/gdrom.c
39698 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39699 .audio_ioctl = gdrom_audio_ioctl,
39700 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39701 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39702 - .n_minors = 1,
39703 };
39704
39705 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39706 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39707 index 6e9f74a..50c7cea 100644
39708 --- a/drivers/char/Kconfig
39709 +++ b/drivers/char/Kconfig
39710 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39711
39712 config DEVKMEM
39713 bool "/dev/kmem virtual device support"
39714 - default y
39715 + default n
39716 + depends on !GRKERNSEC_KMEM
39717 help
39718 Say Y here if you want to support the /dev/kmem device. The
39719 /dev/kmem device is rarely used, but can be used for certain
39720 @@ -577,6 +578,7 @@ config DEVPORT
39721 bool
39722 depends on !M68K
39723 depends on ISA || PCI
39724 + depends on !GRKERNSEC_KMEM
39725 default y
39726
39727 source "drivers/s390/char/Kconfig"
39728 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39729 index a48e05b..6bac831 100644
39730 --- a/drivers/char/agp/compat_ioctl.c
39731 +++ b/drivers/char/agp/compat_ioctl.c
39732 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39733 return -ENOMEM;
39734 }
39735
39736 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39737 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39738 sizeof(*usegment) * ureserve.seg_count)) {
39739 kfree(usegment);
39740 kfree(ksegment);
39741 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39742 index 09f17eb..8531d2f 100644
39743 --- a/drivers/char/agp/frontend.c
39744 +++ b/drivers/char/agp/frontend.c
39745 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39746 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39747 return -EFAULT;
39748
39749 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39750 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39751 return -EFAULT;
39752
39753 client = agp_find_client_by_pid(reserve.pid);
39754 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39755 if (segment == NULL)
39756 return -ENOMEM;
39757
39758 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
39759 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39760 sizeof(struct agp_segment) * reserve.seg_count)) {
39761 kfree(segment);
39762 return -EFAULT;
39763 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39764 index 4f94375..413694e 100644
39765 --- a/drivers/char/genrtc.c
39766 +++ b/drivers/char/genrtc.c
39767 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39768 switch (cmd) {
39769
39770 case RTC_PLL_GET:
39771 + memset(&pll, 0, sizeof(pll));
39772 if (get_rtc_pll(&pll))
39773 return -EINVAL;
39774 else
39775 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39776 index d5d4cd8..22d561d 100644
39777 --- a/drivers/char/hpet.c
39778 +++ b/drivers/char/hpet.c
39779 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39780 }
39781
39782 static int
39783 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39784 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39785 struct hpet_info *info)
39786 {
39787 struct hpet_timer __iomem *timer;
39788 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39789 index 86fe45c..c0ea948 100644
39790 --- a/drivers/char/hw_random/intel-rng.c
39791 +++ b/drivers/char/hw_random/intel-rng.c
39792 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39793
39794 if (no_fwh_detect)
39795 return -ENODEV;
39796 - printk(warning);
39797 + printk("%s", warning);
39798 return -EBUSY;
39799 }
39800
39801 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39802 index e6db938..835e3a2 100644
39803 --- a/drivers/char/ipmi/ipmi_msghandler.c
39804 +++ b/drivers/char/ipmi/ipmi_msghandler.c
39805 @@ -438,7 +438,7 @@ struct ipmi_smi {
39806 struct proc_dir_entry *proc_dir;
39807 char proc_dir_name[10];
39808
39809 - atomic_t stats[IPMI_NUM_STATS];
39810 + atomic_unchecked_t stats[IPMI_NUM_STATS];
39811
39812 /*
39813 * run_to_completion duplicate of smb_info, smi_info
39814 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39815 static DEFINE_MUTEX(smi_watchers_mutex);
39816
39817 #define ipmi_inc_stat(intf, stat) \
39818 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39819 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39820 #define ipmi_get_stat(intf, stat) \
39821 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39822 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39823
39824 static int is_lan_addr(struct ipmi_addr *addr)
39825 {
39826 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39827 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39828 init_waitqueue_head(&intf->waitq);
39829 for (i = 0; i < IPMI_NUM_STATS; i++)
39830 - atomic_set(&intf->stats[i], 0);
39831 + atomic_set_unchecked(&intf->stats[i], 0);
39832
39833 intf->proc_dir = NULL;
39834
39835 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39836 index 5d66568..c9d93c3 100644
39837 --- a/drivers/char/ipmi/ipmi_si_intf.c
39838 +++ b/drivers/char/ipmi/ipmi_si_intf.c
39839 @@ -285,7 +285,7 @@ struct smi_info {
39840 unsigned char slave_addr;
39841
39842 /* Counters and things for the proc filesystem. */
39843 - atomic_t stats[SI_NUM_STATS];
39844 + atomic_unchecked_t stats[SI_NUM_STATS];
39845
39846 struct task_struct *thread;
39847
39848 @@ -294,9 +294,9 @@ struct smi_info {
39849 };
39850
39851 #define smi_inc_stat(smi, stat) \
39852 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39853 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39854 #define smi_get_stat(smi, stat) \
39855 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39856 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39857
39858 #define SI_MAX_PARMS 4
39859
39860 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39861 atomic_set(&new_smi->req_events, 0);
39862 new_smi->run_to_completion = false;
39863 for (i = 0; i < SI_NUM_STATS; i++)
39864 - atomic_set(&new_smi->stats[i], 0);
39865 + atomic_set_unchecked(&new_smi->stats[i], 0);
39866
39867 new_smi->interrupt_disabled = true;
39868 atomic_set(&new_smi->stop_operation, 0);
39869 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39870 index 917403f..dddd899 100644
39871 --- a/drivers/char/mem.c
39872 +++ b/drivers/char/mem.c
39873 @@ -18,6 +18,7 @@
39874 #include <linux/raw.h>
39875 #include <linux/tty.h>
39876 #include <linux/capability.h>
39877 +#include <linux/security.h>
39878 #include <linux/ptrace.h>
39879 #include <linux/device.h>
39880 #include <linux/highmem.h>
39881 @@ -36,6 +37,10 @@
39882
39883 #define DEVPORT_MINOR 4
39884
39885 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39886 +extern const struct file_operations grsec_fops;
39887 +#endif
39888 +
39889 static inline unsigned long size_inside_page(unsigned long start,
39890 unsigned long size)
39891 {
39892 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39893
39894 while (cursor < to) {
39895 if (!devmem_is_allowed(pfn)) {
39896 +#ifdef CONFIG_GRKERNSEC_KMEM
39897 + gr_handle_mem_readwrite(from, to);
39898 +#else
39899 printk(KERN_INFO
39900 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39901 current->comm, from, to);
39902 +#endif
39903 return 0;
39904 }
39905 cursor += PAGE_SIZE;
39906 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39907 }
39908 return 1;
39909 }
39910 +#elif defined(CONFIG_GRKERNSEC_KMEM)
39911 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39912 +{
39913 + return 0;
39914 +}
39915 #else
39916 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39917 {
39918 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39919
39920 while (count > 0) {
39921 unsigned long remaining;
39922 + char *temp;
39923
39924 sz = size_inside_page(p, count);
39925
39926 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39927 if (!ptr)
39928 return -EFAULT;
39929
39930 - remaining = copy_to_user(buf, ptr, sz);
39931 +#ifdef CONFIG_PAX_USERCOPY
39932 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39933 + if (!temp) {
39934 + unxlate_dev_mem_ptr(p, ptr);
39935 + return -ENOMEM;
39936 + }
39937 + memcpy(temp, ptr, sz);
39938 +#else
39939 + temp = ptr;
39940 +#endif
39941 +
39942 + remaining = copy_to_user(buf, temp, sz);
39943 +
39944 +#ifdef CONFIG_PAX_USERCOPY
39945 + kfree(temp);
39946 +#endif
39947 +
39948 unxlate_dev_mem_ptr(p, ptr);
39949 if (remaining)
39950 return -EFAULT;
39951 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39952 size_t count, loff_t *ppos)
39953 {
39954 unsigned long p = *ppos;
39955 - ssize_t low_count, read, sz;
39956 + ssize_t low_count, read, sz, err = 0;
39957 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39958 - int err = 0;
39959
39960 read = 0;
39961 if (p < (unsigned long) high_memory) {
39962 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39963 }
39964 #endif
39965 while (low_count > 0) {
39966 + char *temp;
39967 +
39968 sz = size_inside_page(p, low_count);
39969
39970 /*
39971 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39972 */
39973 kbuf = xlate_dev_kmem_ptr((char *)p);
39974
39975 - if (copy_to_user(buf, kbuf, sz))
39976 +#ifdef CONFIG_PAX_USERCOPY
39977 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39978 + if (!temp)
39979 + return -ENOMEM;
39980 + memcpy(temp, kbuf, sz);
39981 +#else
39982 + temp = kbuf;
39983 +#endif
39984 +
39985 + err = copy_to_user(buf, temp, sz);
39986 +
39987 +#ifdef CONFIG_PAX_USERCOPY
39988 + kfree(temp);
39989 +#endif
39990 +
39991 + if (err)
39992 return -EFAULT;
39993 buf += sz;
39994 p += sz;
39995 @@ -827,6 +874,9 @@ static const struct memdev {
39996 #ifdef CONFIG_PRINTK
39997 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39998 #endif
39999 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40000 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
40001 +#endif
40002 };
40003
40004 static int memory_open(struct inode *inode, struct file *filp)
40005 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
40006 continue;
40007
40008 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
40009 - NULL, devlist[minor].name);
40010 + NULL, "%s", devlist[minor].name);
40011 }
40012
40013 return tty_init();
40014 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
40015 index 9df78e2..01ba9ae 100644
40016 --- a/drivers/char/nvram.c
40017 +++ b/drivers/char/nvram.c
40018 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40019
40020 spin_unlock_irq(&rtc_lock);
40021
40022 - if (copy_to_user(buf, contents, tmp - contents))
40023 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40024 return -EFAULT;
40025
40026 *ppos = i;
40027 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40028 index 0ea9986..e7b07e4 100644
40029 --- a/drivers/char/pcmcia/synclink_cs.c
40030 +++ b/drivers/char/pcmcia/synclink_cs.c
40031 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40032
40033 if (debug_level >= DEBUG_LEVEL_INFO)
40034 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40035 - __FILE__, __LINE__, info->device_name, port->count);
40036 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40037
40038 if (tty_port_close_start(port, tty, filp) == 0)
40039 goto cleanup;
40040 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40041 cleanup:
40042 if (debug_level >= DEBUG_LEVEL_INFO)
40043 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40044 - tty->driver->name, port->count);
40045 + tty->driver->name, atomic_read(&port->count));
40046 }
40047
40048 /* Wait until the transmitter is empty.
40049 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40050
40051 if (debug_level >= DEBUG_LEVEL_INFO)
40052 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40053 - __FILE__, __LINE__, tty->driver->name, port->count);
40054 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40055
40056 /* If port is closing, signal caller to try again */
40057 if (port->flags & ASYNC_CLOSING){
40058 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40059 goto cleanup;
40060 }
40061 spin_lock(&port->lock);
40062 - port->count++;
40063 + atomic_inc(&port->count);
40064 spin_unlock(&port->lock);
40065 spin_unlock_irqrestore(&info->netlock, flags);
40066
40067 - if (port->count == 1) {
40068 + if (atomic_read(&port->count) == 1) {
40069 /* 1st open on this device, init hardware */
40070 retval = startup(info, tty);
40071 if (retval < 0)
40072 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40073 unsigned short new_crctype;
40074
40075 /* return error if TTY interface open */
40076 - if (info->port.count)
40077 + if (atomic_read(&info->port.count))
40078 return -EBUSY;
40079
40080 switch (encoding)
40081 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
40082
40083 /* arbitrate between network and tty opens */
40084 spin_lock_irqsave(&info->netlock, flags);
40085 - if (info->port.count != 0 || info->netcount != 0) {
40086 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40087 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40088 spin_unlock_irqrestore(&info->netlock, flags);
40089 return -EBUSY;
40090 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40091 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40092
40093 /* return error if TTY interface open */
40094 - if (info->port.count)
40095 + if (atomic_read(&info->port.count))
40096 return -EBUSY;
40097
40098 if (cmd != SIOCWANDEV)
40099 diff --git a/drivers/char/random.c b/drivers/char/random.c
40100 index c18d41d..7c499f3 100644
40101 --- a/drivers/char/random.c
40102 +++ b/drivers/char/random.c
40103 @@ -289,9 +289,6 @@
40104 /*
40105 * To allow fractional bits to be tracked, the entropy_count field is
40106 * denominated in units of 1/8th bits.
40107 - *
40108 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40109 - * credit_entropy_bits() needs to be 64 bits wide.
40110 */
40111 #define ENTROPY_SHIFT 3
40112 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40113 @@ -439,9 +436,9 @@ struct entropy_store {
40114 };
40115
40116 static void push_to_pool(struct work_struct *work);
40117 -static __u32 input_pool_data[INPUT_POOL_WORDS];
40118 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40119 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40120 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40121 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40122 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40123
40124 static struct entropy_store input_pool = {
40125 .poolinfo = &poolinfo_table[0],
40126 @@ -635,7 +632,7 @@ retry:
40127 /* The +2 corresponds to the /4 in the denominator */
40128
40129 do {
40130 - unsigned int anfrac = min(pnfrac, pool_size/2);
40131 + u64 anfrac = min(pnfrac, pool_size/2);
40132 unsigned int add =
40133 ((pool_size - entropy_count)*anfrac*3) >> s;
40134
40135 @@ -1106,7 +1103,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
40136 __mix_pool_bytes(r, hash.w, sizeof(hash.w));
40137 spin_unlock_irqrestore(&r->lock, flags);
40138
40139 - memset(workspace, 0, sizeof(workspace));
40140 + memzero_explicit(workspace, sizeof(workspace));
40141
40142 /*
40143 * In case the hash function has some recognizable output
40144 @@ -1118,7 +1115,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
40145 hash.w[2] ^= rol32(hash.w[2], 16);
40146
40147 memcpy(out, &hash, EXTRACT_SIZE);
40148 - memset(&hash, 0, sizeof(hash));
40149 + memzero_explicit(&hash, sizeof(hash));
40150 }
40151
40152 /*
40153 @@ -1175,7 +1172,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
40154 }
40155
40156 /* Wipe data just returned from memory */
40157 - memset(tmp, 0, sizeof(tmp));
40158 + memzero_explicit(tmp, sizeof(tmp));
40159
40160 return ret;
40161 }
40162 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40163
40164 extract_buf(r, tmp);
40165 i = min_t(int, nbytes, EXTRACT_SIZE);
40166 - if (copy_to_user(buf, tmp, i)) {
40167 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40168 ret = -EFAULT;
40169 break;
40170 }
40171 @@ -1218,7 +1215,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40172 }
40173
40174 /* Wipe data just returned from memory */
40175 - memset(tmp, 0, sizeof(tmp));
40176 + memzero_explicit(tmp, sizeof(tmp));
40177
40178 return ret;
40179 }
40180 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
40181 static int proc_do_uuid(struct ctl_table *table, int write,
40182 void __user *buffer, size_t *lenp, loff_t *ppos)
40183 {
40184 - struct ctl_table fake_table;
40185 + ctl_table_no_const fake_table;
40186 unsigned char buf[64], tmp_uuid[16], *uuid;
40187
40188 uuid = table->data;
40189 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40190 static int proc_do_entropy(struct ctl_table *table, int write,
40191 void __user *buffer, size_t *lenp, loff_t *ppos)
40192 {
40193 - struct ctl_table fake_table;
40194 + ctl_table_no_const fake_table;
40195 int entropy_count;
40196
40197 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40198 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40199 index 7cc1fe22..b602d6b 100644
40200 --- a/drivers/char/sonypi.c
40201 +++ b/drivers/char/sonypi.c
40202 @@ -54,6 +54,7 @@
40203
40204 #include <asm/uaccess.h>
40205 #include <asm/io.h>
40206 +#include <asm/local.h>
40207
40208 #include <linux/sonypi.h>
40209
40210 @@ -490,7 +491,7 @@ static struct sonypi_device {
40211 spinlock_t fifo_lock;
40212 wait_queue_head_t fifo_proc_list;
40213 struct fasync_struct *fifo_async;
40214 - int open_count;
40215 + local_t open_count;
40216 int model;
40217 struct input_dev *input_jog_dev;
40218 struct input_dev *input_key_dev;
40219 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40220 static int sonypi_misc_release(struct inode *inode, struct file *file)
40221 {
40222 mutex_lock(&sonypi_device.lock);
40223 - sonypi_device.open_count--;
40224 + local_dec(&sonypi_device.open_count);
40225 mutex_unlock(&sonypi_device.lock);
40226 return 0;
40227 }
40228 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40229 {
40230 mutex_lock(&sonypi_device.lock);
40231 /* Flush input queue on first open */
40232 - if (!sonypi_device.open_count)
40233 + if (!local_read(&sonypi_device.open_count))
40234 kfifo_reset(&sonypi_device.fifo);
40235 - sonypi_device.open_count++;
40236 + local_inc(&sonypi_device.open_count);
40237 mutex_unlock(&sonypi_device.lock);
40238
40239 return 0;
40240 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40241 index 565a947..dcdc06e 100644
40242 --- a/drivers/char/tpm/tpm_acpi.c
40243 +++ b/drivers/char/tpm/tpm_acpi.c
40244 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40245 virt = acpi_os_map_iomem(start, len);
40246 if (!virt) {
40247 kfree(log->bios_event_log);
40248 + log->bios_event_log = NULL;
40249 printk("%s: ERROR - Unable to map memory\n", __func__);
40250 return -EIO;
40251 }
40252
40253 - memcpy_fromio(log->bios_event_log, virt, len);
40254 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40255
40256 acpi_os_unmap_iomem(virt, len);
40257 return 0;
40258 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40259 index 3a56a13..f8cbd25 100644
40260 --- a/drivers/char/tpm/tpm_eventlog.c
40261 +++ b/drivers/char/tpm/tpm_eventlog.c
40262 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40263 event = addr;
40264
40265 if ((event->event_type == 0 && event->event_size == 0) ||
40266 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40267 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40268 return NULL;
40269
40270 return addr;
40271 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40272 return NULL;
40273
40274 if ((event->event_type == 0 && event->event_size == 0) ||
40275 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40276 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40277 return NULL;
40278
40279 (*pos)++;
40280 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40281 int i;
40282
40283 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40284 - seq_putc(m, data[i]);
40285 + if (!seq_putc(m, data[i]))
40286 + return -EFAULT;
40287
40288 return 0;
40289 }
40290 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40291 index b585b47..488f43e 100644
40292 --- a/drivers/char/virtio_console.c
40293 +++ b/drivers/char/virtio_console.c
40294 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40295 if (to_user) {
40296 ssize_t ret;
40297
40298 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40299 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40300 if (ret)
40301 return -EFAULT;
40302 } else {
40303 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40304 if (!port_has_data(port) && !port->host_connected)
40305 return 0;
40306
40307 - return fill_readbuf(port, ubuf, count, true);
40308 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40309 }
40310
40311 static int wait_port_writable(struct port *port, bool nonblock)
40312 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40313 index b9355da..9611f4e 100644
40314 --- a/drivers/clk/clk-composite.c
40315 +++ b/drivers/clk/clk-composite.c
40316 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40317 struct clk *clk;
40318 struct clk_init_data init;
40319 struct clk_composite *composite;
40320 - struct clk_ops *clk_composite_ops;
40321 + clk_ops_no_const *clk_composite_ops;
40322
40323 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40324 if (!composite) {
40325 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40326 index dd3a78c..386d49c 100644
40327 --- a/drivers/clk/socfpga/clk-gate.c
40328 +++ b/drivers/clk/socfpga/clk-gate.c
40329 @@ -22,6 +22,7 @@
40330 #include <linux/mfd/syscon.h>
40331 #include <linux/of.h>
40332 #include <linux/regmap.h>
40333 +#include <asm/pgtable.h>
40334
40335 #include "clk.h"
40336
40337 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40338 return 0;
40339 }
40340
40341 -static struct clk_ops gateclk_ops = {
40342 +static clk_ops_no_const gateclk_ops __read_only = {
40343 .prepare = socfpga_clk_prepare,
40344 .recalc_rate = socfpga_clk_recalc_rate,
40345 .get_parent = socfpga_clk_get_parent,
40346 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40347 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40348 socfpga_clk->hw.bit_idx = clk_gate[1];
40349
40350 - gateclk_ops.enable = clk_gate_ops.enable;
40351 - gateclk_ops.disable = clk_gate_ops.disable;
40352 + pax_open_kernel();
40353 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40354 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40355 + pax_close_kernel();
40356 }
40357
40358 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40359 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40360 index de6da95..c98278b 100644
40361 --- a/drivers/clk/socfpga/clk-pll.c
40362 +++ b/drivers/clk/socfpga/clk-pll.c
40363 @@ -21,6 +21,7 @@
40364 #include <linux/io.h>
40365 #include <linux/of.h>
40366 #include <linux/of_address.h>
40367 +#include <asm/pgtable.h>
40368
40369 #include "clk.h"
40370
40371 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40372 CLK_MGR_PLL_CLK_SRC_MASK;
40373 }
40374
40375 -static struct clk_ops clk_pll_ops = {
40376 +static clk_ops_no_const clk_pll_ops __read_only = {
40377 .recalc_rate = clk_pll_recalc_rate,
40378 .get_parent = clk_pll_get_parent,
40379 };
40380 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40381 pll_clk->hw.hw.init = &init;
40382
40383 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40384 - clk_pll_ops.enable = clk_gate_ops.enable;
40385 - clk_pll_ops.disable = clk_gate_ops.disable;
40386 + pax_open_kernel();
40387 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40388 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40389 + pax_close_kernel();
40390
40391 clk = clk_register(NULL, &pll_clk->hw.hw);
40392 if (WARN_ON(IS_ERR(clk))) {
40393 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40394 index b0c18ed..1713a80 100644
40395 --- a/drivers/cpufreq/acpi-cpufreq.c
40396 +++ b/drivers/cpufreq/acpi-cpufreq.c
40397 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40398 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40399 per_cpu(acfreq_data, cpu) = data;
40400
40401 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40402 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40403 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40404 + pax_open_kernel();
40405 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40406 + pax_close_kernel();
40407 + }
40408
40409 result = acpi_processor_register_performance(data->acpi_data, cpu);
40410 if (result)
40411 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40412 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40413 break;
40414 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40415 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40416 + pax_open_kernel();
40417 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40418 + pax_close_kernel();
40419 break;
40420 default:
40421 break;
40422 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40423 if (!msrs)
40424 return;
40425
40426 - acpi_cpufreq_driver.boost_supported = true;
40427 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40428 + pax_open_kernel();
40429 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40430 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40431 + pax_close_kernel();
40432
40433 cpu_notifier_register_begin();
40434
40435 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40436 index 61190f6..fcd899a 100644
40437 --- a/drivers/cpufreq/cpufreq.c
40438 +++ b/drivers/cpufreq/cpufreq.c
40439 @@ -2095,7 +2095,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40440 }
40441
40442 mutex_lock(&cpufreq_governor_mutex);
40443 - list_del(&governor->governor_list);
40444 + pax_list_del(&governor->governor_list);
40445 mutex_unlock(&cpufreq_governor_mutex);
40446 return;
40447 }
40448 @@ -2311,7 +2311,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40449 return NOTIFY_OK;
40450 }
40451
40452 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40453 +static struct notifier_block cpufreq_cpu_notifier = {
40454 .notifier_call = cpufreq_cpu_callback,
40455 };
40456
40457 @@ -2351,13 +2351,17 @@ int cpufreq_boost_trigger_state(int state)
40458 return 0;
40459
40460 write_lock_irqsave(&cpufreq_driver_lock, flags);
40461 - cpufreq_driver->boost_enabled = state;
40462 + pax_open_kernel();
40463 + *(bool *)&cpufreq_driver->boost_enabled = state;
40464 + pax_close_kernel();
40465 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40466
40467 ret = cpufreq_driver->set_boost(state);
40468 if (ret) {
40469 write_lock_irqsave(&cpufreq_driver_lock, flags);
40470 - cpufreq_driver->boost_enabled = !state;
40471 + pax_open_kernel();
40472 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40473 + pax_close_kernel();
40474 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40475
40476 pr_err("%s: Cannot %s BOOST\n",
40477 @@ -2414,8 +2418,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40478
40479 pr_debug("trying to register driver %s\n", driver_data->name);
40480
40481 - if (driver_data->setpolicy)
40482 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40483 + if (driver_data->setpolicy) {
40484 + pax_open_kernel();
40485 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40486 + pax_close_kernel();
40487 + }
40488
40489 write_lock_irqsave(&cpufreq_driver_lock, flags);
40490 if (cpufreq_driver) {
40491 @@ -2430,8 +2437,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40492 * Check if driver provides function to enable boost -
40493 * if not, use cpufreq_boost_set_sw as default
40494 */
40495 - if (!cpufreq_driver->set_boost)
40496 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40497 + if (!cpufreq_driver->set_boost) {
40498 + pax_open_kernel();
40499 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40500 + pax_close_kernel();
40501 + }
40502
40503 ret = cpufreq_sysfs_create_file(&boost.attr);
40504 if (ret) {
40505 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40506 index 1b44496..b80ff5e 100644
40507 --- a/drivers/cpufreq/cpufreq_governor.c
40508 +++ b/drivers/cpufreq/cpufreq_governor.c
40509 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40510 struct dbs_data *dbs_data;
40511 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40512 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40513 - struct od_ops *od_ops = NULL;
40514 + const struct od_ops *od_ops = NULL;
40515 struct od_dbs_tuners *od_tuners = NULL;
40516 struct cs_dbs_tuners *cs_tuners = NULL;
40517 struct cpu_dbs_common_info *cpu_cdbs;
40518 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40519
40520 if ((cdata->governor == GOV_CONSERVATIVE) &&
40521 (!policy->governor->initialized)) {
40522 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40523 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40524
40525 cpufreq_register_notifier(cs_ops->notifier_block,
40526 CPUFREQ_TRANSITION_NOTIFIER);
40527 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40528
40529 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40530 (policy->governor->initialized == 1)) {
40531 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40532 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40533
40534 cpufreq_unregister_notifier(cs_ops->notifier_block,
40535 CPUFREQ_TRANSITION_NOTIFIER);
40536 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40537 index cc401d1..8197340 100644
40538 --- a/drivers/cpufreq/cpufreq_governor.h
40539 +++ b/drivers/cpufreq/cpufreq_governor.h
40540 @@ -212,7 +212,7 @@ struct common_dbs_data {
40541 void (*exit)(struct dbs_data *dbs_data);
40542
40543 /* Governor specific ops, see below */
40544 - void *gov_ops;
40545 + const void *gov_ops;
40546 };
40547
40548 /* Governor Per policy data */
40549 @@ -232,7 +232,7 @@ struct od_ops {
40550 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40551 unsigned int freq_next, unsigned int relation);
40552 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40553 -};
40554 +} __no_const;
40555
40556 struct cs_ops {
40557 struct notifier_block *notifier_block;
40558 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40559 index ad3f38f..8f086cd 100644
40560 --- a/drivers/cpufreq/cpufreq_ondemand.c
40561 +++ b/drivers/cpufreq/cpufreq_ondemand.c
40562 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40563
40564 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40565
40566 -static struct od_ops od_ops = {
40567 +static struct od_ops od_ops __read_only = {
40568 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40569 .powersave_bias_target = generic_powersave_bias_target,
40570 .freq_increase = dbs_freq_increase,
40571 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40572 (struct cpufreq_policy *, unsigned int, unsigned int),
40573 unsigned int powersave_bias)
40574 {
40575 - od_ops.powersave_bias_target = f;
40576 + pax_open_kernel();
40577 + *(void **)&od_ops.powersave_bias_target = f;
40578 + pax_close_kernel();
40579 od_set_powersave_bias(powersave_bias);
40580 }
40581 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40582
40583 void od_unregister_powersave_bias_handler(void)
40584 {
40585 - od_ops.powersave_bias_target = generic_powersave_bias_target;
40586 + pax_open_kernel();
40587 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40588 + pax_close_kernel();
40589 od_set_powersave_bias(0);
40590 }
40591 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40592 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40593 index 0668b38..2f3ea18 100644
40594 --- a/drivers/cpufreq/intel_pstate.c
40595 +++ b/drivers/cpufreq/intel_pstate.c
40596 @@ -120,10 +120,10 @@ struct pstate_funcs {
40597 struct cpu_defaults {
40598 struct pstate_adjust_policy pid_policy;
40599 struct pstate_funcs funcs;
40600 -};
40601 +} __do_const;
40602
40603 static struct pstate_adjust_policy pid_params;
40604 -static struct pstate_funcs pstate_funcs;
40605 +static struct pstate_funcs *pstate_funcs;
40606
40607 struct perf_limits {
40608 int no_turbo;
40609 @@ -527,17 +527,17 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40610
40611 cpu->pstate.current_pstate = pstate;
40612
40613 - pstate_funcs.set(cpu, pstate);
40614 + pstate_funcs->set(cpu, pstate);
40615 }
40616
40617 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40618 {
40619 - cpu->pstate.min_pstate = pstate_funcs.get_min();
40620 - cpu->pstate.max_pstate = pstate_funcs.get_max();
40621 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40622 + cpu->pstate.min_pstate = pstate_funcs->get_min();
40623 + cpu->pstate.max_pstate = pstate_funcs->get_max();
40624 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40625
40626 - if (pstate_funcs.get_vid)
40627 - pstate_funcs.get_vid(cpu);
40628 + if (pstate_funcs->get_vid)
40629 + pstate_funcs->get_vid(cpu);
40630 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40631 }
40632
40633 @@ -810,9 +810,9 @@ static int intel_pstate_msrs_not_valid(void)
40634 rdmsrl(MSR_IA32_APERF, aperf);
40635 rdmsrl(MSR_IA32_MPERF, mperf);
40636
40637 - if (!pstate_funcs.get_max() ||
40638 - !pstate_funcs.get_min() ||
40639 - !pstate_funcs.get_turbo())
40640 + if (!pstate_funcs->get_max() ||
40641 + !pstate_funcs->get_min() ||
40642 + !pstate_funcs->get_turbo())
40643 return -ENODEV;
40644
40645 rdmsrl(MSR_IA32_APERF, tmp);
40646 @@ -826,7 +826,7 @@ static int intel_pstate_msrs_not_valid(void)
40647 return 0;
40648 }
40649
40650 -static void copy_pid_params(struct pstate_adjust_policy *policy)
40651 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
40652 {
40653 pid_params.sample_rate_ms = policy->sample_rate_ms;
40654 pid_params.p_gain_pct = policy->p_gain_pct;
40655 @@ -838,11 +838,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40656
40657 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40658 {
40659 - pstate_funcs.get_max = funcs->get_max;
40660 - pstate_funcs.get_min = funcs->get_min;
40661 - pstate_funcs.get_turbo = funcs->get_turbo;
40662 - pstate_funcs.set = funcs->set;
40663 - pstate_funcs.get_vid = funcs->get_vid;
40664 + pstate_funcs = funcs;
40665 }
40666
40667 #if IS_ENABLED(CONFIG_ACPI)
40668 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40669 index 529cfd9..0e28fff 100644
40670 --- a/drivers/cpufreq/p4-clockmod.c
40671 +++ b/drivers/cpufreq/p4-clockmod.c
40672 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40673 case 0x0F: /* Core Duo */
40674 case 0x16: /* Celeron Core */
40675 case 0x1C: /* Atom */
40676 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40677 + pax_open_kernel();
40678 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40679 + pax_close_kernel();
40680 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40681 case 0x0D: /* Pentium M (Dothan) */
40682 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40683 + pax_open_kernel();
40684 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40685 + pax_close_kernel();
40686 /* fall through */
40687 case 0x09: /* Pentium M (Banias) */
40688 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40689 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40690
40691 /* on P-4s, the TSC runs with constant frequency independent whether
40692 * throttling is active or not. */
40693 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40694 + pax_open_kernel();
40695 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40696 + pax_close_kernel();
40697
40698 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40699 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40700 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40701 index 9bb42ba..b01b4a2 100644
40702 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
40703 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40704 @@ -18,14 +18,12 @@
40705 #include <asm/head.h>
40706 #include <asm/timer.h>
40707
40708 -static struct cpufreq_driver *cpufreq_us3_driver;
40709 -
40710 struct us3_freq_percpu_info {
40711 struct cpufreq_frequency_table table[4];
40712 };
40713
40714 /* Indexed by cpu number. */
40715 -static struct us3_freq_percpu_info *us3_freq_table;
40716 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40717
40718 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40719 * in the Safari config register.
40720 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40721
40722 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40723 {
40724 - if (cpufreq_us3_driver)
40725 - us3_freq_target(policy, 0);
40726 + us3_freq_target(policy, 0);
40727
40728 return 0;
40729 }
40730
40731 +static int __init us3_freq_init(void);
40732 +static void __exit us3_freq_exit(void);
40733 +
40734 +static struct cpufreq_driver cpufreq_us3_driver = {
40735 + .init = us3_freq_cpu_init,
40736 + .verify = cpufreq_generic_frequency_table_verify,
40737 + .target_index = us3_freq_target,
40738 + .get = us3_freq_get,
40739 + .exit = us3_freq_cpu_exit,
40740 + .name = "UltraSPARC-III",
40741 +
40742 +};
40743 +
40744 static int __init us3_freq_init(void)
40745 {
40746 unsigned long manuf, impl, ver;
40747 - int ret;
40748
40749 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40750 return -ENODEV;
40751 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40752 (impl == CHEETAH_IMPL ||
40753 impl == CHEETAH_PLUS_IMPL ||
40754 impl == JAGUAR_IMPL ||
40755 - impl == PANTHER_IMPL)) {
40756 - struct cpufreq_driver *driver;
40757 -
40758 - ret = -ENOMEM;
40759 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40760 - if (!driver)
40761 - goto err_out;
40762 -
40763 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40764 - GFP_KERNEL);
40765 - if (!us3_freq_table)
40766 - goto err_out;
40767 -
40768 - driver->init = us3_freq_cpu_init;
40769 - driver->verify = cpufreq_generic_frequency_table_verify;
40770 - driver->target_index = us3_freq_target;
40771 - driver->get = us3_freq_get;
40772 - driver->exit = us3_freq_cpu_exit;
40773 - strcpy(driver->name, "UltraSPARC-III");
40774 -
40775 - cpufreq_us3_driver = driver;
40776 - ret = cpufreq_register_driver(driver);
40777 - if (ret)
40778 - goto err_out;
40779 -
40780 - return 0;
40781 -
40782 -err_out:
40783 - if (driver) {
40784 - kfree(driver);
40785 - cpufreq_us3_driver = NULL;
40786 - }
40787 - kfree(us3_freq_table);
40788 - us3_freq_table = NULL;
40789 - return ret;
40790 - }
40791 + impl == PANTHER_IMPL))
40792 + return cpufreq_register_driver(&cpufreq_us3_driver);
40793
40794 return -ENODEV;
40795 }
40796
40797 static void __exit us3_freq_exit(void)
40798 {
40799 - if (cpufreq_us3_driver) {
40800 - cpufreq_unregister_driver(cpufreq_us3_driver);
40801 - kfree(cpufreq_us3_driver);
40802 - cpufreq_us3_driver = NULL;
40803 - kfree(us3_freq_table);
40804 - us3_freq_table = NULL;
40805 - }
40806 + cpufreq_unregister_driver(&cpufreq_us3_driver);
40807 }
40808
40809 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40810 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40811 index 7d4a315..21bb886 100644
40812 --- a/drivers/cpufreq/speedstep-centrino.c
40813 +++ b/drivers/cpufreq/speedstep-centrino.c
40814 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40815 !cpu_has(cpu, X86_FEATURE_EST))
40816 return -ENODEV;
40817
40818 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40819 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40820 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40821 + pax_open_kernel();
40822 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40823 + pax_close_kernel();
40824 + }
40825
40826 if (policy->cpu != 0)
40827 return -ENODEV;
40828 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40829 index e431d11..d0b997e 100644
40830 --- a/drivers/cpuidle/driver.c
40831 +++ b/drivers/cpuidle/driver.c
40832 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40833
40834 static void poll_idle_init(struct cpuidle_driver *drv)
40835 {
40836 - struct cpuidle_state *state = &drv->states[0];
40837 + cpuidle_state_no_const *state = &drv->states[0];
40838
40839 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40840 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40841 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40842 index ca89412..a7b9c49 100644
40843 --- a/drivers/cpuidle/governor.c
40844 +++ b/drivers/cpuidle/governor.c
40845 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40846 mutex_lock(&cpuidle_lock);
40847 if (__cpuidle_find_governor(gov->name) == NULL) {
40848 ret = 0;
40849 - list_add_tail(&gov->governor_list, &cpuidle_governors);
40850 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40851 if (!cpuidle_curr_governor ||
40852 cpuidle_curr_governor->rating < gov->rating)
40853 cpuidle_switch_governor(gov);
40854 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40855 index 97c5903..023ad23 100644
40856 --- a/drivers/cpuidle/sysfs.c
40857 +++ b/drivers/cpuidle/sysfs.c
40858 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40859 NULL
40860 };
40861
40862 -static struct attribute_group cpuidle_attr_group = {
40863 +static attribute_group_no_const cpuidle_attr_group = {
40864 .attrs = cpuidle_default_attrs,
40865 .name = "cpuidle",
40866 };
40867 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40868 index 8d2a772..33826c9 100644
40869 --- a/drivers/crypto/hifn_795x.c
40870 +++ b/drivers/crypto/hifn_795x.c
40871 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40872 MODULE_PARM_DESC(hifn_pll_ref,
40873 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40874
40875 -static atomic_t hifn_dev_number;
40876 +static atomic_unchecked_t hifn_dev_number;
40877
40878 #define ACRYPTO_OP_DECRYPT 0
40879 #define ACRYPTO_OP_ENCRYPT 1
40880 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40881 goto err_out_disable_pci_device;
40882
40883 snprintf(name, sizeof(name), "hifn%d",
40884 - atomic_inc_return(&hifn_dev_number)-1);
40885 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
40886
40887 err = pci_request_regions(pdev, name);
40888 if (err)
40889 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40890 index 9f90369..bfcacdb 100644
40891 --- a/drivers/devfreq/devfreq.c
40892 +++ b/drivers/devfreq/devfreq.c
40893 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40894 goto err_out;
40895 }
40896
40897 - list_add(&governor->node, &devfreq_governor_list);
40898 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40899
40900 list_for_each_entry(devfreq, &devfreq_list, node) {
40901 int ret = 0;
40902 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40903 }
40904 }
40905
40906 - list_del(&governor->node);
40907 + pax_list_del((struct list_head *)&governor->node);
40908 err_out:
40909 mutex_unlock(&devfreq_list_lock);
40910
40911 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40912 index 42d4974..2714f36 100644
40913 --- a/drivers/dma/sh/shdma-base.c
40914 +++ b/drivers/dma/sh/shdma-base.c
40915 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40916 schan->slave_id = -EINVAL;
40917 }
40918
40919 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40920 - sdev->desc_size, GFP_KERNEL);
40921 + schan->desc = kcalloc(sdev->desc_size,
40922 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40923 if (!schan->desc) {
40924 ret = -ENOMEM;
40925 goto edescalloc;
40926 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40927 index 58eb857..d7e42c8 100644
40928 --- a/drivers/dma/sh/shdmac.c
40929 +++ b/drivers/dma/sh/shdmac.c
40930 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40931 return ret;
40932 }
40933
40934 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40935 +static struct notifier_block sh_dmae_nmi_notifier = {
40936 .notifier_call = sh_dmae_nmi_handler,
40937
40938 /* Run before NMI debug handler and KGDB */
40939 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40940 index 592af5f..bb1d583 100644
40941 --- a/drivers/edac/edac_device.c
40942 +++ b/drivers/edac/edac_device.c
40943 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40944 */
40945 int edac_device_alloc_index(void)
40946 {
40947 - static atomic_t device_indexes = ATOMIC_INIT(0);
40948 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40949
40950 - return atomic_inc_return(&device_indexes) - 1;
40951 + return atomic_inc_return_unchecked(&device_indexes) - 1;
40952 }
40953 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40954
40955 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40956 index a6cd361..7bdbf53 100644
40957 --- a/drivers/edac/edac_mc_sysfs.c
40958 +++ b/drivers/edac/edac_mc_sysfs.c
40959 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40960 struct dev_ch_attribute {
40961 struct device_attribute attr;
40962 int channel;
40963 -};
40964 +} __do_const;
40965
40966 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40967 struct dev_ch_attribute dev_attr_legacy_##_name = \
40968 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40969 }
40970
40971 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40972 + pax_open_kernel();
40973 if (mci->get_sdram_scrub_rate) {
40974 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40975 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40976 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40977 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40978 }
40979 if (mci->set_sdram_scrub_rate) {
40980 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40981 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40982 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40983 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40984 }
40985 + pax_close_kernel();
40986 err = device_create_file(&mci->dev,
40987 &dev_attr_sdram_scrub_rate);
40988 if (err) {
40989 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40990 index 2cf44b4d..6dd2dc7 100644
40991 --- a/drivers/edac/edac_pci.c
40992 +++ b/drivers/edac/edac_pci.c
40993 @@ -29,7 +29,7 @@
40994
40995 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40996 static LIST_HEAD(edac_pci_list);
40997 -static atomic_t pci_indexes = ATOMIC_INIT(0);
40998 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40999
41000 /*
41001 * edac_pci_alloc_ctl_info
41002 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
41003 */
41004 int edac_pci_alloc_index(void)
41005 {
41006 - return atomic_inc_return(&pci_indexes) - 1;
41007 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
41008 }
41009 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
41010
41011 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
41012 index e8658e4..22746d6 100644
41013 --- a/drivers/edac/edac_pci_sysfs.c
41014 +++ b/drivers/edac/edac_pci_sysfs.c
41015 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
41016 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
41017 static int edac_pci_poll_msec = 1000; /* one second workq period */
41018
41019 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
41020 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
41021 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
41022 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
41023
41024 static struct kobject *edac_pci_top_main_kobj;
41025 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
41026 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
41027 void *value;
41028 ssize_t(*show) (void *, char *);
41029 ssize_t(*store) (void *, const char *, size_t);
41030 -};
41031 +} __do_const;
41032
41033 /* Set of show/store abstract level functions for PCI Parity object */
41034 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
41035 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41036 edac_printk(KERN_CRIT, EDAC_PCI,
41037 "Signaled System Error on %s\n",
41038 pci_name(dev));
41039 - atomic_inc(&pci_nonparity_count);
41040 + atomic_inc_unchecked(&pci_nonparity_count);
41041 }
41042
41043 if (status & (PCI_STATUS_PARITY)) {
41044 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41045 "Master Data Parity Error on %s\n",
41046 pci_name(dev));
41047
41048 - atomic_inc(&pci_parity_count);
41049 + atomic_inc_unchecked(&pci_parity_count);
41050 }
41051
41052 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41053 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41054 "Detected Parity Error on %s\n",
41055 pci_name(dev));
41056
41057 - atomic_inc(&pci_parity_count);
41058 + atomic_inc_unchecked(&pci_parity_count);
41059 }
41060 }
41061
41062 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41063 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41064 "Signaled System Error on %s\n",
41065 pci_name(dev));
41066 - atomic_inc(&pci_nonparity_count);
41067 + atomic_inc_unchecked(&pci_nonparity_count);
41068 }
41069
41070 if (status & (PCI_STATUS_PARITY)) {
41071 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41072 "Master Data Parity Error on "
41073 "%s\n", pci_name(dev));
41074
41075 - atomic_inc(&pci_parity_count);
41076 + atomic_inc_unchecked(&pci_parity_count);
41077 }
41078
41079 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41080 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41081 "Detected Parity Error on %s\n",
41082 pci_name(dev));
41083
41084 - atomic_inc(&pci_parity_count);
41085 + atomic_inc_unchecked(&pci_parity_count);
41086 }
41087 }
41088 }
41089 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41090 if (!check_pci_errors)
41091 return;
41092
41093 - before_count = atomic_read(&pci_parity_count);
41094 + before_count = atomic_read_unchecked(&pci_parity_count);
41095
41096 /* scan all PCI devices looking for a Parity Error on devices and
41097 * bridges.
41098 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41099 /* Only if operator has selected panic on PCI Error */
41100 if (edac_pci_get_panic_on_pe()) {
41101 /* If the count is different 'after' from 'before' */
41102 - if (before_count != atomic_read(&pci_parity_count))
41103 + if (before_count != atomic_read_unchecked(&pci_parity_count))
41104 panic("EDAC: PCI Parity Error");
41105 }
41106 }
41107 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41108 index 51b7e3a..aa8a3e8 100644
41109 --- a/drivers/edac/mce_amd.h
41110 +++ b/drivers/edac/mce_amd.h
41111 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
41112 bool (*mc0_mce)(u16, u8);
41113 bool (*mc1_mce)(u16, u8);
41114 bool (*mc2_mce)(u16, u8);
41115 -};
41116 +} __no_const;
41117
41118 void amd_report_gart_errors(bool);
41119 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41120 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41121 index 57ea7f4..af06b76 100644
41122 --- a/drivers/firewire/core-card.c
41123 +++ b/drivers/firewire/core-card.c
41124 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41125 const struct fw_card_driver *driver,
41126 struct device *device)
41127 {
41128 - static atomic_t index = ATOMIC_INIT(-1);
41129 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
41130
41131 - card->index = atomic_inc_return(&index);
41132 + card->index = atomic_inc_return_unchecked(&index);
41133 card->driver = driver;
41134 card->device = device;
41135 card->current_tlabel = 0;
41136 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41137
41138 void fw_core_remove_card(struct fw_card *card)
41139 {
41140 - struct fw_card_driver dummy_driver = dummy_driver_template;
41141 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
41142
41143 card->driver->update_phy_reg(card, 4,
41144 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41145 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41146 index 2c6d5e1..a2cca6b 100644
41147 --- a/drivers/firewire/core-device.c
41148 +++ b/drivers/firewire/core-device.c
41149 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41150 struct config_rom_attribute {
41151 struct device_attribute attr;
41152 u32 key;
41153 -};
41154 +} __do_const;
41155
41156 static ssize_t show_immediate(struct device *dev,
41157 struct device_attribute *dattr, char *buf)
41158 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41159 index eb6935c..3cc2bfa 100644
41160 --- a/drivers/firewire/core-transaction.c
41161 +++ b/drivers/firewire/core-transaction.c
41162 @@ -38,6 +38,7 @@
41163 #include <linux/timer.h>
41164 #include <linux/types.h>
41165 #include <linux/workqueue.h>
41166 +#include <linux/sched.h>
41167
41168 #include <asm/byteorder.h>
41169
41170 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41171 index e1480ff6..1a429bd 100644
41172 --- a/drivers/firewire/core.h
41173 +++ b/drivers/firewire/core.h
41174 @@ -111,6 +111,7 @@ struct fw_card_driver {
41175
41176 int (*stop_iso)(struct fw_iso_context *ctx);
41177 };
41178 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41179
41180 void fw_card_initialize(struct fw_card *card,
41181 const struct fw_card_driver *driver, struct device *device);
41182 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41183 index a66a321..f6caf20 100644
41184 --- a/drivers/firewire/ohci.c
41185 +++ b/drivers/firewire/ohci.c
41186 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41187 be32_to_cpu(ohci->next_header));
41188 }
41189
41190 +#ifndef CONFIG_GRKERNSEC
41191 if (param_remote_dma) {
41192 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41193 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41194 }
41195 +#endif
41196
41197 spin_unlock_irq(&ohci->lock);
41198
41199 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41200 unsigned long flags;
41201 int n, ret = 0;
41202
41203 +#ifndef CONFIG_GRKERNSEC
41204 if (param_remote_dma)
41205 return 0;
41206 +#endif
41207
41208 /*
41209 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41210 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41211 index 94a58a0..f5eba42 100644
41212 --- a/drivers/firmware/dmi-id.c
41213 +++ b/drivers/firmware/dmi-id.c
41214 @@ -16,7 +16,7 @@
41215 struct dmi_device_attribute{
41216 struct device_attribute dev_attr;
41217 int field;
41218 -};
41219 +} __do_const;
41220 #define to_dmi_dev_attr(_dev_attr) \
41221 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41222
41223 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41224 index 17afc51..0ef90cd 100644
41225 --- a/drivers/firmware/dmi_scan.c
41226 +++ b/drivers/firmware/dmi_scan.c
41227 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41228 if (buf == NULL)
41229 return -1;
41230
41231 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41232 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41233
41234 dmi_unmap(buf);
41235 return 0;
41236 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41237 index 5b53d61..72cee96 100644
41238 --- a/drivers/firmware/efi/cper.c
41239 +++ b/drivers/firmware/efi/cper.c
41240 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
41241 */
41242 u64 cper_next_record_id(void)
41243 {
41244 - static atomic64_t seq;
41245 + static atomic64_unchecked_t seq;
41246
41247 - if (!atomic64_read(&seq))
41248 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
41249 + if (!atomic64_read_unchecked(&seq))
41250 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41251
41252 - return atomic64_inc_return(&seq);
41253 + return atomic64_inc_return_unchecked(&seq);
41254 }
41255 EXPORT_SYMBOL_GPL(cper_next_record_id);
41256
41257 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41258 index 64ecbb5..d921eb3 100644
41259 --- a/drivers/firmware/efi/efi.c
41260 +++ b/drivers/firmware/efi/efi.c
41261 @@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
41262 };
41263
41264 static struct efivars generic_efivars;
41265 -static struct efivar_operations generic_ops;
41266 +static efivar_operations_no_const generic_ops __read_only;
41267
41268 static int generic_ops_register(void)
41269 {
41270 - generic_ops.get_variable = efi.get_variable;
41271 - generic_ops.set_variable = efi.set_variable;
41272 - generic_ops.get_next_variable = efi.get_next_variable;
41273 - generic_ops.query_variable_store = efi_query_variable_store;
41274 + pax_open_kernel();
41275 + *(void **)&generic_ops.get_variable = efi.get_variable;
41276 + *(void **)&generic_ops.set_variable = efi.set_variable;
41277 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41278 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41279 + pax_close_kernel();
41280
41281 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41282 }
41283 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41284 index f256ecd..387dcb1 100644
41285 --- a/drivers/firmware/efi/efivars.c
41286 +++ b/drivers/firmware/efi/efivars.c
41287 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41288 static int
41289 create_efivars_bin_attributes(void)
41290 {
41291 - struct bin_attribute *attr;
41292 + bin_attribute_no_const *attr;
41293 int error;
41294
41295 /* new_var */
41296 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41297 index 2f569aa..c95f4fb 100644
41298 --- a/drivers/firmware/google/memconsole.c
41299 +++ b/drivers/firmware/google/memconsole.c
41300 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41301 if (!found_memconsole())
41302 return -ENODEV;
41303
41304 - memconsole_bin_attr.size = memconsole_length;
41305 + pax_open_kernel();
41306 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41307 + pax_close_kernel();
41308 +
41309 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41310 }
41311
41312 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41313 index fe49ec3..1ade794 100644
41314 --- a/drivers/gpio/gpio-em.c
41315 +++ b/drivers/gpio/gpio-em.c
41316 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41317 struct em_gio_priv *p;
41318 struct resource *io[2], *irq[2];
41319 struct gpio_chip *gpio_chip;
41320 - struct irq_chip *irq_chip;
41321 + irq_chip_no_const *irq_chip;
41322 const char *name = dev_name(&pdev->dev);
41323 int ret;
41324
41325 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41326 index 3784e81..73637b5 100644
41327 --- a/drivers/gpio/gpio-ich.c
41328 +++ b/drivers/gpio/gpio-ich.c
41329 @@ -94,7 +94,7 @@ struct ichx_desc {
41330 * this option allows driver caching written output values
41331 */
41332 bool use_outlvl_cache;
41333 -};
41334 +} __do_const;
41335
41336 static struct {
41337 spinlock_t lock;
41338 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41339 index bf6c094..6573caf 100644
41340 --- a/drivers/gpio/gpio-rcar.c
41341 +++ b/drivers/gpio/gpio-rcar.c
41342 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41343 struct gpio_rcar_priv *p;
41344 struct resource *io, *irq;
41345 struct gpio_chip *gpio_chip;
41346 - struct irq_chip *irq_chip;
41347 + irq_chip_no_const *irq_chip;
41348 struct device *dev = &pdev->dev;
41349 const char *name = dev_name(dev);
41350 int ret;
41351 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41352 index dbf28fa..04dad4e 100644
41353 --- a/drivers/gpio/gpio-vr41xx.c
41354 +++ b/drivers/gpio/gpio-vr41xx.c
41355 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41356 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41357 maskl, pendl, maskh, pendh);
41358
41359 - atomic_inc(&irq_err_count);
41360 + atomic_inc_unchecked(&irq_err_count);
41361
41362 return -EINVAL;
41363 }
41364 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41365 index c68d037..2f4f9a9 100644
41366 --- a/drivers/gpio/gpiolib.c
41367 +++ b/drivers/gpio/gpiolib.c
41368 @@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41369 }
41370
41371 if (gpiochip->irqchip) {
41372 - gpiochip->irqchip->irq_request_resources = NULL;
41373 - gpiochip->irqchip->irq_release_resources = NULL;
41374 + pax_open_kernel();
41375 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41376 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41377 + pax_close_kernel();
41378 gpiochip->irqchip = NULL;
41379 }
41380 }
41381 @@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41382 gpiochip->irqchip = NULL;
41383 return -EINVAL;
41384 }
41385 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41386 - irqchip->irq_release_resources = gpiochip_irq_relres;
41387 +
41388 + pax_open_kernel();
41389 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41390 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41391 + pax_close_kernel();
41392
41393 /*
41394 * Prepare the mapping since the irqchip shall be orthogonal to
41395 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41396 index 90e7730..3b41807 100644
41397 --- a/drivers/gpu/drm/drm_crtc.c
41398 +++ b/drivers/gpu/drm/drm_crtc.c
41399 @@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41400 goto done;
41401 }
41402
41403 - if (copy_to_user(&enum_ptr[copied].name,
41404 + if (copy_to_user(enum_ptr[copied].name,
41405 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41406 ret = -EFAULT;
41407 goto done;
41408 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41409 index 3242e20..7e4f621 100644
41410 --- a/drivers/gpu/drm/drm_drv.c
41411 +++ b/drivers/gpu/drm/drm_drv.c
41412 @@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41413
41414 drm_device_set_unplugged(dev);
41415
41416 - if (dev->open_count == 0) {
41417 + if (local_read(&dev->open_count) == 0) {
41418 drm_put_dev(dev);
41419 }
41420 mutex_unlock(&drm_global_mutex);
41421 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41422 index 79d5221..7ff73496 100644
41423 --- a/drivers/gpu/drm/drm_fops.c
41424 +++ b/drivers/gpu/drm/drm_fops.c
41425 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41426 return PTR_ERR(minor);
41427
41428 dev = minor->dev;
41429 - if (!dev->open_count++)
41430 + if (local_inc_return(&dev->open_count) == 1)
41431 need_setup = 1;
41432
41433 /* share address_space across all char-devs of a single device */
41434 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41435 return 0;
41436
41437 err_undo:
41438 - dev->open_count--;
41439 + local_dec(&dev->open_count);
41440 drm_minor_release(minor);
41441 return retcode;
41442 }
41443 @@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41444
41445 mutex_lock(&drm_global_mutex);
41446
41447 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41448 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41449
41450 mutex_lock(&dev->struct_mutex);
41451 list_del(&file_priv->lhead);
41452 @@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41453 * Begin inline drm_release
41454 */
41455
41456 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41457 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41458 task_pid_nr(current),
41459 (long)old_encode_dev(file_priv->minor->kdev->devt),
41460 - dev->open_count);
41461 + local_read(&dev->open_count));
41462
41463 /* Release any auth tokens that might point to this file_priv,
41464 (do that under the drm_global_mutex) */
41465 @@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41466 * End inline drm_release
41467 */
41468
41469 - if (!--dev->open_count) {
41470 + if (local_dec_and_test(&dev->open_count)) {
41471 retcode = drm_lastclose(dev);
41472 if (drm_device_is_unplugged(dev))
41473 drm_put_dev(dev);
41474 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41475 index 3d2e91c..d31c4c9 100644
41476 --- a/drivers/gpu/drm/drm_global.c
41477 +++ b/drivers/gpu/drm/drm_global.c
41478 @@ -36,7 +36,7 @@
41479 struct drm_global_item {
41480 struct mutex mutex;
41481 void *object;
41482 - int refcount;
41483 + atomic_t refcount;
41484 };
41485
41486 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41487 @@ -49,7 +49,7 @@ void drm_global_init(void)
41488 struct drm_global_item *item = &glob[i];
41489 mutex_init(&item->mutex);
41490 item->object = NULL;
41491 - item->refcount = 0;
41492 + atomic_set(&item->refcount, 0);
41493 }
41494 }
41495
41496 @@ -59,7 +59,7 @@ void drm_global_release(void)
41497 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41498 struct drm_global_item *item = &glob[i];
41499 BUG_ON(item->object != NULL);
41500 - BUG_ON(item->refcount != 0);
41501 + BUG_ON(atomic_read(&item->refcount) != 0);
41502 }
41503 }
41504
41505 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41506 struct drm_global_item *item = &glob[ref->global_type];
41507
41508 mutex_lock(&item->mutex);
41509 - if (item->refcount == 0) {
41510 + if (atomic_read(&item->refcount) == 0) {
41511 item->object = kzalloc(ref->size, GFP_KERNEL);
41512 if (unlikely(item->object == NULL)) {
41513 ret = -ENOMEM;
41514 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41515 goto out_err;
41516
41517 }
41518 - ++item->refcount;
41519 + atomic_inc(&item->refcount);
41520 ref->object = item->object;
41521 mutex_unlock(&item->mutex);
41522 return 0;
41523 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41524 struct drm_global_item *item = &glob[ref->global_type];
41525
41526 mutex_lock(&item->mutex);
41527 - BUG_ON(item->refcount == 0);
41528 + BUG_ON(atomic_read(&item->refcount) == 0);
41529 BUG_ON(ref->object != item->object);
41530 - if (--item->refcount == 0) {
41531 + if (atomic_dec_and_test(&item->refcount)) {
41532 ref->release(ref);
41533 item->object = NULL;
41534 }
41535 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41536 index ecaf0fa..a49cee9 100644
41537 --- a/drivers/gpu/drm/drm_info.c
41538 +++ b/drivers/gpu/drm/drm_info.c
41539 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41540 struct drm_local_map *map;
41541 struct drm_map_list *r_list;
41542
41543 - /* Hardcoded from _DRM_FRAME_BUFFER,
41544 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41545 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41546 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41547 + static const char * const types[] = {
41548 + [_DRM_FRAME_BUFFER] = "FB",
41549 + [_DRM_REGISTERS] = "REG",
41550 + [_DRM_SHM] = "SHM",
41551 + [_DRM_AGP] = "AGP",
41552 + [_DRM_SCATTER_GATHER] = "SG",
41553 + [_DRM_CONSISTENT] = "PCI"};
41554 const char *type;
41555 int i;
41556
41557 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41558 map = r_list->map;
41559 if (!map)
41560 continue;
41561 - if (map->type < 0 || map->type > 5)
41562 + if (map->type >= ARRAY_SIZE(types))
41563 type = "??";
41564 else
41565 type = types[map->type];
41566 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41567 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41568 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41569 vma->vm_flags & VM_IO ? 'i' : '-',
41570 +#ifdef CONFIG_GRKERNSEC_HIDESYM
41571 + 0);
41572 +#else
41573 vma->vm_pgoff);
41574 +#endif
41575
41576 #if defined(__i386__)
41577 pgprot = pgprot_val(vma->vm_page_prot);
41578 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41579 index 2f4c4343..dd12cd2 100644
41580 --- a/drivers/gpu/drm/drm_ioc32.c
41581 +++ b/drivers/gpu/drm/drm_ioc32.c
41582 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41583 request = compat_alloc_user_space(nbytes);
41584 if (!access_ok(VERIFY_WRITE, request, nbytes))
41585 return -EFAULT;
41586 - list = (struct drm_buf_desc *) (request + 1);
41587 + list = (struct drm_buf_desc __user *) (request + 1);
41588
41589 if (__put_user(count, &request->count)
41590 || __put_user(list, &request->list))
41591 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41592 request = compat_alloc_user_space(nbytes);
41593 if (!access_ok(VERIFY_WRITE, request, nbytes))
41594 return -EFAULT;
41595 - list = (struct drm_buf_pub *) (request + 1);
41596 + list = (struct drm_buf_pub __user *) (request + 1);
41597
41598 if (__put_user(count, &request->count)
41599 || __put_user(list, &request->list))
41600 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41601 return 0;
41602 }
41603
41604 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
41605 +drm_ioctl_compat_t drm_compat_ioctls[] = {
41606 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41607 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41608 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41609 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41610 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41611 {
41612 unsigned int nr = DRM_IOCTL_NR(cmd);
41613 - drm_ioctl_compat_t *fn;
41614 int ret;
41615
41616 /* Assume that ioctls without an explicit compat routine will just
41617 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41618 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41619 return drm_ioctl(filp, cmd, arg);
41620
41621 - fn = drm_compat_ioctls[nr];
41622 -
41623 - if (fn != NULL)
41624 - ret = (*fn) (filp, cmd, arg);
41625 + if (drm_compat_ioctls[nr] != NULL)
41626 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41627 else
41628 ret = drm_ioctl(filp, cmd, arg);
41629
41630 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41631 index 40be746..fd78faf 100644
41632 --- a/drivers/gpu/drm/drm_ioctl.c
41633 +++ b/drivers/gpu/drm/drm_ioctl.c
41634 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41635 struct drm_file *file_priv = filp->private_data;
41636 struct drm_device *dev;
41637 const struct drm_ioctl_desc *ioctl = NULL;
41638 - drm_ioctl_t *func;
41639 + drm_ioctl_no_const_t func;
41640 unsigned int nr = DRM_IOCTL_NR(cmd);
41641 int retcode = -EINVAL;
41642 char stack_kdata[128];
41643 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41644 index d4d16ed..8fb0b51 100644
41645 --- a/drivers/gpu/drm/i810/i810_drv.h
41646 +++ b/drivers/gpu/drm/i810/i810_drv.h
41647 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41648 int page_flipping;
41649
41650 wait_queue_head_t irq_queue;
41651 - atomic_t irq_received;
41652 - atomic_t irq_emitted;
41653 + atomic_unchecked_t irq_received;
41654 + atomic_unchecked_t irq_emitted;
41655
41656 int front_offset;
41657 } drm_i810_private_t;
41658 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41659 index 9933c26..32cc097 100644
41660 --- a/drivers/gpu/drm/i915/i915_dma.c
41661 +++ b/drivers/gpu/drm/i915/i915_dma.c
41662 @@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41663 * locking inversion with the driver load path. And the access here is
41664 * completely racy anyway. So don't bother with locking for now.
41665 */
41666 - return dev->open_count == 0;
41667 + return local_read(&dev->open_count) == 0;
41668 }
41669
41670 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41671 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41672 index 60998fc..3b244bc 100644
41673 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41674 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41675 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41676
41677 static int
41678 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41679 - int count)
41680 + unsigned int count)
41681 {
41682 - int i;
41683 + unsigned int i;
41684 unsigned relocs_total = 0;
41685 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41686
41687 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41688 index 2e0613e..a8b94d9 100644
41689 --- a/drivers/gpu/drm/i915/i915_ioc32.c
41690 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
41691 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41692 (unsigned long)request);
41693 }
41694
41695 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41696 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
41697 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41698 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41699 [DRM_I915_GETPARAM] = compat_i915_getparam,
41700 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41701 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41702 {
41703 unsigned int nr = DRM_IOCTL_NR(cmd);
41704 - drm_ioctl_compat_t *fn = NULL;
41705 int ret;
41706
41707 if (nr < DRM_COMMAND_BASE)
41708 return drm_compat_ioctl(filp, cmd, arg);
41709
41710 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41711 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41712 -
41713 - if (fn != NULL)
41714 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41715 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41716 ret = (*fn) (filp, cmd, arg);
41717 - else
41718 + } else
41719 ret = drm_ioctl(filp, cmd, arg);
41720
41721 return ret;
41722 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41723 index d8324c6..fc9b704 100644
41724 --- a/drivers/gpu/drm/i915/intel_display.c
41725 +++ b/drivers/gpu/drm/i915/intel_display.c
41726 @@ -12437,13 +12437,13 @@ struct intel_quirk {
41727 int subsystem_vendor;
41728 int subsystem_device;
41729 void (*hook)(struct drm_device *dev);
41730 -};
41731 +} __do_const;
41732
41733 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41734 struct intel_dmi_quirk {
41735 void (*hook)(struct drm_device *dev);
41736 const struct dmi_system_id (*dmi_id_list)[];
41737 -};
41738 +} __do_const;
41739
41740 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41741 {
41742 @@ -12451,18 +12451,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41743 return 1;
41744 }
41745
41746 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41747 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
41748 {
41749 - .dmi_id_list = &(const struct dmi_system_id[]) {
41750 - {
41751 - .callback = intel_dmi_reverse_brightness,
41752 - .ident = "NCR Corporation",
41753 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41754 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
41755 - },
41756 - },
41757 - { } /* terminating entry */
41758 + .callback = intel_dmi_reverse_brightness,
41759 + .ident = "NCR Corporation",
41760 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41761 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
41762 },
41763 + },
41764 + { } /* terminating entry */
41765 +};
41766 +
41767 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41768 + {
41769 + .dmi_id_list = &intel_dmi_quirks_table,
41770 .hook = quirk_invert_brightness,
41771 },
41772 };
41773 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41774 index fe45321..836fdca 100644
41775 --- a/drivers/gpu/drm/mga/mga_drv.h
41776 +++ b/drivers/gpu/drm/mga/mga_drv.h
41777 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41778 u32 clear_cmd;
41779 u32 maccess;
41780
41781 - atomic_t vbl_received; /**< Number of vblanks received. */
41782 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41783 wait_queue_head_t fence_queue;
41784 - atomic_t last_fence_retired;
41785 + atomic_unchecked_t last_fence_retired;
41786 u32 next_fence_to_post;
41787
41788 unsigned int fb_cpp;
41789 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41790 index 729bfd5..ead8823 100644
41791 --- a/drivers/gpu/drm/mga/mga_ioc32.c
41792 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
41793 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41794 return 0;
41795 }
41796
41797 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
41798 +drm_ioctl_compat_t mga_compat_ioctls[] = {
41799 [DRM_MGA_INIT] = compat_mga_init,
41800 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41801 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41802 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41803 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41804 {
41805 unsigned int nr = DRM_IOCTL_NR(cmd);
41806 - drm_ioctl_compat_t *fn = NULL;
41807 int ret;
41808
41809 if (nr < DRM_COMMAND_BASE)
41810 return drm_compat_ioctl(filp, cmd, arg);
41811
41812 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41813 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41814 -
41815 - if (fn != NULL)
41816 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41817 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41818 ret = (*fn) (filp, cmd, arg);
41819 - else
41820 + } else
41821 ret = drm_ioctl(filp, cmd, arg);
41822
41823 return ret;
41824 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41825 index 1b071b8..de8601a 100644
41826 --- a/drivers/gpu/drm/mga/mga_irq.c
41827 +++ b/drivers/gpu/drm/mga/mga_irq.c
41828 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41829 if (crtc != 0)
41830 return 0;
41831
41832 - return atomic_read(&dev_priv->vbl_received);
41833 + return atomic_read_unchecked(&dev_priv->vbl_received);
41834 }
41835
41836
41837 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41838 /* VBLANK interrupt */
41839 if (status & MGA_VLINEPEN) {
41840 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41841 - atomic_inc(&dev_priv->vbl_received);
41842 + atomic_inc_unchecked(&dev_priv->vbl_received);
41843 drm_handle_vblank(dev, 0);
41844 handled = 1;
41845 }
41846 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41847 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41848 MGA_WRITE(MGA_PRIMEND, prim_end);
41849
41850 - atomic_inc(&dev_priv->last_fence_retired);
41851 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
41852 wake_up(&dev_priv->fence_queue);
41853 handled = 1;
41854 }
41855 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41856 * using fences.
41857 */
41858 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41859 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41860 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41861 - *sequence) <= (1 << 23)));
41862
41863 *sequence = cur_fence;
41864 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41865 index dae2c96..324dbe4 100644
41866 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41867 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41868 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41869 struct bit_table {
41870 const char id;
41871 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41872 -};
41873 +} __no_const;
41874
41875 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41876
41877 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41878 index b02b024..aed7bad 100644
41879 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41880 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41881 @@ -119,7 +119,6 @@ struct nouveau_drm {
41882 struct drm_global_reference mem_global_ref;
41883 struct ttm_bo_global_ref bo_global_ref;
41884 struct ttm_bo_device bdev;
41885 - atomic_t validate_sequence;
41886 int (*move)(struct nouveau_channel *,
41887 struct ttm_buffer_object *,
41888 struct ttm_mem_reg *, struct ttm_mem_reg *);
41889 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41890 index 462679a..88e32a7 100644
41891 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41892 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41893 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41894 unsigned long arg)
41895 {
41896 unsigned int nr = DRM_IOCTL_NR(cmd);
41897 - drm_ioctl_compat_t *fn = NULL;
41898 + drm_ioctl_compat_t fn = NULL;
41899 int ret;
41900
41901 if (nr < DRM_COMMAND_BASE)
41902 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41903 index 53874b7..1db0a68 100644
41904 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41905 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41906 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41907 }
41908
41909 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41910 - nouveau_vram_manager_init,
41911 - nouveau_vram_manager_fini,
41912 - nouveau_vram_manager_new,
41913 - nouveau_vram_manager_del,
41914 - nouveau_vram_manager_debug
41915 + .init = nouveau_vram_manager_init,
41916 + .takedown = nouveau_vram_manager_fini,
41917 + .get_node = nouveau_vram_manager_new,
41918 + .put_node = nouveau_vram_manager_del,
41919 + .debug = nouveau_vram_manager_debug
41920 };
41921
41922 static int
41923 @@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41924 }
41925
41926 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41927 - nouveau_gart_manager_init,
41928 - nouveau_gart_manager_fini,
41929 - nouveau_gart_manager_new,
41930 - nouveau_gart_manager_del,
41931 - nouveau_gart_manager_debug
41932 + .init = nouveau_gart_manager_init,
41933 + .takedown = nouveau_gart_manager_fini,
41934 + .get_node = nouveau_gart_manager_new,
41935 + .put_node = nouveau_gart_manager_del,
41936 + .debug = nouveau_gart_manager_debug
41937 };
41938
41939 /*XXX*/
41940 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41941 }
41942
41943 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41944 - nv04_gart_manager_init,
41945 - nv04_gart_manager_fini,
41946 - nv04_gart_manager_new,
41947 - nv04_gart_manager_del,
41948 - nv04_gart_manager_debug
41949 + .init = nv04_gart_manager_init,
41950 + .takedown = nv04_gart_manager_fini,
41951 + .get_node = nv04_gart_manager_new,
41952 + .put_node = nv04_gart_manager_del,
41953 + .debug = nv04_gart_manager_debug
41954 };
41955
41956 int
41957 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41958 index c7592ec..dd45ebc 100644
41959 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41960 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41961 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41962 * locking inversion with the driver load path. And the access here is
41963 * completely racy anyway. So don't bother with locking for now.
41964 */
41965 - return dev->open_count == 0;
41966 + return local_read(&dev->open_count) == 0;
41967 }
41968
41969 static const struct vga_switcheroo_client_ops
41970 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41971 index eb89653..613cf71 100644
41972 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41973 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41974 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41975 int ret;
41976
41977 mutex_lock(&qdev->async_io_mutex);
41978 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41979 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41980 if (qdev->last_sent_io_cmd > irq_num) {
41981 if (intr)
41982 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41983 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41984 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41985 else
41986 ret = wait_event_timeout(qdev->io_cmd_event,
41987 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41988 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41989 /* 0 is timeout, just bail the "hw" has gone away */
41990 if (ret <= 0)
41991 goto out;
41992 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41993 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41994 }
41995 outb(val, addr);
41996 qdev->last_sent_io_cmd = irq_num + 1;
41997 if (intr)
41998 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41999 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42000 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42001 else
42002 ret = wait_event_timeout(qdev->io_cmd_event,
42003 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42004 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42005 out:
42006 if (ret > 0)
42007 ret = 0;
42008 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
42009 index c3c2bbd..bc3c0fb 100644
42010 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
42011 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
42012 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
42013 struct drm_info_node *node = (struct drm_info_node *) m->private;
42014 struct qxl_device *qdev = node->minor->dev->dev_private;
42015
42016 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
42017 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
42018 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
42019 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
42020 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
42021 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
42022 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
42023 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
42024 seq_printf(m, "%d\n", qdev->irq_received_error);
42025 return 0;
42026 }
42027 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
42028 index 36ed40b..0397633 100644
42029 --- a/drivers/gpu/drm/qxl/qxl_drv.h
42030 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
42031 @@ -290,10 +290,10 @@ struct qxl_device {
42032 unsigned int last_sent_io_cmd;
42033
42034 /* interrupt handling */
42035 - atomic_t irq_received;
42036 - atomic_t irq_received_display;
42037 - atomic_t irq_received_cursor;
42038 - atomic_t irq_received_io_cmd;
42039 + atomic_unchecked_t irq_received;
42040 + atomic_unchecked_t irq_received_display;
42041 + atomic_unchecked_t irq_received_cursor;
42042 + atomic_unchecked_t irq_received_io_cmd;
42043 unsigned irq_received_error;
42044 wait_queue_head_t display_event;
42045 wait_queue_head_t cursor_event;
42046 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
42047 index b110883..dd06418 100644
42048 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42049 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42050 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42051
42052 /* TODO copy slow path code from i915 */
42053 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42054 - 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);
42055 + 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);
42056
42057 {
42058 struct qxl_drawable *draw = fb_cmd;
42059 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42060 struct drm_qxl_reloc reloc;
42061
42062 if (copy_from_user(&reloc,
42063 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42064 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42065 sizeof(reloc))) {
42066 ret = -EFAULT;
42067 goto out_free_bos;
42068 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42069
42070 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42071
42072 - struct drm_qxl_command *commands =
42073 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42074 + struct drm_qxl_command __user *commands =
42075 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42076
42077 - if (copy_from_user(&user_cmd, &commands[cmd_num],
42078 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42079 sizeof(user_cmd)))
42080 return -EFAULT;
42081
42082 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42083 index 0bf1e20..42a7310 100644
42084 --- a/drivers/gpu/drm/qxl/qxl_irq.c
42085 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
42086 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42087 if (!pending)
42088 return IRQ_NONE;
42089
42090 - atomic_inc(&qdev->irq_received);
42091 + atomic_inc_unchecked(&qdev->irq_received);
42092
42093 if (pending & QXL_INTERRUPT_DISPLAY) {
42094 - atomic_inc(&qdev->irq_received_display);
42095 + atomic_inc_unchecked(&qdev->irq_received_display);
42096 wake_up_all(&qdev->display_event);
42097 qxl_queue_garbage_collect(qdev, false);
42098 }
42099 if (pending & QXL_INTERRUPT_CURSOR) {
42100 - atomic_inc(&qdev->irq_received_cursor);
42101 + atomic_inc_unchecked(&qdev->irq_received_cursor);
42102 wake_up_all(&qdev->cursor_event);
42103 }
42104 if (pending & QXL_INTERRUPT_IO_CMD) {
42105 - atomic_inc(&qdev->irq_received_io_cmd);
42106 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42107 wake_up_all(&qdev->io_cmd_event);
42108 }
42109 if (pending & QXL_INTERRUPT_ERROR) {
42110 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42111 init_waitqueue_head(&qdev->io_cmd_event);
42112 INIT_WORK(&qdev->client_monitors_config_work,
42113 qxl_client_monitors_config_work_func);
42114 - atomic_set(&qdev->irq_received, 0);
42115 - atomic_set(&qdev->irq_received_display, 0);
42116 - atomic_set(&qdev->irq_received_cursor, 0);
42117 - atomic_set(&qdev->irq_received_io_cmd, 0);
42118 + atomic_set_unchecked(&qdev->irq_received, 0);
42119 + atomic_set_unchecked(&qdev->irq_received_display, 0);
42120 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42121 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42122 qdev->irq_received_error = 0;
42123 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42124 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42125 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42126 index 71a1bae..cb1f103 100644
42127 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
42128 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42129 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42130 }
42131 }
42132
42133 -static struct vm_operations_struct qxl_ttm_vm_ops;
42134 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42135 static const struct vm_operations_struct *ttm_vm_ops;
42136
42137 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42138 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42139 return r;
42140 if (unlikely(ttm_vm_ops == NULL)) {
42141 ttm_vm_ops = vma->vm_ops;
42142 + pax_open_kernel();
42143 qxl_ttm_vm_ops = *ttm_vm_ops;
42144 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42145 + pax_close_kernel();
42146 }
42147 vma->vm_ops = &qxl_ttm_vm_ops;
42148 return 0;
42149 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42150 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42151 {
42152 #if defined(CONFIG_DEBUG_FS)
42153 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42154 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42155 - unsigned i;
42156 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42157 + {
42158 + .name = "qxl_mem_mm",
42159 + .show = &qxl_mm_dump_table,
42160 + },
42161 + {
42162 + .name = "qxl_surf_mm",
42163 + .show = &qxl_mm_dump_table,
42164 + }
42165 + };
42166
42167 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42168 - if (i == 0)
42169 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42170 - else
42171 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42172 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42173 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42174 - qxl_mem_types_list[i].driver_features = 0;
42175 - if (i == 0)
42176 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42177 - else
42178 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42179 + pax_open_kernel();
42180 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42181 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42182 + pax_close_kernel();
42183
42184 - }
42185 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42186 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42187 #else
42188 return 0;
42189 #endif
42190 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42191 index 59459fe..be26b31 100644
42192 --- a/drivers/gpu/drm/r128/r128_cce.c
42193 +++ b/drivers/gpu/drm/r128/r128_cce.c
42194 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42195
42196 /* GH: Simple idle check.
42197 */
42198 - atomic_set(&dev_priv->idle_count, 0);
42199 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42200
42201 /* We don't support anything other than bus-mastering ring mode,
42202 * but the ring can be in either AGP or PCI space for the ring
42203 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42204 index 5bf3f5f..7000661 100644
42205 --- a/drivers/gpu/drm/r128/r128_drv.h
42206 +++ b/drivers/gpu/drm/r128/r128_drv.h
42207 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42208 int is_pci;
42209 unsigned long cce_buffers_offset;
42210
42211 - atomic_t idle_count;
42212 + atomic_unchecked_t idle_count;
42213
42214 int page_flipping;
42215 int current_page;
42216 u32 crtc_offset;
42217 u32 crtc_offset_cntl;
42218
42219 - atomic_t vbl_received;
42220 + atomic_unchecked_t vbl_received;
42221
42222 u32 color_fmt;
42223 unsigned int front_offset;
42224 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42225 index 663f38c..c689495 100644
42226 --- a/drivers/gpu/drm/r128/r128_ioc32.c
42227 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
42228 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42229 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42230 }
42231
42232 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
42233 +drm_ioctl_compat_t r128_compat_ioctls[] = {
42234 [DRM_R128_INIT] = compat_r128_init,
42235 [DRM_R128_DEPTH] = compat_r128_depth,
42236 [DRM_R128_STIPPLE] = compat_r128_stipple,
42237 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42238 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42239 {
42240 unsigned int nr = DRM_IOCTL_NR(cmd);
42241 - drm_ioctl_compat_t *fn = NULL;
42242 int ret;
42243
42244 if (nr < DRM_COMMAND_BASE)
42245 return drm_compat_ioctl(filp, cmd, arg);
42246
42247 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42248 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42249 -
42250 - if (fn != NULL)
42251 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42252 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42253 ret = (*fn) (filp, cmd, arg);
42254 - else
42255 + } else
42256 ret = drm_ioctl(filp, cmd, arg);
42257
42258 return ret;
42259 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42260 index c2ae496..30b5993 100644
42261 --- a/drivers/gpu/drm/r128/r128_irq.c
42262 +++ b/drivers/gpu/drm/r128/r128_irq.c
42263 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42264 if (crtc != 0)
42265 return 0;
42266
42267 - return atomic_read(&dev_priv->vbl_received);
42268 + return atomic_read_unchecked(&dev_priv->vbl_received);
42269 }
42270
42271 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42272 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42273 /* VBLANK interrupt */
42274 if (status & R128_CRTC_VBLANK_INT) {
42275 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42276 - atomic_inc(&dev_priv->vbl_received);
42277 + atomic_inc_unchecked(&dev_priv->vbl_received);
42278 drm_handle_vblank(dev, 0);
42279 return IRQ_HANDLED;
42280 }
42281 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42282 index 575e986..66e62ca 100644
42283 --- a/drivers/gpu/drm/r128/r128_state.c
42284 +++ b/drivers/gpu/drm/r128/r128_state.c
42285 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42286
42287 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42288 {
42289 - if (atomic_read(&dev_priv->idle_count) == 0)
42290 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42291 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42292 else
42293 - atomic_set(&dev_priv->idle_count, 0);
42294 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42295 }
42296
42297 #endif
42298 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42299 index 4a85bb6..aaea819 100644
42300 --- a/drivers/gpu/drm/radeon/mkregtable.c
42301 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42302 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42303 regex_t mask_rex;
42304 regmatch_t match[4];
42305 char buf[1024];
42306 - size_t end;
42307 + long end;
42308 int len;
42309 int done = 0;
42310 int r;
42311 unsigned o;
42312 struct offset *offset;
42313 char last_reg_s[10];
42314 - int last_reg;
42315 + unsigned long last_reg;
42316
42317 if (regcomp
42318 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42319 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42320 index 12c8329..a69e2e8 100644
42321 --- a/drivers/gpu/drm/radeon/radeon_device.c
42322 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42323 @@ -1213,7 +1213,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42324 * locking inversion with the driver load path. And the access here is
42325 * completely racy anyway. So don't bother with locking for now.
42326 */
42327 - return dev->open_count == 0;
42328 + return local_read(&dev->open_count) == 0;
42329 }
42330
42331 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42332 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42333 index dafd812..1bf20c7 100644
42334 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42335 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42336 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42337
42338 /* SW interrupt */
42339 wait_queue_head_t swi_queue;
42340 - atomic_t swi_emitted;
42341 + atomic_unchecked_t swi_emitted;
42342 int vblank_crtc;
42343 uint32_t irq_enable_reg;
42344 uint32_t r500_disp_irq_reg;
42345 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42346 index 0b98ea1..0881827 100644
42347 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42348 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42349 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42350 request = compat_alloc_user_space(sizeof(*request));
42351 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42352 || __put_user(req32.param, &request->param)
42353 - || __put_user((void __user *)(unsigned long)req32.value,
42354 + || __put_user((unsigned long)req32.value,
42355 &request->value))
42356 return -EFAULT;
42357
42358 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42359 #define compat_radeon_cp_setparam NULL
42360 #endif /* X86_64 || IA64 */
42361
42362 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42363 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42364 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42365 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42366 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42367 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42368 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42369 {
42370 unsigned int nr = DRM_IOCTL_NR(cmd);
42371 - drm_ioctl_compat_t *fn = NULL;
42372 int ret;
42373
42374 if (nr < DRM_COMMAND_BASE)
42375 return drm_compat_ioctl(filp, cmd, arg);
42376
42377 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42378 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42379 -
42380 - if (fn != NULL)
42381 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42382 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42383 ret = (*fn) (filp, cmd, arg);
42384 - else
42385 + } else
42386 ret = drm_ioctl(filp, cmd, arg);
42387
42388 return ret;
42389 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42390 index 244b19b..c19226d 100644
42391 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42392 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42393 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42394 unsigned int ret;
42395 RING_LOCALS;
42396
42397 - atomic_inc(&dev_priv->swi_emitted);
42398 - ret = atomic_read(&dev_priv->swi_emitted);
42399 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42400 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42401
42402 BEGIN_RING(4);
42403 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42404 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42405 drm_radeon_private_t *dev_priv =
42406 (drm_radeon_private_t *) dev->dev_private;
42407
42408 - atomic_set(&dev_priv->swi_emitted, 0);
42409 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42410 init_waitqueue_head(&dev_priv->swi_queue);
42411
42412 dev->max_vblank_count = 0x001fffff;
42413 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42414 index 23bb64f..69d7234 100644
42415 --- a/drivers/gpu/drm/radeon/radeon_state.c
42416 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42417 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42418 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42419 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42420
42421 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42422 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42423 sarea_priv->nbox * sizeof(depth_boxes[0])))
42424 return -EFAULT;
42425
42426 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42427 {
42428 drm_radeon_private_t *dev_priv = dev->dev_private;
42429 drm_radeon_getparam_t *param = data;
42430 - int value;
42431 + int value = 0;
42432
42433 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42434
42435 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42436 index 72afe82..056a57a 100644
42437 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42438 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42439 @@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42440 man->size = size >> PAGE_SHIFT;
42441 }
42442
42443 -static struct vm_operations_struct radeon_ttm_vm_ops;
42444 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42445 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42446
42447 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42448 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42449 }
42450 if (unlikely(ttm_vm_ops == NULL)) {
42451 ttm_vm_ops = vma->vm_ops;
42452 + pax_open_kernel();
42453 radeon_ttm_vm_ops = *ttm_vm_ops;
42454 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42455 + pax_close_kernel();
42456 }
42457 vma->vm_ops = &radeon_ttm_vm_ops;
42458 return 0;
42459 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42460 index 6553fd2..aecd29c 100644
42461 --- a/drivers/gpu/drm/tegra/dc.c
42462 +++ b/drivers/gpu/drm/tegra/dc.c
42463 @@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42464 }
42465
42466 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42467 - dc->debugfs_files[i].data = dc;
42468 + *(void **)&dc->debugfs_files[i].data = dc;
42469
42470 err = drm_debugfs_create_files(dc->debugfs_files,
42471 ARRAY_SIZE(debugfs_files),
42472 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42473 index f787445..2df2c65 100644
42474 --- a/drivers/gpu/drm/tegra/dsi.c
42475 +++ b/drivers/gpu/drm/tegra/dsi.c
42476 @@ -41,7 +41,7 @@ struct tegra_dsi {
42477 struct clk *clk_lp;
42478 struct clk *clk;
42479
42480 - struct drm_info_list *debugfs_files;
42481 + drm_info_list_no_const *debugfs_files;
42482 struct drm_minor *minor;
42483 struct dentry *debugfs;
42484
42485 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42486 index ffe2654..03c7b1c 100644
42487 --- a/drivers/gpu/drm/tegra/hdmi.c
42488 +++ b/drivers/gpu/drm/tegra/hdmi.c
42489 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42490 bool stereo;
42491 bool dvi;
42492
42493 - struct drm_info_list *debugfs_files;
42494 + drm_info_list_no_const *debugfs_files;
42495 struct drm_minor *minor;
42496 struct dentry *debugfs;
42497 };
42498 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42499 index 9e103a48..0e117f3 100644
42500 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42501 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42502 @@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42503 }
42504
42505 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42506 - ttm_bo_man_init,
42507 - ttm_bo_man_takedown,
42508 - ttm_bo_man_get_node,
42509 - ttm_bo_man_put_node,
42510 - ttm_bo_man_debug
42511 + .init = ttm_bo_man_init,
42512 + .takedown = ttm_bo_man_takedown,
42513 + .get_node = ttm_bo_man_get_node,
42514 + .put_node = ttm_bo_man_put_node,
42515 + .debug = ttm_bo_man_debug
42516 };
42517 EXPORT_SYMBOL(ttm_bo_manager_func);
42518 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42519 index dbc2def..0a9f710 100644
42520 --- a/drivers/gpu/drm/ttm/ttm_memory.c
42521 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
42522 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42523 zone->glob = glob;
42524 glob->zone_kernel = zone;
42525 ret = kobject_init_and_add(
42526 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42527 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42528 if (unlikely(ret != 0)) {
42529 kobject_put(&zone->kobj);
42530 return ret;
42531 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42532 zone->glob = glob;
42533 glob->zone_dma32 = zone;
42534 ret = kobject_init_and_add(
42535 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42536 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42537 if (unlikely(ret != 0)) {
42538 kobject_put(&zone->kobj);
42539 return ret;
42540 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42541 index d1da339..829235e 100644
42542 --- a/drivers/gpu/drm/udl/udl_fb.c
42543 +++ b/drivers/gpu/drm/udl/udl_fb.c
42544 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42545 fb_deferred_io_cleanup(info);
42546 kfree(info->fbdefio);
42547 info->fbdefio = NULL;
42548 - info->fbops->fb_mmap = udl_fb_mmap;
42549 }
42550
42551 pr_warn("released /dev/fb%d user=%d count=%d\n",
42552 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42553 index ad02732..144f5ed 100644
42554 --- a/drivers/gpu/drm/via/via_drv.h
42555 +++ b/drivers/gpu/drm/via/via_drv.h
42556 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42557 typedef uint32_t maskarray_t[5];
42558
42559 typedef struct drm_via_irq {
42560 - atomic_t irq_received;
42561 + atomic_unchecked_t irq_received;
42562 uint32_t pending_mask;
42563 uint32_t enable_mask;
42564 wait_queue_head_t irq_queue;
42565 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
42566 struct timeval last_vblank;
42567 int last_vblank_valid;
42568 unsigned usec_per_vblank;
42569 - atomic_t vbl_received;
42570 + atomic_unchecked_t vbl_received;
42571 drm_via_state_t hc_state;
42572 char pci_buf[VIA_PCI_BUF_SIZE];
42573 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42574 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42575 index 1319433..a993b0c 100644
42576 --- a/drivers/gpu/drm/via/via_irq.c
42577 +++ b/drivers/gpu/drm/via/via_irq.c
42578 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42579 if (crtc != 0)
42580 return 0;
42581
42582 - return atomic_read(&dev_priv->vbl_received);
42583 + return atomic_read_unchecked(&dev_priv->vbl_received);
42584 }
42585
42586 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42587 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42588
42589 status = VIA_READ(VIA_REG_INTERRUPT);
42590 if (status & VIA_IRQ_VBLANK_PENDING) {
42591 - atomic_inc(&dev_priv->vbl_received);
42592 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42593 + atomic_inc_unchecked(&dev_priv->vbl_received);
42594 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42595 do_gettimeofday(&cur_vblank);
42596 if (dev_priv->last_vblank_valid) {
42597 dev_priv->usec_per_vblank =
42598 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42599 dev_priv->last_vblank = cur_vblank;
42600 dev_priv->last_vblank_valid = 1;
42601 }
42602 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42603 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42604 DRM_DEBUG("US per vblank is: %u\n",
42605 dev_priv->usec_per_vblank);
42606 }
42607 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42608
42609 for (i = 0; i < dev_priv->num_irqs; ++i) {
42610 if (status & cur_irq->pending_mask) {
42611 - atomic_inc(&cur_irq->irq_received);
42612 + atomic_inc_unchecked(&cur_irq->irq_received);
42613 wake_up(&cur_irq->irq_queue);
42614 handled = 1;
42615 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42616 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42617 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42618 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42619 masks[irq][4]));
42620 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42621 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42622 } else {
42623 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42624 (((cur_irq_sequence =
42625 - atomic_read(&cur_irq->irq_received)) -
42626 + atomic_read_unchecked(&cur_irq->irq_received)) -
42627 *sequence) <= (1 << 23)));
42628 }
42629 *sequence = cur_irq_sequence;
42630 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42631 }
42632
42633 for (i = 0; i < dev_priv->num_irqs; ++i) {
42634 - atomic_set(&cur_irq->irq_received, 0);
42635 + atomic_set_unchecked(&cur_irq->irq_received, 0);
42636 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42637 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42638 init_waitqueue_head(&cur_irq->irq_queue);
42639 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42640 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42641 case VIA_IRQ_RELATIVE:
42642 irqwait->request.sequence +=
42643 - atomic_read(&cur_irq->irq_received);
42644 + atomic_read_unchecked(&cur_irq->irq_received);
42645 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42646 case VIA_IRQ_ABSOLUTE:
42647 break;
42648 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42649 index 99f7317..33a835b 100644
42650 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42651 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42652 @@ -447,7 +447,7 @@ struct vmw_private {
42653 * Fencing and IRQs.
42654 */
42655
42656 - atomic_t marker_seq;
42657 + atomic_unchecked_t marker_seq;
42658 wait_queue_head_t fence_queue;
42659 wait_queue_head_t fifo_queue;
42660 int fence_queue_waiters; /* Protected by hw_mutex */
42661 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42662 index 6eae14d..aa311b3 100644
42663 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42664 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42665 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42666 (unsigned int) min,
42667 (unsigned int) fifo->capabilities);
42668
42669 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42670 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42671 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42672 vmw_marker_queue_init(&fifo->marker_queue);
42673 return vmw_fifo_send_fence(dev_priv, &dummy);
42674 @@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42675 if (reserveable)
42676 iowrite32(bytes, fifo_mem +
42677 SVGA_FIFO_RESERVED);
42678 - return fifo_mem + (next_cmd >> 2);
42679 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42680 } else {
42681 need_bounce = true;
42682 }
42683 @@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42684
42685 fm = vmw_fifo_reserve(dev_priv, bytes);
42686 if (unlikely(fm == NULL)) {
42687 - *seqno = atomic_read(&dev_priv->marker_seq);
42688 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42689 ret = -ENOMEM;
42690 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42691 false, 3*HZ);
42692 @@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42693 }
42694
42695 do {
42696 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42697 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42698 } while (*seqno == 0);
42699
42700 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42701 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42702 index 26f8bdd..90a0008 100644
42703 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42704 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42705 @@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42706 }
42707
42708 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42709 - vmw_gmrid_man_init,
42710 - vmw_gmrid_man_takedown,
42711 - vmw_gmrid_man_get_node,
42712 - vmw_gmrid_man_put_node,
42713 - vmw_gmrid_man_debug
42714 + .init = vmw_gmrid_man_init,
42715 + .takedown = vmw_gmrid_man_takedown,
42716 + .get_node = vmw_gmrid_man_get_node,
42717 + .put_node = vmw_gmrid_man_put_node,
42718 + .debug = vmw_gmrid_man_debug
42719 };
42720 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42721 index 37881ec..319065d 100644
42722 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42723 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42724 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42725 int ret;
42726
42727 num_clips = arg->num_clips;
42728 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42729 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42730
42731 if (unlikely(num_clips == 0))
42732 return 0;
42733 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42734 int ret;
42735
42736 num_clips = arg->num_clips;
42737 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42738 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42739
42740 if (unlikely(num_clips == 0))
42741 return 0;
42742 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42743 index 0c42376..6febe77 100644
42744 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42745 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42746 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42747 * emitted. Then the fence is stale and signaled.
42748 */
42749
42750 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42751 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42752 > VMW_FENCE_WRAP);
42753
42754 return ret;
42755 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42756
42757 if (fifo_idle)
42758 down_read(&fifo_state->rwsem);
42759 - signal_seq = atomic_read(&dev_priv->marker_seq);
42760 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42761 ret = 0;
42762
42763 for (;;) {
42764 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42765 index efd1ffd..0ae13ca 100644
42766 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42767 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42768 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42769 while (!vmw_lag_lt(queue, us)) {
42770 spin_lock(&queue->lock);
42771 if (list_empty(&queue->head))
42772 - seqno = atomic_read(&dev_priv->marker_seq);
42773 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42774 else {
42775 marker = list_first_entry(&queue->head,
42776 struct vmw_marker, head);
42777 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42778 index 37ac7b5..d52a5c9 100644
42779 --- a/drivers/gpu/vga/vga_switcheroo.c
42780 +++ b/drivers/gpu/vga/vga_switcheroo.c
42781 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42782
42783 /* this version is for the case where the power switch is separate
42784 to the device being powered down. */
42785 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42786 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42787 {
42788 /* copy over all the bus versions */
42789 if (dev->bus && dev->bus->pm) {
42790 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42791 return ret;
42792 }
42793
42794 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42795 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42796 {
42797 /* copy over all the bus versions */
42798 if (dev->bus && dev->bus->pm) {
42799 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42800 index 12b6e67..ddd983c 100644
42801 --- a/drivers/hid/hid-core.c
42802 +++ b/drivers/hid/hid-core.c
42803 @@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42804
42805 int hid_add_device(struct hid_device *hdev)
42806 {
42807 - static atomic_t id = ATOMIC_INIT(0);
42808 + static atomic_unchecked_t id = ATOMIC_INIT(0);
42809 int ret;
42810
42811 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42812 @@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42813 /* XXX hack, any other cleaner solution after the driver core
42814 * is converted to allow more than 20 bytes as the device name? */
42815 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42816 - hdev->vendor, hdev->product, atomic_inc_return(&id));
42817 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42818
42819 hid_debug_register(hdev, dev_name(&hdev->dev));
42820 ret = device_add(&hdev->dev);
42821 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42822 index 9bf8637..f462416 100644
42823 --- a/drivers/hid/hid-logitech-dj.c
42824 +++ b/drivers/hid/hid-logitech-dj.c
42825 @@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42826 * device (via hid_input_report() ) and return 1 so hid-core does not do
42827 * anything else with it.
42828 */
42829 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42830 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42831 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42832 + __func__, dj_report->device_index);
42833 + return false;
42834 + }
42835
42836 /* case 1) */
42837 if (data[0] != REPORT_ID_DJ_SHORT)
42838 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42839 index c13fb5b..55a3802 100644
42840 --- a/drivers/hid/hid-wiimote-debug.c
42841 +++ b/drivers/hid/hid-wiimote-debug.c
42842 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42843 else if (size == 0)
42844 return -EIO;
42845
42846 - if (copy_to_user(u, buf, size))
42847 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42848 return -EFAULT;
42849
42850 *off += size;
42851 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42852 index 0cb92e3..c7d453d 100644
42853 --- a/drivers/hid/uhid.c
42854 +++ b/drivers/hid/uhid.c
42855 @@ -47,7 +47,7 @@ struct uhid_device {
42856 struct mutex report_lock;
42857 wait_queue_head_t report_wait;
42858 atomic_t report_done;
42859 - atomic_t report_id;
42860 + atomic_unchecked_t report_id;
42861 struct uhid_event report_buf;
42862 };
42863
42864 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42865
42866 spin_lock_irqsave(&uhid->qlock, flags);
42867 ev->type = UHID_FEATURE;
42868 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42869 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42870 ev->u.feature.rnum = rnum;
42871 ev->u.feature.rtype = report_type;
42872
42873 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42874 spin_lock_irqsave(&uhid->qlock, flags);
42875
42876 /* id for old report; drop it silently */
42877 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42878 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42879 goto unlock;
42880 if (atomic_read(&uhid->report_done))
42881 goto unlock;
42882 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42883 index 531a593..0b43a69 100644
42884 --- a/drivers/hv/channel.c
42885 +++ b/drivers/hv/channel.c
42886 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42887 int ret = 0;
42888 int t;
42889
42890 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42891 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42892 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42893 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42894
42895 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42896 if (ret)
42897 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42898 index edfc848..d83e195 100644
42899 --- a/drivers/hv/hv.c
42900 +++ b/drivers/hv/hv.c
42901 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42902 u64 output_address = (output) ? virt_to_phys(output) : 0;
42903 u32 output_address_hi = output_address >> 32;
42904 u32 output_address_lo = output_address & 0xFFFFFFFF;
42905 - void *hypercall_page = hv_context.hypercall_page;
42906 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42907
42908 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42909 "=a"(hv_status_lo) : "d" (control_hi),
42910 @@ -154,7 +154,7 @@ int hv_init(void)
42911 /* See if the hypercall page is already set */
42912 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42913
42914 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42915 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42916
42917 if (!virtaddr)
42918 goto cleanup;
42919 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42920 index 5e90c5d..d8fcefb 100644
42921 --- a/drivers/hv/hv_balloon.c
42922 +++ b/drivers/hv/hv_balloon.c
42923 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42924
42925 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42926 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42927 -static atomic_t trans_id = ATOMIC_INIT(0);
42928 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42929
42930 static int dm_ring_size = (5 * PAGE_SIZE);
42931
42932 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42933 pr_info("Memory hot add failed\n");
42934
42935 dm->state = DM_INITIALIZED;
42936 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42937 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42938 vmbus_sendpacket(dm->dev->channel, &resp,
42939 sizeof(struct dm_hot_add_response),
42940 (unsigned long)NULL,
42941 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42942 memset(&status, 0, sizeof(struct dm_status));
42943 status.hdr.type = DM_STATUS_REPORT;
42944 status.hdr.size = sizeof(struct dm_status);
42945 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42946 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42947
42948 /*
42949 * The host expects the guest to report free memory.
42950 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42951 * send the status. This can happen if we were interrupted
42952 * after we picked our transaction ID.
42953 */
42954 - if (status.hdr.trans_id != atomic_read(&trans_id))
42955 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42956 return;
42957
42958 /*
42959 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42960 */
42961
42962 do {
42963 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42964 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42965 ret = vmbus_sendpacket(dm_device.dev->channel,
42966 bl_resp,
42967 bl_resp->hdr.size,
42968 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42969
42970 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42971 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42972 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42973 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42974 resp.hdr.size = sizeof(struct dm_unballoon_response);
42975
42976 vmbus_sendpacket(dm_device.dev->channel, &resp,
42977 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42978 memset(&version_req, 0, sizeof(struct dm_version_request));
42979 version_req.hdr.type = DM_VERSION_REQUEST;
42980 version_req.hdr.size = sizeof(struct dm_version_request);
42981 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42982 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42983 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42984 version_req.is_last_attempt = 1;
42985
42986 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42987 memset(&version_req, 0, sizeof(struct dm_version_request));
42988 version_req.hdr.type = DM_VERSION_REQUEST;
42989 version_req.hdr.size = sizeof(struct dm_version_request);
42990 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42991 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42992 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42993 version_req.is_last_attempt = 0;
42994
42995 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42996 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42997 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42998 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42999 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43000 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43001
43002 cap_msg.caps.cap_bits.balloon = 1;
43003 cap_msg.caps.cap_bits.hot_add = 1;
43004 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43005 index 22b7507..fc2fc47 100644
43006 --- a/drivers/hv/hyperv_vmbus.h
43007 +++ b/drivers/hv/hyperv_vmbus.h
43008 @@ -607,7 +607,7 @@ enum vmbus_connect_state {
43009 struct vmbus_connection {
43010 enum vmbus_connect_state conn_state;
43011
43012 - atomic_t next_gpadl_handle;
43013 + atomic_unchecked_t next_gpadl_handle;
43014
43015 /*
43016 * Represents channel interrupts. Each bit position represents a
43017 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43018 index 4d6b269..2e23b86 100644
43019 --- a/drivers/hv/vmbus_drv.c
43020 +++ b/drivers/hv/vmbus_drv.c
43021 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43022 {
43023 int ret = 0;
43024
43025 - static atomic_t device_num = ATOMIC_INIT(0);
43026 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43027
43028 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43029 - atomic_inc_return(&device_num));
43030 + atomic_inc_return_unchecked(&device_num));
43031
43032 child_device_obj->device.bus = &hv_bus;
43033 child_device_obj->device.parent = &hv_acpi_dev->dev;
43034 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43035 index 579bdf9..75118b5 100644
43036 --- a/drivers/hwmon/acpi_power_meter.c
43037 +++ b/drivers/hwmon/acpi_power_meter.c
43038 @@ -116,7 +116,7 @@ struct sensor_template {
43039 struct device_attribute *devattr,
43040 const char *buf, size_t count);
43041 int index;
43042 -};
43043 +} __do_const;
43044
43045 /* Averaging interval */
43046 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43047 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43048 struct sensor_template *attrs)
43049 {
43050 struct device *dev = &resource->acpi_dev->dev;
43051 - struct sensor_device_attribute *sensors =
43052 + sensor_device_attribute_no_const *sensors =
43053 &resource->sensors[resource->num_sensors];
43054 int res = 0;
43055
43056 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43057 index 3288f13..71cfb4e 100644
43058 --- a/drivers/hwmon/applesmc.c
43059 +++ b/drivers/hwmon/applesmc.c
43060 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43061 {
43062 struct applesmc_node_group *grp;
43063 struct applesmc_dev_attr *node;
43064 - struct attribute *attr;
43065 + attribute_no_const *attr;
43066 int ret, i;
43067
43068 for (grp = groups; grp->format; grp++) {
43069 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43070 index cccef87..06ce8ec 100644
43071 --- a/drivers/hwmon/asus_atk0110.c
43072 +++ b/drivers/hwmon/asus_atk0110.c
43073 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43074 struct atk_sensor_data {
43075 struct list_head list;
43076 struct atk_data *data;
43077 - struct device_attribute label_attr;
43078 - struct device_attribute input_attr;
43079 - struct device_attribute limit1_attr;
43080 - struct device_attribute limit2_attr;
43081 + device_attribute_no_const label_attr;
43082 + device_attribute_no_const input_attr;
43083 + device_attribute_no_const limit1_attr;
43084 + device_attribute_no_const limit2_attr;
43085 char label_attr_name[ATTR_NAME_SIZE];
43086 char input_attr_name[ATTR_NAME_SIZE];
43087 char limit1_attr_name[ATTR_NAME_SIZE];
43088 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43089 static struct device_attribute atk_name_attr =
43090 __ATTR(name, 0444, atk_name_show, NULL);
43091
43092 -static void atk_init_attribute(struct device_attribute *attr, char *name,
43093 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43094 sysfs_show_func show)
43095 {
43096 sysfs_attr_init(&attr->attr);
43097 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43098 index d76f0b7..55ae976 100644
43099 --- a/drivers/hwmon/coretemp.c
43100 +++ b/drivers/hwmon/coretemp.c
43101 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43102 return NOTIFY_OK;
43103 }
43104
43105 -static struct notifier_block coretemp_cpu_notifier __refdata = {
43106 +static struct notifier_block coretemp_cpu_notifier = {
43107 .notifier_call = coretemp_cpu_callback,
43108 };
43109
43110 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43111 index 7a8a6fb..015c1fd 100644
43112 --- a/drivers/hwmon/ibmaem.c
43113 +++ b/drivers/hwmon/ibmaem.c
43114 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
43115 struct aem_rw_sensor_template *rw)
43116 {
43117 struct device *dev = &data->pdev->dev;
43118 - struct sensor_device_attribute *sensors = data->sensors;
43119 + sensor_device_attribute_no_const *sensors = data->sensors;
43120 int err;
43121
43122 /* Set up read-only sensors */
43123 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43124 index 14c82da..09b25d7 100644
43125 --- a/drivers/hwmon/iio_hwmon.c
43126 +++ b/drivers/hwmon/iio_hwmon.c
43127 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43128 {
43129 struct device *dev = &pdev->dev;
43130 struct iio_hwmon_state *st;
43131 - struct sensor_device_attribute *a;
43132 + sensor_device_attribute_no_const *a;
43133 int ret, i;
43134 int in_i = 1, temp_i = 1, curr_i = 1;
43135 enum iio_chan_type type;
43136 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43137 index 7710f46..427a28d 100644
43138 --- a/drivers/hwmon/nct6683.c
43139 +++ b/drivers/hwmon/nct6683.c
43140 @@ -397,11 +397,11 @@ static struct attribute_group *
43141 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43142 int repeat)
43143 {
43144 - struct sensor_device_attribute_2 *a2;
43145 - struct sensor_device_attribute *a;
43146 + sensor_device_attribute_2_no_const *a2;
43147 + sensor_device_attribute_no_const *a;
43148 struct sensor_device_template **t;
43149 struct sensor_device_attr_u *su;
43150 - struct attribute_group *group;
43151 + attribute_group_no_const *group;
43152 struct attribute **attrs;
43153 int i, j, count;
43154
43155 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43156 index 504cbdd..35d6f25 100644
43157 --- a/drivers/hwmon/nct6775.c
43158 +++ b/drivers/hwmon/nct6775.c
43159 @@ -943,10 +943,10 @@ static struct attribute_group *
43160 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43161 int repeat)
43162 {
43163 - struct attribute_group *group;
43164 + attribute_group_no_const *group;
43165 struct sensor_device_attr_u *su;
43166 - struct sensor_device_attribute *a;
43167 - struct sensor_device_attribute_2 *a2;
43168 + sensor_device_attribute_no_const *a;
43169 + sensor_device_attribute_2_no_const *a2;
43170 struct attribute **attrs;
43171 struct sensor_device_template **t;
43172 int i, count;
43173 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43174 index 291d11f..3f0dbbd 100644
43175 --- a/drivers/hwmon/pmbus/pmbus_core.c
43176 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43177 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43178 return 0;
43179 }
43180
43181 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43182 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43183 const char *name,
43184 umode_t mode,
43185 ssize_t (*show)(struct device *dev,
43186 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43187 dev_attr->store = store;
43188 }
43189
43190 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43191 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43192 const char *name,
43193 umode_t mode,
43194 ssize_t (*show)(struct device *dev,
43195 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43196 u16 reg, u8 mask)
43197 {
43198 struct pmbus_boolean *boolean;
43199 - struct sensor_device_attribute *a;
43200 + sensor_device_attribute_no_const *a;
43201
43202 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43203 if (!boolean)
43204 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43205 bool update, bool readonly)
43206 {
43207 struct pmbus_sensor *sensor;
43208 - struct device_attribute *a;
43209 + device_attribute_no_const *a;
43210
43211 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43212 if (!sensor)
43213 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43214 const char *lstring, int index)
43215 {
43216 struct pmbus_label *label;
43217 - struct device_attribute *a;
43218 + device_attribute_no_const *a;
43219
43220 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43221 if (!label)
43222 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43223 index 97cd45a..ac54d8b 100644
43224 --- a/drivers/hwmon/sht15.c
43225 +++ b/drivers/hwmon/sht15.c
43226 @@ -169,7 +169,7 @@ struct sht15_data {
43227 int supply_uv;
43228 bool supply_uv_valid;
43229 struct work_struct update_supply_work;
43230 - atomic_t interrupt_handled;
43231 + atomic_unchecked_t interrupt_handled;
43232 };
43233
43234 /**
43235 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43236 ret = gpio_direction_input(data->pdata->gpio_data);
43237 if (ret)
43238 return ret;
43239 - atomic_set(&data->interrupt_handled, 0);
43240 + atomic_set_unchecked(&data->interrupt_handled, 0);
43241
43242 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43243 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43244 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43245 /* Only relevant if the interrupt hasn't occurred. */
43246 - if (!atomic_read(&data->interrupt_handled))
43247 + if (!atomic_read_unchecked(&data->interrupt_handled))
43248 schedule_work(&data->read_work);
43249 }
43250 ret = wait_event_timeout(data->wait_queue,
43251 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43252
43253 /* First disable the interrupt */
43254 disable_irq_nosync(irq);
43255 - atomic_inc(&data->interrupt_handled);
43256 + atomic_inc_unchecked(&data->interrupt_handled);
43257 /* Then schedule a reading work struct */
43258 if (data->state != SHT15_READING_NOTHING)
43259 schedule_work(&data->read_work);
43260 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43261 * If not, then start the interrupt again - care here as could
43262 * have gone low in meantime so verify it hasn't!
43263 */
43264 - atomic_set(&data->interrupt_handled, 0);
43265 + atomic_set_unchecked(&data->interrupt_handled, 0);
43266 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43267 /* If still not occurred or another handler was scheduled */
43268 if (gpio_get_value(data->pdata->gpio_data)
43269 - || atomic_read(&data->interrupt_handled))
43270 + || atomic_read_unchecked(&data->interrupt_handled))
43271 return;
43272 }
43273
43274 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43275 index 8df43c5..b07b91d 100644
43276 --- a/drivers/hwmon/via-cputemp.c
43277 +++ b/drivers/hwmon/via-cputemp.c
43278 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43279 return NOTIFY_OK;
43280 }
43281
43282 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43283 +static struct notifier_block via_cputemp_cpu_notifier = {
43284 .notifier_call = via_cputemp_cpu_callback,
43285 };
43286
43287 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43288 index 41fc683..a39cfea 100644
43289 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43290 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43291 @@ -43,7 +43,7 @@
43292 extern struct i2c_adapter amd756_smbus;
43293
43294 static struct i2c_adapter *s4882_adapter;
43295 -static struct i2c_algorithm *s4882_algo;
43296 +static i2c_algorithm_no_const *s4882_algo;
43297
43298 /* Wrapper access functions for multiplexed SMBus */
43299 static DEFINE_MUTEX(amd756_lock);
43300 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43301 index b19a310..d6eece0 100644
43302 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43303 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43304 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43305 /* usb layer */
43306
43307 /* Send command to device, and get response. */
43308 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43309 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43310 {
43311 int ret = 0;
43312 int actual;
43313 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43314 index b170bdf..3c76427 100644
43315 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43316 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43317 @@ -41,7 +41,7 @@
43318 extern struct i2c_adapter *nforce2_smbus;
43319
43320 static struct i2c_adapter *s4985_adapter;
43321 -static struct i2c_algorithm *s4985_algo;
43322 +static i2c_algorithm_no_const *s4985_algo;
43323
43324 /* Wrapper access functions for multiplexed SMBus */
43325 static DEFINE_MUTEX(nforce2_lock);
43326 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43327 index 80b47e8..1a6040d9 100644
43328 --- a/drivers/i2c/i2c-dev.c
43329 +++ b/drivers/i2c/i2c-dev.c
43330 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43331 break;
43332 }
43333
43334 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43335 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43336 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43337 if (IS_ERR(rdwr_pa[i].buf)) {
43338 res = PTR_ERR(rdwr_pa[i].buf);
43339 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43340 index 0b510ba..4fbb5085 100644
43341 --- a/drivers/ide/ide-cd.c
43342 +++ b/drivers/ide/ide-cd.c
43343 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43344 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43345 if ((unsigned long)buf & alignment
43346 || blk_rq_bytes(rq) & q->dma_pad_mask
43347 - || object_is_on_stack(buf))
43348 + || object_starts_on_stack(buf))
43349 drive->dma = 0;
43350 }
43351 }
43352 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43353 index af3e76d..96dfe5e 100644
43354 --- a/drivers/iio/industrialio-core.c
43355 +++ b/drivers/iio/industrialio-core.c
43356 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43357 }
43358
43359 static
43360 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43361 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43362 const char *postfix,
43363 struct iio_chan_spec const *chan,
43364 ssize_t (*readfunc)(struct device *dev,
43365 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43366 index e28a494..f7c2671 100644
43367 --- a/drivers/infiniband/core/cm.c
43368 +++ b/drivers/infiniband/core/cm.c
43369 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43370
43371 struct cm_counter_group {
43372 struct kobject obj;
43373 - atomic_long_t counter[CM_ATTR_COUNT];
43374 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43375 };
43376
43377 struct cm_counter_attribute {
43378 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43379 struct ib_mad_send_buf *msg = NULL;
43380 int ret;
43381
43382 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43383 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43384 counter[CM_REQ_COUNTER]);
43385
43386 /* Quick state check to discard duplicate REQs. */
43387 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43388 if (!cm_id_priv)
43389 return;
43390
43391 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43392 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43393 counter[CM_REP_COUNTER]);
43394 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43395 if (ret)
43396 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43397 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43398 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43399 spin_unlock_irq(&cm_id_priv->lock);
43400 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43401 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43402 counter[CM_RTU_COUNTER]);
43403 goto out;
43404 }
43405 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43406 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43407 dreq_msg->local_comm_id);
43408 if (!cm_id_priv) {
43409 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43410 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43411 counter[CM_DREQ_COUNTER]);
43412 cm_issue_drep(work->port, work->mad_recv_wc);
43413 return -EINVAL;
43414 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43415 case IB_CM_MRA_REP_RCVD:
43416 break;
43417 case IB_CM_TIMEWAIT:
43418 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43419 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43420 counter[CM_DREQ_COUNTER]);
43421 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43422 goto unlock;
43423 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43424 cm_free_msg(msg);
43425 goto deref;
43426 case IB_CM_DREQ_RCVD:
43427 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43428 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43429 counter[CM_DREQ_COUNTER]);
43430 goto unlock;
43431 default:
43432 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43433 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43434 cm_id_priv->msg, timeout)) {
43435 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43436 - atomic_long_inc(&work->port->
43437 + atomic_long_inc_unchecked(&work->port->
43438 counter_group[CM_RECV_DUPLICATES].
43439 counter[CM_MRA_COUNTER]);
43440 goto out;
43441 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43442 break;
43443 case IB_CM_MRA_REQ_RCVD:
43444 case IB_CM_MRA_REP_RCVD:
43445 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43446 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43447 counter[CM_MRA_COUNTER]);
43448 /* fall through */
43449 default:
43450 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43451 case IB_CM_LAP_IDLE:
43452 break;
43453 case IB_CM_MRA_LAP_SENT:
43454 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43455 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43456 counter[CM_LAP_COUNTER]);
43457 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43458 goto unlock;
43459 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43460 cm_free_msg(msg);
43461 goto deref;
43462 case IB_CM_LAP_RCVD:
43463 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43464 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43465 counter[CM_LAP_COUNTER]);
43466 goto unlock;
43467 default:
43468 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43469 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43470 if (cur_cm_id_priv) {
43471 spin_unlock_irq(&cm.lock);
43472 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43473 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43474 counter[CM_SIDR_REQ_COUNTER]);
43475 goto out; /* Duplicate message. */
43476 }
43477 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43478 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43479 msg->retries = 1;
43480
43481 - atomic_long_add(1 + msg->retries,
43482 + atomic_long_add_unchecked(1 + msg->retries,
43483 &port->counter_group[CM_XMIT].counter[attr_index]);
43484 if (msg->retries)
43485 - atomic_long_add(msg->retries,
43486 + atomic_long_add_unchecked(msg->retries,
43487 &port->counter_group[CM_XMIT_RETRIES].
43488 counter[attr_index]);
43489
43490 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43491 }
43492
43493 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43494 - atomic_long_inc(&port->counter_group[CM_RECV].
43495 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43496 counter[attr_id - CM_ATTR_ID_OFFSET]);
43497
43498 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43499 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43500 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43501
43502 return sprintf(buf, "%ld\n",
43503 - atomic_long_read(&group->counter[cm_attr->index]));
43504 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43505 }
43506
43507 static const struct sysfs_ops cm_counter_ops = {
43508 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43509 index 9f5ad7c..588cd84 100644
43510 --- a/drivers/infiniband/core/fmr_pool.c
43511 +++ b/drivers/infiniband/core/fmr_pool.c
43512 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
43513
43514 struct task_struct *thread;
43515
43516 - atomic_t req_ser;
43517 - atomic_t flush_ser;
43518 + atomic_unchecked_t req_ser;
43519 + atomic_unchecked_t flush_ser;
43520
43521 wait_queue_head_t force_wait;
43522 };
43523 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43524 struct ib_fmr_pool *pool = pool_ptr;
43525
43526 do {
43527 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43528 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43529 ib_fmr_batch_release(pool);
43530
43531 - atomic_inc(&pool->flush_ser);
43532 + atomic_inc_unchecked(&pool->flush_ser);
43533 wake_up_interruptible(&pool->force_wait);
43534
43535 if (pool->flush_function)
43536 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43537 }
43538
43539 set_current_state(TASK_INTERRUPTIBLE);
43540 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43541 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43542 !kthread_should_stop())
43543 schedule();
43544 __set_current_state(TASK_RUNNING);
43545 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43546 pool->dirty_watermark = params->dirty_watermark;
43547 pool->dirty_len = 0;
43548 spin_lock_init(&pool->pool_lock);
43549 - atomic_set(&pool->req_ser, 0);
43550 - atomic_set(&pool->flush_ser, 0);
43551 + atomic_set_unchecked(&pool->req_ser, 0);
43552 + atomic_set_unchecked(&pool->flush_ser, 0);
43553 init_waitqueue_head(&pool->force_wait);
43554
43555 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43556 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43557 }
43558 spin_unlock_irq(&pool->pool_lock);
43559
43560 - serial = atomic_inc_return(&pool->req_ser);
43561 + serial = atomic_inc_return_unchecked(&pool->req_ser);
43562 wake_up_process(pool->thread);
43563
43564 if (wait_event_interruptible(pool->force_wait,
43565 - atomic_read(&pool->flush_ser) - serial >= 0))
43566 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43567 return -EINTR;
43568
43569 return 0;
43570 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43571 } else {
43572 list_add_tail(&fmr->list, &pool->dirty_list);
43573 if (++pool->dirty_len >= pool->dirty_watermark) {
43574 - atomic_inc(&pool->req_ser);
43575 + atomic_inc_unchecked(&pool->req_ser);
43576 wake_up_process(pool->thread);
43577 }
43578 }
43579 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43580 index ec7a298..8742e59 100644
43581 --- a/drivers/infiniband/hw/cxgb4/mem.c
43582 +++ b/drivers/infiniband/hw/cxgb4/mem.c
43583 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43584 int err;
43585 struct fw_ri_tpte tpt;
43586 u32 stag_idx;
43587 - static atomic_t key;
43588 + static atomic_unchecked_t key;
43589
43590 if (c4iw_fatal_error(rdev))
43591 return -EIO;
43592 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43593 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43594 rdev->stats.stag.max = rdev->stats.stag.cur;
43595 mutex_unlock(&rdev->stats.lock);
43596 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43597 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43598 }
43599 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43600 __func__, stag_state, type, pdid, stag_idx);
43601 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43602 index 79b3dbc..96e5fcc 100644
43603 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
43604 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43605 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43606 struct ib_atomic_eth *ateth;
43607 struct ipath_ack_entry *e;
43608 u64 vaddr;
43609 - atomic64_t *maddr;
43610 + atomic64_unchecked_t *maddr;
43611 u64 sdata;
43612 u32 rkey;
43613 u8 next;
43614 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43615 IB_ACCESS_REMOTE_ATOMIC)))
43616 goto nack_acc_unlck;
43617 /* Perform atomic OP and save result. */
43618 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43619 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43620 sdata = be64_to_cpu(ateth->swap_data);
43621 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43622 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43623 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43624 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43625 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43626 be64_to_cpu(ateth->compare_data),
43627 sdata);
43628 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43629 index 1f95bba..9530f87 100644
43630 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43631 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43632 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43633 unsigned long flags;
43634 struct ib_wc wc;
43635 u64 sdata;
43636 - atomic64_t *maddr;
43637 + atomic64_unchecked_t *maddr;
43638 enum ib_wc_status send_status;
43639
43640 /*
43641 @@ -382,11 +382,11 @@ again:
43642 IB_ACCESS_REMOTE_ATOMIC)))
43643 goto acc_err;
43644 /* Perform atomic OP and save result. */
43645 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43646 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43647 sdata = wqe->wr.wr.atomic.compare_add;
43648 *(u64 *) sqp->s_sge.sge.vaddr =
43649 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43650 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43651 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43652 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43653 sdata, wqe->wr.wr.atomic.swap);
43654 goto send_comp;
43655 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43656 index 82a7dd8..8fb6ba6 100644
43657 --- a/drivers/infiniband/hw/mlx4/mad.c
43658 +++ b/drivers/infiniband/hw/mlx4/mad.c
43659 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43660
43661 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43662 {
43663 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43664 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43665 cpu_to_be64(0xff00000000000000LL);
43666 }
43667
43668 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43669 index ed327e6..ca1739e0 100644
43670 --- a/drivers/infiniband/hw/mlx4/mcg.c
43671 +++ b/drivers/infiniband/hw/mlx4/mcg.c
43672 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43673 {
43674 char name[20];
43675
43676 - atomic_set(&ctx->tid, 0);
43677 + atomic_set_unchecked(&ctx->tid, 0);
43678 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43679 ctx->mcg_wq = create_singlethread_workqueue(name);
43680 if (!ctx->mcg_wq)
43681 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43682 index 6eb743f..a7b0f6d 100644
43683 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43684 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43685 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43686 struct list_head mcg_mgid0_list;
43687 struct workqueue_struct *mcg_wq;
43688 struct mlx4_ib_demux_pv_ctx **tun;
43689 - atomic_t tid;
43690 + atomic_unchecked_t tid;
43691 int flushing; /* flushing the work queue */
43692 };
43693
43694 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43695 index 9d3e5c1..6f166df 100644
43696 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43697 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43698 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43699 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43700 }
43701
43702 -int mthca_QUERY_FW(struct mthca_dev *dev)
43703 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43704 {
43705 struct mthca_mailbox *mailbox;
43706 u32 *outbox;
43707 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43708 CMD_TIME_CLASS_B);
43709 }
43710
43711 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43712 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43713 int num_mtt)
43714 {
43715 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43716 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43717 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43718 }
43719
43720 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43721 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43722 int eq_num)
43723 {
43724 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43725 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43726 CMD_TIME_CLASS_B);
43727 }
43728
43729 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43730 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43731 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43732 void *in_mad, void *response_mad)
43733 {
43734 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43735 index ded76c1..0cf0a08 100644
43736 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43737 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43738 @@ -692,7 +692,7 @@ err_close:
43739 return err;
43740 }
43741
43742 -static int mthca_setup_hca(struct mthca_dev *dev)
43743 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43744 {
43745 int err;
43746
43747 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43748 index ed9a989..6aa5dc2 100644
43749 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43750 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43751 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43752 * through the bitmaps)
43753 */
43754
43755 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43756 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43757 {
43758 int o;
43759 int m;
43760 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43761 return key;
43762 }
43763
43764 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43765 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43766 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43767 {
43768 struct mthca_mailbox *mailbox;
43769 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43770 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43771 }
43772
43773 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43774 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43775 u64 *buffer_list, int buffer_size_shift,
43776 int list_len, u64 iova, u64 total_size,
43777 u32 access, struct mthca_mr *mr)
43778 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43779 index 415f8e1..e34214e 100644
43780 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43781 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43782 @@ -764,7 +764,7 @@ unlock:
43783 return 0;
43784 }
43785
43786 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43787 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43788 {
43789 struct mthca_dev *dev = to_mdev(ibcq->device);
43790 struct mthca_cq *cq = to_mcq(ibcq);
43791 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43792 index 3b2a6dc..bce26ff 100644
43793 --- a/drivers/infiniband/hw/nes/nes.c
43794 +++ b/drivers/infiniband/hw/nes/nes.c
43795 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43796 LIST_HEAD(nes_adapter_list);
43797 static LIST_HEAD(nes_dev_list);
43798
43799 -atomic_t qps_destroyed;
43800 +atomic_unchecked_t qps_destroyed;
43801
43802 static unsigned int ee_flsh_adapter;
43803 static unsigned int sysfs_nonidx_addr;
43804 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43805 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43806 struct nes_adapter *nesadapter = nesdev->nesadapter;
43807
43808 - atomic_inc(&qps_destroyed);
43809 + atomic_inc_unchecked(&qps_destroyed);
43810
43811 /* Free the control structures */
43812
43813 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43814 index bd9d132..70d84f4 100644
43815 --- a/drivers/infiniband/hw/nes/nes.h
43816 +++ b/drivers/infiniband/hw/nes/nes.h
43817 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43818 extern unsigned int wqm_quanta;
43819 extern struct list_head nes_adapter_list;
43820
43821 -extern atomic_t cm_connects;
43822 -extern atomic_t cm_accepts;
43823 -extern atomic_t cm_disconnects;
43824 -extern atomic_t cm_closes;
43825 -extern atomic_t cm_connecteds;
43826 -extern atomic_t cm_connect_reqs;
43827 -extern atomic_t cm_rejects;
43828 -extern atomic_t mod_qp_timouts;
43829 -extern atomic_t qps_created;
43830 -extern atomic_t qps_destroyed;
43831 -extern atomic_t sw_qps_destroyed;
43832 +extern atomic_unchecked_t cm_connects;
43833 +extern atomic_unchecked_t cm_accepts;
43834 +extern atomic_unchecked_t cm_disconnects;
43835 +extern atomic_unchecked_t cm_closes;
43836 +extern atomic_unchecked_t cm_connecteds;
43837 +extern atomic_unchecked_t cm_connect_reqs;
43838 +extern atomic_unchecked_t cm_rejects;
43839 +extern atomic_unchecked_t mod_qp_timouts;
43840 +extern atomic_unchecked_t qps_created;
43841 +extern atomic_unchecked_t qps_destroyed;
43842 +extern atomic_unchecked_t sw_qps_destroyed;
43843 extern u32 mh_detected;
43844 extern u32 mh_pauses_sent;
43845 extern u32 cm_packets_sent;
43846 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43847 extern u32 cm_packets_received;
43848 extern u32 cm_packets_dropped;
43849 extern u32 cm_packets_retrans;
43850 -extern atomic_t cm_listens_created;
43851 -extern atomic_t cm_listens_destroyed;
43852 +extern atomic_unchecked_t cm_listens_created;
43853 +extern atomic_unchecked_t cm_listens_destroyed;
43854 extern u32 cm_backlog_drops;
43855 -extern atomic_t cm_loopbacks;
43856 -extern atomic_t cm_nodes_created;
43857 -extern atomic_t cm_nodes_destroyed;
43858 -extern atomic_t cm_accel_dropped_pkts;
43859 -extern atomic_t cm_resets_recvd;
43860 -extern atomic_t pau_qps_created;
43861 -extern atomic_t pau_qps_destroyed;
43862 +extern atomic_unchecked_t cm_loopbacks;
43863 +extern atomic_unchecked_t cm_nodes_created;
43864 +extern atomic_unchecked_t cm_nodes_destroyed;
43865 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43866 +extern atomic_unchecked_t cm_resets_recvd;
43867 +extern atomic_unchecked_t pau_qps_created;
43868 +extern atomic_unchecked_t pau_qps_destroyed;
43869
43870 extern u32 int_mod_timer_init;
43871 extern u32 int_mod_cq_depth_256;
43872 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43873 index 6f09a72..cf4399d 100644
43874 --- a/drivers/infiniband/hw/nes/nes_cm.c
43875 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43876 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43877 u32 cm_packets_retrans;
43878 u32 cm_packets_created;
43879 u32 cm_packets_received;
43880 -atomic_t cm_listens_created;
43881 -atomic_t cm_listens_destroyed;
43882 +atomic_unchecked_t cm_listens_created;
43883 +atomic_unchecked_t cm_listens_destroyed;
43884 u32 cm_backlog_drops;
43885 -atomic_t cm_loopbacks;
43886 -atomic_t cm_nodes_created;
43887 -atomic_t cm_nodes_destroyed;
43888 -atomic_t cm_accel_dropped_pkts;
43889 -atomic_t cm_resets_recvd;
43890 +atomic_unchecked_t cm_loopbacks;
43891 +atomic_unchecked_t cm_nodes_created;
43892 +atomic_unchecked_t cm_nodes_destroyed;
43893 +atomic_unchecked_t cm_accel_dropped_pkts;
43894 +atomic_unchecked_t cm_resets_recvd;
43895
43896 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43897 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43898 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43899 /* instance of function pointers for client API */
43900 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43901 static struct nes_cm_ops nes_cm_api = {
43902 - mini_cm_accelerated,
43903 - mini_cm_listen,
43904 - mini_cm_del_listen,
43905 - mini_cm_connect,
43906 - mini_cm_close,
43907 - mini_cm_accept,
43908 - mini_cm_reject,
43909 - mini_cm_recv_pkt,
43910 - mini_cm_dealloc_core,
43911 - mini_cm_get,
43912 - mini_cm_set
43913 + .accelerated = mini_cm_accelerated,
43914 + .listen = mini_cm_listen,
43915 + .stop_listener = mini_cm_del_listen,
43916 + .connect = mini_cm_connect,
43917 + .close = mini_cm_close,
43918 + .accept = mini_cm_accept,
43919 + .reject = mini_cm_reject,
43920 + .recv_pkt = mini_cm_recv_pkt,
43921 + .destroy_cm_core = mini_cm_dealloc_core,
43922 + .get = mini_cm_get,
43923 + .set = mini_cm_set
43924 };
43925
43926 static struct nes_cm_core *g_cm_core;
43927
43928 -atomic_t cm_connects;
43929 -atomic_t cm_accepts;
43930 -atomic_t cm_disconnects;
43931 -atomic_t cm_closes;
43932 -atomic_t cm_connecteds;
43933 -atomic_t cm_connect_reqs;
43934 -atomic_t cm_rejects;
43935 +atomic_unchecked_t cm_connects;
43936 +atomic_unchecked_t cm_accepts;
43937 +atomic_unchecked_t cm_disconnects;
43938 +atomic_unchecked_t cm_closes;
43939 +atomic_unchecked_t cm_connecteds;
43940 +atomic_unchecked_t cm_connect_reqs;
43941 +atomic_unchecked_t cm_rejects;
43942
43943 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43944 {
43945 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43946 kfree(listener);
43947 listener = NULL;
43948 ret = 0;
43949 - atomic_inc(&cm_listens_destroyed);
43950 + atomic_inc_unchecked(&cm_listens_destroyed);
43951 } else {
43952 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43953 }
43954 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43955 cm_node->rem_mac);
43956
43957 add_hte_node(cm_core, cm_node);
43958 - atomic_inc(&cm_nodes_created);
43959 + atomic_inc_unchecked(&cm_nodes_created);
43960
43961 return cm_node;
43962 }
43963 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43964 }
43965
43966 atomic_dec(&cm_core->node_cnt);
43967 - atomic_inc(&cm_nodes_destroyed);
43968 + atomic_inc_unchecked(&cm_nodes_destroyed);
43969 nesqp = cm_node->nesqp;
43970 if (nesqp) {
43971 nesqp->cm_node = NULL;
43972 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43973
43974 static void drop_packet(struct sk_buff *skb)
43975 {
43976 - atomic_inc(&cm_accel_dropped_pkts);
43977 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43978 dev_kfree_skb_any(skb);
43979 }
43980
43981 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43982 {
43983
43984 int reset = 0; /* whether to send reset in case of err.. */
43985 - atomic_inc(&cm_resets_recvd);
43986 + atomic_inc_unchecked(&cm_resets_recvd);
43987 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43988 " refcnt=%d\n", cm_node, cm_node->state,
43989 atomic_read(&cm_node->ref_count));
43990 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43991 rem_ref_cm_node(cm_node->cm_core, cm_node);
43992 return NULL;
43993 }
43994 - atomic_inc(&cm_loopbacks);
43995 + atomic_inc_unchecked(&cm_loopbacks);
43996 loopbackremotenode->loopbackpartner = cm_node;
43997 loopbackremotenode->tcp_cntxt.rcv_wscale =
43998 NES_CM_DEFAULT_RCV_WND_SCALE;
43999 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44000 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44001 else {
44002 rem_ref_cm_node(cm_core, cm_node);
44003 - atomic_inc(&cm_accel_dropped_pkts);
44004 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44005 dev_kfree_skb_any(skb);
44006 }
44007 break;
44008 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44009
44010 if ((cm_id) && (cm_id->event_handler)) {
44011 if (issue_disconn) {
44012 - atomic_inc(&cm_disconnects);
44013 + atomic_inc_unchecked(&cm_disconnects);
44014 cm_event.event = IW_CM_EVENT_DISCONNECT;
44015 cm_event.status = disconn_status;
44016 cm_event.local_addr = cm_id->local_addr;
44017 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44018 }
44019
44020 if (issue_close) {
44021 - atomic_inc(&cm_closes);
44022 + atomic_inc_unchecked(&cm_closes);
44023 nes_disconnect(nesqp, 1);
44024
44025 cm_id->provider_data = nesqp;
44026 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44027
44028 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44029 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44030 - atomic_inc(&cm_accepts);
44031 + atomic_inc_unchecked(&cm_accepts);
44032
44033 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44034 netdev_refcnt_read(nesvnic->netdev));
44035 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44036 struct nes_cm_core *cm_core;
44037 u8 *start_buff;
44038
44039 - atomic_inc(&cm_rejects);
44040 + atomic_inc_unchecked(&cm_rejects);
44041 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44042 loopback = cm_node->loopbackpartner;
44043 cm_core = cm_node->cm_core;
44044 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44045 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44046 ntohs(laddr->sin_port));
44047
44048 - atomic_inc(&cm_connects);
44049 + atomic_inc_unchecked(&cm_connects);
44050 nesqp->active_conn = 1;
44051
44052 /* cache the cm_id in the qp */
44053 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44054 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44055 return err;
44056 }
44057 - atomic_inc(&cm_listens_created);
44058 + atomic_inc_unchecked(&cm_listens_created);
44059 }
44060
44061 cm_id->add_ref(cm_id);
44062 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44063
44064 if (nesqp->destroyed)
44065 return;
44066 - atomic_inc(&cm_connecteds);
44067 + atomic_inc_unchecked(&cm_connecteds);
44068 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44069 " local port 0x%04X. jiffies = %lu.\n",
44070 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44071 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44072
44073 cm_id->add_ref(cm_id);
44074 ret = cm_id->event_handler(cm_id, &cm_event);
44075 - atomic_inc(&cm_closes);
44076 + atomic_inc_unchecked(&cm_closes);
44077 cm_event.event = IW_CM_EVENT_CLOSE;
44078 cm_event.status = 0;
44079 cm_event.provider_data = cm_id->provider_data;
44080 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44081 return;
44082 cm_id = cm_node->cm_id;
44083
44084 - atomic_inc(&cm_connect_reqs);
44085 + atomic_inc_unchecked(&cm_connect_reqs);
44086 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44087 cm_node, cm_id, jiffies);
44088
44089 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44090 return;
44091 cm_id = cm_node->cm_id;
44092
44093 - atomic_inc(&cm_connect_reqs);
44094 + atomic_inc_unchecked(&cm_connect_reqs);
44095 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44096 cm_node, cm_id, jiffies);
44097
44098 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44099 index 4166452..fc952c3 100644
44100 --- a/drivers/infiniband/hw/nes/nes_mgt.c
44101 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
44102 @@ -40,8 +40,8 @@
44103 #include "nes.h"
44104 #include "nes_mgt.h"
44105
44106 -atomic_t pau_qps_created;
44107 -atomic_t pau_qps_destroyed;
44108 +atomic_unchecked_t pau_qps_created;
44109 +atomic_unchecked_t pau_qps_destroyed;
44110
44111 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44112 {
44113 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44114 {
44115 struct sk_buff *skb;
44116 unsigned long flags;
44117 - atomic_inc(&pau_qps_destroyed);
44118 + atomic_inc_unchecked(&pau_qps_destroyed);
44119
44120 /* Free packets that have not yet been forwarded */
44121 /* Lock is acquired by skb_dequeue when removing the skb */
44122 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44123 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44124 skb_queue_head_init(&nesqp->pau_list);
44125 spin_lock_init(&nesqp->pau_lock);
44126 - atomic_inc(&pau_qps_created);
44127 + atomic_inc_unchecked(&pau_qps_created);
44128 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44129 }
44130
44131 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44132 index 49eb511..a774366 100644
44133 --- a/drivers/infiniband/hw/nes/nes_nic.c
44134 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44135 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44136 target_stat_values[++index] = mh_detected;
44137 target_stat_values[++index] = mh_pauses_sent;
44138 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44139 - target_stat_values[++index] = atomic_read(&cm_connects);
44140 - target_stat_values[++index] = atomic_read(&cm_accepts);
44141 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44142 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44143 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44144 - target_stat_values[++index] = atomic_read(&cm_rejects);
44145 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44146 - target_stat_values[++index] = atomic_read(&qps_created);
44147 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44148 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44149 - target_stat_values[++index] = atomic_read(&cm_closes);
44150 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44151 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44152 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44153 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44154 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44155 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44156 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44157 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44158 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44159 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44160 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44161 target_stat_values[++index] = cm_packets_sent;
44162 target_stat_values[++index] = cm_packets_bounced;
44163 target_stat_values[++index] = cm_packets_created;
44164 target_stat_values[++index] = cm_packets_received;
44165 target_stat_values[++index] = cm_packets_dropped;
44166 target_stat_values[++index] = cm_packets_retrans;
44167 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44168 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44169 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44170 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44171 target_stat_values[++index] = cm_backlog_drops;
44172 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44173 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44174 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44175 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44176 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44177 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44178 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44179 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44180 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44181 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44182 target_stat_values[++index] = nesadapter->free_4kpbl;
44183 target_stat_values[++index] = nesadapter->free_256pbl;
44184 target_stat_values[++index] = int_mod_timer_init;
44185 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44186 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44187 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44188 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44189 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44190 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44191 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44192 }
44193
44194 /**
44195 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44196 index fef067c..6a25ccd 100644
44197 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44198 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44199 @@ -46,9 +46,9 @@
44200
44201 #include <rdma/ib_umem.h>
44202
44203 -atomic_t mod_qp_timouts;
44204 -atomic_t qps_created;
44205 -atomic_t sw_qps_destroyed;
44206 +atomic_unchecked_t mod_qp_timouts;
44207 +atomic_unchecked_t qps_created;
44208 +atomic_unchecked_t sw_qps_destroyed;
44209
44210 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44211
44212 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44213 if (init_attr->create_flags)
44214 return ERR_PTR(-EINVAL);
44215
44216 - atomic_inc(&qps_created);
44217 + atomic_inc_unchecked(&qps_created);
44218 switch (init_attr->qp_type) {
44219 case IB_QPT_RC:
44220 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44221 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44222 struct iw_cm_event cm_event;
44223 int ret = 0;
44224
44225 - atomic_inc(&sw_qps_destroyed);
44226 + atomic_inc_unchecked(&sw_qps_destroyed);
44227 nesqp->destroyed = 1;
44228
44229 /* Blow away the connection if it exists. */
44230 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44231 index c00ae09..04e91be 100644
44232 --- a/drivers/infiniband/hw/qib/qib.h
44233 +++ b/drivers/infiniband/hw/qib/qib.h
44234 @@ -52,6 +52,7 @@
44235 #include <linux/kref.h>
44236 #include <linux/sched.h>
44237 #include <linux/kthread.h>
44238 +#include <linux/slab.h>
44239
44240 #include "qib_common.h"
44241 #include "qib_verbs.h"
44242 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44243 index 24c41ba..102d71f 100644
44244 --- a/drivers/input/gameport/gameport.c
44245 +++ b/drivers/input/gameport/gameport.c
44246 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44247 */
44248 static void gameport_init_port(struct gameport *gameport)
44249 {
44250 - static atomic_t gameport_no = ATOMIC_INIT(0);
44251 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44252
44253 __module_get(THIS_MODULE);
44254
44255 mutex_init(&gameport->drv_mutex);
44256 device_initialize(&gameport->dev);
44257 dev_set_name(&gameport->dev, "gameport%lu",
44258 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44259 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44260 gameport->dev.bus = &gameport_bus;
44261 gameport->dev.release = gameport_release_port;
44262 if (gameport->parent)
44263 diff --git a/drivers/input/input.c b/drivers/input/input.c
44264 index 29ca0bb..f4bc2e3 100644
44265 --- a/drivers/input/input.c
44266 +++ b/drivers/input/input.c
44267 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44268 */
44269 struct input_dev *input_allocate_device(void)
44270 {
44271 - static atomic_t input_no = ATOMIC_INIT(0);
44272 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44273 struct input_dev *dev;
44274
44275 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44276 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44277 INIT_LIST_HEAD(&dev->node);
44278
44279 dev_set_name(&dev->dev, "input%ld",
44280 - (unsigned long) atomic_inc_return(&input_no) - 1);
44281 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44282
44283 __module_get(THIS_MODULE);
44284 }
44285 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44286 index 4a95b22..874c182 100644
44287 --- a/drivers/input/joystick/sidewinder.c
44288 +++ b/drivers/input/joystick/sidewinder.c
44289 @@ -30,6 +30,7 @@
44290 #include <linux/kernel.h>
44291 #include <linux/module.h>
44292 #include <linux/slab.h>
44293 +#include <linux/sched.h>
44294 #include <linux/input.h>
44295 #include <linux/gameport.h>
44296 #include <linux/jiffies.h>
44297 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44298 index 177602c..ec78499 100644
44299 --- a/drivers/input/joystick/xpad.c
44300 +++ b/drivers/input/joystick/xpad.c
44301 @@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44302
44303 static int xpad_led_probe(struct usb_xpad *xpad)
44304 {
44305 - static atomic_t led_seq = ATOMIC_INIT(0);
44306 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44307 long led_no;
44308 struct xpad_led *led;
44309 struct led_classdev *led_cdev;
44310 @@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44311 if (!led)
44312 return -ENOMEM;
44313
44314 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44315 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44316
44317 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44318 led->xpad = xpad;
44319 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44320 index 719410f..1896169 100644
44321 --- a/drivers/input/misc/ims-pcu.c
44322 +++ b/drivers/input/misc/ims-pcu.c
44323 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44324
44325 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44326 {
44327 - static atomic_t device_no = ATOMIC_INIT(0);
44328 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44329
44330 const struct ims_pcu_device_info *info;
44331 int error;
44332 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44333 }
44334
44335 /* Device appears to be operable, complete initialization */
44336 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44337 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44338
44339 /*
44340 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44341 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44342 index 2f0b39d..7370f13 100644
44343 --- a/drivers/input/mouse/psmouse.h
44344 +++ b/drivers/input/mouse/psmouse.h
44345 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44346 ssize_t (*set)(struct psmouse *psmouse, void *data,
44347 const char *buf, size_t count);
44348 bool protect;
44349 -};
44350 +} __do_const;
44351 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44352
44353 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44354 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44355 index b604564..3f14ae4 100644
44356 --- a/drivers/input/mousedev.c
44357 +++ b/drivers/input/mousedev.c
44358 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44359
44360 spin_unlock_irq(&client->packet_lock);
44361
44362 - if (copy_to_user(buffer, data, count))
44363 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44364 return -EFAULT;
44365
44366 return count;
44367 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44368 index b29134d..394deb0 100644
44369 --- a/drivers/input/serio/serio.c
44370 +++ b/drivers/input/serio/serio.c
44371 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44372 */
44373 static void serio_init_port(struct serio *serio)
44374 {
44375 - static atomic_t serio_no = ATOMIC_INIT(0);
44376 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44377
44378 __module_get(THIS_MODULE);
44379
44380 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44381 mutex_init(&serio->drv_mutex);
44382 device_initialize(&serio->dev);
44383 dev_set_name(&serio->dev, "serio%ld",
44384 - (long)atomic_inc_return(&serio_no) - 1);
44385 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44386 serio->dev.bus = &serio_bus;
44387 serio->dev.release = serio_release_port;
44388 serio->dev.groups = serio_device_attr_groups;
44389 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44390 index c9a02fe..0debc75 100644
44391 --- a/drivers/input/serio/serio_raw.c
44392 +++ b/drivers/input/serio/serio_raw.c
44393 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44394
44395 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44396 {
44397 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44398 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44399 struct serio_raw *serio_raw;
44400 int err;
44401
44402 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44403 }
44404
44405 snprintf(serio_raw->name, sizeof(serio_raw->name),
44406 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44407 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44408 kref_init(&serio_raw->kref);
44409 INIT_LIST_HEAD(&serio_raw->client_list);
44410 init_waitqueue_head(&serio_raw->wait);
44411 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44412 index a83cc2a..64462e6 100644
44413 --- a/drivers/iommu/arm-smmu.c
44414 +++ b/drivers/iommu/arm-smmu.c
44415 @@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44416 cfg->irptndx = cfg->cbndx;
44417 }
44418
44419 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
44420 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44421 arm_smmu_init_context_bank(smmu_domain);
44422 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44423
44424 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44425 index 33c4395..e06447e 100644
44426 --- a/drivers/iommu/irq_remapping.c
44427 +++ b/drivers/iommu/irq_remapping.c
44428 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44429 void panic_if_irq_remap(const char *msg)
44430 {
44431 if (irq_remapping_enabled)
44432 - panic(msg);
44433 + panic("%s", msg);
44434 }
44435
44436 static void ir_ack_apic_edge(struct irq_data *data)
44437 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44438
44439 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44440 {
44441 - chip->irq_print_chip = ir_print_prefix;
44442 - chip->irq_ack = ir_ack_apic_edge;
44443 - chip->irq_eoi = ir_ack_apic_level;
44444 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44445 + pax_open_kernel();
44446 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44447 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44448 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44449 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44450 + pax_close_kernel();
44451 }
44452
44453 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44454 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44455 index dda6dbc..f9adebb 100644
44456 --- a/drivers/irqchip/irq-gic.c
44457 +++ b/drivers/irqchip/irq-gic.c
44458 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44459 * Supported arch specific GIC irq extension.
44460 * Default make them NULL.
44461 */
44462 -struct irq_chip gic_arch_extn = {
44463 +irq_chip_no_const gic_arch_extn = {
44464 .irq_eoi = NULL,
44465 .irq_mask = NULL,
44466 .irq_unmask = NULL,
44467 @@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44468 chained_irq_exit(chip, desc);
44469 }
44470
44471 -static struct irq_chip gic_chip = {
44472 +static irq_chip_no_const gic_chip __read_only = {
44473 .name = "GIC",
44474 .irq_mask = gic_mask_irq,
44475 .irq_unmask = gic_unmask_irq,
44476 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44477 index 8777065..a4a9967 100644
44478 --- a/drivers/irqchip/irq-renesas-irqc.c
44479 +++ b/drivers/irqchip/irq-renesas-irqc.c
44480 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44481 struct irqc_priv *p;
44482 struct resource *io;
44483 struct resource *irq;
44484 - struct irq_chip *irq_chip;
44485 + irq_chip_no_const *irq_chip;
44486 const char *name = dev_name(&pdev->dev);
44487 int ret;
44488 int k;
44489 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44490 index 6a2df32..dc962f1 100644
44491 --- a/drivers/isdn/capi/capi.c
44492 +++ b/drivers/isdn/capi/capi.c
44493 @@ -81,8 +81,8 @@ struct capiminor {
44494
44495 struct capi20_appl *ap;
44496 u32 ncci;
44497 - atomic_t datahandle;
44498 - atomic_t msgid;
44499 + atomic_unchecked_t datahandle;
44500 + atomic_unchecked_t msgid;
44501
44502 struct tty_port port;
44503 int ttyinstop;
44504 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44505 capimsg_setu16(s, 2, mp->ap->applid);
44506 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44507 capimsg_setu8 (s, 5, CAPI_RESP);
44508 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44509 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44510 capimsg_setu32(s, 8, mp->ncci);
44511 capimsg_setu16(s, 12, datahandle);
44512 }
44513 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44514 mp->outbytes -= len;
44515 spin_unlock_bh(&mp->outlock);
44516
44517 - datahandle = atomic_inc_return(&mp->datahandle);
44518 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44519 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44520 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44521 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44522 capimsg_setu16(skb->data, 2, mp->ap->applid);
44523 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44524 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44525 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44526 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44527 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44528 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44529 capimsg_setu16(skb->data, 16, len); /* Data length */
44530 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44531 index b7ae0a0..04590fa 100644
44532 --- a/drivers/isdn/gigaset/bas-gigaset.c
44533 +++ b/drivers/isdn/gigaset/bas-gigaset.c
44534 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44535
44536
44537 static const struct gigaset_ops gigops = {
44538 - gigaset_write_cmd,
44539 - gigaset_write_room,
44540 - gigaset_chars_in_buffer,
44541 - gigaset_brkchars,
44542 - gigaset_init_bchannel,
44543 - gigaset_close_bchannel,
44544 - gigaset_initbcshw,
44545 - gigaset_freebcshw,
44546 - gigaset_reinitbcshw,
44547 - gigaset_initcshw,
44548 - gigaset_freecshw,
44549 - gigaset_set_modem_ctrl,
44550 - gigaset_baud_rate,
44551 - gigaset_set_line_ctrl,
44552 - gigaset_isoc_send_skb,
44553 - gigaset_isoc_input,
44554 + .write_cmd = gigaset_write_cmd,
44555 + .write_room = gigaset_write_room,
44556 + .chars_in_buffer = gigaset_chars_in_buffer,
44557 + .brkchars = gigaset_brkchars,
44558 + .init_bchannel = gigaset_init_bchannel,
44559 + .close_bchannel = gigaset_close_bchannel,
44560 + .initbcshw = gigaset_initbcshw,
44561 + .freebcshw = gigaset_freebcshw,
44562 + .reinitbcshw = gigaset_reinitbcshw,
44563 + .initcshw = gigaset_initcshw,
44564 + .freecshw = gigaset_freecshw,
44565 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44566 + .baud_rate = gigaset_baud_rate,
44567 + .set_line_ctrl = gigaset_set_line_ctrl,
44568 + .send_skb = gigaset_isoc_send_skb,
44569 + .handle_input = gigaset_isoc_input,
44570 };
44571
44572 /* bas_gigaset_init
44573 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44574 index 600c79b..3752bab 100644
44575 --- a/drivers/isdn/gigaset/interface.c
44576 +++ b/drivers/isdn/gigaset/interface.c
44577 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44578 }
44579 tty->driver_data = cs;
44580
44581 - ++cs->port.count;
44582 + atomic_inc(&cs->port.count);
44583
44584 - if (cs->port.count == 1) {
44585 + if (atomic_read(&cs->port.count) == 1) {
44586 tty_port_tty_set(&cs->port, tty);
44587 cs->port.low_latency = 1;
44588 }
44589 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44590
44591 if (!cs->connected)
44592 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44593 - else if (!cs->port.count)
44594 + else if (!atomic_read(&cs->port.count))
44595 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44596 - else if (!--cs->port.count)
44597 + else if (!atomic_dec_return(&cs->port.count))
44598 tty_port_tty_set(&cs->port, NULL);
44599
44600 mutex_unlock(&cs->mutex);
44601 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44602 index 8c91fd5..14f13ce 100644
44603 --- a/drivers/isdn/gigaset/ser-gigaset.c
44604 +++ b/drivers/isdn/gigaset/ser-gigaset.c
44605 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44606 }
44607
44608 static const struct gigaset_ops ops = {
44609 - gigaset_write_cmd,
44610 - gigaset_write_room,
44611 - gigaset_chars_in_buffer,
44612 - gigaset_brkchars,
44613 - gigaset_init_bchannel,
44614 - gigaset_close_bchannel,
44615 - gigaset_initbcshw,
44616 - gigaset_freebcshw,
44617 - gigaset_reinitbcshw,
44618 - gigaset_initcshw,
44619 - gigaset_freecshw,
44620 - gigaset_set_modem_ctrl,
44621 - gigaset_baud_rate,
44622 - gigaset_set_line_ctrl,
44623 - gigaset_m10x_send_skb, /* asyncdata.c */
44624 - gigaset_m10x_input, /* asyncdata.c */
44625 + .write_cmd = gigaset_write_cmd,
44626 + .write_room = gigaset_write_room,
44627 + .chars_in_buffer = gigaset_chars_in_buffer,
44628 + .brkchars = gigaset_brkchars,
44629 + .init_bchannel = gigaset_init_bchannel,
44630 + .close_bchannel = gigaset_close_bchannel,
44631 + .initbcshw = gigaset_initbcshw,
44632 + .freebcshw = gigaset_freebcshw,
44633 + .reinitbcshw = gigaset_reinitbcshw,
44634 + .initcshw = gigaset_initcshw,
44635 + .freecshw = gigaset_freecshw,
44636 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44637 + .baud_rate = gigaset_baud_rate,
44638 + .set_line_ctrl = gigaset_set_line_ctrl,
44639 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44640 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44641 };
44642
44643
44644 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44645 index d0a41cb..b953e50 100644
44646 --- a/drivers/isdn/gigaset/usb-gigaset.c
44647 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44648 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44649 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44650 memcpy(cs->hw.usb->bchars, buf, 6);
44651 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44652 - 0, 0, &buf, 6, 2000);
44653 + 0, 0, buf, 6, 2000);
44654 }
44655
44656 static void gigaset_freebcshw(struct bc_state *bcs)
44657 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44658 }
44659
44660 static const struct gigaset_ops ops = {
44661 - gigaset_write_cmd,
44662 - gigaset_write_room,
44663 - gigaset_chars_in_buffer,
44664 - gigaset_brkchars,
44665 - gigaset_init_bchannel,
44666 - gigaset_close_bchannel,
44667 - gigaset_initbcshw,
44668 - gigaset_freebcshw,
44669 - gigaset_reinitbcshw,
44670 - gigaset_initcshw,
44671 - gigaset_freecshw,
44672 - gigaset_set_modem_ctrl,
44673 - gigaset_baud_rate,
44674 - gigaset_set_line_ctrl,
44675 - gigaset_m10x_send_skb,
44676 - gigaset_m10x_input,
44677 + .write_cmd = gigaset_write_cmd,
44678 + .write_room = gigaset_write_room,
44679 + .chars_in_buffer = gigaset_chars_in_buffer,
44680 + .brkchars = gigaset_brkchars,
44681 + .init_bchannel = gigaset_init_bchannel,
44682 + .close_bchannel = gigaset_close_bchannel,
44683 + .initbcshw = gigaset_initbcshw,
44684 + .freebcshw = gigaset_freebcshw,
44685 + .reinitbcshw = gigaset_reinitbcshw,
44686 + .initcshw = gigaset_initcshw,
44687 + .freecshw = gigaset_freecshw,
44688 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44689 + .baud_rate = gigaset_baud_rate,
44690 + .set_line_ctrl = gigaset_set_line_ctrl,
44691 + .send_skb = gigaset_m10x_send_skb,
44692 + .handle_input = gigaset_m10x_input,
44693 };
44694
44695 /*
44696 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44697 index 4d9b195..455075c 100644
44698 --- a/drivers/isdn/hardware/avm/b1.c
44699 +++ b/drivers/isdn/hardware/avm/b1.c
44700 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44701 }
44702 if (left) {
44703 if (t4file->user) {
44704 - if (copy_from_user(buf, dp, left))
44705 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44706 return -EFAULT;
44707 } else {
44708 memcpy(buf, dp, left);
44709 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44710 }
44711 if (left) {
44712 if (config->user) {
44713 - if (copy_from_user(buf, dp, left))
44714 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44715 return -EFAULT;
44716 } else {
44717 memcpy(buf, dp, left);
44718 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44719 index 9b856e1..fa03c92 100644
44720 --- a/drivers/isdn/i4l/isdn_common.c
44721 +++ b/drivers/isdn/i4l/isdn_common.c
44722 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44723 } else
44724 return -EINVAL;
44725 case IIOCDBGVAR:
44726 + if (!capable(CAP_SYS_RAWIO))
44727 + return -EPERM;
44728 if (arg) {
44729 if (copy_to_user(argp, &dev, sizeof(ulong)))
44730 return -EFAULT;
44731 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44732 index 91d5730..336523e 100644
44733 --- a/drivers/isdn/i4l/isdn_concap.c
44734 +++ b/drivers/isdn/i4l/isdn_concap.c
44735 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44736 }
44737
44738 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44739 - &isdn_concap_dl_data_req,
44740 - &isdn_concap_dl_connect_req,
44741 - &isdn_concap_dl_disconn_req
44742 + .data_req = &isdn_concap_dl_data_req,
44743 + .connect_req = &isdn_concap_dl_connect_req,
44744 + .disconn_req = &isdn_concap_dl_disconn_req
44745 };
44746
44747 /* The following should better go into a dedicated source file such that
44748 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44749 index 3c5f249..5fac4d0 100644
44750 --- a/drivers/isdn/i4l/isdn_tty.c
44751 +++ b/drivers/isdn/i4l/isdn_tty.c
44752 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44753
44754 #ifdef ISDN_DEBUG_MODEM_OPEN
44755 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44756 - port->count);
44757 + atomic_read(&port->count));
44758 #endif
44759 - port->count++;
44760 + atomic_inc(&port->count);
44761 port->tty = tty;
44762 /*
44763 * Start up serial port
44764 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44765 #endif
44766 return;
44767 }
44768 - if ((tty->count == 1) && (port->count != 1)) {
44769 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44770 /*
44771 * Uh, oh. tty->count is 1, which means that the tty
44772 * structure will be freed. Info->count should always
44773 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44774 * serial port won't be shutdown.
44775 */
44776 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44777 - "info->count is %d\n", port->count);
44778 - port->count = 1;
44779 + "info->count is %d\n", atomic_read(&port->count));
44780 + atomic_set(&port->count, 1);
44781 }
44782 - if (--port->count < 0) {
44783 + if (atomic_dec_return(&port->count) < 0) {
44784 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44785 - info->line, port->count);
44786 - port->count = 0;
44787 + info->line, atomic_read(&port->count));
44788 + atomic_set(&port->count, 0);
44789 }
44790 - if (port->count) {
44791 + if (atomic_read(&port->count)) {
44792 #ifdef ISDN_DEBUG_MODEM_OPEN
44793 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44794 #endif
44795 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44796 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44797 return;
44798 isdn_tty_shutdown(info);
44799 - port->count = 0;
44800 + atomic_set(&port->count, 0);
44801 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44802 port->tty = NULL;
44803 wake_up_interruptible(&port->open_wait);
44804 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44805 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44806 modem_info *info = &dev->mdm.info[i];
44807
44808 - if (info->port.count == 0)
44809 + if (atomic_read(&info->port.count) == 0)
44810 continue;
44811 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44812 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44813 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44814 index e2d4e58..40cd045 100644
44815 --- a/drivers/isdn/i4l/isdn_x25iface.c
44816 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44817 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44818
44819
44820 static struct concap_proto_ops ix25_pops = {
44821 - &isdn_x25iface_proto_new,
44822 - &isdn_x25iface_proto_del,
44823 - &isdn_x25iface_proto_restart,
44824 - &isdn_x25iface_proto_close,
44825 - &isdn_x25iface_xmit,
44826 - &isdn_x25iface_receive,
44827 - &isdn_x25iface_connect_ind,
44828 - &isdn_x25iface_disconn_ind
44829 + .proto_new = &isdn_x25iface_proto_new,
44830 + .proto_del = &isdn_x25iface_proto_del,
44831 + .restart = &isdn_x25iface_proto_restart,
44832 + .close = &isdn_x25iface_proto_close,
44833 + .encap_and_xmit = &isdn_x25iface_xmit,
44834 + .data_ind = &isdn_x25iface_receive,
44835 + .connect_ind = &isdn_x25iface_connect_ind,
44836 + .disconn_ind = &isdn_x25iface_disconn_ind
44837 };
44838
44839 /* error message helper function */
44840 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44841 index 6a7447c..cae33fe 100644
44842 --- a/drivers/isdn/icn/icn.c
44843 +++ b/drivers/isdn/icn/icn.c
44844 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44845 if (count > len)
44846 count = len;
44847 if (user) {
44848 - if (copy_from_user(msg, buf, count))
44849 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44850 return -EFAULT;
44851 } else
44852 memcpy(msg, buf, count);
44853 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44854 index a4f05c5..1433bc5 100644
44855 --- a/drivers/isdn/mISDN/dsp_cmx.c
44856 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44857 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44858 static u16 dsp_count; /* last sample count */
44859 static int dsp_count_valid; /* if we have last sample count */
44860
44861 -void
44862 +void __intentional_overflow(-1)
44863 dsp_cmx_send(void *arg)
44864 {
44865 struct dsp_conf *conf;
44866 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44867 index f58a354..fbae176 100644
44868 --- a/drivers/leds/leds-clevo-mail.c
44869 +++ b/drivers/leds/leds-clevo-mail.c
44870 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44871 * detected as working, but in reality it is not) as low as
44872 * possible.
44873 */
44874 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44875 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44876 {
44877 .callback = clevo_mail_led_dmi_callback,
44878 .ident = "Clevo D410J",
44879 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44880 index 046cb70..6b20d39 100644
44881 --- a/drivers/leds/leds-ss4200.c
44882 +++ b/drivers/leds/leds-ss4200.c
44883 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44884 * detected as working, but in reality it is not) as low as
44885 * possible.
44886 */
44887 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44888 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44889 {
44890 .callback = ss4200_led_dmi_callback,
44891 .ident = "Intel SS4200-E",
44892 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44893 index 6590558..a74c5dd 100644
44894 --- a/drivers/lguest/core.c
44895 +++ b/drivers/lguest/core.c
44896 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44897 * The end address needs +1 because __get_vm_area allocates an
44898 * extra guard page, so we need space for that.
44899 */
44900 +
44901 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44902 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44903 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44904 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44905 +#else
44906 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44907 VM_ALLOC, switcher_addr, switcher_addr
44908 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44909 +#endif
44910 +
44911 if (!switcher_vma) {
44912 err = -ENOMEM;
44913 printk("lguest: could not map switcher pages high\n");
44914 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44915 * Now the Switcher is mapped at the right address, we can't fail!
44916 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44917 */
44918 - memcpy(switcher_vma->addr, start_switcher_text,
44919 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44920 end_switcher_text - start_switcher_text);
44921
44922 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44923 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44924 index e8b55c3..3514c37 100644
44925 --- a/drivers/lguest/page_tables.c
44926 +++ b/drivers/lguest/page_tables.c
44927 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44928 /*:*/
44929
44930 #ifdef CONFIG_X86_PAE
44931 -static void release_pmd(pmd_t *spmd)
44932 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44933 {
44934 /* If the entry's not present, there's nothing to release. */
44935 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44936 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44937 index 922a1ac..9dd0c2a 100644
44938 --- a/drivers/lguest/x86/core.c
44939 +++ b/drivers/lguest/x86/core.c
44940 @@ -59,7 +59,7 @@ static struct {
44941 /* Offset from where switcher.S was compiled to where we've copied it */
44942 static unsigned long switcher_offset(void)
44943 {
44944 - return switcher_addr - (unsigned long)start_switcher_text;
44945 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44946 }
44947
44948 /* This cpu's struct lguest_pages (after the Switcher text page) */
44949 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44950 * These copies are pretty cheap, so we do them unconditionally: */
44951 /* Save the current Host top-level page directory.
44952 */
44953 +
44954 +#ifdef CONFIG_PAX_PER_CPU_PGD
44955 + pages->state.host_cr3 = read_cr3();
44956 +#else
44957 pages->state.host_cr3 = __pa(current->mm->pgd);
44958 +#endif
44959 +
44960 /*
44961 * Set up the Guest's page tables to see this CPU's pages (and no
44962 * other CPU's pages).
44963 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44964 * compiled-in switcher code and the high-mapped copy we just made.
44965 */
44966 for (i = 0; i < IDT_ENTRIES; i++)
44967 - default_idt_entries[i] += switcher_offset();
44968 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44969
44970 /*
44971 * Set up the Switcher's per-cpu areas.
44972 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44973 * it will be undisturbed when we switch. To change %cs and jump we
44974 * need this structure to feed to Intel's "lcall" instruction.
44975 */
44976 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44977 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44978 lguest_entry.segment = LGUEST_CS;
44979
44980 /*
44981 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44982 index 40634b0..4f5855e 100644
44983 --- a/drivers/lguest/x86/switcher_32.S
44984 +++ b/drivers/lguest/x86/switcher_32.S
44985 @@ -87,6 +87,7 @@
44986 #include <asm/page.h>
44987 #include <asm/segment.h>
44988 #include <asm/lguest.h>
44989 +#include <asm/processor-flags.h>
44990
44991 // We mark the start of the code to copy
44992 // It's placed in .text tho it's never run here
44993 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44994 // Changes type when we load it: damn Intel!
44995 // For after we switch over our page tables
44996 // That entry will be read-only: we'd crash.
44997 +
44998 +#ifdef CONFIG_PAX_KERNEXEC
44999 + mov %cr0, %edx
45000 + xor $X86_CR0_WP, %edx
45001 + mov %edx, %cr0
45002 +#endif
45003 +
45004 movl $(GDT_ENTRY_TSS*8), %edx
45005 ltr %dx
45006
45007 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45008 // Let's clear it again for our return.
45009 // The GDT descriptor of the Host
45010 // Points to the table after two "size" bytes
45011 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45012 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45013 // Clear "used" from type field (byte 5, bit 2)
45014 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45015 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45016 +
45017 +#ifdef CONFIG_PAX_KERNEXEC
45018 + mov %cr0, %eax
45019 + xor $X86_CR0_WP, %eax
45020 + mov %eax, %cr0
45021 +#endif
45022
45023 // Once our page table's switched, the Guest is live!
45024 // The Host fades as we run this final step.
45025 @@ -295,13 +309,12 @@ deliver_to_host:
45026 // I consulted gcc, and it gave
45027 // These instructions, which I gladly credit:
45028 leal (%edx,%ebx,8), %eax
45029 - movzwl (%eax),%edx
45030 - movl 4(%eax), %eax
45031 - xorw %ax, %ax
45032 - orl %eax, %edx
45033 + movl 4(%eax), %edx
45034 + movw (%eax), %dx
45035 // Now the address of the handler's in %edx
45036 // We call it now: its "iret" drops us home.
45037 - jmp *%edx
45038 + ljmp $__KERNEL_CS, $1f
45039 +1: jmp *%edx
45040
45041 // Every interrupt can come to us here
45042 // But we must truly tell each apart.
45043 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45044 index a08e3ee..df8ade2 100644
45045 --- a/drivers/md/bcache/closure.h
45046 +++ b/drivers/md/bcache/closure.h
45047 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45048 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45049 struct workqueue_struct *wq)
45050 {
45051 - BUG_ON(object_is_on_stack(cl));
45052 + BUG_ON(object_starts_on_stack(cl));
45053 closure_set_ip(cl);
45054 cl->fn = fn;
45055 cl->wq = wq;
45056 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45057 index 67f8b31..9418f2b 100644
45058 --- a/drivers/md/bitmap.c
45059 +++ b/drivers/md/bitmap.c
45060 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45061 chunk_kb ? "KB" : "B");
45062 if (bitmap->storage.file) {
45063 seq_printf(seq, ", file: ");
45064 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45065 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45066 }
45067
45068 seq_printf(seq, "\n");
45069 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45070 index 5152142..623d141 100644
45071 --- a/drivers/md/dm-ioctl.c
45072 +++ b/drivers/md/dm-ioctl.c
45073 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45074 cmd == DM_LIST_VERSIONS_CMD)
45075 return 0;
45076
45077 - if ((cmd == DM_DEV_CREATE_CMD)) {
45078 + if (cmd == DM_DEV_CREATE_CMD) {
45079 if (!*param->name) {
45080 DMWARN("name not supplied when creating device");
45081 return -EINVAL;
45082 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45083 index 7dfdb5c..4caada6 100644
45084 --- a/drivers/md/dm-raid1.c
45085 +++ b/drivers/md/dm-raid1.c
45086 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45087
45088 struct mirror {
45089 struct mirror_set *ms;
45090 - atomic_t error_count;
45091 + atomic_unchecked_t error_count;
45092 unsigned long error_type;
45093 struct dm_dev *dev;
45094 sector_t offset;
45095 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45096 struct mirror *m;
45097
45098 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45099 - if (!atomic_read(&m->error_count))
45100 + if (!atomic_read_unchecked(&m->error_count))
45101 return m;
45102
45103 return NULL;
45104 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45105 * simple way to tell if a device has encountered
45106 * errors.
45107 */
45108 - atomic_inc(&m->error_count);
45109 + atomic_inc_unchecked(&m->error_count);
45110
45111 if (test_and_set_bit(error_type, &m->error_type))
45112 return;
45113 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45114 struct mirror *m = get_default_mirror(ms);
45115
45116 do {
45117 - if (likely(!atomic_read(&m->error_count)))
45118 + if (likely(!atomic_read_unchecked(&m->error_count)))
45119 return m;
45120
45121 if (m-- == ms->mirror)
45122 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45123 {
45124 struct mirror *default_mirror = get_default_mirror(m->ms);
45125
45126 - return !atomic_read(&default_mirror->error_count);
45127 + return !atomic_read_unchecked(&default_mirror->error_count);
45128 }
45129
45130 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45131 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45132 */
45133 if (likely(region_in_sync(ms, region, 1)))
45134 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45135 - else if (m && atomic_read(&m->error_count))
45136 + else if (m && atomic_read_unchecked(&m->error_count))
45137 m = NULL;
45138
45139 if (likely(m))
45140 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45141 }
45142
45143 ms->mirror[mirror].ms = ms;
45144 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45145 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45146 ms->mirror[mirror].error_type = 0;
45147 ms->mirror[mirror].offset = offset;
45148
45149 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45150 */
45151 static char device_status_char(struct mirror *m)
45152 {
45153 - if (!atomic_read(&(m->error_count)))
45154 + if (!atomic_read_unchecked(&(m->error_count)))
45155 return 'A';
45156
45157 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45158 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45159 index 28a9012..9c0f6a5 100644
45160 --- a/drivers/md/dm-stats.c
45161 +++ b/drivers/md/dm-stats.c
45162 @@ -382,7 +382,7 @@ do_sync_free:
45163 synchronize_rcu_expedited();
45164 dm_stat_free(&s->rcu_head);
45165 } else {
45166 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45167 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45168 call_rcu(&s->rcu_head, dm_stat_free);
45169 }
45170 return 0;
45171 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45172 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45173 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45174 ));
45175 - ACCESS_ONCE(last->last_sector) = end_sector;
45176 - ACCESS_ONCE(last->last_rw) = bi_rw;
45177 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45178 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45179 }
45180
45181 rcu_read_lock();
45182 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45183 index d1600d2..4c3af3a 100644
45184 --- a/drivers/md/dm-stripe.c
45185 +++ b/drivers/md/dm-stripe.c
45186 @@ -21,7 +21,7 @@ struct stripe {
45187 struct dm_dev *dev;
45188 sector_t physical_start;
45189
45190 - atomic_t error_count;
45191 + atomic_unchecked_t error_count;
45192 };
45193
45194 struct stripe_c {
45195 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45196 kfree(sc);
45197 return r;
45198 }
45199 - atomic_set(&(sc->stripe[i].error_count), 0);
45200 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45201 }
45202
45203 ti->private = sc;
45204 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45205 DMEMIT("%d ", sc->stripes);
45206 for (i = 0; i < sc->stripes; i++) {
45207 DMEMIT("%s ", sc->stripe[i].dev->name);
45208 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45209 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45210 'D' : 'A';
45211 }
45212 buffer[i] = '\0';
45213 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45214 */
45215 for (i = 0; i < sc->stripes; i++)
45216 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45217 - atomic_inc(&(sc->stripe[i].error_count));
45218 - if (atomic_read(&(sc->stripe[i].error_count)) <
45219 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
45220 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45221 DM_IO_ERROR_THRESHOLD)
45222 schedule_work(&sc->trigger_event);
45223 }
45224 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45225 index f9c6cb8..e272df6 100644
45226 --- a/drivers/md/dm-table.c
45227 +++ b/drivers/md/dm-table.c
45228 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45229 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45230 struct mapped_device *md)
45231 {
45232 - static char *_claim_ptr = "I belong to device-mapper";
45233 + static char _claim_ptr[] = "I belong to device-mapper";
45234 struct block_device *bdev;
45235
45236 int r;
45237 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45238 if (!dev_size)
45239 return 0;
45240
45241 - if ((start >= dev_size) || (start + len > dev_size)) {
45242 + if ((start >= dev_size) || (len > dev_size - start)) {
45243 DMWARN("%s: %s too small for target: "
45244 "start=%llu, len=%llu, dev_size=%llu",
45245 dm_device_name(ti->table->md), bdevname(bdev, b),
45246 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
45247 index e9d33ad..dae9880d 100644
45248 --- a/drivers/md/dm-thin-metadata.c
45249 +++ b/drivers/md/dm-thin-metadata.c
45250 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45251 {
45252 pmd->info.tm = pmd->tm;
45253 pmd->info.levels = 2;
45254 - pmd->info.value_type.context = pmd->data_sm;
45255 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45256 pmd->info.value_type.size = sizeof(__le64);
45257 pmd->info.value_type.inc = data_block_inc;
45258 pmd->info.value_type.dec = data_block_dec;
45259 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45260
45261 pmd->bl_info.tm = pmd->tm;
45262 pmd->bl_info.levels = 1;
45263 - pmd->bl_info.value_type.context = pmd->data_sm;
45264 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45265 pmd->bl_info.value_type.size = sizeof(__le64);
45266 pmd->bl_info.value_type.inc = data_block_inc;
45267 pmd->bl_info.value_type.dec = data_block_dec;
45268 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
45269 index 32b958d..34011e8 100644
45270 --- a/drivers/md/dm.c
45271 +++ b/drivers/md/dm.c
45272 @@ -180,9 +180,9 @@ struct mapped_device {
45273 /*
45274 * Event handling.
45275 */
45276 - atomic_t event_nr;
45277 + atomic_unchecked_t event_nr;
45278 wait_queue_head_t eventq;
45279 - atomic_t uevent_seq;
45280 + atomic_unchecked_t uevent_seq;
45281 struct list_head uevent_list;
45282 spinlock_t uevent_lock; /* Protect access to uevent_list */
45283
45284 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
45285 spin_lock_init(&md->deferred_lock);
45286 atomic_set(&md->holders, 1);
45287 atomic_set(&md->open_count, 0);
45288 - atomic_set(&md->event_nr, 0);
45289 - atomic_set(&md->uevent_seq, 0);
45290 + atomic_set_unchecked(&md->event_nr, 0);
45291 + atomic_set_unchecked(&md->uevent_seq, 0);
45292 INIT_LIST_HEAD(&md->uevent_list);
45293 spin_lock_init(&md->uevent_lock);
45294
45295 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
45296
45297 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
45298
45299 - atomic_inc(&md->event_nr);
45300 + atomic_inc_unchecked(&md->event_nr);
45301 wake_up(&md->eventq);
45302 }
45303
45304 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
45305
45306 uint32_t dm_next_uevent_seq(struct mapped_device *md)
45307 {
45308 - return atomic_add_return(1, &md->uevent_seq);
45309 + return atomic_add_return_unchecked(1, &md->uevent_seq);
45310 }
45311
45312 uint32_t dm_get_event_nr(struct mapped_device *md)
45313 {
45314 - return atomic_read(&md->event_nr);
45315 + return atomic_read_unchecked(&md->event_nr);
45316 }
45317
45318 int dm_wait_event(struct mapped_device *md, int event_nr)
45319 {
45320 return wait_event_interruptible(md->eventq,
45321 - (event_nr != atomic_read(&md->event_nr)));
45322 + (event_nr != atomic_read_unchecked(&md->event_nr)));
45323 }
45324
45325 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
45326 diff --git a/drivers/md/md.c b/drivers/md/md.c
45327 index 1294238..a442227 100644
45328 --- a/drivers/md/md.c
45329 +++ b/drivers/md/md.c
45330 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45331 * start build, activate spare
45332 */
45333 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45334 -static atomic_t md_event_count;
45335 +static atomic_unchecked_t md_event_count;
45336 void md_new_event(struct mddev *mddev)
45337 {
45338 - atomic_inc(&md_event_count);
45339 + atomic_inc_unchecked(&md_event_count);
45340 wake_up(&md_event_waiters);
45341 }
45342 EXPORT_SYMBOL_GPL(md_new_event);
45343 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45344 */
45345 static void md_new_event_inintr(struct mddev *mddev)
45346 {
45347 - atomic_inc(&md_event_count);
45348 + atomic_inc_unchecked(&md_event_count);
45349 wake_up(&md_event_waiters);
45350 }
45351
45352 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45353 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45354 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45355 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45356 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45357 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45358
45359 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45360 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45361 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45362 else
45363 sb->resync_offset = cpu_to_le64(0);
45364
45365 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45366 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45367
45368 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45369 sb->size = cpu_to_le64(mddev->dev_sectors);
45370 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45371 static ssize_t
45372 errors_show(struct md_rdev *rdev, char *page)
45373 {
45374 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45375 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45376 }
45377
45378 static ssize_t
45379 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45380 char *e;
45381 unsigned long n = simple_strtoul(buf, &e, 10);
45382 if (*buf && (*e == 0 || *e == '\n')) {
45383 - atomic_set(&rdev->corrected_errors, n);
45384 + atomic_set_unchecked(&rdev->corrected_errors, n);
45385 return len;
45386 }
45387 return -EINVAL;
45388 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45389 rdev->sb_loaded = 0;
45390 rdev->bb_page = NULL;
45391 atomic_set(&rdev->nr_pending, 0);
45392 - atomic_set(&rdev->read_errors, 0);
45393 - atomic_set(&rdev->corrected_errors, 0);
45394 + atomic_set_unchecked(&rdev->read_errors, 0);
45395 + atomic_set_unchecked(&rdev->corrected_errors, 0);
45396
45397 INIT_LIST_HEAD(&rdev->same_set);
45398 init_waitqueue_head(&rdev->blocked_wait);
45399 @@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45400
45401 spin_unlock(&pers_lock);
45402 seq_printf(seq, "\n");
45403 - seq->poll_event = atomic_read(&md_event_count);
45404 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45405 return 0;
45406 }
45407 if (v == (void*)2) {
45408 @@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45409 return error;
45410
45411 seq = file->private_data;
45412 - seq->poll_event = atomic_read(&md_event_count);
45413 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45414 return error;
45415 }
45416
45417 @@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45418 /* always allow read */
45419 mask = POLLIN | POLLRDNORM;
45420
45421 - if (seq->poll_event != atomic_read(&md_event_count))
45422 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45423 mask |= POLLERR | POLLPRI;
45424 return mask;
45425 }
45426 @@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45427 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45428 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45429 (int)part_stat_read(&disk->part0, sectors[1]) -
45430 - atomic_read(&disk->sync_io);
45431 + atomic_read_unchecked(&disk->sync_io);
45432 /* sync IO will cause sync_io to increase before the disk_stats
45433 * as sync_io is counted when a request starts, and
45434 * disk_stats is counted when it completes.
45435 diff --git a/drivers/md/md.h b/drivers/md/md.h
45436 index a49d991..3582bb7 100644
45437 --- a/drivers/md/md.h
45438 +++ b/drivers/md/md.h
45439 @@ -94,13 +94,13 @@ struct md_rdev {
45440 * only maintained for arrays that
45441 * support hot removal
45442 */
45443 - atomic_t read_errors; /* number of consecutive read errors that
45444 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
45445 * we have tried to ignore.
45446 */
45447 struct timespec last_read_error; /* monotonic time since our
45448 * last read error
45449 */
45450 - atomic_t corrected_errors; /* number of corrected read errors,
45451 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45452 * for reporting to userspace and storing
45453 * in superblock.
45454 */
45455 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45456
45457 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45458 {
45459 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45460 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45461 }
45462
45463 struct md_personality
45464 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45465 index 786b689..ea8c956 100644
45466 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
45467 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45468 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45469 * Flick into a mode where all blocks get allocated in the new area.
45470 */
45471 smm->begin = old_len;
45472 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
45473 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45474
45475 /*
45476 * Extend.
45477 @@ -710,7 +710,7 @@ out:
45478 /*
45479 * Switch back to normal behaviour.
45480 */
45481 - memcpy(sm, &ops, sizeof(*sm));
45482 + memcpy((void *)sm, &ops, sizeof(*sm));
45483 return r;
45484 }
45485
45486 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45487 index 3e6d115..ffecdeb 100644
45488 --- a/drivers/md/persistent-data/dm-space-map.h
45489 +++ b/drivers/md/persistent-data/dm-space-map.h
45490 @@ -71,6 +71,7 @@ struct dm_space_map {
45491 dm_sm_threshold_fn fn,
45492 void *context);
45493 };
45494 +typedef struct dm_space_map __no_const dm_space_map_no_const;
45495
45496 /*----------------------------------------------------------------*/
45497
45498 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45499 index 55de4f6..b1c57fe 100644
45500 --- a/drivers/md/raid1.c
45501 +++ b/drivers/md/raid1.c
45502 @@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45503 if (r1_sync_page_io(rdev, sect, s,
45504 bio->bi_io_vec[idx].bv_page,
45505 READ) != 0)
45506 - atomic_add(s, &rdev->corrected_errors);
45507 + atomic_add_unchecked(s, &rdev->corrected_errors);
45508 }
45509 sectors -= s;
45510 sect += s;
45511 @@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45512 !test_bit(Faulty, &rdev->flags)) {
45513 if (r1_sync_page_io(rdev, sect, s,
45514 conf->tmppage, READ)) {
45515 - atomic_add(s, &rdev->corrected_errors);
45516 + atomic_add_unchecked(s, &rdev->corrected_errors);
45517 printk(KERN_INFO
45518 "md/raid1:%s: read error corrected "
45519 "(%d sectors at %llu on %s)\n",
45520 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45521 index 6703751..187af1e 100644
45522 --- a/drivers/md/raid10.c
45523 +++ b/drivers/md/raid10.c
45524 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45525 /* The write handler will notice the lack of
45526 * R10BIO_Uptodate and record any errors etc
45527 */
45528 - atomic_add(r10_bio->sectors,
45529 + atomic_add_unchecked(r10_bio->sectors,
45530 &conf->mirrors[d].rdev->corrected_errors);
45531
45532 /* for reconstruct, we always reschedule after a read.
45533 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45534 {
45535 struct timespec cur_time_mon;
45536 unsigned long hours_since_last;
45537 - unsigned int read_errors = atomic_read(&rdev->read_errors);
45538 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45539
45540 ktime_get_ts(&cur_time_mon);
45541
45542 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45543 * overflowing the shift of read_errors by hours_since_last.
45544 */
45545 if (hours_since_last >= 8 * sizeof(read_errors))
45546 - atomic_set(&rdev->read_errors, 0);
45547 + atomic_set_unchecked(&rdev->read_errors, 0);
45548 else
45549 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45550 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45551 }
45552
45553 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45554 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45555 return;
45556
45557 check_decay_read_errors(mddev, rdev);
45558 - atomic_inc(&rdev->read_errors);
45559 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
45560 + atomic_inc_unchecked(&rdev->read_errors);
45561 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45562 char b[BDEVNAME_SIZE];
45563 bdevname(rdev->bdev, b);
45564
45565 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45566 "md/raid10:%s: %s: Raid device exceeded "
45567 "read_error threshold [cur %d:max %d]\n",
45568 mdname(mddev), b,
45569 - atomic_read(&rdev->read_errors), max_read_errors);
45570 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45571 printk(KERN_NOTICE
45572 "md/raid10:%s: %s: Failing raid device\n",
45573 mdname(mddev), b);
45574 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45575 sect +
45576 choose_data_offset(r10_bio, rdev)),
45577 bdevname(rdev->bdev, b));
45578 - atomic_add(s, &rdev->corrected_errors);
45579 + atomic_add_unchecked(s, &rdev->corrected_errors);
45580 }
45581
45582 rdev_dec_pending(rdev, mddev);
45583 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45584 index 9f0fbec..991e7a1 100644
45585 --- a/drivers/md/raid5.c
45586 +++ b/drivers/md/raid5.c
45587 @@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45588 return 1;
45589 }
45590
45591 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45592 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45593 +#endif
45594 +
45595 static int grow_stripes(struct r5conf *conf, int num)
45596 {
45597 struct kmem_cache *sc;
45598 @@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45599 "raid%d-%s", conf->level, mdname(conf->mddev));
45600 else
45601 sprintf(conf->cache_name[0],
45602 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45603 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45604 +#else
45605 "raid%d-%p", conf->level, conf->mddev);
45606 +#endif
45607 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45608
45609 conf->active_name = 0;
45610 @@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45611 mdname(conf->mddev), STRIPE_SECTORS,
45612 (unsigned long long)s,
45613 bdevname(rdev->bdev, b));
45614 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45615 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45616 clear_bit(R5_ReadError, &sh->dev[i].flags);
45617 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45618 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45619 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45620
45621 - if (atomic_read(&rdev->read_errors))
45622 - atomic_set(&rdev->read_errors, 0);
45623 + if (atomic_read_unchecked(&rdev->read_errors))
45624 + atomic_set_unchecked(&rdev->read_errors, 0);
45625 } else {
45626 const char *bdn = bdevname(rdev->bdev, b);
45627 int retry = 0;
45628 int set_bad = 0;
45629
45630 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45631 - atomic_inc(&rdev->read_errors);
45632 + atomic_inc_unchecked(&rdev->read_errors);
45633 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45634 printk_ratelimited(
45635 KERN_WARNING
45636 @@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45637 mdname(conf->mddev),
45638 (unsigned long long)s,
45639 bdn);
45640 - } else if (atomic_read(&rdev->read_errors)
45641 + } else if (atomic_read_unchecked(&rdev->read_errors)
45642 > conf->max_nr_stripes)
45643 printk(KERN_WARNING
45644 "md/raid:%s: Too many read errors, failing device %s.\n",
45645 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45646 index 983db75..ef9248c 100644
45647 --- a/drivers/media/dvb-core/dvbdev.c
45648 +++ b/drivers/media/dvb-core/dvbdev.c
45649 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45650 const struct dvb_device *template, void *priv, int type)
45651 {
45652 struct dvb_device *dvbdev;
45653 - struct file_operations *dvbdevfops;
45654 + file_operations_no_const *dvbdevfops;
45655 struct device *clsdev;
45656 int minor;
45657 int id;
45658 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45659 index 539f4db..cdd403b 100644
45660 --- a/drivers/media/dvb-frontends/af9033.h
45661 +++ b/drivers/media/dvb-frontends/af9033.h
45662 @@ -82,7 +82,7 @@ struct af9033_ops {
45663 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45664 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45665 int onoff);
45666 -};
45667 +} __no_const;
45668
45669
45670 #if IS_ENABLED(CONFIG_DVB_AF9033)
45671 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45672 index 9b6c3bb..baeb5c7 100644
45673 --- a/drivers/media/dvb-frontends/dib3000.h
45674 +++ b/drivers/media/dvb-frontends/dib3000.h
45675 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45676 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45677 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45678 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45679 -};
45680 +} __no_const;
45681
45682 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45683 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45684 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45685 index 1fea0e9..321ce8f 100644
45686 --- a/drivers/media/dvb-frontends/dib7000p.h
45687 +++ b/drivers/media/dvb-frontends/dib7000p.h
45688 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45689 int (*get_adc_power)(struct dvb_frontend *fe);
45690 int (*slave_reset)(struct dvb_frontend *fe);
45691 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45692 -};
45693 +} __no_const;
45694
45695 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45696 void *dib7000p_attach(struct dib7000p_ops *ops);
45697 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45698 index 84cc103..5780c54 100644
45699 --- a/drivers/media/dvb-frontends/dib8000.h
45700 +++ b/drivers/media/dvb-frontends/dib8000.h
45701 @@ -61,7 +61,7 @@ struct dib8000_ops {
45702 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45703 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45704 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45705 -};
45706 +} __no_const;
45707
45708 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45709 void *dib8000_attach(struct dib8000_ops *ops);
45710 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45711 index ed8cb90..5ef7f79 100644
45712 --- a/drivers/media/pci/cx88/cx88-video.c
45713 +++ b/drivers/media/pci/cx88/cx88-video.c
45714 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45715
45716 /* ------------------------------------------------------------------ */
45717
45718 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45719 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45720 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45721 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45722 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45723 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45724
45725 module_param_array(video_nr, int, NULL, 0444);
45726 module_param_array(vbi_nr, int, NULL, 0444);
45727 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45728 index 802642d..5534900 100644
45729 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45730 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45731 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45732 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45733
45734 /* ivtv instance counter */
45735 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45736 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45737
45738 /* Parameter declarations */
45739 static int cardtype[IVTV_MAX_CARDS];
45740 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45741 index 172583d..0f806f4 100644
45742 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45743 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45744 @@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45745
45746 static int solo_sysfs_init(struct solo_dev *solo_dev)
45747 {
45748 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45749 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45750 struct device *dev = &solo_dev->dev;
45751 const char *driver;
45752 int i;
45753 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45754 index c7141f2..5301fec 100644
45755 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45756 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45757 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45758
45759 int solo_g723_init(struct solo_dev *solo_dev)
45760 {
45761 - static struct snd_device_ops ops = { NULL };
45762 + static struct snd_device_ops ops = { };
45763 struct snd_card *card;
45764 struct snd_kcontrol_new kctl;
45765 char name[32];
45766 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45767 index 8c84846..27b4f83 100644
45768 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45769 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45770 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45771
45772 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45773 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45774 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45775 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45776 if (p2m_id < 0)
45777 p2m_id = -p2m_id;
45778 }
45779 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45780 index c6154b0..73e4ae9 100644
45781 --- a/drivers/media/pci/solo6x10/solo6x10.h
45782 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45783 @@ -219,7 +219,7 @@ struct solo_dev {
45784
45785 /* P2M DMA Engine */
45786 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45787 - atomic_t p2m_count;
45788 + atomic_unchecked_t p2m_count;
45789 int p2m_jiffies;
45790 unsigned int p2m_timeouts;
45791
45792 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45793 index 2d177fa..5b925a1 100644
45794 --- a/drivers/media/platform/omap/omap_vout.c
45795 +++ b/drivers/media/platform/omap/omap_vout.c
45796 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45797 OMAP_VIDEO2,
45798 };
45799
45800 -static struct videobuf_queue_ops video_vbq_ops;
45801 /* Variables configurable through module params*/
45802 static u32 video1_numbuffers = 3;
45803 static u32 video2_numbuffers = 3;
45804 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45805 {
45806 struct videobuf_queue *q;
45807 struct omap_vout_device *vout = NULL;
45808 + static struct videobuf_queue_ops video_vbq_ops = {
45809 + .buf_setup = omap_vout_buffer_setup,
45810 + .buf_prepare = omap_vout_buffer_prepare,
45811 + .buf_release = omap_vout_buffer_release,
45812 + .buf_queue = omap_vout_buffer_queue,
45813 + };
45814
45815 vout = video_drvdata(file);
45816 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45817 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45818 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45819
45820 q = &vout->vbq;
45821 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45822 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45823 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45824 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45825 spin_lock_init(&vout->vbq_lock);
45826
45827 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45828 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45829 index fb2acc5..a2fcbdc4 100644
45830 --- a/drivers/media/platform/s5p-tv/mixer.h
45831 +++ b/drivers/media/platform/s5p-tv/mixer.h
45832 @@ -156,7 +156,7 @@ struct mxr_layer {
45833 /** layer index (unique identifier) */
45834 int idx;
45835 /** callbacks for layer methods */
45836 - struct mxr_layer_ops ops;
45837 + struct mxr_layer_ops *ops;
45838 /** format array */
45839 const struct mxr_format **fmt_array;
45840 /** size of format array */
45841 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45842 index 74344c7..a39e70e 100644
45843 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45844 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45845 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45846 {
45847 struct mxr_layer *layer;
45848 int ret;
45849 - struct mxr_layer_ops ops = {
45850 + static struct mxr_layer_ops ops = {
45851 .release = mxr_graph_layer_release,
45852 .buffer_set = mxr_graph_buffer_set,
45853 .stream_set = mxr_graph_stream_set,
45854 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45855 index b713403..53cb5ad 100644
45856 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45857 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45858 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45859 layer->update_buf = next;
45860 }
45861
45862 - layer->ops.buffer_set(layer, layer->update_buf);
45863 + layer->ops->buffer_set(layer, layer->update_buf);
45864
45865 if (done && done != layer->shadow_buf)
45866 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45867 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45868 index b4d2696..91df48e 100644
45869 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45870 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45871 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45872 layer->geo.src.height = layer->geo.src.full_height;
45873
45874 mxr_geometry_dump(mdev, &layer->geo);
45875 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45876 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45877 mxr_geometry_dump(mdev, &layer->geo);
45878 }
45879
45880 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45881 layer->geo.dst.full_width = mbus_fmt.width;
45882 layer->geo.dst.full_height = mbus_fmt.height;
45883 layer->geo.dst.field = mbus_fmt.field;
45884 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45885 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45886
45887 mxr_geometry_dump(mdev, &layer->geo);
45888 }
45889 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45890 /* set source size to highest accepted value */
45891 geo->src.full_width = max(geo->dst.full_width, pix->width);
45892 geo->src.full_height = max(geo->dst.full_height, pix->height);
45893 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45894 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45895 mxr_geometry_dump(mdev, &layer->geo);
45896 /* set cropping to total visible screen */
45897 geo->src.width = pix->width;
45898 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45899 geo->src.x_offset = 0;
45900 geo->src.y_offset = 0;
45901 /* assure consistency of geometry */
45902 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45903 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45904 mxr_geometry_dump(mdev, &layer->geo);
45905 /* set full size to lowest possible value */
45906 geo->src.full_width = 0;
45907 geo->src.full_height = 0;
45908 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45909 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45910 mxr_geometry_dump(mdev, &layer->geo);
45911
45912 /* returning results */
45913 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45914 target->width = s->r.width;
45915 target->height = s->r.height;
45916
45917 - layer->ops.fix_geometry(layer, stage, s->flags);
45918 + layer->ops->fix_geometry(layer, stage, s->flags);
45919
45920 /* retrieve update selection rectangle */
45921 res.left = target->x_offset;
45922 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45923 mxr_output_get(mdev);
45924
45925 mxr_layer_update_output(layer);
45926 - layer->ops.format_set(layer);
45927 + layer->ops->format_set(layer);
45928 /* enabling layer in hardware */
45929 spin_lock_irqsave(&layer->enq_slock, flags);
45930 layer->state = MXR_LAYER_STREAMING;
45931 spin_unlock_irqrestore(&layer->enq_slock, flags);
45932
45933 - layer->ops.stream_set(layer, MXR_ENABLE);
45934 + layer->ops->stream_set(layer, MXR_ENABLE);
45935 mxr_streamer_get(mdev);
45936
45937 return 0;
45938 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45939 spin_unlock_irqrestore(&layer->enq_slock, flags);
45940
45941 /* disabling layer in hardware */
45942 - layer->ops.stream_set(layer, MXR_DISABLE);
45943 + layer->ops->stream_set(layer, MXR_DISABLE);
45944 /* remove one streamer */
45945 mxr_streamer_put(mdev);
45946 /* allow changes in output configuration */
45947 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45948
45949 void mxr_layer_release(struct mxr_layer *layer)
45950 {
45951 - if (layer->ops.release)
45952 - layer->ops.release(layer);
45953 + if (layer->ops->release)
45954 + layer->ops->release(layer);
45955 }
45956
45957 void mxr_base_layer_release(struct mxr_layer *layer)
45958 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45959
45960 layer->mdev = mdev;
45961 layer->idx = idx;
45962 - layer->ops = *ops;
45963 + layer->ops = ops;
45964
45965 spin_lock_init(&layer->enq_slock);
45966 INIT_LIST_HEAD(&layer->enq_list);
45967 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45968 index c9388c4..ce71ece 100644
45969 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45970 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45971 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45972 {
45973 struct mxr_layer *layer;
45974 int ret;
45975 - struct mxr_layer_ops ops = {
45976 + static struct mxr_layer_ops ops = {
45977 .release = mxr_vp_layer_release,
45978 .buffer_set = mxr_vp_buffer_set,
45979 .stream_set = mxr_vp_stream_set,
45980 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45981 index 8033371..de5bca0 100644
45982 --- a/drivers/media/platform/vivi.c
45983 +++ b/drivers/media/platform/vivi.c
45984 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45985 MODULE_LICENSE("Dual BSD/GPL");
45986 MODULE_VERSION(VIVI_VERSION);
45987
45988 -static unsigned video_nr = -1;
45989 -module_param(video_nr, uint, 0644);
45990 +static int video_nr = -1;
45991 +module_param(video_nr, int, 0644);
45992 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45993
45994 static unsigned n_devs = 1;
45995 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45996 index 82affae..42833ec 100644
45997 --- a/drivers/media/radio/radio-cadet.c
45998 +++ b/drivers/media/radio/radio-cadet.c
45999 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46000 unsigned char readbuf[RDS_BUFFER];
46001 int i = 0;
46002
46003 + if (count > RDS_BUFFER)
46004 + return -EFAULT;
46005 mutex_lock(&dev->lock);
46006 if (dev->rdsstat == 0)
46007 cadet_start_rds(dev);
46008 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46009 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46010 mutex_unlock(&dev->lock);
46011
46012 - if (i && copy_to_user(data, readbuf, i))
46013 - return -EFAULT;
46014 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46015 + i = -EFAULT;
46016 +
46017 return i;
46018 }
46019
46020 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46021 index 5236035..c622c74 100644
46022 --- a/drivers/media/radio/radio-maxiradio.c
46023 +++ b/drivers/media/radio/radio-maxiradio.c
46024 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46025 /* TEA5757 pin mappings */
46026 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46027
46028 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46029 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46030
46031 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46032 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46033 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46034 index 050b3bb..79f62b9 100644
46035 --- a/drivers/media/radio/radio-shark.c
46036 +++ b/drivers/media/radio/radio-shark.c
46037 @@ -79,7 +79,7 @@ struct shark_device {
46038 u32 last_val;
46039 };
46040
46041 -static atomic_t shark_instance = ATOMIC_INIT(0);
46042 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46043
46044 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46045 {
46046 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46047 index 8654e0d..0608a64 100644
46048 --- a/drivers/media/radio/radio-shark2.c
46049 +++ b/drivers/media/radio/radio-shark2.c
46050 @@ -74,7 +74,7 @@ struct shark_device {
46051 u8 *transfer_buffer;
46052 };
46053
46054 -static atomic_t shark_instance = ATOMIC_INIT(0);
46055 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46056
46057 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46058 {
46059 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46060 index 633022b..7f10754 100644
46061 --- a/drivers/media/radio/radio-si476x.c
46062 +++ b/drivers/media/radio/radio-si476x.c
46063 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46064 struct si476x_radio *radio;
46065 struct v4l2_ctrl *ctrl;
46066
46067 - static atomic_t instance = ATOMIC_INIT(0);
46068 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46069
46070 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46071 if (!radio)
46072 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46073 index 9fd1527..8927230 100644
46074 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
46075 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46076 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
46077
46078 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
46079 {
46080 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
46081 - char result[64];
46082 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
46083 - sizeof(result), 0);
46084 + char *buf;
46085 + char *result;
46086 + int retval;
46087 +
46088 + buf = kmalloc(2, GFP_KERNEL);
46089 + if (buf == NULL)
46090 + return -ENOMEM;
46091 + result = kmalloc(64, GFP_KERNEL);
46092 + if (result == NULL) {
46093 + kfree(buf);
46094 + return -ENOMEM;
46095 + }
46096 +
46097 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
46098 + buf[1] = enable ? 1 : 0;
46099 +
46100 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
46101 +
46102 + kfree(buf);
46103 + kfree(result);
46104 + return retval;
46105 }
46106
46107 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
46108 {
46109 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
46110 - char state[3];
46111 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
46112 + char *buf;
46113 + char *state;
46114 + int retval;
46115 +
46116 + buf = kmalloc(2, GFP_KERNEL);
46117 + if (buf == NULL)
46118 + return -ENOMEM;
46119 + state = kmalloc(3, GFP_KERNEL);
46120 + if (state == NULL) {
46121 + kfree(buf);
46122 + return -ENOMEM;
46123 + }
46124 +
46125 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
46126 + buf[1] = enable ? 1 : 0;
46127 +
46128 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
46129 +
46130 + kfree(buf);
46131 + kfree(state);
46132 + return retval;
46133 }
46134
46135 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46136 {
46137 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
46138 - char state[3];
46139 + char *query;
46140 + char *state;
46141 int ret;
46142 + query = kmalloc(1, GFP_KERNEL);
46143 + if (query == NULL)
46144 + return -ENOMEM;
46145 + state = kmalloc(3, GFP_KERNEL);
46146 + if (state == NULL) {
46147 + kfree(query);
46148 + return -ENOMEM;
46149 + }
46150 +
46151 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
46152
46153 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
46154
46155 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
46156 - sizeof(state), 0);
46157 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
46158 if (ret < 0) {
46159 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
46160 "state info\n");
46161 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46162
46163 /* Copy this pointer as we are gonna need it in the release phase */
46164 cinergyt2_usb_device = adap->dev;
46165 -
46166 + kfree(query);
46167 + kfree(state);
46168 return 0;
46169 }
46170
46171 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
46172 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46173 {
46174 struct cinergyt2_state *st = d->priv;
46175 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
46176 + u8 *key, *cmd;
46177 int i;
46178
46179 + cmd = kmalloc(1, GFP_KERNEL);
46180 + if (cmd == NULL)
46181 + return -EINVAL;
46182 + key = kzalloc(5, GFP_KERNEL);
46183 + if (key == NULL) {
46184 + kfree(cmd);
46185 + return -EINVAL;
46186 + }
46187 +
46188 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
46189 +
46190 *state = REMOTE_NO_KEY_PRESSED;
46191
46192 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
46193 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
46194 if (key[4] == 0xff) {
46195 /* key repeat */
46196 st->rc_counter++;
46197 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46198 *event = d->last_event;
46199 deb_rc("repeat key, event %x\n",
46200 *event);
46201 - return 0;
46202 + goto out;
46203 }
46204 }
46205 deb_rc("repeated key (non repeatable)\n");
46206 }
46207 - return 0;
46208 + goto out;
46209 }
46210
46211 /* hack to pass checksum on the custom field */
46212 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46213
46214 deb_rc("key: %*ph\n", 5, key);
46215 }
46216 +out:
46217 + kfree(cmd);
46218 + kfree(key);
46219 return 0;
46220 }
46221
46222 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46223 index c890fe4..f9b2ae6 100644
46224 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46225 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46226 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
46227 fe_status_t *status)
46228 {
46229 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46230 - struct dvbt_get_status_msg result;
46231 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46232 + struct dvbt_get_status_msg *result;
46233 + u8 *cmd;
46234 int ret;
46235
46236 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
46237 - sizeof(result), 0);
46238 + cmd = kmalloc(1, GFP_KERNEL);
46239 + if (cmd == NULL)
46240 + return -ENOMEM;
46241 + result = kmalloc(sizeof(*result), GFP_KERNEL);
46242 + if (result == NULL) {
46243 + kfree(cmd);
46244 + return -ENOMEM;
46245 + }
46246 +
46247 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46248 +
46249 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
46250 + sizeof(*result), 0);
46251 if (ret < 0)
46252 - return ret;
46253 + goto out;
46254
46255 *status = 0;
46256
46257 - if (0xffff - le16_to_cpu(result.gain) > 30)
46258 + if (0xffff - le16_to_cpu(result->gain) > 30)
46259 *status |= FE_HAS_SIGNAL;
46260 - if (result.lock_bits & (1 << 6))
46261 + if (result->lock_bits & (1 << 6))
46262 *status |= FE_HAS_LOCK;
46263 - if (result.lock_bits & (1 << 5))
46264 + if (result->lock_bits & (1 << 5))
46265 *status |= FE_HAS_SYNC;
46266 - if (result.lock_bits & (1 << 4))
46267 + if (result->lock_bits & (1 << 4))
46268 *status |= FE_HAS_CARRIER;
46269 - if (result.lock_bits & (1 << 1))
46270 + if (result->lock_bits & (1 << 1))
46271 *status |= FE_HAS_VITERBI;
46272
46273 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
46274 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
46275 *status &= ~FE_HAS_LOCK;
46276
46277 - return 0;
46278 +out:
46279 + kfree(cmd);
46280 + kfree(result);
46281 + return ret;
46282 }
46283
46284 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
46285 {
46286 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46287 - struct dvbt_get_status_msg status;
46288 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46289 + struct dvbt_get_status_msg *status;
46290 + char *cmd;
46291 int ret;
46292
46293 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46294 - sizeof(status), 0);
46295 + cmd = kmalloc(1, GFP_KERNEL);
46296 + if (cmd == NULL)
46297 + return -ENOMEM;
46298 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46299 + if (status == NULL) {
46300 + kfree(cmd);
46301 + return -ENOMEM;
46302 + }
46303 +
46304 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46305 +
46306 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46307 + sizeof(*status), 0);
46308 if (ret < 0)
46309 - return ret;
46310 + goto out;
46311
46312 - *ber = le32_to_cpu(status.viterbi_error_rate);
46313 + *ber = le32_to_cpu(status->viterbi_error_rate);
46314 +out:
46315 + kfree(cmd);
46316 + kfree(status);
46317 return 0;
46318 }
46319
46320 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
46321 {
46322 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46323 - struct dvbt_get_status_msg status;
46324 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46325 + struct dvbt_get_status_msg *status;
46326 + u8 *cmd;
46327 int ret;
46328
46329 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46330 - sizeof(status), 0);
46331 + cmd = kmalloc(1, GFP_KERNEL);
46332 + if (cmd == NULL)
46333 + return -ENOMEM;
46334 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46335 + if (status == NULL) {
46336 + kfree(cmd);
46337 + return -ENOMEM;
46338 + }
46339 +
46340 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46341 +
46342 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46343 + sizeof(*status), 0);
46344 if (ret < 0) {
46345 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46346 ret);
46347 - return ret;
46348 + goto out;
46349 }
46350 - *unc = le32_to_cpu(status.uncorrected_block_count);
46351 - return 0;
46352 + *unc = le32_to_cpu(status->uncorrected_block_count);
46353 +
46354 +out:
46355 + kfree(cmd);
46356 + kfree(status);
46357 + return ret;
46358 }
46359
46360 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46361 u16 *strength)
46362 {
46363 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46364 - struct dvbt_get_status_msg status;
46365 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46366 + struct dvbt_get_status_msg *status;
46367 + char *cmd;
46368 int ret;
46369
46370 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46371 - sizeof(status), 0);
46372 + cmd = kmalloc(1, GFP_KERNEL);
46373 + if (cmd == NULL)
46374 + return -ENOMEM;
46375 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46376 + if (status == NULL) {
46377 + kfree(cmd);
46378 + return -ENOMEM;
46379 + }
46380 +
46381 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46382 +
46383 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46384 + sizeof(*status), 0);
46385 if (ret < 0) {
46386 err("cinergyt2_fe_read_signal_strength() Failed!"
46387 " (Error=%d)\n", ret);
46388 - return ret;
46389 + goto out;
46390 }
46391 - *strength = (0xffff - le16_to_cpu(status.gain));
46392 + *strength = (0xffff - le16_to_cpu(status->gain));
46393 +
46394 +out:
46395 + kfree(cmd);
46396 + kfree(status);
46397 return 0;
46398 }
46399
46400 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46401 {
46402 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46403 - struct dvbt_get_status_msg status;
46404 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46405 + struct dvbt_get_status_msg *status;
46406 + char *cmd;
46407 int ret;
46408
46409 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46410 - sizeof(status), 0);
46411 + cmd = kmalloc(1, GFP_KERNEL);
46412 + if (cmd == NULL)
46413 + return -ENOMEM;
46414 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46415 + if (status == NULL) {
46416 + kfree(cmd);
46417 + return -ENOMEM;
46418 + }
46419 +
46420 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46421 +
46422 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46423 + sizeof(*status), 0);
46424 if (ret < 0) {
46425 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46426 - return ret;
46427 + goto out;
46428 }
46429 - *snr = (status.snr << 8) | status.snr;
46430 - return 0;
46431 + *snr = (status->snr << 8) | status->snr;
46432 +
46433 +out:
46434 + kfree(cmd);
46435 + kfree(status);
46436 + return ret;
46437 }
46438
46439 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46440 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46441 {
46442 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46443 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46444 - struct dvbt_set_parameters_msg param;
46445 - char result[2];
46446 + struct dvbt_set_parameters_msg *param;
46447 + char *result;
46448 int err;
46449
46450 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46451 - param.tps = cpu_to_le16(compute_tps(fep));
46452 - param.freq = cpu_to_le32(fep->frequency / 1000);
46453 - param.flags = 0;
46454 + result = kmalloc(2, GFP_KERNEL);
46455 + if (result == NULL)
46456 + return -ENOMEM;
46457 + param = kmalloc(sizeof(*param), GFP_KERNEL);
46458 + if (param == NULL) {
46459 + kfree(result);
46460 + return -ENOMEM;
46461 + }
46462 +
46463 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46464 + param->tps = cpu_to_le16(compute_tps(fep));
46465 + param->freq = cpu_to_le32(fep->frequency / 1000);
46466 + param->flags = 0;
46467
46468 switch (fep->bandwidth_hz) {
46469 default:
46470 case 8000000:
46471 - param.bandwidth = 8;
46472 + param->bandwidth = 8;
46473 break;
46474 case 7000000:
46475 - param.bandwidth = 7;
46476 + param->bandwidth = 7;
46477 break;
46478 case 6000000:
46479 - param.bandwidth = 6;
46480 + param->bandwidth = 6;
46481 break;
46482 }
46483
46484 err = dvb_usb_generic_rw(state->d,
46485 - (char *)&param, sizeof(param),
46486 - result, sizeof(result), 0);
46487 + (char *)param, sizeof(*param),
46488 + result, 2, 0);
46489 if (err < 0)
46490 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46491
46492 - return (err < 0) ? err : 0;
46493 + kfree(result);
46494 + kfree(param);
46495 + return err;
46496 }
46497
46498 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46499 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46500 index 733a7ff..f8b52e3 100644
46501 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46502 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46503 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46504
46505 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46506 {
46507 - struct hexline hx;
46508 - u8 reset;
46509 + struct hexline *hx;
46510 + u8 *reset;
46511 int ret,pos=0;
46512
46513 + reset = kmalloc(1, GFP_KERNEL);
46514 + if (reset == NULL)
46515 + return -ENOMEM;
46516 +
46517 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46518 + if (hx == NULL) {
46519 + kfree(reset);
46520 + return -ENOMEM;
46521 + }
46522 +
46523 /* stop the CPU */
46524 - reset = 1;
46525 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46526 + reset[0] = 1;
46527 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46528 err("could not stop the USB controller CPU.");
46529
46530 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46531 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46532 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46533 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46534 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46535 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46536
46537 - if (ret != hx.len) {
46538 + if (ret != hx->len) {
46539 err("error while transferring firmware "
46540 "(transferred size: %d, block size: %d)",
46541 - ret,hx.len);
46542 + ret,hx->len);
46543 ret = -EINVAL;
46544 break;
46545 }
46546 }
46547 if (ret < 0) {
46548 err("firmware download failed at %d with %d",pos,ret);
46549 + kfree(reset);
46550 + kfree(hx);
46551 return ret;
46552 }
46553
46554 if (ret == 0) {
46555 /* restart the CPU */
46556 - reset = 0;
46557 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46558 + reset[0] = 0;
46559 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46560 err("could not restart the USB controller CPU.");
46561 ret = -EINVAL;
46562 }
46563 } else
46564 ret = -EIO;
46565
46566 + kfree(reset);
46567 + kfree(hx);
46568 +
46569 return ret;
46570 }
46571 EXPORT_SYMBOL(usb_cypress_load_firmware);
46572 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46573 index 2add8c5..c33b854 100644
46574 --- a/drivers/media/usb/dvb-usb/dw2102.c
46575 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46576 @@ -118,7 +118,7 @@ struct su3000_state {
46577
46578 struct s6x0_state {
46579 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46580 -};
46581 +} __no_const;
46582
46583 /* debug */
46584 static int dvb_usb_dw2102_debug;
46585 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46586 index 6b0b8b6b..4038398 100644
46587 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46588 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46589 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46590 static int technisat_usb2_i2c_access(struct usb_device *udev,
46591 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46592 {
46593 - u8 b[64];
46594 - int ret, actual_length;
46595 + u8 *b = kmalloc(64, GFP_KERNEL);
46596 + int ret, actual_length, error = 0;
46597 +
46598 + if (b == NULL)
46599 + return -ENOMEM;
46600
46601 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46602 debug_dump(tx, txlen, deb_i2c);
46603 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46604
46605 if (ret < 0) {
46606 err("i2c-error: out failed %02x = %d", device_addr, ret);
46607 - return -ENODEV;
46608 + error = -ENODEV;
46609 + goto out;
46610 }
46611
46612 ret = usb_bulk_msg(udev,
46613 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46614 b, 64, &actual_length, 1000);
46615 if (ret < 0) {
46616 err("i2c-error: in failed %02x = %d", device_addr, ret);
46617 - return -ENODEV;
46618 + error = -ENODEV;
46619 + goto out;
46620 }
46621
46622 if (b[0] != I2C_STATUS_OK) {
46623 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46624 /* handle tuner-i2c-nak */
46625 if (!(b[0] == I2C_STATUS_NAK &&
46626 device_addr == 0x60
46627 - /* && device_is_technisat_usb2 */))
46628 - return -ENODEV;
46629 + /* && device_is_technisat_usb2 */)) {
46630 + error = -ENODEV;
46631 + goto out;
46632 + }
46633 }
46634
46635 deb_i2c("status: %d, ", b[0]);
46636 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46637
46638 deb_i2c("\n");
46639
46640 - return 0;
46641 +out:
46642 + kfree(b);
46643 + return error;
46644 }
46645
46646 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46647 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46648 {
46649 int ret;
46650
46651 - u8 led[8] = {
46652 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46653 - 0
46654 - };
46655 + u8 *led = kzalloc(8, GFP_KERNEL);
46656 +
46657 + if (led == NULL)
46658 + return -ENOMEM;
46659
46660 if (disable_led_control && state != TECH_LED_OFF)
46661 return 0;
46662
46663 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46664 +
46665 switch (state) {
46666 case TECH_LED_ON:
46667 led[1] = 0x82;
46668 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46669 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46670 USB_TYPE_VENDOR | USB_DIR_OUT,
46671 0, 0,
46672 - led, sizeof(led), 500);
46673 + led, 8, 500);
46674
46675 mutex_unlock(&d->i2c_mutex);
46676 +
46677 + kfree(led);
46678 +
46679 return ret;
46680 }
46681
46682 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46683 {
46684 int ret;
46685 - u8 b = 0;
46686 + u8 *b = kzalloc(1, GFP_KERNEL);
46687 +
46688 + if (b == NULL)
46689 + return -ENOMEM;
46690
46691 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46692 return -EAGAIN;
46693 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46694 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46695 USB_TYPE_VENDOR | USB_DIR_OUT,
46696 (red << 8) | green, 0,
46697 - &b, 1, 500);
46698 + b, 1, 500);
46699
46700 mutex_unlock(&d->i2c_mutex);
46701
46702 + kfree(b);
46703 +
46704 return ret;
46705 }
46706
46707 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46708 struct dvb_usb_device_description **desc, int *cold)
46709 {
46710 int ret;
46711 - u8 version[3];
46712 + u8 *version = kmalloc(3, GFP_KERNEL);
46713
46714 /* first select the interface */
46715 if (usb_set_interface(udev, 0, 1) != 0)
46716 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46717
46718 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46719
46720 + if (version == NULL)
46721 + return 0;
46722 +
46723 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46724 GET_VERSION_INFO_VENDOR_REQUEST,
46725 USB_TYPE_VENDOR | USB_DIR_IN,
46726 0, 0,
46727 - version, sizeof(version), 500);
46728 + version, 3, 500);
46729
46730 if (ret < 0)
46731 *cold = 1;
46732 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46733 *cold = 0;
46734 }
46735
46736 + kfree(version);
46737 +
46738 return 0;
46739 }
46740
46741 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46742
46743 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46744 {
46745 - u8 buf[62], *b;
46746 + u8 *buf, *b;
46747 int ret;
46748 struct ir_raw_event ev;
46749
46750 + buf = kmalloc(62, GFP_KERNEL);
46751 +
46752 + if (buf == NULL)
46753 + return -ENOMEM;
46754 +
46755 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46756 buf[1] = 0x08;
46757 buf[2] = 0x8f;
46758 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46759 GET_IR_DATA_VENDOR_REQUEST,
46760 USB_TYPE_VENDOR | USB_DIR_IN,
46761 0x8080, 0,
46762 - buf, sizeof(buf), 500);
46763 + buf, 62, 500);
46764
46765 unlock:
46766 mutex_unlock(&d->i2c_mutex);
46767
46768 - if (ret < 0)
46769 + if (ret < 0) {
46770 + kfree(buf);
46771 return ret;
46772 + }
46773
46774 - if (ret == 1)
46775 + if (ret == 1) {
46776 + kfree(buf);
46777 return 0; /* no key pressed */
46778 + }
46779
46780 /* decoding */
46781 b = buf+1;
46782 @@ -653,6 +686,8 @@ unlock:
46783
46784 ir_raw_event_handle(d->rc_dev);
46785
46786 + kfree(buf);
46787 +
46788 return 1;
46789 }
46790
46791 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46792 index cca6c2f..77b9a18 100644
46793 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46794 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46795 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46796 __u32 reserved;
46797 };
46798
46799 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46800 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46801 enum v4l2_memory memory)
46802 {
46803 void __user *up_pln;
46804 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46805 return 0;
46806 }
46807
46808 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46809 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46810 enum v4l2_memory memory)
46811 {
46812 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46813 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46814 * by passing a very big num_planes value */
46815 uplane = compat_alloc_user_space(num_planes *
46816 sizeof(struct v4l2_plane));
46817 - kp->m.planes = uplane;
46818 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46819
46820 while (--num_planes >= 0) {
46821 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46822 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46823 if (num_planes == 0)
46824 return 0;
46825
46826 - uplane = kp->m.planes;
46827 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46828 if (get_user(p, &up->m.planes))
46829 return -EFAULT;
46830 uplane32 = compat_ptr(p);
46831 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46832 get_user(kp->flags, &up->flags) ||
46833 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46834 return -EFAULT;
46835 - kp->base = compat_ptr(tmp);
46836 + kp->base = (void __force_kernel *)compat_ptr(tmp);
46837 return 0;
46838 }
46839
46840 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46841 n * sizeof(struct v4l2_ext_control32)))
46842 return -EFAULT;
46843 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46844 - kp->controls = kcontrols;
46845 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46846 while (--n >= 0) {
46847 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46848 return -EFAULT;
46849 @@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46850 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46851 {
46852 struct v4l2_ext_control32 __user *ucontrols;
46853 - struct v4l2_ext_control __user *kcontrols = kp->controls;
46854 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46855 int n = kp->count;
46856 compat_caddr_t p;
46857
46858 @@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46859 put_user(kp->start_block, &up->start_block) ||
46860 put_user(kp->blocks, &up->blocks) ||
46861 put_user(tmp, &up->edid) ||
46862 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46863 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46864 return -EFAULT;
46865 return 0;
46866 }
46867 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46868 index 015f92a..59e311e 100644
46869 --- a/drivers/media/v4l2-core/v4l2-device.c
46870 +++ b/drivers/media/v4l2-core/v4l2-device.c
46871 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46872 EXPORT_SYMBOL_GPL(v4l2_device_put);
46873
46874 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46875 - atomic_t *instance)
46876 + atomic_unchecked_t *instance)
46877 {
46878 - int num = atomic_inc_return(instance) - 1;
46879 + int num = atomic_inc_return_unchecked(instance) - 1;
46880 int len = strlen(basename);
46881
46882 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46883 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46884 index d15e167..337f374 100644
46885 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46886 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46887 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46888 struct file *file, void *fh, void *p);
46889 } u;
46890 void (*debug)(const void *arg, bool write_only);
46891 -};
46892 +} __do_const;
46893 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46894
46895 /* This control needs a priority check */
46896 #define INFO_FL_PRIO (1 << 0)
46897 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46898 struct video_device *vfd = video_devdata(file);
46899 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46900 bool write_only = false;
46901 - struct v4l2_ioctl_info default_info;
46902 + v4l2_ioctl_info_no_const default_info;
46903 const struct v4l2_ioctl_info *info;
46904 void *fh = file->private_data;
46905 struct v4l2_fh *vfh = NULL;
46906 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46907 ret = -EINVAL;
46908 break;
46909 }
46910 - *user_ptr = (void __user *)buf->m.planes;
46911 + *user_ptr = (void __force_user *)buf->m.planes;
46912 *kernel_ptr = (void **)&buf->m.planes;
46913 *array_size = sizeof(struct v4l2_plane) * buf->length;
46914 ret = 1;
46915 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46916 ret = -EINVAL;
46917 break;
46918 }
46919 - *user_ptr = (void __user *)edid->edid;
46920 + *user_ptr = (void __force_user *)edid->edid;
46921 *kernel_ptr = (void **)&edid->edid;
46922 *array_size = edid->blocks * 128;
46923 ret = 1;
46924 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46925 ret = -EINVAL;
46926 break;
46927 }
46928 - *user_ptr = (void __user *)ctrls->controls;
46929 + *user_ptr = (void __force_user *)ctrls->controls;
46930 *kernel_ptr = (void **)&ctrls->controls;
46931 *array_size = sizeof(struct v4l2_ext_control)
46932 * ctrls->count;
46933 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46934 }
46935
46936 if (has_array_args) {
46937 - *kernel_ptr = (void __force *)user_ptr;
46938 + *kernel_ptr = (void __force_kernel *)user_ptr;
46939 if (copy_to_user(user_ptr, mbuf, array_size))
46940 err = -EFAULT;
46941 goto out_array_args;
46942 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46943 index a896d94..a5d56b1 100644
46944 --- a/drivers/message/fusion/mptbase.c
46945 +++ b/drivers/message/fusion/mptbase.c
46946 @@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46947 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46948 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46949
46950 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46951 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46952 +#else
46953 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46954 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46955 +#endif
46956 +
46957 /*
46958 * Rounding UP to nearest 4-kB boundary here...
46959 */
46960 @@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46961 ioc->facts.GlobalCredits);
46962
46963 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46964 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46965 + NULL, NULL);
46966 +#else
46967 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46968 +#endif
46969 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46970 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46971 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46972 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46973 index 0707fa2..70ca794 100644
46974 --- a/drivers/message/fusion/mptsas.c
46975 +++ b/drivers/message/fusion/mptsas.c
46976 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46977 return 0;
46978 }
46979
46980 +static inline void
46981 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46982 +{
46983 + if (phy_info->port_details) {
46984 + phy_info->port_details->rphy = rphy;
46985 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46986 + ioc->name, rphy));
46987 + }
46988 +
46989 + if (rphy) {
46990 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46991 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46992 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46993 + ioc->name, rphy, rphy->dev.release));
46994 + }
46995 +}
46996 +
46997 /* no mutex */
46998 static void
46999 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47000 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47001 return NULL;
47002 }
47003
47004 -static inline void
47005 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47006 -{
47007 - if (phy_info->port_details) {
47008 - phy_info->port_details->rphy = rphy;
47009 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47010 - ioc->name, rphy));
47011 - }
47012 -
47013 - if (rphy) {
47014 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47015 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47016 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47017 - ioc->name, rphy, rphy->dev.release));
47018 - }
47019 -}
47020 -
47021 static inline struct sas_port *
47022 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47023 {
47024 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47025 index b7d87cd..3fb36da 100644
47026 --- a/drivers/message/i2o/i2o_proc.c
47027 +++ b/drivers/message/i2o/i2o_proc.c
47028 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47029 "Array Controller Device"
47030 };
47031
47032 -static char *chtostr(char *tmp, u8 *chars, int n)
47033 -{
47034 - tmp[0] = 0;
47035 - return strncat(tmp, (char *)chars, n);
47036 -}
47037 -
47038 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47039 char *group)
47040 {
47041 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47042 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47043 {
47044 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47045 - static u32 work32[5];
47046 - static u8 *work8 = (u8 *) work32;
47047 - static u16 *work16 = (u16 *) work32;
47048 + u32 work32[5];
47049 + u8 *work8 = (u8 *) work32;
47050 + u16 *work16 = (u16 *) work32;
47051 int token;
47052 u32 hwcap;
47053
47054 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47055 } *result;
47056
47057 i2o_exec_execute_ddm_table ddm_table;
47058 - char tmp[28 + 1];
47059
47060 result = kmalloc(sizeof(*result), GFP_KERNEL);
47061 if (!result)
47062 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47063
47064 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47065 seq_printf(seq, "%-#8x", ddm_table.module_id);
47066 - seq_printf(seq, "%-29s",
47067 - chtostr(tmp, ddm_table.module_name_version, 28));
47068 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47069 seq_printf(seq, "%9d ", ddm_table.data_size);
47070 seq_printf(seq, "%8d", ddm_table.code_size);
47071
47072 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47073
47074 i2o_driver_result_table *result;
47075 i2o_driver_store_table *dst;
47076 - char tmp[28 + 1];
47077
47078 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47079 if (result == NULL)
47080 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47081
47082 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47083 seq_printf(seq, "%-#8x", dst->module_id);
47084 - seq_printf(seq, "%-29s",
47085 - chtostr(tmp, dst->module_name_version, 28));
47086 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47087 + seq_printf(seq, "%-.28s", dst->module_name_version);
47088 + seq_printf(seq, "%-.8s", dst->date);
47089 seq_printf(seq, "%8d ", dst->module_size);
47090 seq_printf(seq, "%8d ", dst->mpb_size);
47091 seq_printf(seq, "0x%04x", dst->module_flags);
47092 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47093 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47094 {
47095 struct i2o_device *d = (struct i2o_device *)seq->private;
47096 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47097 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47098 // == (allow) 512d bytes (max)
47099 - static u16 *work16 = (u16 *) work32;
47100 + u16 *work16 = (u16 *) work32;
47101 int token;
47102 - char tmp[16 + 1];
47103
47104 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47105
47106 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47107 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47108 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47109 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47110 - seq_printf(seq, "Vendor info : %s\n",
47111 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47112 - seq_printf(seq, "Product info : %s\n",
47113 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47114 - seq_printf(seq, "Description : %s\n",
47115 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47116 - seq_printf(seq, "Product rev. : %s\n",
47117 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47118 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47119 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47120 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47121 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47122
47123 seq_printf(seq, "Serial number : ");
47124 print_serial_number(seq, (u8 *) (work32 + 16),
47125 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47126 u8 pad[256]; // allow up to 256 byte (max) serial number
47127 } result;
47128
47129 - char tmp[24 + 1];
47130 -
47131 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47132
47133 if (token < 0) {
47134 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47135 }
47136
47137 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47138 - seq_printf(seq, "Module name : %s\n",
47139 - chtostr(tmp, result.module_name, 24));
47140 - seq_printf(seq, "Module revision : %s\n",
47141 - chtostr(tmp, result.module_rev, 8));
47142 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47143 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47144
47145 seq_printf(seq, "Serial number : ");
47146 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47147 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47148 u8 instance_number[4];
47149 } result;
47150
47151 - char tmp[64 + 1];
47152 -
47153 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47154
47155 if (token < 0) {
47156 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47157 return 0;
47158 }
47159
47160 - seq_printf(seq, "Device name : %s\n",
47161 - chtostr(tmp, result.device_name, 64));
47162 - seq_printf(seq, "Service name : %s\n",
47163 - chtostr(tmp, result.service_name, 64));
47164 - seq_printf(seq, "Physical name : %s\n",
47165 - chtostr(tmp, result.physical_location, 64));
47166 - seq_printf(seq, "Instance number : %s\n",
47167 - chtostr(tmp, result.instance_number, 4));
47168 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47169 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47170 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47171 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47172
47173 return 0;
47174 }
47175 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47176 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47177 {
47178 struct i2o_device *d = (struct i2o_device *)seq->private;
47179 - static u32 work32[12];
47180 - static u16 *work16 = (u16 *) work32;
47181 - static u8 *work8 = (u8 *) work32;
47182 + u32 work32[12];
47183 + u16 *work16 = (u16 *) work32;
47184 + u8 *work8 = (u8 *) work32;
47185 int token;
47186
47187 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47188 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47189 index 92752fb..a7494f6 100644
47190 --- a/drivers/message/i2o/iop.c
47191 +++ b/drivers/message/i2o/iop.c
47192 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47193
47194 spin_lock_irqsave(&c->context_list_lock, flags);
47195
47196 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47197 - atomic_inc(&c->context_list_counter);
47198 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47199 + atomic_inc_unchecked(&c->context_list_counter);
47200
47201 - entry->context = atomic_read(&c->context_list_counter);
47202 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47203
47204 list_add(&entry->list, &c->context_list);
47205
47206 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47207
47208 #if BITS_PER_LONG == 64
47209 spin_lock_init(&c->context_list_lock);
47210 - atomic_set(&c->context_list_counter, 0);
47211 + atomic_set_unchecked(&c->context_list_counter, 0);
47212 INIT_LIST_HEAD(&c->context_list);
47213 #endif
47214
47215 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47216 index b2c7e3b..85aa4764 100644
47217 --- a/drivers/mfd/ab8500-debugfs.c
47218 +++ b/drivers/mfd/ab8500-debugfs.c
47219 @@ -100,7 +100,7 @@ static int irq_last;
47220 static u32 *irq_count;
47221 static int num_irqs;
47222
47223 -static struct device_attribute **dev_attr;
47224 +static device_attribute_no_const **dev_attr;
47225 static char **event_name;
47226
47227 static u8 avg_sample = SAMPLE_16;
47228 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47229 index ecbe78e..b2ca870 100644
47230 --- a/drivers/mfd/max8925-i2c.c
47231 +++ b/drivers/mfd/max8925-i2c.c
47232 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47233 const struct i2c_device_id *id)
47234 {
47235 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47236 - static struct max8925_chip *chip;
47237 + struct max8925_chip *chip;
47238 struct device_node *node = client->dev.of_node;
47239
47240 if (node && !pdata) {
47241 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47242 index f243e75..322176c 100644
47243 --- a/drivers/mfd/tps65910.c
47244 +++ b/drivers/mfd/tps65910.c
47245 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47246 struct tps65910_platform_data *pdata)
47247 {
47248 int ret = 0;
47249 - static struct regmap_irq_chip *tps6591x_irqs_chip;
47250 + struct regmap_irq_chip *tps6591x_irqs_chip;
47251
47252 if (!irq) {
47253 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47254 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47255 index b1dabba..24a88f2 100644
47256 --- a/drivers/mfd/twl4030-irq.c
47257 +++ b/drivers/mfd/twl4030-irq.c
47258 @@ -34,6 +34,7 @@
47259 #include <linux/of.h>
47260 #include <linux/irqdomain.h>
47261 #include <linux/i2c/twl.h>
47262 +#include <asm/pgtable.h>
47263
47264 #include "twl-core.h"
47265
47266 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47267 * Install an irq handler for each of the SIH modules;
47268 * clone dummy irq_chip since PIH can't *do* anything
47269 */
47270 - twl4030_irq_chip = dummy_irq_chip;
47271 - twl4030_irq_chip.name = "twl4030";
47272 + pax_open_kernel();
47273 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47274 + *(const char **)&twl4030_irq_chip.name = "twl4030";
47275
47276 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47277 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47278 + pax_close_kernel();
47279
47280 for (i = irq_base; i < irq_end; i++) {
47281 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47282 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47283 index 464419b..64bae8d 100644
47284 --- a/drivers/misc/c2port/core.c
47285 +++ b/drivers/misc/c2port/core.c
47286 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47287 goto error_idr_alloc;
47288 c2dev->id = ret;
47289
47290 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47291 + pax_open_kernel();
47292 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47293 + pax_close_kernel();
47294
47295 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47296 "c2port%d", c2dev->id);
47297 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47298 index 3f2b625..945e179 100644
47299 --- a/drivers/misc/eeprom/sunxi_sid.c
47300 +++ b/drivers/misc/eeprom/sunxi_sid.c
47301 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47302
47303 platform_set_drvdata(pdev, sid_data);
47304
47305 - sid_bin_attr.size = sid_data->keysize;
47306 + pax_open_kernel();
47307 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47308 + pax_close_kernel();
47309 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47310 return -ENODEV;
47311
47312 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47313 index 36f5d52..32311c3 100644
47314 --- a/drivers/misc/kgdbts.c
47315 +++ b/drivers/misc/kgdbts.c
47316 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47317 char before[BREAK_INSTR_SIZE];
47318 char after[BREAK_INSTR_SIZE];
47319
47320 - probe_kernel_read(before, (char *)kgdbts_break_test,
47321 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47322 BREAK_INSTR_SIZE);
47323 init_simple_test();
47324 ts.tst = plant_and_detach_test;
47325 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47326 /* Activate test with initial breakpoint */
47327 if (!is_early)
47328 kgdb_breakpoint();
47329 - probe_kernel_read(after, (char *)kgdbts_break_test,
47330 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47331 BREAK_INSTR_SIZE);
47332 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47333 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47334 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47335 index 3ef4627..8d00486 100644
47336 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47337 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47338 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47339 * the lid is closed. This leads to interrupts as soon as a little move
47340 * is done.
47341 */
47342 - atomic_inc(&lis3->count);
47343 + atomic_inc_unchecked(&lis3->count);
47344
47345 wake_up_interruptible(&lis3->misc_wait);
47346 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47347 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47348 if (lis3->pm_dev)
47349 pm_runtime_get_sync(lis3->pm_dev);
47350
47351 - atomic_set(&lis3->count, 0);
47352 + atomic_set_unchecked(&lis3->count, 0);
47353 return 0;
47354 }
47355
47356 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47357 add_wait_queue(&lis3->misc_wait, &wait);
47358 while (true) {
47359 set_current_state(TASK_INTERRUPTIBLE);
47360 - data = atomic_xchg(&lis3->count, 0);
47361 + data = atomic_xchg_unchecked(&lis3->count, 0);
47362 if (data)
47363 break;
47364
47365 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47366 struct lis3lv02d, miscdev);
47367
47368 poll_wait(file, &lis3->misc_wait, wait);
47369 - if (atomic_read(&lis3->count))
47370 + if (atomic_read_unchecked(&lis3->count))
47371 return POLLIN | POLLRDNORM;
47372 return 0;
47373 }
47374 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47375 index c439c82..1f20f57 100644
47376 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47377 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47378 @@ -297,7 +297,7 @@ struct lis3lv02d {
47379 struct input_polled_dev *idev; /* input device */
47380 struct platform_device *pdev; /* platform device */
47381 struct regulator_bulk_data regulators[2];
47382 - atomic_t count; /* interrupt count after last read */
47383 + atomic_unchecked_t count; /* interrupt count after last read */
47384 union axis_conversion ac; /* hw -> logical axis */
47385 int mapped_btns[3];
47386
47387 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47388 index 2f30bad..c4c13d0 100644
47389 --- a/drivers/misc/sgi-gru/gruhandles.c
47390 +++ b/drivers/misc/sgi-gru/gruhandles.c
47391 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47392 unsigned long nsec;
47393
47394 nsec = CLKS2NSEC(clks);
47395 - atomic_long_inc(&mcs_op_statistics[op].count);
47396 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47397 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47398 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47399 if (mcs_op_statistics[op].max < nsec)
47400 mcs_op_statistics[op].max = nsec;
47401 }
47402 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47403 index 4f76359..cdfcb2e 100644
47404 --- a/drivers/misc/sgi-gru/gruprocfs.c
47405 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47406 @@ -32,9 +32,9 @@
47407
47408 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47409
47410 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47411 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47412 {
47413 - unsigned long val = atomic_long_read(v);
47414 + unsigned long val = atomic_long_read_unchecked(v);
47415
47416 seq_printf(s, "%16lu %s\n", val, id);
47417 }
47418 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47419
47420 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47421 for (op = 0; op < mcsop_last; op++) {
47422 - count = atomic_long_read(&mcs_op_statistics[op].count);
47423 - total = atomic_long_read(&mcs_op_statistics[op].total);
47424 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47425 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47426 max = mcs_op_statistics[op].max;
47427 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47428 count ? total / count : 0, max);
47429 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47430 index 5c3ce24..4915ccb 100644
47431 --- a/drivers/misc/sgi-gru/grutables.h
47432 +++ b/drivers/misc/sgi-gru/grutables.h
47433 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47434 * GRU statistics.
47435 */
47436 struct gru_stats_s {
47437 - atomic_long_t vdata_alloc;
47438 - atomic_long_t vdata_free;
47439 - atomic_long_t gts_alloc;
47440 - atomic_long_t gts_free;
47441 - atomic_long_t gms_alloc;
47442 - atomic_long_t gms_free;
47443 - atomic_long_t gts_double_allocate;
47444 - atomic_long_t assign_context;
47445 - atomic_long_t assign_context_failed;
47446 - atomic_long_t free_context;
47447 - atomic_long_t load_user_context;
47448 - atomic_long_t load_kernel_context;
47449 - atomic_long_t lock_kernel_context;
47450 - atomic_long_t unlock_kernel_context;
47451 - atomic_long_t steal_user_context;
47452 - atomic_long_t steal_kernel_context;
47453 - atomic_long_t steal_context_failed;
47454 - atomic_long_t nopfn;
47455 - atomic_long_t asid_new;
47456 - atomic_long_t asid_next;
47457 - atomic_long_t asid_wrap;
47458 - atomic_long_t asid_reuse;
47459 - atomic_long_t intr;
47460 - atomic_long_t intr_cbr;
47461 - atomic_long_t intr_tfh;
47462 - atomic_long_t intr_spurious;
47463 - atomic_long_t intr_mm_lock_failed;
47464 - atomic_long_t call_os;
47465 - atomic_long_t call_os_wait_queue;
47466 - atomic_long_t user_flush_tlb;
47467 - atomic_long_t user_unload_context;
47468 - atomic_long_t user_exception;
47469 - atomic_long_t set_context_option;
47470 - atomic_long_t check_context_retarget_intr;
47471 - atomic_long_t check_context_unload;
47472 - atomic_long_t tlb_dropin;
47473 - atomic_long_t tlb_preload_page;
47474 - atomic_long_t tlb_dropin_fail_no_asid;
47475 - atomic_long_t tlb_dropin_fail_upm;
47476 - atomic_long_t tlb_dropin_fail_invalid;
47477 - atomic_long_t tlb_dropin_fail_range_active;
47478 - atomic_long_t tlb_dropin_fail_idle;
47479 - atomic_long_t tlb_dropin_fail_fmm;
47480 - atomic_long_t tlb_dropin_fail_no_exception;
47481 - atomic_long_t tfh_stale_on_fault;
47482 - atomic_long_t mmu_invalidate_range;
47483 - atomic_long_t mmu_invalidate_page;
47484 - atomic_long_t flush_tlb;
47485 - atomic_long_t flush_tlb_gru;
47486 - atomic_long_t flush_tlb_gru_tgh;
47487 - atomic_long_t flush_tlb_gru_zero_asid;
47488 + atomic_long_unchecked_t vdata_alloc;
47489 + atomic_long_unchecked_t vdata_free;
47490 + atomic_long_unchecked_t gts_alloc;
47491 + atomic_long_unchecked_t gts_free;
47492 + atomic_long_unchecked_t gms_alloc;
47493 + atomic_long_unchecked_t gms_free;
47494 + atomic_long_unchecked_t gts_double_allocate;
47495 + atomic_long_unchecked_t assign_context;
47496 + atomic_long_unchecked_t assign_context_failed;
47497 + atomic_long_unchecked_t free_context;
47498 + atomic_long_unchecked_t load_user_context;
47499 + atomic_long_unchecked_t load_kernel_context;
47500 + atomic_long_unchecked_t lock_kernel_context;
47501 + atomic_long_unchecked_t unlock_kernel_context;
47502 + atomic_long_unchecked_t steal_user_context;
47503 + atomic_long_unchecked_t steal_kernel_context;
47504 + atomic_long_unchecked_t steal_context_failed;
47505 + atomic_long_unchecked_t nopfn;
47506 + atomic_long_unchecked_t asid_new;
47507 + atomic_long_unchecked_t asid_next;
47508 + atomic_long_unchecked_t asid_wrap;
47509 + atomic_long_unchecked_t asid_reuse;
47510 + atomic_long_unchecked_t intr;
47511 + atomic_long_unchecked_t intr_cbr;
47512 + atomic_long_unchecked_t intr_tfh;
47513 + atomic_long_unchecked_t intr_spurious;
47514 + atomic_long_unchecked_t intr_mm_lock_failed;
47515 + atomic_long_unchecked_t call_os;
47516 + atomic_long_unchecked_t call_os_wait_queue;
47517 + atomic_long_unchecked_t user_flush_tlb;
47518 + atomic_long_unchecked_t user_unload_context;
47519 + atomic_long_unchecked_t user_exception;
47520 + atomic_long_unchecked_t set_context_option;
47521 + atomic_long_unchecked_t check_context_retarget_intr;
47522 + atomic_long_unchecked_t check_context_unload;
47523 + atomic_long_unchecked_t tlb_dropin;
47524 + atomic_long_unchecked_t tlb_preload_page;
47525 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47526 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47527 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47528 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47529 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47530 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47531 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47532 + atomic_long_unchecked_t tfh_stale_on_fault;
47533 + atomic_long_unchecked_t mmu_invalidate_range;
47534 + atomic_long_unchecked_t mmu_invalidate_page;
47535 + atomic_long_unchecked_t flush_tlb;
47536 + atomic_long_unchecked_t flush_tlb_gru;
47537 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47538 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47539
47540 - atomic_long_t copy_gpa;
47541 - atomic_long_t read_gpa;
47542 + atomic_long_unchecked_t copy_gpa;
47543 + atomic_long_unchecked_t read_gpa;
47544
47545 - atomic_long_t mesq_receive;
47546 - atomic_long_t mesq_receive_none;
47547 - atomic_long_t mesq_send;
47548 - atomic_long_t mesq_send_failed;
47549 - atomic_long_t mesq_noop;
47550 - atomic_long_t mesq_send_unexpected_error;
47551 - atomic_long_t mesq_send_lb_overflow;
47552 - atomic_long_t mesq_send_qlimit_reached;
47553 - atomic_long_t mesq_send_amo_nacked;
47554 - atomic_long_t mesq_send_put_nacked;
47555 - atomic_long_t mesq_page_overflow;
47556 - atomic_long_t mesq_qf_locked;
47557 - atomic_long_t mesq_qf_noop_not_full;
47558 - atomic_long_t mesq_qf_switch_head_failed;
47559 - atomic_long_t mesq_qf_unexpected_error;
47560 - atomic_long_t mesq_noop_unexpected_error;
47561 - atomic_long_t mesq_noop_lb_overflow;
47562 - atomic_long_t mesq_noop_qlimit_reached;
47563 - atomic_long_t mesq_noop_amo_nacked;
47564 - atomic_long_t mesq_noop_put_nacked;
47565 - atomic_long_t mesq_noop_page_overflow;
47566 + atomic_long_unchecked_t mesq_receive;
47567 + atomic_long_unchecked_t mesq_receive_none;
47568 + atomic_long_unchecked_t mesq_send;
47569 + atomic_long_unchecked_t mesq_send_failed;
47570 + atomic_long_unchecked_t mesq_noop;
47571 + atomic_long_unchecked_t mesq_send_unexpected_error;
47572 + atomic_long_unchecked_t mesq_send_lb_overflow;
47573 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47574 + atomic_long_unchecked_t mesq_send_amo_nacked;
47575 + atomic_long_unchecked_t mesq_send_put_nacked;
47576 + atomic_long_unchecked_t mesq_page_overflow;
47577 + atomic_long_unchecked_t mesq_qf_locked;
47578 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47579 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47580 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47581 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47582 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47583 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47584 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47585 + atomic_long_unchecked_t mesq_noop_put_nacked;
47586 + atomic_long_unchecked_t mesq_noop_page_overflow;
47587
47588 };
47589
47590 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47591 tghop_invalidate, mcsop_last};
47592
47593 struct mcs_op_statistic {
47594 - atomic_long_t count;
47595 - atomic_long_t total;
47596 + atomic_long_unchecked_t count;
47597 + atomic_long_unchecked_t total;
47598 unsigned long max;
47599 };
47600
47601 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47602
47603 #define STAT(id) do { \
47604 if (gru_options & OPT_STATS) \
47605 - atomic_long_inc(&gru_stats.id); \
47606 + atomic_long_inc_unchecked(&gru_stats.id); \
47607 } while (0)
47608
47609 #ifdef CONFIG_SGI_GRU_DEBUG
47610 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47611 index c862cd4..0d176fe 100644
47612 --- a/drivers/misc/sgi-xp/xp.h
47613 +++ b/drivers/misc/sgi-xp/xp.h
47614 @@ -288,7 +288,7 @@ struct xpc_interface {
47615 xpc_notify_func, void *);
47616 void (*received) (short, int, void *);
47617 enum xp_retval (*partid_to_nasids) (short, void *);
47618 -};
47619 +} __no_const;
47620
47621 extern struct xpc_interface xpc_interface;
47622
47623 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47624 index 01be66d..e3a0c7e 100644
47625 --- a/drivers/misc/sgi-xp/xp_main.c
47626 +++ b/drivers/misc/sgi-xp/xp_main.c
47627 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47628 }
47629
47630 struct xpc_interface xpc_interface = {
47631 - (void (*)(int))xpc_notloaded,
47632 - (void (*)(int))xpc_notloaded,
47633 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47634 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47635 + .connect = (void (*)(int))xpc_notloaded,
47636 + .disconnect = (void (*)(int))xpc_notloaded,
47637 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47638 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47639 void *))xpc_notloaded,
47640 - (void (*)(short, int, void *))xpc_notloaded,
47641 - (enum xp_retval(*)(short, void *))xpc_notloaded
47642 + .received = (void (*)(short, int, void *))xpc_notloaded,
47643 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47644 };
47645 EXPORT_SYMBOL_GPL(xpc_interface);
47646
47647 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47648 index b94d5f7..7f494c5 100644
47649 --- a/drivers/misc/sgi-xp/xpc.h
47650 +++ b/drivers/misc/sgi-xp/xpc.h
47651 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47652 void (*received_payload) (struct xpc_channel *, void *);
47653 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47654 };
47655 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47656
47657 /* struct xpc_partition act_state values (for XPC HB) */
47658
47659 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47660 /* found in xpc_main.c */
47661 extern struct device *xpc_part;
47662 extern struct device *xpc_chan;
47663 -extern struct xpc_arch_operations xpc_arch_ops;
47664 +extern xpc_arch_operations_no_const xpc_arch_ops;
47665 extern int xpc_disengage_timelimit;
47666 extern int xpc_disengage_timedout;
47667 extern int xpc_activate_IRQ_rcvd;
47668 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47669 index 82dc574..8539ab2 100644
47670 --- a/drivers/misc/sgi-xp/xpc_main.c
47671 +++ b/drivers/misc/sgi-xp/xpc_main.c
47672 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47673 .notifier_call = xpc_system_die,
47674 };
47675
47676 -struct xpc_arch_operations xpc_arch_ops;
47677 +xpc_arch_operations_no_const xpc_arch_ops;
47678
47679 /*
47680 * Timer function to enforce the timelimit on the partition disengage.
47681 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47682
47683 if (((die_args->trapnr == X86_TRAP_MF) ||
47684 (die_args->trapnr == X86_TRAP_XF)) &&
47685 - !user_mode_vm(die_args->regs))
47686 + !user_mode(die_args->regs))
47687 xpc_die_deactivate();
47688
47689 break;
47690 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47691 index ede41f0..744fbd9 100644
47692 --- a/drivers/mmc/card/block.c
47693 +++ b/drivers/mmc/card/block.c
47694 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47695 if (idata->ic.postsleep_min_us)
47696 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47697
47698 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47699 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47700 err = -EFAULT;
47701 goto cmd_rel_host;
47702 }
47703 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47704 index f51b5ba..86614a7 100644
47705 --- a/drivers/mmc/core/mmc_ops.c
47706 +++ b/drivers/mmc/core/mmc_ops.c
47707 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47708 void *data_buf;
47709 int is_on_stack;
47710
47711 - is_on_stack = object_is_on_stack(buf);
47712 + is_on_stack = object_starts_on_stack(buf);
47713 if (is_on_stack) {
47714 /*
47715 * dma onto stack is unsafe/nonportable, but callers to this
47716 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47717 index 08fd956..370487a 100644
47718 --- a/drivers/mmc/host/dw_mmc.h
47719 +++ b/drivers/mmc/host/dw_mmc.h
47720 @@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47721 int (*parse_dt)(struct dw_mci *host);
47722 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47723 struct dw_mci_tuning_data *tuning_data);
47724 -};
47725 +} __do_const;
47726 #endif /* _DW_MMC_H_ */
47727 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47728 index e4d4707..28262a3 100644
47729 --- a/drivers/mmc/host/mmci.c
47730 +++ b/drivers/mmc/host/mmci.c
47731 @@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47732 mmc->caps |= MMC_CAP_CMD23;
47733
47734 if (variant->busy_detect) {
47735 - mmci_ops.card_busy = mmci_card_busy;
47736 + pax_open_kernel();
47737 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47738 + pax_close_kernel();
47739 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47740 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47741 mmc->max_busy_timeout = 0;
47742 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47743 index ccec0e3..199f9ce 100644
47744 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47745 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47746 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47747 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47748 }
47749
47750 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47751 - sdhci_esdhc_ops.platform_execute_tuning =
47752 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47753 + pax_open_kernel();
47754 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47755 esdhc_executing_tuning;
47756 + pax_close_kernel();
47757 + }
47758
47759 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47760 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47761 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47762 index fa5954a..56840e5 100644
47763 --- a/drivers/mmc/host/sdhci-s3c.c
47764 +++ b/drivers/mmc/host/sdhci-s3c.c
47765 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47766 * we can use overriding functions instead of default.
47767 */
47768 if (sc->no_divider) {
47769 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47770 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47771 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47772 + pax_open_kernel();
47773 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47774 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47775 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47776 + pax_close_kernel();
47777 }
47778
47779 /* It supports additional host capabilities if needed */
47780 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47781 index 423666b..81ff5eb 100644
47782 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47783 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47784 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47785 size_t totlen = 0, thislen;
47786 int ret = 0;
47787 size_t buflen = 0;
47788 - static char *buffer;
47789 + char *buffer;
47790
47791 if (!ECCBUF_SIZE) {
47792 /* We should fall back to a general writev implementation.
47793 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47794 index 0b071a3..8ec3d5b 100644
47795 --- a/drivers/mtd/nand/denali.c
47796 +++ b/drivers/mtd/nand/denali.c
47797 @@ -24,6 +24,7 @@
47798 #include <linux/slab.h>
47799 #include <linux/mtd/mtd.h>
47800 #include <linux/module.h>
47801 +#include <linux/slab.h>
47802
47803 #include "denali.h"
47804
47805 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47806 index 959cb9b..8520fe5 100644
47807 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47808 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47809 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47810
47811 /* first try to map the upper buffer directly */
47812 if (virt_addr_valid(this->upper_buf) &&
47813 - !object_is_on_stack(this->upper_buf)) {
47814 + !object_starts_on_stack(this->upper_buf)) {
47815 sg_init_one(sgl, this->upper_buf, this->upper_len);
47816 ret = dma_map_sg(this->dev, sgl, 1, dr);
47817 if (ret == 0)
47818 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47819 index 51b9d6a..52af9a7 100644
47820 --- a/drivers/mtd/nftlmount.c
47821 +++ b/drivers/mtd/nftlmount.c
47822 @@ -24,6 +24,7 @@
47823 #include <asm/errno.h>
47824 #include <linux/delay.h>
47825 #include <linux/slab.h>
47826 +#include <linux/sched.h>
47827 #include <linux/mtd/mtd.h>
47828 #include <linux/mtd/nand.h>
47829 #include <linux/mtd/nftl.h>
47830 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47831 index cf49c22..971b133 100644
47832 --- a/drivers/mtd/sm_ftl.c
47833 +++ b/drivers/mtd/sm_ftl.c
47834 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47835 #define SM_CIS_VENDOR_OFFSET 0x59
47836 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47837 {
47838 - struct attribute_group *attr_group;
47839 + attribute_group_no_const *attr_group;
47840 struct attribute **attributes;
47841 struct sm_sysfs_attribute *vendor_attribute;
47842 char *vendor;
47843 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47844 index d163e11..f517018 100644
47845 --- a/drivers/net/bonding/bond_netlink.c
47846 +++ b/drivers/net/bonding/bond_netlink.c
47847 @@ -548,7 +548,7 @@ nla_put_failure:
47848 return -EMSGSIZE;
47849 }
47850
47851 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47852 +struct rtnl_link_ops bond_link_ops = {
47853 .kind = "bond",
47854 .priv_size = sizeof(struct bonding),
47855 .setup = bond_setup,
47856 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47857 index 4168822..f38eeddf 100644
47858 --- a/drivers/net/can/Kconfig
47859 +++ b/drivers/net/can/Kconfig
47860 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47861
47862 config CAN_FLEXCAN
47863 tristate "Support for Freescale FLEXCAN based chips"
47864 - depends on ARM || PPC
47865 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47866 ---help---
47867 Say Y here if you want to support for Freescale FlexCAN.
47868
47869 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47870 index 1d162cc..b546a75 100644
47871 --- a/drivers/net/ethernet/8390/ax88796.c
47872 +++ b/drivers/net/ethernet/8390/ax88796.c
47873 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47874 if (ax->plat->reg_offsets)
47875 ei_local->reg_offset = ax->plat->reg_offsets;
47876 else {
47877 + resource_size_t _mem_size = mem_size;
47878 + do_div(_mem_size, 0x18);
47879 ei_local->reg_offset = ax->reg_offsets;
47880 for (ret = 0; ret < 0x18; ret++)
47881 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47882 + ax->reg_offsets[ret] = _mem_size * ret;
47883 }
47884
47885 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47886 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47887 index 7330681..7e9e463 100644
47888 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47889 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47890 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47891 return 0;
47892 }
47893
47894 -static struct net_device_ops altera_tse_netdev_ops = {
47895 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47896 .ndo_open = tse_open,
47897 .ndo_stop = tse_shutdown,
47898 .ndo_start_xmit = tse_start_xmit,
47899 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47900 ndev->netdev_ops = &altera_tse_netdev_ops;
47901 altera_tse_set_ethtool_ops(ndev);
47902
47903 + pax_open_kernel();
47904 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47905
47906 if (priv->hash_filter)
47907 altera_tse_netdev_ops.ndo_set_rx_mode =
47908 tse_set_rx_mode_hashfilter;
47909 + pax_close_kernel();
47910
47911 /* Scatter/gather IO is not supported,
47912 * so it is turned off
47913 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47914 index cc25a3a..c8d72d3 100644
47915 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47916 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47917 @@ -1083,14 +1083,14 @@ do { \
47918 * operations, everything works on mask values.
47919 */
47920 #define XMDIO_READ(_pdata, _mmd, _reg) \
47921 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47922 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47923 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47924
47925 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47926 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47927
47928 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47929 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47930 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47931 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47932
47933 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47934 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47935 index 7d6a49b..e6d403b 100644
47936 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47937 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47938 @@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47939
47940 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47941
47942 - pdata->hw_if.config_dcb_tc(pdata);
47943 + pdata->hw_if->config_dcb_tc(pdata);
47944
47945 return 0;
47946 }
47947 @@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47948
47949 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47950
47951 - pdata->hw_if.config_dcb_pfc(pdata);
47952 + pdata->hw_if->config_dcb_pfc(pdata);
47953
47954 return 0;
47955 }
47956 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47957 index 1c5d62e..8e14d54 100644
47958 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47959 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47960 @@ -236,7 +236,7 @@ err_ring:
47961
47962 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47963 {
47964 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47965 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47966 struct xgbe_channel *channel;
47967 struct xgbe_ring *ring;
47968 struct xgbe_ring_data *rdata;
47969 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47970
47971 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47972 {
47973 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47974 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47975 struct xgbe_channel *channel;
47976 struct xgbe_ring *ring;
47977 struct xgbe_ring_desc *rdesc;
47978 @@ -506,7 +506,7 @@ err_out:
47979 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47980 {
47981 struct xgbe_prv_data *pdata = channel->pdata;
47982 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47983 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47984 struct xgbe_ring *ring = channel->rx_ring;
47985 struct xgbe_ring_data *rdata;
47986 struct sk_buff *skb = NULL;
47987 @@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47988 DBGPR("<--xgbe_realloc_skb\n");
47989 }
47990
47991 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47992 -{
47993 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47994 -
47995 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47996 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47997 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47998 - desc_if->realloc_skb = xgbe_realloc_skb;
47999 - desc_if->unmap_skb = xgbe_unmap_skb;
48000 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48001 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48002 -
48003 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
48004 -}
48005 +const struct xgbe_desc_if default_xgbe_desc_if = {
48006 + .alloc_ring_resources = xgbe_alloc_ring_resources,
48007 + .free_ring_resources = xgbe_free_ring_resources,
48008 + .map_tx_skb = xgbe_map_tx_skb,
48009 + .realloc_skb = xgbe_realloc_skb,
48010 + .unmap_skb = xgbe_unmap_skb,
48011 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48012 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48013 +};
48014 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48015 index ea27383..d695e45 100644
48016 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48017 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48018 @@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48019
48020 static int xgbe_init(struct xgbe_prv_data *pdata)
48021 {
48022 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48023 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48024 int ret;
48025
48026 DBGPR("-->xgbe_init\n");
48027 @@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48028 return 0;
48029 }
48030
48031 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48032 -{
48033 - DBGPR("-->xgbe_init_function_ptrs\n");
48034 -
48035 - hw_if->tx_complete = xgbe_tx_complete;
48036 -
48037 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48038 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48039 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
48040 - hw_if->set_mac_address = xgbe_set_mac_address;
48041 -
48042 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48043 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48044 -
48045 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48046 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48047 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
48048 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
48049 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
48050 -
48051 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48052 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48053 -
48054 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48055 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48056 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48057 -
48058 - hw_if->enable_tx = xgbe_enable_tx;
48059 - hw_if->disable_tx = xgbe_disable_tx;
48060 - hw_if->enable_rx = xgbe_enable_rx;
48061 - hw_if->disable_rx = xgbe_disable_rx;
48062 -
48063 - hw_if->powerup_tx = xgbe_powerup_tx;
48064 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48065 - hw_if->powerup_rx = xgbe_powerup_rx;
48066 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48067 -
48068 - hw_if->pre_xmit = xgbe_pre_xmit;
48069 - hw_if->dev_read = xgbe_dev_read;
48070 - hw_if->enable_int = xgbe_enable_int;
48071 - hw_if->disable_int = xgbe_disable_int;
48072 - hw_if->init = xgbe_init;
48073 - hw_if->exit = xgbe_exit;
48074 +const struct xgbe_hw_if default_xgbe_hw_if = {
48075 + .tx_complete = xgbe_tx_complete,
48076 +
48077 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48078 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48079 + .add_mac_addresses = xgbe_add_mac_addresses,
48080 + .set_mac_address = xgbe_set_mac_address,
48081 +
48082 + .enable_rx_csum = xgbe_enable_rx_csum,
48083 + .disable_rx_csum = xgbe_disable_rx_csum,
48084 +
48085 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48086 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48087 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
48088 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
48089 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
48090 +
48091 + .read_mmd_regs = xgbe_read_mmd_regs,
48092 + .write_mmd_regs = xgbe_write_mmd_regs,
48093 +
48094 + .set_gmii_speed = xgbe_set_gmii_speed,
48095 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48096 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48097 +
48098 + .enable_tx = xgbe_enable_tx,
48099 + .disable_tx = xgbe_disable_tx,
48100 + .enable_rx = xgbe_enable_rx,
48101 + .disable_rx = xgbe_disable_rx,
48102 +
48103 + .powerup_tx = xgbe_powerup_tx,
48104 + .powerdown_tx = xgbe_powerdown_tx,
48105 + .powerup_rx = xgbe_powerup_rx,
48106 + .powerdown_rx = xgbe_powerdown_rx,
48107 +
48108 + .pre_xmit = xgbe_pre_xmit,
48109 + .dev_read = xgbe_dev_read,
48110 + .enable_int = xgbe_enable_int,
48111 + .disable_int = xgbe_disable_int,
48112 + .init = xgbe_init,
48113 + .exit = xgbe_exit,
48114
48115 /* Descriptor related Sequences have to be initialized here */
48116 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48117 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48118 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48119 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48120 - hw_if->is_last_desc = xgbe_is_last_desc;
48121 - hw_if->is_context_desc = xgbe_is_context_desc;
48122 + .tx_desc_init = xgbe_tx_desc_init,
48123 + .rx_desc_init = xgbe_rx_desc_init,
48124 + .tx_desc_reset = xgbe_tx_desc_reset,
48125 + .rx_desc_reset = xgbe_rx_desc_reset,
48126 + .is_last_desc = xgbe_is_last_desc,
48127 + .is_context_desc = xgbe_is_context_desc,
48128
48129 /* For FLOW ctrl */
48130 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48131 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48132 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48133 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48134
48135 /* For RX coalescing */
48136 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48137 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48138 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48139 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48140 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48141 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48142 + .usec_to_riwt = xgbe_usec_to_riwt,
48143 + .riwt_to_usec = xgbe_riwt_to_usec,
48144
48145 /* For RX and TX threshold config */
48146 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48147 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48148 + .config_rx_threshold = xgbe_config_rx_threshold,
48149 + .config_tx_threshold = xgbe_config_tx_threshold,
48150
48151 /* For RX and TX Store and Forward Mode config */
48152 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48153 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48154 + .config_rsf_mode = xgbe_config_rsf_mode,
48155 + .config_tsf_mode = xgbe_config_tsf_mode,
48156
48157 /* For TX DMA Operating on Second Frame config */
48158 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48159 + .config_osp_mode = xgbe_config_osp_mode,
48160
48161 /* For RX and TX PBL config */
48162 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48163 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48164 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48165 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48166 - hw_if->config_pblx8 = xgbe_config_pblx8;
48167 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48168 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48169 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48170 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48171 + .config_pblx8 = xgbe_config_pblx8,
48172
48173 /* For MMC statistics support */
48174 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48175 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48176 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48177 + .tx_mmc_int = xgbe_tx_mmc_int,
48178 + .rx_mmc_int = xgbe_rx_mmc_int,
48179 + .read_mmc_stats = xgbe_read_mmc_stats,
48180
48181 /* For PTP config */
48182 - hw_if->config_tstamp = xgbe_config_tstamp;
48183 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
48184 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
48185 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
48186 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
48187 + .config_tstamp = xgbe_config_tstamp,
48188 + .update_tstamp_addend = xgbe_update_tstamp_addend,
48189 + .set_tstamp_time = xgbe_set_tstamp_time,
48190 + .get_tstamp_time = xgbe_get_tstamp_time,
48191 + .get_tx_tstamp = xgbe_get_tx_tstamp,
48192
48193 /* For Data Center Bridging config */
48194 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
48195 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
48196 -
48197 - DBGPR("<--xgbe_init_function_ptrs\n");
48198 -}
48199 + .config_dcb_tc = xgbe_config_dcb_tc,
48200 + .config_dcb_pfc = xgbe_config_dcb_pfc
48201 +};
48202 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48203 index b26d758..b0d1c3b 100644
48204 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48205 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48206 @@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48207
48208 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48209 {
48210 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48211 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48212 struct xgbe_channel *channel;
48213 enum xgbe_int int_id;
48214 unsigned int i;
48215 @@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48216
48217 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48218 {
48219 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48220 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48221 struct xgbe_channel *channel;
48222 enum xgbe_int int_id;
48223 unsigned int i;
48224 @@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48225 static irqreturn_t xgbe_isr(int irq, void *data)
48226 {
48227 struct xgbe_prv_data *pdata = data;
48228 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48229 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48230 struct xgbe_channel *channel;
48231 unsigned int dma_isr, dma_ch_isr;
48232 unsigned int mac_isr, mac_tssr;
48233 @@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
48234
48235 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48236 {
48237 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48238 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48239
48240 DBGPR("-->xgbe_init_tx_coalesce\n");
48241
48242 @@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48243
48244 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48245 {
48246 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48247 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48248
48249 DBGPR("-->xgbe_init_rx_coalesce\n");
48250
48251 @@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48252
48253 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48254 {
48255 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48256 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48257 struct xgbe_channel *channel;
48258 struct xgbe_ring *ring;
48259 struct xgbe_ring_data *rdata;
48260 @@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48261
48262 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48263 {
48264 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48265 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48266 struct xgbe_channel *channel;
48267 struct xgbe_ring *ring;
48268 struct xgbe_ring_data *rdata;
48269 @@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48270 static void xgbe_adjust_link(struct net_device *netdev)
48271 {
48272 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48273 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48274 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48275 struct phy_device *phydev = pdata->phydev;
48276 int new_state = 0;
48277
48278 @@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
48279 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48280 {
48281 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48282 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48283 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48284 unsigned long flags;
48285
48286 DBGPR("-->xgbe_powerdown\n");
48287 @@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48288 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48289 {
48290 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48291 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48292 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48293 unsigned long flags;
48294
48295 DBGPR("-->xgbe_powerup\n");
48296 @@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48297
48298 static int xgbe_start(struct xgbe_prv_data *pdata)
48299 {
48300 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48301 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48302 struct net_device *netdev = pdata->netdev;
48303
48304 DBGPR("-->xgbe_start\n");
48305 @@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48306
48307 static void xgbe_stop(struct xgbe_prv_data *pdata)
48308 {
48309 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48310 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48311 struct net_device *netdev = pdata->netdev;
48312
48313 DBGPR("-->xgbe_stop\n");
48314 @@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48315
48316 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48317 {
48318 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48319 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48320
48321 DBGPR("-->xgbe_restart_dev\n");
48322
48323 @@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48324 return -ERANGE;
48325 }
48326
48327 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
48328 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
48329
48330 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48331
48332 @@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48333 static int xgbe_open(struct net_device *netdev)
48334 {
48335 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48336 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48337 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48338 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48339 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48340 int ret;
48341
48342 DBGPR("-->xgbe_open\n");
48343 @@ -1171,8 +1171,8 @@ err_phy_init:
48344 static int xgbe_close(struct net_device *netdev)
48345 {
48346 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48347 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48348 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48349 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48350 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48351
48352 DBGPR("-->xgbe_close\n");
48353
48354 @@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48355 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48356 {
48357 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48358 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48359 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48360 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48361 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48362 struct xgbe_channel *channel;
48363 struct xgbe_ring *ring;
48364 struct xgbe_packet_data *packet;
48365 @@ -1276,7 +1276,7 @@ tx_netdev_return:
48366 static void xgbe_set_rx_mode(struct net_device *netdev)
48367 {
48368 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48369 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48370 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48371 unsigned int pr_mode, am_mode;
48372
48373 DBGPR("-->xgbe_set_rx_mode\n");
48374 @@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48375 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48376 {
48377 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48378 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48379 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48380 struct sockaddr *saddr = addr;
48381
48382 DBGPR("-->xgbe_set_mac_address\n");
48383 @@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48384
48385 DBGPR("-->%s\n", __func__);
48386
48387 - pdata->hw_if.read_mmc_stats(pdata);
48388 + pdata->hw_if->read_mmc_stats(pdata);
48389
48390 s->rx_packets = pstats->rxframecount_gb;
48391 s->rx_bytes = pstats->rxoctetcount_gb;
48392 @@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48393 u16 vid)
48394 {
48395 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48396 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48397 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48398
48399 DBGPR("-->%s\n", __func__);
48400
48401 @@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48402 u16 vid)
48403 {
48404 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48405 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48406 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48407
48408 DBGPR("-->%s\n", __func__);
48409
48410 @@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48411 netdev_features_t features)
48412 {
48413 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48414 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48415 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48416 unsigned int rxcsum, rxvlan, rxvlan_filter;
48417
48418 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48419 @@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48420 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48421 {
48422 struct xgbe_prv_data *pdata = channel->pdata;
48423 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48424 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48425 struct xgbe_ring *ring = channel->rx_ring;
48426 struct xgbe_ring_data *rdata;
48427
48428 @@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48429 static int xgbe_tx_poll(struct xgbe_channel *channel)
48430 {
48431 struct xgbe_prv_data *pdata = channel->pdata;
48432 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48433 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48434 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48435 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48436 struct xgbe_ring *ring = channel->tx_ring;
48437 struct xgbe_ring_data *rdata;
48438 struct xgbe_ring_desc *rdesc;
48439 @@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48440 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48441 {
48442 struct xgbe_prv_data *pdata = channel->pdata;
48443 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48444 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48445 struct xgbe_ring *ring = channel->rx_ring;
48446 struct xgbe_ring_data *rdata;
48447 struct xgbe_packet_data *packet;
48448 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48449 index 46f6130..f37dde3 100644
48450 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48451 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48452 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48453
48454 DBGPR("-->%s\n", __func__);
48455
48456 - pdata->hw_if.read_mmc_stats(pdata);
48457 + pdata->hw_if->read_mmc_stats(pdata);
48458 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48459 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48460 *data++ = *(u64 *)stat;
48461 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48462 struct ethtool_coalesce *ec)
48463 {
48464 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48465 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48466 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48467 unsigned int riwt;
48468
48469 DBGPR("-->xgbe_get_coalesce\n");
48470 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48471 struct ethtool_coalesce *ec)
48472 {
48473 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48474 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48475 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48476 unsigned int rx_frames, rx_riwt, rx_usecs;
48477 unsigned int tx_frames, tx_usecs;
48478
48479 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48480 index bdf9cfa..340aea1 100644
48481 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48482 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48483 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48484 DBGPR("<--xgbe_default_config\n");
48485 }
48486
48487 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48488 -{
48489 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48490 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48491 -}
48492 -
48493 static int xgbe_probe(struct platform_device *pdev)
48494 {
48495 struct xgbe_prv_data *pdata;
48496 @@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48497 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48498
48499 /* Set all the function pointers */
48500 - xgbe_init_all_fptrs(pdata);
48501 - hw_if = &pdata->hw_if;
48502 - desc_if = &pdata->desc_if;
48503 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48504 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48505
48506 /* Issue software reset to device */
48507 hw_if->exit(pdata);
48508 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48509 index 6d2221e..47d1325 100644
48510 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48511 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48512 @@ -127,7 +127,7 @@
48513 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48514 {
48515 struct xgbe_prv_data *pdata = mii->priv;
48516 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48517 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48518 int mmd_data;
48519
48520 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48521 @@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48522 u16 mmd_val)
48523 {
48524 struct xgbe_prv_data *pdata = mii->priv;
48525 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48526 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48527 int mmd_data = mmd_val;
48528
48529 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48530 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48531 index 37e64cf..c3b61cf 100644
48532 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48533 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48534 @@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48535 tstamp_cc);
48536 u64 nsec;
48537
48538 - nsec = pdata->hw_if.get_tstamp_time(pdata);
48539 + nsec = pdata->hw_if->get_tstamp_time(pdata);
48540
48541 return nsec;
48542 }
48543 @@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48544
48545 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48546
48547 - pdata->hw_if.update_tstamp_addend(pdata, addend);
48548 + pdata->hw_if->update_tstamp_addend(pdata, addend);
48549
48550 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48551
48552 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48553 index e9fe6e6..875fbaf 100644
48554 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48555 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48556 @@ -585,8 +585,8 @@ struct xgbe_prv_data {
48557
48558 int irq_number;
48559
48560 - struct xgbe_hw_if hw_if;
48561 - struct xgbe_desc_if desc_if;
48562 + const struct xgbe_hw_if *hw_if;
48563 + const struct xgbe_desc_if *desc_if;
48564
48565 /* AXI DMA settings */
48566 unsigned int axdomain;
48567 @@ -699,6 +699,9 @@ struct xgbe_prv_data {
48568 #endif
48569 };
48570
48571 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48572 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48573 +
48574 /* Function prototypes*/
48575
48576 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48577 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48578 index 571427c..e9fe9e7 100644
48579 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48580 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48581 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48582 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48583 {
48584 /* RX_MODE controlling object */
48585 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48586 + bnx2x_init_rx_mode_obj(bp);
48587
48588 /* multicast configuration controlling object */
48589 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48590 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48591 index b193604..8873bfd 100644
48592 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48593 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48594 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48595 return rc;
48596 }
48597
48598 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48599 - struct bnx2x_rx_mode_obj *o)
48600 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48601 {
48602 if (CHIP_IS_E1x(bp)) {
48603 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48604 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48605 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48606 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48607 } else {
48608 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48609 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48610 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48611 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48612 }
48613 }
48614
48615 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48616 index 718ecd2..2183b2f 100644
48617 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48618 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48619 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48620
48621 /********************* RX MODE ****************/
48622
48623 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48624 - struct bnx2x_rx_mode_obj *o);
48625 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48626
48627 /**
48628 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48629 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48630 index 31c9f82..e65e986 100644
48631 --- a/drivers/net/ethernet/broadcom/tg3.h
48632 +++ b/drivers/net/ethernet/broadcom/tg3.h
48633 @@ -150,6 +150,7 @@
48634 #define CHIPREV_ID_5750_A0 0x4000
48635 #define CHIPREV_ID_5750_A1 0x4001
48636 #define CHIPREV_ID_5750_A3 0x4003
48637 +#define CHIPREV_ID_5750_C1 0x4201
48638 #define CHIPREV_ID_5750_C2 0x4202
48639 #define CHIPREV_ID_5752_A0_HW 0x5000
48640 #define CHIPREV_ID_5752_A0 0x6000
48641 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48642 index 13f9636..228040f 100644
48643 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48644 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48645 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48646 }
48647
48648 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48649 - bna_cb_ioceth_enable,
48650 - bna_cb_ioceth_disable,
48651 - bna_cb_ioceth_hbfail,
48652 - bna_cb_ioceth_reset
48653 + .enable_cbfn = bna_cb_ioceth_enable,
48654 + .disable_cbfn = bna_cb_ioceth_disable,
48655 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48656 + .reset_cbfn = bna_cb_ioceth_reset
48657 };
48658
48659 static void bna_attr_init(struct bna_ioceth *ioceth)
48660 diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48661 index ffc92a4..40edc77 100644
48662 --- a/drivers/net/ethernet/brocade/bna/bnad.c
48663 +++ b/drivers/net/ethernet/brocade/bna/bnad.c
48664 @@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48665
48666 len = (vec == nvecs) ?
48667 last_fraglen : unmap->vector.len;
48668 + skb->truesize += unmap->vector.len;
48669 totlen += len;
48670
48671 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48672 @@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48673
48674 skb->len += totlen;
48675 skb->data_len += totlen;
48676 - skb->truesize += totlen;
48677 }
48678
48679 static inline void
48680 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48681 index 8cffcdf..aadf043 100644
48682 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48683 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48684 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48685 */
48686 struct l2t_skb_cb {
48687 arp_failure_handler_func arp_failure_handler;
48688 -};
48689 +} __no_const;
48690
48691 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48692
48693 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48694 index e5be511..16cb55c 100644
48695 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48696 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48697 @@ -2355,7 +2355,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48698
48699 int i;
48700 struct adapter *ap = netdev2adap(dev);
48701 - static const unsigned int *reg_ranges;
48702 + const unsigned int *reg_ranges;
48703 int arr_size = 0, buf_size = 0;
48704
48705 if (is_t4(ap->params.chip)) {
48706 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48707 index cf8b6ff..274271e 100644
48708 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48709 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48710 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48711 for (i=0; i<ETH_ALEN; i++) {
48712 tmp.addr[i] = dev->dev_addr[i];
48713 }
48714 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48715 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48716 break;
48717
48718 case DE4X5_SET_HWADDR: /* Set the hardware address */
48719 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48720 spin_lock_irqsave(&lp->lock, flags);
48721 memcpy(&statbuf, &lp->pktStats, ioc->len);
48722 spin_unlock_irqrestore(&lp->lock, flags);
48723 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48724 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48725 return -EFAULT;
48726 break;
48727 }
48728 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48729 index 93ff8ef..01e0537 100644
48730 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48731 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48732 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48733
48734 if (wrapped)
48735 newacc += 65536;
48736 - ACCESS_ONCE(*acc) = newacc;
48737 + ACCESS_ONCE_RW(*acc) = newacc;
48738 }
48739
48740 static void populate_erx_stats(struct be_adapter *adapter,
48741 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48742 index c77fa4a..7fd42fc 100644
48743 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48744 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48745 @@ -30,6 +30,8 @@
48746 #include <linux/netdevice.h>
48747 #include <linux/phy.h>
48748 #include <linux/platform_device.h>
48749 +#include <linux/interrupt.h>
48750 +#include <linux/irqreturn.h>
48751 #include <net/ip.h>
48752
48753 #include "ftgmac100.h"
48754 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48755 index 4ff1adc..0ea6bf4 100644
48756 --- a/drivers/net/ethernet/faraday/ftmac100.c
48757 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48758 @@ -31,6 +31,8 @@
48759 #include <linux/module.h>
48760 #include <linux/netdevice.h>
48761 #include <linux/platform_device.h>
48762 +#include <linux/interrupt.h>
48763 +#include <linux/irqreturn.h>
48764
48765 #include "ftmac100.h"
48766
48767 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48768 index 537b621..07f87ce 100644
48769 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48770 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48771 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48772 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48773
48774 /* Update the base adjustement value. */
48775 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48776 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48777 smp_mb(); /* Force the above update. */
48778 }
48779
48780 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48781 index 5fd4b52..87aa34b 100644
48782 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48783 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48784 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48785 }
48786
48787 /* update the base incval used to calculate frequency adjustment */
48788 - ACCESS_ONCE(adapter->base_incval) = incval;
48789 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48790 smp_mb();
48791
48792 /* need lock to prevent incorrect read while modifying cyclecounter */
48793 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48794 index c14d4d8..66da603 100644
48795 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48796 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48797 @@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48798 struct ixgbe_hw *hw = &adapter->hw;
48799 u32 regval;
48800
48801 + if (vf >= adapter->num_vfs)
48802 + return -EINVAL;
48803 +
48804 adapter->vfinfo[vf].spoofchk_enabled = setting;
48805
48806 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48807 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48808 index 2bbd01f..e8baa64 100644
48809 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48810 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48811 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48812 struct __vxge_hw_fifo *fifo;
48813 struct vxge_hw_fifo_config *config;
48814 u32 txdl_size, txdl_per_memblock;
48815 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48816 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48817 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48818 + };
48819 +
48820 struct __vxge_hw_virtualpath *vpath;
48821
48822 if ((vp == NULL) || (attr == NULL)) {
48823 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48824 goto exit;
48825 }
48826
48827 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48828 -
48829 fifo->mempool =
48830 __vxge_hw_mempool_create(vpath->hldev,
48831 fifo->config->memblock_size,
48832 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48833 index 3172cdf..d01ab34 100644
48834 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48835 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48836 @@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48837 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48838 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48839 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48840 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48841 + pax_open_kernel();
48842 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48843 + pax_close_kernel();
48844 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48845 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48846 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48847 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48848 index be7d7a6..a8983f8 100644
48849 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48850 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48851 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48852 case QLCNIC_NON_PRIV_FUNC:
48853 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48854 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48855 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48856 + pax_open_kernel();
48857 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48858 + pax_close_kernel();
48859 break;
48860 case QLCNIC_PRIV_FUNC:
48861 ahw->op_mode = QLCNIC_PRIV_FUNC;
48862 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48863 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48864 + pax_open_kernel();
48865 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48866 + pax_close_kernel();
48867 break;
48868 case QLCNIC_MGMT_FUNC:
48869 ahw->op_mode = QLCNIC_MGMT_FUNC;
48870 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48871 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48872 + pax_open_kernel();
48873 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48874 + pax_close_kernel();
48875 break;
48876 default:
48877 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48878 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48879 index c9f57fb..208bdc1 100644
48880 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48881 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48882 @@ -1285,7 +1285,7 @@ flash_temp:
48883 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48884 {
48885 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48886 - static const struct qlcnic_dump_operations *fw_dump_ops;
48887 + const struct qlcnic_dump_operations *fw_dump_ops;
48888 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48889 u32 entry_offset, dump, no_entries, buf_offset = 0;
48890 int i, k, ops_cnt, ops_index, dump_size = 0;
48891 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48892 index 0921302..927f761 100644
48893 --- a/drivers/net/ethernet/realtek/r8169.c
48894 +++ b/drivers/net/ethernet/realtek/r8169.c
48895 @@ -744,22 +744,22 @@ struct rtl8169_private {
48896 struct mdio_ops {
48897 void (*write)(struct rtl8169_private *, int, int);
48898 int (*read)(struct rtl8169_private *, int);
48899 - } mdio_ops;
48900 + } __no_const mdio_ops;
48901
48902 struct pll_power_ops {
48903 void (*down)(struct rtl8169_private *);
48904 void (*up)(struct rtl8169_private *);
48905 - } pll_power_ops;
48906 + } __no_const pll_power_ops;
48907
48908 struct jumbo_ops {
48909 void (*enable)(struct rtl8169_private *);
48910 void (*disable)(struct rtl8169_private *);
48911 - } jumbo_ops;
48912 + } __no_const jumbo_ops;
48913
48914 struct csi_ops {
48915 void (*write)(struct rtl8169_private *, int, int);
48916 u32 (*read)(struct rtl8169_private *, int);
48917 - } csi_ops;
48918 + } __no_const csi_ops;
48919
48920 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48921 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48922 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48923 index 6b861e3..204ac86 100644
48924 --- a/drivers/net/ethernet/sfc/ptp.c
48925 +++ b/drivers/net/ethernet/sfc/ptp.c
48926 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48927 ptp->start.dma_addr);
48928
48929 /* Clear flag that signals MC ready */
48930 - ACCESS_ONCE(*start) = 0;
48931 + ACCESS_ONCE_RW(*start) = 0;
48932 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48933 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48934 EFX_BUG_ON_PARANOID(rc);
48935 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48936 index 08c483b..2c4a553 100644
48937 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48938 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48939 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48940
48941 writel(value, ioaddr + MMC_CNTRL);
48942
48943 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48944 - MMC_CNTRL, value);
48945 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48946 +// MMC_CNTRL, value);
48947 }
48948
48949 /* To mask all all interrupts.*/
48950 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48951 index d5e07de..e3bf20a 100644
48952 --- a/drivers/net/hyperv/hyperv_net.h
48953 +++ b/drivers/net/hyperv/hyperv_net.h
48954 @@ -171,7 +171,7 @@ struct rndis_device {
48955 enum rndis_device_state state;
48956 bool link_state;
48957 bool link_change;
48958 - atomic_t new_req_id;
48959 + atomic_unchecked_t new_req_id;
48960
48961 spinlock_t request_lock;
48962 struct list_head req_list;
48963 diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
48964 index 0fcb5e7..148fda3 100644
48965 --- a/drivers/net/hyperv/netvsc_drv.c
48966 +++ b/drivers/net/hyperv/netvsc_drv.c
48967 @@ -556,6 +556,7 @@ do_lso:
48968 do_send:
48969 /* Start filling in the page buffers with the rndis hdr */
48970 rndis_msg->msg_len += rndis_msg_size;
48971 + packet->total_data_buflen = rndis_msg->msg_len;
48972 packet->page_buf_cnt = init_page_array(rndis_msg, rndis_msg_size,
48973 skb, &packet->page_buf[0]);
48974
48975 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48976 index 2b86f0b..ecc996f 100644
48977 --- a/drivers/net/hyperv/rndis_filter.c
48978 +++ b/drivers/net/hyperv/rndis_filter.c
48979 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48980 * template
48981 */
48982 set = &rndis_msg->msg.set_req;
48983 - set->req_id = atomic_inc_return(&dev->new_req_id);
48984 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48985
48986 /* Add to the request list */
48987 spin_lock_irqsave(&dev->request_lock, flags);
48988 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48989
48990 /* Setup the rndis set */
48991 halt = &request->request_msg.msg.halt_req;
48992 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48993 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48994
48995 /* Ignore return since this msg is optional. */
48996 rndis_filter_send_request(dev, request);
48997 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48998 index 9ce854f..e43fa17 100644
48999 --- a/drivers/net/ieee802154/fakehard.c
49000 +++ b/drivers/net/ieee802154/fakehard.c
49001 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49002 phy->transmit_power = 0xbf;
49003
49004 dev->netdev_ops = &fake_ops;
49005 - dev->ml_priv = &fake_mlme;
49006 + dev->ml_priv = (void *)&fake_mlme;
49007
49008 priv = netdev_priv(dev);
49009 priv->phy = phy;
49010 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49011 index 726edab..8939092 100644
49012 --- a/drivers/net/macvlan.c
49013 +++ b/drivers/net/macvlan.c
49014 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49015 free_nskb:
49016 kfree_skb(nskb);
49017 err:
49018 - atomic_long_inc(&skb->dev->rx_dropped);
49019 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49020 }
49021
49022 /* called under rcu_read_lock() from netif_receive_skb */
49023 @@ -1144,13 +1144,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49024 int macvlan_link_register(struct rtnl_link_ops *ops)
49025 {
49026 /* common fields */
49027 - ops->priv_size = sizeof(struct macvlan_dev);
49028 - ops->validate = macvlan_validate;
49029 - ops->maxtype = IFLA_MACVLAN_MAX;
49030 - ops->policy = macvlan_policy;
49031 - ops->changelink = macvlan_changelink;
49032 - ops->get_size = macvlan_get_size;
49033 - ops->fill_info = macvlan_fill_info;
49034 + pax_open_kernel();
49035 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49036 + *(void **)&ops->validate = macvlan_validate;
49037 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49038 + *(const void **)&ops->policy = macvlan_policy;
49039 + *(void **)&ops->changelink = macvlan_changelink;
49040 + *(void **)&ops->get_size = macvlan_get_size;
49041 + *(void **)&ops->fill_info = macvlan_fill_info;
49042 + pax_close_kernel();
49043
49044 return rtnl_link_register(ops);
49045 };
49046 @@ -1230,7 +1232,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49047 return NOTIFY_DONE;
49048 }
49049
49050 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49051 +static struct notifier_block macvlan_notifier_block = {
49052 .notifier_call = macvlan_device_event,
49053 };
49054
49055 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49056 index 0c6adaa..0784e3f 100644
49057 --- a/drivers/net/macvtap.c
49058 +++ b/drivers/net/macvtap.c
49059 @@ -1018,7 +1018,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49060 }
49061
49062 ret = 0;
49063 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49064 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49065 put_user(q->flags, &ifr->ifr_flags))
49066 ret = -EFAULT;
49067 macvtap_put_vlan(vlan);
49068 @@ -1188,7 +1188,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49069 return NOTIFY_DONE;
49070 }
49071
49072 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49073 +static struct notifier_block macvtap_notifier_block = {
49074 .notifier_call = macvtap_device_event,
49075 };
49076
49077 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49078 index fa0d717..bab8c01 100644
49079 --- a/drivers/net/ppp/ppp_generic.c
49080 +++ b/drivers/net/ppp/ppp_generic.c
49081 @@ -594,7 +594,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
49082 if (file == ppp->owner)
49083 ppp_shutdown_interface(ppp);
49084 }
49085 - if (atomic_long_read(&file->f_count) <= 2) {
49086 + if (atomic_long_read(&file->f_count) < 2) {
49087 ppp_release(NULL, file);
49088 err = 0;
49089 } else
49090 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49091 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
49092 struct ppp_stats stats;
49093 struct ppp_comp_stats cstats;
49094 - char *vers;
49095
49096 switch (cmd) {
49097 case SIOCGPPPSTATS:
49098 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49099 break;
49100
49101 case SIOCGPPPVER:
49102 - vers = PPP_VERSION;
49103 - if (copy_to_user(addr, vers, strlen(vers) + 1))
49104 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
49105 break;
49106 err = 0;
49107 break;
49108 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49109 index 079f7ad..b2a2bfa7 100644
49110 --- a/drivers/net/slip/slhc.c
49111 +++ b/drivers/net/slip/slhc.c
49112 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49113 register struct tcphdr *thp;
49114 register struct iphdr *ip;
49115 register struct cstate *cs;
49116 - int len, hdrlen;
49117 + long len, hdrlen;
49118 unsigned char *cp = icp;
49119
49120 /* We've got a compressed packet; read the change byte */
49121 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49122 index 1f76c2ea..9681171 100644
49123 --- a/drivers/net/team/team.c
49124 +++ b/drivers/net/team/team.c
49125 @@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
49126 return NOTIFY_DONE;
49127 }
49128
49129 -static struct notifier_block team_notifier_block __read_mostly = {
49130 +static struct notifier_block team_notifier_block = {
49131 .notifier_call = team_device_event,
49132 };
49133
49134 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49135 index acaaf67..a33483d 100644
49136 --- a/drivers/net/tun.c
49137 +++ b/drivers/net/tun.c
49138 @@ -1855,7 +1855,7 @@ unlock:
49139 }
49140
49141 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49142 - unsigned long arg, int ifreq_len)
49143 + unsigned long arg, size_t ifreq_len)
49144 {
49145 struct tun_file *tfile = file->private_data;
49146 struct tun_struct *tun;
49147 @@ -1868,6 +1868,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49148 unsigned int ifindex;
49149 int ret;
49150
49151 + if (ifreq_len > sizeof ifr)
49152 + return -EFAULT;
49153 +
49154 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49155 if (copy_from_user(&ifr, argp, ifreq_len))
49156 return -EFAULT;
49157 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49158 index babda7d..e40c90a 100644
49159 --- a/drivers/net/usb/hso.c
49160 +++ b/drivers/net/usb/hso.c
49161 @@ -71,7 +71,7 @@
49162 #include <asm/byteorder.h>
49163 #include <linux/serial_core.h>
49164 #include <linux/serial.h>
49165 -
49166 +#include <asm/local.h>
49167
49168 #define MOD_AUTHOR "Option Wireless"
49169 #define MOD_DESCRIPTION "USB High Speed Option driver"
49170 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49171 struct urb *urb;
49172
49173 urb = serial->rx_urb[0];
49174 - if (serial->port.count > 0) {
49175 + if (atomic_read(&serial->port.count) > 0) {
49176 count = put_rxbuf_data(urb, serial);
49177 if (count == -1)
49178 return;
49179 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49180 DUMP1(urb->transfer_buffer, urb->actual_length);
49181
49182 /* Anyone listening? */
49183 - if (serial->port.count == 0)
49184 + if (atomic_read(&serial->port.count) == 0)
49185 return;
49186
49187 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49188 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49189 tty_port_tty_set(&serial->port, tty);
49190
49191 /* check for port already opened, if not set the termios */
49192 - serial->port.count++;
49193 - if (serial->port.count == 1) {
49194 + if (atomic_inc_return(&serial->port.count) == 1) {
49195 serial->rx_state = RX_IDLE;
49196 /* Force default termio settings */
49197 _hso_serial_set_termios(tty, NULL);
49198 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49199 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49200 if (result) {
49201 hso_stop_serial_device(serial->parent);
49202 - serial->port.count--;
49203 + atomic_dec(&serial->port.count);
49204 kref_put(&serial->parent->ref, hso_serial_ref_free);
49205 }
49206 } else {
49207 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49208
49209 /* reset the rts and dtr */
49210 /* do the actual close */
49211 - serial->port.count--;
49212 + atomic_dec(&serial->port.count);
49213
49214 - if (serial->port.count <= 0) {
49215 - serial->port.count = 0;
49216 + if (atomic_read(&serial->port.count) <= 0) {
49217 + atomic_set(&serial->port.count, 0);
49218 tty_port_tty_set(&serial->port, NULL);
49219 if (!usb_gone)
49220 hso_stop_serial_device(serial->parent);
49221 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49222
49223 /* the actual setup */
49224 spin_lock_irqsave(&serial->serial_lock, flags);
49225 - if (serial->port.count)
49226 + if (atomic_read(&serial->port.count))
49227 _hso_serial_set_termios(tty, old);
49228 else
49229 tty->termios = *old;
49230 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
49231 D1("Pending read interrupt on port %d\n", i);
49232 spin_lock(&serial->serial_lock);
49233 if (serial->rx_state == RX_IDLE &&
49234 - serial->port.count > 0) {
49235 + atomic_read(&serial->port.count) > 0) {
49236 /* Setup and send a ctrl req read on
49237 * port i */
49238 if (!serial->rx_urb_filled[0]) {
49239 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
49240 /* Start all serial ports */
49241 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49242 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49243 - if (dev2ser(serial_table[i])->port.count) {
49244 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49245 result =
49246 hso_start_serial_device(serial_table[i], GFP_NOIO);
49247 hso_kick_transmit(dev2ser(serial_table[i]));
49248 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49249 index 604ef21..d1f49a1 100644
49250 --- a/drivers/net/usb/r8152.c
49251 +++ b/drivers/net/usb/r8152.c
49252 @@ -575,7 +575,7 @@ struct r8152 {
49253 void (*up)(struct r8152 *);
49254 void (*down)(struct r8152 *);
49255 void (*unload)(struct r8152 *);
49256 - } rtl_ops;
49257 + } __no_const rtl_ops;
49258
49259 int intr_interval;
49260 u32 saved_wolopts;
49261 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49262 index a2515887..6d13233 100644
49263 --- a/drivers/net/usb/sierra_net.c
49264 +++ b/drivers/net/usb/sierra_net.c
49265 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49266 /* atomic counter partially included in MAC address to make sure 2 devices
49267 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49268 */
49269 -static atomic_t iface_counter = ATOMIC_INIT(0);
49270 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49271
49272 /*
49273 * SYNC Timer Delay definition used to set the expiry time
49274 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49275 dev->net->netdev_ops = &sierra_net_device_ops;
49276
49277 /* change MAC addr to include, ifacenum, and to be unique */
49278 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49279 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49280 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49281
49282 /* we will have to manufacture ethernet headers, prepare template */
49283 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49284 index 59caa06..de191b3 100644
49285 --- a/drivers/net/virtio_net.c
49286 +++ b/drivers/net/virtio_net.c
49287 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
49288 #define RECEIVE_AVG_WEIGHT 64
49289
49290 /* Minimum alignment for mergeable packet buffers. */
49291 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49292 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49293
49294 #define VIRTNET_DRIVER_VERSION "1.0.0"
49295
49296 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49297 index beb377b..b5bbf08 100644
49298 --- a/drivers/net/vxlan.c
49299 +++ b/drivers/net/vxlan.c
49300 @@ -1440,9 +1440,6 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
49301 if (!in6_dev)
49302 goto out;
49303
49304 - if (!pskb_may_pull(skb, skb->len))
49305 - goto out;
49306 -
49307 iphdr = ipv6_hdr(skb);
49308 saddr = &iphdr->saddr;
49309 daddr = &iphdr->daddr;
49310 @@ -1717,6 +1714,8 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
49311 struct pcpu_sw_netstats *tx_stats, *rx_stats;
49312 union vxlan_addr loopback;
49313 union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip;
49314 + struct net_device *dev = skb->dev;
49315 + int len = skb->len;
49316
49317 tx_stats = this_cpu_ptr(src_vxlan->dev->tstats);
49318 rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats);
49319 @@ -1740,16 +1739,16 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
49320
49321 u64_stats_update_begin(&tx_stats->syncp);
49322 tx_stats->tx_packets++;
49323 - tx_stats->tx_bytes += skb->len;
49324 + tx_stats->tx_bytes += len;
49325 u64_stats_update_end(&tx_stats->syncp);
49326
49327 if (netif_rx(skb) == NET_RX_SUCCESS) {
49328 u64_stats_update_begin(&rx_stats->syncp);
49329 rx_stats->rx_packets++;
49330 - rx_stats->rx_bytes += skb->len;
49331 + rx_stats->rx_bytes += len;
49332 u64_stats_update_end(&rx_stats->syncp);
49333 } else {
49334 - skb->dev->stats.rx_dropped++;
49335 + dev->stats.rx_dropped++;
49336 }
49337 }
49338
49339 @@ -1927,7 +1926,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
49340 return arp_reduce(dev, skb);
49341 #if IS_ENABLED(CONFIG_IPV6)
49342 else if (ntohs(eth->h_proto) == ETH_P_IPV6 &&
49343 - skb->len >= sizeof(struct ipv6hdr) + sizeof(struct nd_msg) &&
49344 + pskb_may_pull(skb, sizeof(struct ipv6hdr)
49345 + + sizeof(struct nd_msg)) &&
49346 ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {
49347 struct nd_msg *msg;
49348
49349 @@ -2750,7 +2750,7 @@ nla_put_failure:
49350 return -EMSGSIZE;
49351 }
49352
49353 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49354 +static struct rtnl_link_ops vxlan_link_ops = {
49355 .kind = "vxlan",
49356 .maxtype = IFLA_VXLAN_MAX,
49357 .policy = vxlan_policy,
49358 @@ -2797,7 +2797,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49359 return NOTIFY_DONE;
49360 }
49361
49362 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49363 +static struct notifier_block vxlan_notifier_block = {
49364 .notifier_call = vxlan_lowerdev_event,
49365 };
49366
49367 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49368 index 5920c99..ff2e4a5 100644
49369 --- a/drivers/net/wan/lmc/lmc_media.c
49370 +++ b/drivers/net/wan/lmc/lmc_media.c
49371 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49372 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49373
49374 lmc_media_t lmc_ds3_media = {
49375 - lmc_ds3_init, /* special media init stuff */
49376 - lmc_ds3_default, /* reset to default state */
49377 - lmc_ds3_set_status, /* reset status to state provided */
49378 - lmc_dummy_set_1, /* set clock source */
49379 - lmc_dummy_set2_1, /* set line speed */
49380 - lmc_ds3_set_100ft, /* set cable length */
49381 - lmc_ds3_set_scram, /* set scrambler */
49382 - lmc_ds3_get_link_status, /* get link status */
49383 - lmc_dummy_set_1, /* set link status */
49384 - lmc_ds3_set_crc_length, /* set CRC length */
49385 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49386 - lmc_ds3_watchdog
49387 + .init = lmc_ds3_init, /* special media init stuff */
49388 + .defaults = lmc_ds3_default, /* reset to default state */
49389 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49390 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49391 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49392 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49393 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49394 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49395 + .set_link_status = lmc_dummy_set_1, /* set link status */
49396 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49397 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49398 + .watchdog = lmc_ds3_watchdog
49399 };
49400
49401 lmc_media_t lmc_hssi_media = {
49402 - lmc_hssi_init, /* special media init stuff */
49403 - lmc_hssi_default, /* reset to default state */
49404 - lmc_hssi_set_status, /* reset status to state provided */
49405 - lmc_hssi_set_clock, /* set clock source */
49406 - lmc_dummy_set2_1, /* set line speed */
49407 - lmc_dummy_set_1, /* set cable length */
49408 - lmc_dummy_set_1, /* set scrambler */
49409 - lmc_hssi_get_link_status, /* get link status */
49410 - lmc_hssi_set_link_status, /* set link status */
49411 - lmc_hssi_set_crc_length, /* set CRC length */
49412 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49413 - lmc_hssi_watchdog
49414 + .init = lmc_hssi_init, /* special media init stuff */
49415 + .defaults = lmc_hssi_default, /* reset to default state */
49416 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49417 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49418 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49419 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49420 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49421 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49422 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49423 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49424 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49425 + .watchdog = lmc_hssi_watchdog
49426 };
49427
49428 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49429 - lmc_ssi_default, /* reset to default state */
49430 - lmc_ssi_set_status, /* reset status to state provided */
49431 - lmc_ssi_set_clock, /* set clock source */
49432 - lmc_ssi_set_speed, /* set line speed */
49433 - lmc_dummy_set_1, /* set cable length */
49434 - lmc_dummy_set_1, /* set scrambler */
49435 - lmc_ssi_get_link_status, /* get link status */
49436 - lmc_ssi_set_link_status, /* set link status */
49437 - lmc_ssi_set_crc_length, /* set CRC length */
49438 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49439 - lmc_ssi_watchdog
49440 +lmc_media_t lmc_ssi_media = {
49441 + .init = lmc_ssi_init, /* special media init stuff */
49442 + .defaults = lmc_ssi_default, /* reset to default state */
49443 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49444 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49445 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49446 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49447 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49448 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49449 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49450 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49451 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49452 + .watchdog = lmc_ssi_watchdog
49453 };
49454
49455 lmc_media_t lmc_t1_media = {
49456 - lmc_t1_init, /* special media init stuff */
49457 - lmc_t1_default, /* reset to default state */
49458 - lmc_t1_set_status, /* reset status to state provided */
49459 - lmc_t1_set_clock, /* set clock source */
49460 - lmc_dummy_set2_1, /* set line speed */
49461 - lmc_dummy_set_1, /* set cable length */
49462 - lmc_dummy_set_1, /* set scrambler */
49463 - lmc_t1_get_link_status, /* get link status */
49464 - lmc_dummy_set_1, /* set link status */
49465 - lmc_t1_set_crc_length, /* set CRC length */
49466 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49467 - lmc_t1_watchdog
49468 + .init = lmc_t1_init, /* special media init stuff */
49469 + .defaults = lmc_t1_default, /* reset to default state */
49470 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49471 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49472 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49473 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49474 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49475 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49476 + .set_link_status = lmc_dummy_set_1, /* set link status */
49477 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49478 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49479 + .watchdog = lmc_t1_watchdog
49480 };
49481
49482 static void
49483 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49484 index feacc3b..5bac0de 100644
49485 --- a/drivers/net/wan/z85230.c
49486 +++ b/drivers/net/wan/z85230.c
49487 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49488
49489 struct z8530_irqhandler z8530_sync =
49490 {
49491 - z8530_rx,
49492 - z8530_tx,
49493 - z8530_status
49494 + .rx = z8530_rx,
49495 + .tx = z8530_tx,
49496 + .status = z8530_status
49497 };
49498
49499 EXPORT_SYMBOL(z8530_sync);
49500 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49501 }
49502
49503 static struct z8530_irqhandler z8530_dma_sync = {
49504 - z8530_dma_rx,
49505 - z8530_dma_tx,
49506 - z8530_dma_status
49507 + .rx = z8530_dma_rx,
49508 + .tx = z8530_dma_tx,
49509 + .status = z8530_dma_status
49510 };
49511
49512 static struct z8530_irqhandler z8530_txdma_sync = {
49513 - z8530_rx,
49514 - z8530_dma_tx,
49515 - z8530_dma_status
49516 + .rx = z8530_rx,
49517 + .tx = z8530_dma_tx,
49518 + .status = z8530_dma_status
49519 };
49520
49521 /**
49522 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49523
49524 struct z8530_irqhandler z8530_nop=
49525 {
49526 - z8530_rx_clear,
49527 - z8530_tx_clear,
49528 - z8530_status_clear
49529 + .rx = z8530_rx_clear,
49530 + .tx = z8530_tx_clear,
49531 + .status = z8530_status_clear
49532 };
49533
49534
49535 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49536 index 0b60295..b8bfa5b 100644
49537 --- a/drivers/net/wimax/i2400m/rx.c
49538 +++ b/drivers/net/wimax/i2400m/rx.c
49539 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49540 if (i2400m->rx_roq == NULL)
49541 goto error_roq_alloc;
49542
49543 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49544 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49545 GFP_KERNEL);
49546 if (rd == NULL) {
49547 result = -ENOMEM;
49548 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49549 index e71a2ce..2268d61 100644
49550 --- a/drivers/net/wireless/airo.c
49551 +++ b/drivers/net/wireless/airo.c
49552 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49553 struct airo_info *ai = dev->ml_priv;
49554 int ridcode;
49555 int enabled;
49556 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49557 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49558 unsigned char *iobuf;
49559
49560 /* Only super-user can write RIDs */
49561 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49562 index da92bfa..5a9001a 100644
49563 --- a/drivers/net/wireless/at76c50x-usb.c
49564 +++ b/drivers/net/wireless/at76c50x-usb.c
49565 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49566 }
49567
49568 /* Convert timeout from the DFU status to jiffies */
49569 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49570 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49571 {
49572 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49573 | (s->poll_timeout[1] << 8)
49574 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49575 index 5fdc40d..3975205 100644
49576 --- a/drivers/net/wireless/ath/ath10k/htc.c
49577 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49578 @@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49579 /* registered target arrival callback from the HIF layer */
49580 int ath10k_htc_init(struct ath10k *ar)
49581 {
49582 - struct ath10k_hif_cb htc_callbacks;
49583 + static struct ath10k_hif_cb htc_callbacks = {
49584 + .rx_completion = ath10k_htc_rx_completion_handler,
49585 + .tx_completion = ath10k_htc_tx_completion_handler,
49586 + };
49587 struct ath10k_htc_ep *ep = NULL;
49588 struct ath10k_htc *htc = &ar->htc;
49589
49590 @@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49591 ath10k_htc_reset_endpoint_states(htc);
49592
49593 /* setup HIF layer callbacks */
49594 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49595 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49596 htc->ar = ar;
49597
49598 /* Get HIF default pipe for HTC message exchange */
49599 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49600 index 4716d33..a688310 100644
49601 --- a/drivers/net/wireless/ath/ath10k/htc.h
49602 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49603 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49604
49605 struct ath10k_htc_ops {
49606 void (*target_send_suspend_complete)(struct ath10k *ar);
49607 -};
49608 +} __no_const;
49609
49610 struct ath10k_htc_ep_ops {
49611 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49612 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49613 void (*ep_tx_credits)(struct ath10k *);
49614 -};
49615 +} __no_const;
49616
49617 /* service connection information */
49618 struct ath10k_htc_svc_conn_req {
49619 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49620 index 59af9f9..5f3564f 100644
49621 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49622 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49623 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49624 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49625 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49626
49627 - ACCESS_ONCE(ads->ds_link) = i->link;
49628 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49629 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49630 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49631
49632 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49633 ctl6 = SM(i->keytype, AR_EncrType);
49634 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49635
49636 if ((i->is_first || i->is_last) &&
49637 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49638 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49639 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49640 | set11nTries(i->rates, 1)
49641 | set11nTries(i->rates, 2)
49642 | set11nTries(i->rates, 3)
49643 | (i->dur_update ? AR_DurUpdateEna : 0)
49644 | SM(0, AR_BurstDur);
49645
49646 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49647 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49648 | set11nRate(i->rates, 1)
49649 | set11nRate(i->rates, 2)
49650 | set11nRate(i->rates, 3);
49651 } else {
49652 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49653 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49654 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49655 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49656 }
49657
49658 if (!i->is_first) {
49659 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49660 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49661 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49662 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49663 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49664 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49665 return;
49666 }
49667
49668 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49669 break;
49670 }
49671
49672 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49673 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49674 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49675 | SM(i->txpower, AR_XmitPower0)
49676 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49677 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49678 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49679 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49680
49681 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49682 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49683 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49684 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49685
49686 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49687 return;
49688
49689 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49690 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49691 | set11nPktDurRTSCTS(i->rates, 1);
49692
49693 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49694 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49695 | set11nPktDurRTSCTS(i->rates, 3);
49696
49697 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49698 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49699 | set11nRateFlags(i->rates, 1)
49700 | set11nRateFlags(i->rates, 2)
49701 | set11nRateFlags(i->rates, 3)
49702 | SM(i->rtscts_rate, AR_RTSCTSRate);
49703
49704 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49705 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49706 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49707 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49708 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49709 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49710 }
49711
49712 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49713 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49714 index 71e38e8..5ac96ca 100644
49715 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49716 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49717 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49718 (i->qcu << AR_TxQcuNum_S) | desc_len;
49719
49720 checksum += val;
49721 - ACCESS_ONCE(ads->info) = val;
49722 + ACCESS_ONCE_RW(ads->info) = val;
49723
49724 checksum += i->link;
49725 - ACCESS_ONCE(ads->link) = i->link;
49726 + ACCESS_ONCE_RW(ads->link) = i->link;
49727
49728 checksum += i->buf_addr[0];
49729 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49730 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49731 checksum += i->buf_addr[1];
49732 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49733 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49734 checksum += i->buf_addr[2];
49735 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49736 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49737 checksum += i->buf_addr[3];
49738 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49739 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49740
49741 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49742 - ACCESS_ONCE(ads->ctl3) = val;
49743 + ACCESS_ONCE_RW(ads->ctl3) = val;
49744 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49745 - ACCESS_ONCE(ads->ctl5) = val;
49746 + ACCESS_ONCE_RW(ads->ctl5) = val;
49747 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49748 - ACCESS_ONCE(ads->ctl7) = val;
49749 + ACCESS_ONCE_RW(ads->ctl7) = val;
49750 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49751 - ACCESS_ONCE(ads->ctl9) = val;
49752 + ACCESS_ONCE_RW(ads->ctl9) = val;
49753
49754 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49755 - ACCESS_ONCE(ads->ctl10) = checksum;
49756 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49757
49758 if (i->is_first || i->is_last) {
49759 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49760 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49761 | set11nTries(i->rates, 1)
49762 | set11nTries(i->rates, 2)
49763 | set11nTries(i->rates, 3)
49764 | (i->dur_update ? AR_DurUpdateEna : 0)
49765 | SM(0, AR_BurstDur);
49766
49767 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49768 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49769 | set11nRate(i->rates, 1)
49770 | set11nRate(i->rates, 2)
49771 | set11nRate(i->rates, 3);
49772 } else {
49773 - ACCESS_ONCE(ads->ctl13) = 0;
49774 - ACCESS_ONCE(ads->ctl14) = 0;
49775 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49776 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49777 }
49778
49779 ads->ctl20 = 0;
49780 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49781
49782 ctl17 = SM(i->keytype, AR_EncrType);
49783 if (!i->is_first) {
49784 - ACCESS_ONCE(ads->ctl11) = 0;
49785 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49786 - ACCESS_ONCE(ads->ctl15) = 0;
49787 - ACCESS_ONCE(ads->ctl16) = 0;
49788 - ACCESS_ONCE(ads->ctl17) = ctl17;
49789 - ACCESS_ONCE(ads->ctl18) = 0;
49790 - ACCESS_ONCE(ads->ctl19) = 0;
49791 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49792 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49793 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49794 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49795 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49796 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49797 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49798 return;
49799 }
49800
49801 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49802 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49803 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49804 | SM(i->txpower, AR_XmitPower0)
49805 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49806 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49807 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49808 ctl12 |= SM(val, AR_PAPRDChainMask);
49809
49810 - ACCESS_ONCE(ads->ctl12) = ctl12;
49811 - ACCESS_ONCE(ads->ctl17) = ctl17;
49812 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49813 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49814
49815 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49816 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49817 | set11nPktDurRTSCTS(i->rates, 1);
49818
49819 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49820 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49821 | set11nPktDurRTSCTS(i->rates, 3);
49822
49823 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49824 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49825 | set11nRateFlags(i->rates, 1)
49826 | set11nRateFlags(i->rates, 2)
49827 | set11nRateFlags(i->rates, 3)
49828 | SM(i->rtscts_rate, AR_RTSCTSRate);
49829
49830 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49831 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49832
49833 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49834 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49835 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49836 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49837 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49838 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49839 }
49840
49841 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49842 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49843 index 51b4ebe..d1929dd 100644
49844 --- a/drivers/net/wireless/ath/ath9k/hw.h
49845 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49846 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49847
49848 /* ANI */
49849 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49850 -};
49851 +} __no_const;
49852
49853 /**
49854 * struct ath_spec_scan - parameters for Atheros spectral scan
49855 @@ -706,7 +706,7 @@ struct ath_hw_ops {
49856 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49857 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49858 #endif
49859 -};
49860 +} __no_const;
49861
49862 struct ath_nf_limits {
49863 s16 max;
49864 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49865 index 4b148bb..ac738fa 100644
49866 --- a/drivers/net/wireless/ath/ath9k/main.c
49867 +++ b/drivers/net/wireless/ath/ath9k/main.c
49868 @@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49869 if (!ath9k_use_chanctx)
49870 return;
49871
49872 - ath9k_ops.hw_scan = ath9k_hw_scan;
49873 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49874 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49875 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49876 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49877 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49878 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49879 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49880 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49881 - ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49882 + pax_open_kernel();
49883 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49884 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49885 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49886 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49887 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49888 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49889 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49890 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49891 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49892 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49893 + pax_close_kernel();
49894 }
49895
49896 struct ieee80211_ops ath9k_ops = {
49897 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49898 index 92190da..f3a4c4c 100644
49899 --- a/drivers/net/wireless/b43/phy_lp.c
49900 +++ b/drivers/net/wireless/b43/phy_lp.c
49901 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49902 {
49903 struct ssb_bus *bus = dev->dev->sdev->bus;
49904
49905 - static const struct b206x_channel *chandata = NULL;
49906 + const struct b206x_channel *chandata = NULL;
49907 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49908 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49909 u16 old_comm15, scale;
49910 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49911 index dc1d20c..f7a4f06 100644
49912 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49913 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49914 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49915 */
49916 if (il3945_mod_params.disable_hw_scan) {
49917 D_INFO("Disabling hw_scan\n");
49918 - il3945_mac_ops.hw_scan = NULL;
49919 + pax_open_kernel();
49920 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49921 + pax_close_kernel();
49922 }
49923
49924 D_INFO("*** LOAD DRIVER ***\n");
49925 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49926 index 0ffb6ff..c0b7f0e 100644
49927 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49928 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49929 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49930 {
49931 struct iwl_priv *priv = file->private_data;
49932 char buf[64];
49933 - int buf_size;
49934 + size_t buf_size;
49935 u32 offset, len;
49936
49937 memset(buf, 0, sizeof(buf));
49938 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49939 struct iwl_priv *priv = file->private_data;
49940
49941 char buf[8];
49942 - int buf_size;
49943 + size_t buf_size;
49944 u32 reset_flag;
49945
49946 memset(buf, 0, sizeof(buf));
49947 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49948 {
49949 struct iwl_priv *priv = file->private_data;
49950 char buf[8];
49951 - int buf_size;
49952 + size_t buf_size;
49953 int ht40;
49954
49955 memset(buf, 0, sizeof(buf));
49956 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49957 {
49958 struct iwl_priv *priv = file->private_data;
49959 char buf[8];
49960 - int buf_size;
49961 + size_t buf_size;
49962 int value;
49963
49964 memset(buf, 0, sizeof(buf));
49965 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49966 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49967 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49968
49969 -static const char *fmt_value = " %-30s %10u\n";
49970 -static const char *fmt_hex = " %-30s 0x%02X\n";
49971 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49972 -static const char *fmt_header =
49973 +static const char fmt_value[] = " %-30s %10u\n";
49974 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49975 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49976 +static const char fmt_header[] =
49977 "%-32s current cumulative delta max\n";
49978
49979 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49980 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49981 {
49982 struct iwl_priv *priv = file->private_data;
49983 char buf[8];
49984 - int buf_size;
49985 + size_t buf_size;
49986 int clear;
49987
49988 memset(buf, 0, sizeof(buf));
49989 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49990 {
49991 struct iwl_priv *priv = file->private_data;
49992 char buf[8];
49993 - int buf_size;
49994 + size_t buf_size;
49995 int trace;
49996
49997 memset(buf, 0, sizeof(buf));
49998 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49999 {
50000 struct iwl_priv *priv = file->private_data;
50001 char buf[8];
50002 - int buf_size;
50003 + size_t buf_size;
50004 int missed;
50005
50006 memset(buf, 0, sizeof(buf));
50007 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50008
50009 struct iwl_priv *priv = file->private_data;
50010 char buf[8];
50011 - int buf_size;
50012 + size_t buf_size;
50013 int plcp;
50014
50015 memset(buf, 0, sizeof(buf));
50016 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50017
50018 struct iwl_priv *priv = file->private_data;
50019 char buf[8];
50020 - int buf_size;
50021 + size_t buf_size;
50022 int flush;
50023
50024 memset(buf, 0, sizeof(buf));
50025 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50026
50027 struct iwl_priv *priv = file->private_data;
50028 char buf[8];
50029 - int buf_size;
50030 + size_t buf_size;
50031 int rts;
50032
50033 if (!priv->cfg->ht_params)
50034 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50035 {
50036 struct iwl_priv *priv = file->private_data;
50037 char buf[8];
50038 - int buf_size;
50039 + size_t buf_size;
50040
50041 memset(buf, 0, sizeof(buf));
50042 buf_size = min(count, sizeof(buf) - 1);
50043 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50044 struct iwl_priv *priv = file->private_data;
50045 u32 event_log_flag;
50046 char buf[8];
50047 - int buf_size;
50048 + size_t buf_size;
50049
50050 /* check that the interface is up */
50051 if (!iwl_is_ready(priv))
50052 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50053 struct iwl_priv *priv = file->private_data;
50054 char buf[8];
50055 u32 calib_disabled;
50056 - int buf_size;
50057 + size_t buf_size;
50058
50059 memset(buf, 0, sizeof(buf));
50060 buf_size = min(count, sizeof(buf) - 1);
50061 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50062 index 06e04aa..d5e1f0d 100644
50063 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50064 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50065 @@ -1684,7 +1684,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50066 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50067
50068 char buf[8];
50069 - int buf_size;
50070 + size_t buf_size;
50071 u32 reset_flag;
50072
50073 memset(buf, 0, sizeof(buf));
50074 @@ -1705,7 +1705,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50075 {
50076 struct iwl_trans *trans = file->private_data;
50077 char buf[8];
50078 - int buf_size;
50079 + size_t buf_size;
50080 int csr;
50081
50082 memset(buf, 0, sizeof(buf));
50083 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50084 index 1326f61..9e56010f 100644
50085 --- a/drivers/net/wireless/mac80211_hwsim.c
50086 +++ b/drivers/net/wireless/mac80211_hwsim.c
50087 @@ -2575,20 +2575,20 @@ static int __init init_mac80211_hwsim(void)
50088 if (channels < 1)
50089 return -EINVAL;
50090
50091 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50092 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50093 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50094 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50095 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50096 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50097 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50098 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50099 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50100 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50101 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50102 - mac80211_hwsim_assign_vif_chanctx;
50103 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50104 - mac80211_hwsim_unassign_vif_chanctx;
50105 + pax_open_kernel();
50106 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50107 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50108 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50109 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50110 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50111 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50112 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50113 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50114 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50115 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50116 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50117 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50118 + pax_close_kernel();
50119
50120 spin_lock_init(&hwsim_radio_lock);
50121 INIT_LIST_HEAD(&hwsim_radios);
50122 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50123 index d2a9a08..0cb175d 100644
50124 --- a/drivers/net/wireless/rndis_wlan.c
50125 +++ b/drivers/net/wireless/rndis_wlan.c
50126 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50127
50128 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50129
50130 - if (rts_threshold < 0 || rts_threshold > 2347)
50131 + if (rts_threshold > 2347)
50132 rts_threshold = 2347;
50133
50134 tmp = cpu_to_le32(rts_threshold);
50135 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50136 index d13f25c..2573994 100644
50137 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50138 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50139 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50140 * for hardware which doesn't support hardware
50141 * sequence counting.
50142 */
50143 - atomic_t seqno;
50144 + atomic_unchecked_t seqno;
50145 };
50146
50147 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50148 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50149 index 8e68f87..c35ba29 100644
50150 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50151 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50152 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50153 * sequence counter given by mac80211.
50154 */
50155 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50156 - seqno = atomic_add_return(0x10, &intf->seqno);
50157 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50158 else
50159 - seqno = atomic_read(&intf->seqno);
50160 + seqno = atomic_read_unchecked(&intf->seqno);
50161
50162 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50163 hdr->seq_ctrl |= cpu_to_le16(seqno);
50164 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50165 index b661f896..ddf7d2b 100644
50166 --- a/drivers/net/wireless/ti/wl1251/sdio.c
50167 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
50168 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50169
50170 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50171
50172 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50173 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50174 + pax_open_kernel();
50175 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50176 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50177 + pax_close_kernel();
50178
50179 wl1251_info("using dedicated interrupt line");
50180 } else {
50181 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50182 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50183 + pax_open_kernel();
50184 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50185 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50186 + pax_close_kernel();
50187
50188 wl1251_info("using SDIO interrupt");
50189 }
50190 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50191 index 0bccf12..3d95068 100644
50192 --- a/drivers/net/wireless/ti/wl12xx/main.c
50193 +++ b/drivers/net/wireless/ti/wl12xx/main.c
50194 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50195 sizeof(wl->conf.mem));
50196
50197 /* read data preparation is only needed by wl127x */
50198 - wl->ops->prepare_read = wl127x_prepare_read;
50199 + pax_open_kernel();
50200 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50201 + pax_close_kernel();
50202
50203 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50204 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50205 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50206 sizeof(wl->conf.mem));
50207
50208 /* read data preparation is only needed by wl127x */
50209 - wl->ops->prepare_read = wl127x_prepare_read;
50210 + pax_open_kernel();
50211 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50212 + pax_close_kernel();
50213
50214 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50215 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50216 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50217 index 7af1936..128bb35 100644
50218 --- a/drivers/net/wireless/ti/wl18xx/main.c
50219 +++ b/drivers/net/wireless/ti/wl18xx/main.c
50220 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50221 }
50222
50223 if (!checksum_param) {
50224 - wl18xx_ops.set_rx_csum = NULL;
50225 - wl18xx_ops.init_vif = NULL;
50226 + pax_open_kernel();
50227 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
50228 + *(void **)&wl18xx_ops.init_vif = NULL;
50229 + pax_close_kernel();
50230 }
50231
50232 /* Enable 11a Band only if we have 5G antennas */
50233 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50234 index a912dc0..a8225ba 100644
50235 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
50236 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50237 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50238 {
50239 struct zd_usb *usb = urb->context;
50240 struct zd_usb_interrupt *intr = &usb->intr;
50241 - int len;
50242 + unsigned int len;
50243 u16 int_num;
50244
50245 ZD_ASSERT(in_interrupt());
50246 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50247 index 683671a..4519fc2 100644
50248 --- a/drivers/nfc/nfcwilink.c
50249 +++ b/drivers/nfc/nfcwilink.c
50250 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50251
50252 static int nfcwilink_probe(struct platform_device *pdev)
50253 {
50254 - static struct nfcwilink *drv;
50255 + struct nfcwilink *drv;
50256 int rc;
50257 __u32 protocols;
50258
50259 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50260 index d93b2b6..ae50401 100644
50261 --- a/drivers/oprofile/buffer_sync.c
50262 +++ b/drivers/oprofile/buffer_sync.c
50263 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50264 if (cookie == NO_COOKIE)
50265 offset = pc;
50266 if (cookie == INVALID_COOKIE) {
50267 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50268 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50269 offset = pc;
50270 }
50271 if (cookie != last_cookie) {
50272 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50273 /* add userspace sample */
50274
50275 if (!mm) {
50276 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
50277 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50278 return 0;
50279 }
50280
50281 cookie = lookup_dcookie(mm, s->eip, &offset);
50282
50283 if (cookie == INVALID_COOKIE) {
50284 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50285 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50286 return 0;
50287 }
50288
50289 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50290 /* ignore backtraces if failed to add a sample */
50291 if (state == sb_bt_start) {
50292 state = sb_bt_ignore;
50293 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50294 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50295 }
50296 }
50297 release_mm(mm);
50298 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50299 index c0cc4e7..44d4e54 100644
50300 --- a/drivers/oprofile/event_buffer.c
50301 +++ b/drivers/oprofile/event_buffer.c
50302 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50303 }
50304
50305 if (buffer_pos == buffer_size) {
50306 - atomic_inc(&oprofile_stats.event_lost_overflow);
50307 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50308 return;
50309 }
50310
50311 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50312 index ed2c3ec..deda85a 100644
50313 --- a/drivers/oprofile/oprof.c
50314 +++ b/drivers/oprofile/oprof.c
50315 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50316 if (oprofile_ops.switch_events())
50317 return;
50318
50319 - atomic_inc(&oprofile_stats.multiplex_counter);
50320 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50321 start_switch_worker();
50322 }
50323
50324 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50325 index ee2cfce..7f8f699 100644
50326 --- a/drivers/oprofile/oprofile_files.c
50327 +++ b/drivers/oprofile/oprofile_files.c
50328 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50329
50330 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50331
50332 -static ssize_t timeout_read(struct file *file, char __user *buf,
50333 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50334 size_t count, loff_t *offset)
50335 {
50336 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50337 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50338 index 59659ce..6c860a0 100644
50339 --- a/drivers/oprofile/oprofile_stats.c
50340 +++ b/drivers/oprofile/oprofile_stats.c
50341 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50342 cpu_buf->sample_invalid_eip = 0;
50343 }
50344
50345 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50346 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50347 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50348 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50349 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50350 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50351 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50352 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50353 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50354 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50355 }
50356
50357
50358 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50359 index 1fc622b..8c48fc3 100644
50360 --- a/drivers/oprofile/oprofile_stats.h
50361 +++ b/drivers/oprofile/oprofile_stats.h
50362 @@ -13,11 +13,11 @@
50363 #include <linux/atomic.h>
50364
50365 struct oprofile_stat_struct {
50366 - atomic_t sample_lost_no_mm;
50367 - atomic_t sample_lost_no_mapping;
50368 - atomic_t bt_lost_no_mapping;
50369 - atomic_t event_lost_overflow;
50370 - atomic_t multiplex_counter;
50371 + atomic_unchecked_t sample_lost_no_mm;
50372 + atomic_unchecked_t sample_lost_no_mapping;
50373 + atomic_unchecked_t bt_lost_no_mapping;
50374 + atomic_unchecked_t event_lost_overflow;
50375 + atomic_unchecked_t multiplex_counter;
50376 };
50377
50378 extern struct oprofile_stat_struct oprofile_stats;
50379 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50380 index 3f49345..c750d0b 100644
50381 --- a/drivers/oprofile/oprofilefs.c
50382 +++ b/drivers/oprofile/oprofilefs.c
50383 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50384
50385 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50386 {
50387 - atomic_t *val = file->private_data;
50388 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50389 + atomic_unchecked_t *val = file->private_data;
50390 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50391 }
50392
50393
50394 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50395
50396
50397 int oprofilefs_create_ro_atomic(struct dentry *root,
50398 - char const *name, atomic_t *val)
50399 + char const *name, atomic_unchecked_t *val)
50400 {
50401 return __oprofilefs_create_file(root, name,
50402 &atomic_ro_fops, 0444, val);
50403 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50404 index 61be1d9..dec05d7 100644
50405 --- a/drivers/oprofile/timer_int.c
50406 +++ b/drivers/oprofile/timer_int.c
50407 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50408 return NOTIFY_OK;
50409 }
50410
50411 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50412 +static struct notifier_block oprofile_cpu_notifier = {
50413 .notifier_call = oprofile_cpu_notify,
50414 };
50415
50416 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50417 index 3b47080..6cd05dd 100644
50418 --- a/drivers/parport/procfs.c
50419 +++ b/drivers/parport/procfs.c
50420 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50421
50422 *ppos += len;
50423
50424 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50425 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50426 }
50427
50428 #ifdef CONFIG_PARPORT_1284
50429 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50430
50431 *ppos += len;
50432
50433 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50434 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50435 }
50436 #endif /* IEEE1284.3 support. */
50437
50438 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50439 index 8dcccff..35d701d 100644
50440 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50441 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50442 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50443 goto init_cleanup;
50444 }
50445
50446 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50447 + pax_open_kernel();
50448 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50449 + pax_close_kernel();
50450 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50451
50452 return retval;
50453 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50454 index 04fcd78..39e83f1 100644
50455 --- a/drivers/pci/hotplug/cpcihp_generic.c
50456 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50457 @@ -73,7 +73,6 @@ static u16 port;
50458 static unsigned int enum_bit;
50459 static u8 enum_mask;
50460
50461 -static struct cpci_hp_controller_ops generic_hpc_ops;
50462 static struct cpci_hp_controller generic_hpc;
50463
50464 static int __init validate_parameters(void)
50465 @@ -139,6 +138,10 @@ static int query_enum(void)
50466 return ((value & enum_mask) == enum_mask);
50467 }
50468
50469 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50470 + .query_enum = query_enum,
50471 +};
50472 +
50473 static int __init cpcihp_generic_init(void)
50474 {
50475 int status;
50476 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50477 pci_dev_put(dev);
50478
50479 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50480 - generic_hpc_ops.query_enum = query_enum;
50481 generic_hpc.ops = &generic_hpc_ops;
50482
50483 status = cpci_hp_register_controller(&generic_hpc);
50484 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50485 index 6757b3e..d3bad62 100644
50486 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50487 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50488 @@ -59,7 +59,6 @@
50489 /* local variables */
50490 static bool debug;
50491 static bool poll;
50492 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50493 static struct cpci_hp_controller zt5550_hpc;
50494
50495 /* Primary cPCI bus bridge device */
50496 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50497 return 0;
50498 }
50499
50500 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50501 + .query_enum = zt5550_hc_query_enum,
50502 +};
50503 +
50504 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50505 {
50506 int status;
50507 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50508 dbg("returned from zt5550_hc_config");
50509
50510 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50511 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50512 zt5550_hpc.ops = &zt5550_hpc_ops;
50513 if(!poll) {
50514 zt5550_hpc.irq = hc_dev->irq;
50515 zt5550_hpc.irq_flags = IRQF_SHARED;
50516 zt5550_hpc.dev_id = hc_dev;
50517
50518 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50519 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50520 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50521 + pax_open_kernel();
50522 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50523 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50524 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50525 + pax_open_kernel();
50526 } else {
50527 info("using ENUM# polling mode");
50528 }
50529 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50530 index 0968a9b..5a00edf 100644
50531 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50532 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50533 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50534
50535 void compaq_nvram_init (void __iomem *rom_start)
50536 {
50537 +
50538 +#ifndef CONFIG_PAX_KERNEXEC
50539 if (rom_start) {
50540 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50541 }
50542 +#endif
50543 +
50544 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50545
50546 /* initialize our int15 lock */
50547 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50548 index 56d8486..f26113f 100644
50549 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50550 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50551 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50552 return -EINVAL;
50553 }
50554
50555 - slot->ops->owner = owner;
50556 - slot->ops->mod_name = mod_name;
50557 + pax_open_kernel();
50558 + *(struct module **)&slot->ops->owner = owner;
50559 + *(const char **)&slot->ops->mod_name = mod_name;
50560 + pax_close_kernel();
50561
50562 mutex_lock(&pci_hp_mutex);
50563 /*
50564 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50565 index 07aa722..84514b4 100644
50566 --- a/drivers/pci/hotplug/pciehp_core.c
50567 +++ b/drivers/pci/hotplug/pciehp_core.c
50568 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50569 struct slot *slot = ctrl->slot;
50570 struct hotplug_slot *hotplug = NULL;
50571 struct hotplug_slot_info *info = NULL;
50572 - struct hotplug_slot_ops *ops = NULL;
50573 + hotplug_slot_ops_no_const *ops = NULL;
50574 char name[SLOT_NAME_SIZE];
50575 int retval = -ENOMEM;
50576
50577 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50578 index 5a40516..136d5a7 100644
50579 --- a/drivers/pci/msi.c
50580 +++ b/drivers/pci/msi.c
50581 @@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50582 {
50583 struct attribute **msi_attrs;
50584 struct attribute *msi_attr;
50585 - struct device_attribute *msi_dev_attr;
50586 - struct attribute_group *msi_irq_group;
50587 + device_attribute_no_const *msi_dev_attr;
50588 + attribute_group_no_const *msi_irq_group;
50589 const struct attribute_group **msi_irq_groups;
50590 struct msi_desc *entry;
50591 int ret = -ENOMEM;
50592 @@ -568,7 +568,7 @@ error_attrs:
50593 count = 0;
50594 msi_attr = msi_attrs[count];
50595 while (msi_attr) {
50596 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50597 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50598 kfree(msi_attr->name);
50599 kfree(msi_dev_attr);
50600 ++count;
50601 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50602 index 9ff0a90..e819dda 100644
50603 --- a/drivers/pci/pci-sysfs.c
50604 +++ b/drivers/pci/pci-sysfs.c
50605 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50606 {
50607 /* allocate attribute structure, piggyback attribute name */
50608 int name_len = write_combine ? 13 : 10;
50609 - struct bin_attribute *res_attr;
50610 + bin_attribute_no_const *res_attr;
50611 int retval;
50612
50613 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50614 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50615 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50616 {
50617 int retval;
50618 - struct bin_attribute *attr;
50619 + bin_attribute_no_const *attr;
50620
50621 /* If the device has VPD, try to expose it in sysfs. */
50622 if (dev->vpd) {
50623 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50624 {
50625 int retval;
50626 int rom_size = 0;
50627 - struct bin_attribute *attr;
50628 + bin_attribute_no_const *attr;
50629
50630 if (!sysfs_initialized)
50631 return -EACCES;
50632 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50633 index 0601890..dc15007 100644
50634 --- a/drivers/pci/pci.h
50635 +++ b/drivers/pci/pci.h
50636 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
50637 struct pci_vpd {
50638 unsigned int len;
50639 const struct pci_vpd_ops *ops;
50640 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50641 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50642 };
50643
50644 int pci_vpd_pci22_init(struct pci_dev *dev);
50645 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50646 index e1e7026..d28dd33 100644
50647 --- a/drivers/pci/pcie/aspm.c
50648 +++ b/drivers/pci/pcie/aspm.c
50649 @@ -27,9 +27,9 @@
50650 #define MODULE_PARAM_PREFIX "pcie_aspm."
50651
50652 /* Note: those are not register definitions */
50653 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50654 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50655 -#define ASPM_STATE_L1 (4) /* L1 state */
50656 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50657 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50658 +#define ASPM_STATE_L1 (4U) /* L1 state */
50659 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50660 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50661
50662 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50663 index 4170113..7cc5339 100644
50664 --- a/drivers/pci/probe.c
50665 +++ b/drivers/pci/probe.c
50666 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50667 struct pci_bus_region region, inverted_region;
50668 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50669
50670 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50671 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50672
50673 /* No printks while decoding is disabled! */
50674 if (!dev->mmio_always_on) {
50675 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50676 index 3f155e7..0f4b1f0 100644
50677 --- a/drivers/pci/proc.c
50678 +++ b/drivers/pci/proc.c
50679 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50680 static int __init pci_proc_init(void)
50681 {
50682 struct pci_dev *dev = NULL;
50683 +
50684 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50685 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50686 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50687 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50688 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50689 +#endif
50690 +#else
50691 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50692 +#endif
50693 proc_create("devices", 0, proc_bus_pci_dir,
50694 &proc_bus_pci_dev_operations);
50695 proc_initialized = 1;
50696 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50697 index d866db8..c827d1f 100644
50698 --- a/drivers/platform/chrome/chromeos_laptop.c
50699 +++ b/drivers/platform/chrome/chromeos_laptop.c
50700 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50701 .callback = chromeos_laptop_dmi_matched, \
50702 .driver_data = (void *)&board_
50703
50704 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50705 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50706 {
50707 .ident = "Samsung Series 5 550",
50708 .matches = {
50709 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50710 index c5af23b..3d62d5e 100644
50711 --- a/drivers/platform/x86/alienware-wmi.c
50712 +++ b/drivers/platform/x86/alienware-wmi.c
50713 @@ -150,7 +150,7 @@ struct wmax_led_args {
50714 } __packed;
50715
50716 static struct platform_device *platform_device;
50717 -static struct device_attribute *zone_dev_attrs;
50718 +static device_attribute_no_const *zone_dev_attrs;
50719 static struct attribute **zone_attrs;
50720 static struct platform_zone *zone_data;
50721
50722 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50723 }
50724 };
50725
50726 -static struct attribute_group zone_attribute_group = {
50727 +static attribute_group_no_const zone_attribute_group = {
50728 .name = "rgb_zones",
50729 };
50730
50731 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50732 index 21fc932..ee9394a 100644
50733 --- a/drivers/platform/x86/asus-wmi.c
50734 +++ b/drivers/platform/x86/asus-wmi.c
50735 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50736 int err;
50737 u32 retval = -1;
50738
50739 +#ifdef CONFIG_GRKERNSEC_KMEM
50740 + return -EPERM;
50741 +#endif
50742 +
50743 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50744
50745 if (err < 0)
50746 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50747 int err;
50748 u32 retval = -1;
50749
50750 +#ifdef CONFIG_GRKERNSEC_KMEM
50751 + return -EPERM;
50752 +#endif
50753 +
50754 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50755 &retval);
50756
50757 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50758 union acpi_object *obj;
50759 acpi_status status;
50760
50761 +#ifdef CONFIG_GRKERNSEC_KMEM
50762 + return -EPERM;
50763 +#endif
50764 +
50765 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50766 1, asus->debug.method_id,
50767 &input, &output);
50768 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50769 index 62f8030..c7f2a45 100644
50770 --- a/drivers/platform/x86/msi-laptop.c
50771 +++ b/drivers/platform/x86/msi-laptop.c
50772 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50773
50774 if (!quirks->ec_read_only) {
50775 /* allow userland write sysfs file */
50776 - dev_attr_bluetooth.store = store_bluetooth;
50777 - dev_attr_wlan.store = store_wlan;
50778 - dev_attr_threeg.store = store_threeg;
50779 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50780 - dev_attr_wlan.attr.mode |= S_IWUSR;
50781 - dev_attr_threeg.attr.mode |= S_IWUSR;
50782 + pax_open_kernel();
50783 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50784 + *(void **)&dev_attr_wlan.store = store_wlan;
50785 + *(void **)&dev_attr_threeg.store = store_threeg;
50786 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50787 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50788 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50789 + pax_close_kernel();
50790 }
50791
50792 /* disable hardware control by fn key */
50793 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50794 index 70222f2..8c8ce66 100644
50795 --- a/drivers/platform/x86/msi-wmi.c
50796 +++ b/drivers/platform/x86/msi-wmi.c
50797 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50798 static void msi_wmi_notify(u32 value, void *context)
50799 {
50800 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50801 - static struct key_entry *key;
50802 + struct key_entry *key;
50803 union acpi_object *obj;
50804 acpi_status status;
50805
50806 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50807 index 26ad9ff..7c52909 100644
50808 --- a/drivers/platform/x86/sony-laptop.c
50809 +++ b/drivers/platform/x86/sony-laptop.c
50810 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50811 }
50812
50813 /* High speed charging function */
50814 -static struct device_attribute *hsc_handle;
50815 +static device_attribute_no_const *hsc_handle;
50816
50817 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50818 struct device_attribute *attr,
50819 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50820 }
50821
50822 /* low battery function */
50823 -static struct device_attribute *lowbatt_handle;
50824 +static device_attribute_no_const *lowbatt_handle;
50825
50826 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50827 struct device_attribute *attr,
50828 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50829 }
50830
50831 /* fan speed function */
50832 -static struct device_attribute *fan_handle, *hsf_handle;
50833 +static device_attribute_no_const *fan_handle, *hsf_handle;
50834
50835 static ssize_t sony_nc_hsfan_store(struct device *dev,
50836 struct device_attribute *attr,
50837 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50838 }
50839
50840 /* USB charge function */
50841 -static struct device_attribute *uc_handle;
50842 +static device_attribute_no_const *uc_handle;
50843
50844 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50845 struct device_attribute *attr,
50846 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50847 }
50848
50849 /* Panel ID function */
50850 -static struct device_attribute *panel_handle;
50851 +static device_attribute_no_const *panel_handle;
50852
50853 static ssize_t sony_nc_panelid_show(struct device *dev,
50854 struct device_attribute *attr, char *buffer)
50855 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50856 }
50857
50858 /* smart connect function */
50859 -static struct device_attribute *sc_handle;
50860 +static device_attribute_no_const *sc_handle;
50861
50862 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50863 struct device_attribute *attr,
50864 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50865 index 3bbc6eb..7760460 100644
50866 --- a/drivers/platform/x86/thinkpad_acpi.c
50867 +++ b/drivers/platform/x86/thinkpad_acpi.c
50868 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50869 return 0;
50870 }
50871
50872 -void static hotkey_mask_warn_incomplete_mask(void)
50873 +static void hotkey_mask_warn_incomplete_mask(void)
50874 {
50875 /* log only what the user can fix... */
50876 const u32 wantedmask = hotkey_driver_mask &
50877 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50878 && !tp_features.bright_unkfw)
50879 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50880 }
50881 +}
50882
50883 #undef TPACPI_COMPARE_KEY
50884 #undef TPACPI_MAY_SEND_KEY
50885 -}
50886
50887 /*
50888 * Polling driver
50889 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50890 index 438d4c7..ca8a2fb 100644
50891 --- a/drivers/pnp/pnpbios/bioscalls.c
50892 +++ b/drivers/pnp/pnpbios/bioscalls.c
50893 @@ -59,7 +59,7 @@ do { \
50894 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50895 } while(0)
50896
50897 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50898 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50899 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50900
50901 /*
50902 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50903
50904 cpu = get_cpu();
50905 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50906 +
50907 + pax_open_kernel();
50908 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50909 + pax_close_kernel();
50910
50911 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50912 spin_lock_irqsave(&pnp_bios_lock, flags);
50913 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50914 :"memory");
50915 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50916
50917 + pax_open_kernel();
50918 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50919 + pax_close_kernel();
50920 +
50921 put_cpu();
50922
50923 /* If we get here and this is set then the PnP BIOS faulted on us. */
50924 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50925 return status;
50926 }
50927
50928 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50929 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50930 {
50931 int i;
50932
50933 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50934 pnp_bios_callpoint.offset = header->fields.pm16offset;
50935 pnp_bios_callpoint.segment = PNP_CS16;
50936
50937 + pax_open_kernel();
50938 +
50939 for_each_possible_cpu(i) {
50940 struct desc_struct *gdt = get_cpu_gdt_table(i);
50941 if (!gdt)
50942 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50943 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50944 (unsigned long)__va(header->fields.pm16dseg));
50945 }
50946 +
50947 + pax_close_kernel();
50948 }
50949 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50950 index 0c52e2a..3421ab7 100644
50951 --- a/drivers/power/pda_power.c
50952 +++ b/drivers/power/pda_power.c
50953 @@ -37,7 +37,11 @@ static int polling;
50954
50955 #if IS_ENABLED(CONFIG_USB_PHY)
50956 static struct usb_phy *transceiver;
50957 -static struct notifier_block otg_nb;
50958 +static int otg_handle_notification(struct notifier_block *nb,
50959 + unsigned long event, void *unused);
50960 +static struct notifier_block otg_nb = {
50961 + .notifier_call = otg_handle_notification
50962 +};
50963 #endif
50964
50965 static struct regulator *ac_draw;
50966 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50967
50968 #if IS_ENABLED(CONFIG_USB_PHY)
50969 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50970 - otg_nb.notifier_call = otg_handle_notification;
50971 ret = usb_register_notifier(transceiver, &otg_nb);
50972 if (ret) {
50973 dev_err(dev, "failure to register otg notifier\n");
50974 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50975 index cc439fd..8fa30df 100644
50976 --- a/drivers/power/power_supply.h
50977 +++ b/drivers/power/power_supply.h
50978 @@ -16,12 +16,12 @@ struct power_supply;
50979
50980 #ifdef CONFIG_SYSFS
50981
50982 -extern void power_supply_init_attrs(struct device_type *dev_type);
50983 +extern void power_supply_init_attrs(void);
50984 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50985
50986 #else
50987
50988 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50989 +static inline void power_supply_init_attrs(void) {}
50990 #define power_supply_uevent NULL
50991
50992 #endif /* CONFIG_SYSFS */
50993 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50994 index 078afd6..fbac9da 100644
50995 --- a/drivers/power/power_supply_core.c
50996 +++ b/drivers/power/power_supply_core.c
50997 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50998 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50999 EXPORT_SYMBOL_GPL(power_supply_notifier);
51000
51001 -static struct device_type power_supply_dev_type;
51002 +extern const struct attribute_group *power_supply_attr_groups[];
51003 +static struct device_type power_supply_dev_type = {
51004 + .groups = power_supply_attr_groups,
51005 +};
51006
51007 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51008 struct power_supply *supply)
51009 @@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
51010 return PTR_ERR(power_supply_class);
51011
51012 power_supply_class->dev_uevent = power_supply_uevent;
51013 - power_supply_init_attrs(&power_supply_dev_type);
51014 + power_supply_init_attrs();
51015
51016 return 0;
51017 }
51018 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51019 index 750a202..99c8f4b 100644
51020 --- a/drivers/power/power_supply_sysfs.c
51021 +++ b/drivers/power/power_supply_sysfs.c
51022 @@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
51023 .is_visible = power_supply_attr_is_visible,
51024 };
51025
51026 -static const struct attribute_group *power_supply_attr_groups[] = {
51027 +const struct attribute_group *power_supply_attr_groups[] = {
51028 &power_supply_attr_group,
51029 NULL,
51030 };
51031
51032 -void power_supply_init_attrs(struct device_type *dev_type)
51033 +void power_supply_init_attrs(void)
51034 {
51035 int i;
51036
51037 - dev_type->groups = power_supply_attr_groups;
51038 -
51039 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51040 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51041 }
51042 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51043 index 84419af..268ede8 100644
51044 --- a/drivers/powercap/powercap_sys.c
51045 +++ b/drivers/powercap/powercap_sys.c
51046 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51047 struct device_attribute name_attr;
51048 };
51049
51050 +static ssize_t show_constraint_name(struct device *dev,
51051 + struct device_attribute *dev_attr,
51052 + char *buf);
51053 +
51054 static struct powercap_constraint_attr
51055 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51056 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51057 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51058 + .power_limit_attr = {
51059 + .attr = {
51060 + .name = NULL,
51061 + .mode = S_IWUSR | S_IRUGO
51062 + },
51063 + .show = show_constraint_power_limit_uw,
51064 + .store = store_constraint_power_limit_uw
51065 + },
51066 +
51067 + .time_window_attr = {
51068 + .attr = {
51069 + .name = NULL,
51070 + .mode = S_IWUSR | S_IRUGO
51071 + },
51072 + .show = show_constraint_time_window_us,
51073 + .store = store_constraint_time_window_us
51074 + },
51075 +
51076 + .max_power_attr = {
51077 + .attr = {
51078 + .name = NULL,
51079 + .mode = S_IRUGO
51080 + },
51081 + .show = show_constraint_max_power_uw,
51082 + .store = NULL
51083 + },
51084 +
51085 + .min_power_attr = {
51086 + .attr = {
51087 + .name = NULL,
51088 + .mode = S_IRUGO
51089 + },
51090 + .show = show_constraint_min_power_uw,
51091 + .store = NULL
51092 + },
51093 +
51094 + .max_time_window_attr = {
51095 + .attr = {
51096 + .name = NULL,
51097 + .mode = S_IRUGO
51098 + },
51099 + .show = show_constraint_max_time_window_us,
51100 + .store = NULL
51101 + },
51102 +
51103 + .min_time_window_attr = {
51104 + .attr = {
51105 + .name = NULL,
51106 + .mode = S_IRUGO
51107 + },
51108 + .show = show_constraint_min_time_window_us,
51109 + .store = NULL
51110 + },
51111 +
51112 + .name_attr = {
51113 + .attr = {
51114 + .name = NULL,
51115 + .mode = S_IRUGO
51116 + },
51117 + .show = show_constraint_name,
51118 + .store = NULL
51119 + }
51120 + }
51121 +};
51122
51123 /* A list of powercap control_types */
51124 static LIST_HEAD(powercap_cntrl_list);
51125 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51126 }
51127
51128 static int create_constraint_attribute(int id, const char *name,
51129 - int mode,
51130 - struct device_attribute *dev_attr,
51131 - ssize_t (*show)(struct device *,
51132 - struct device_attribute *, char *),
51133 - ssize_t (*store)(struct device *,
51134 - struct device_attribute *,
51135 - const char *, size_t)
51136 - )
51137 + struct device_attribute *dev_attr)
51138 {
51139 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51140
51141 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51142 - id, name);
51143 - if (!dev_attr->attr.name)
51144 + if (!name)
51145 return -ENOMEM;
51146 - dev_attr->attr.mode = mode;
51147 - dev_attr->show = show;
51148 - dev_attr->store = store;
51149 +
51150 + pax_open_kernel();
51151 + *(const char **)&dev_attr->attr.name = name;
51152 + pax_close_kernel();
51153
51154 return 0;
51155 }
51156 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51157
51158 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51159 ret = create_constraint_attribute(i, "power_limit_uw",
51160 - S_IWUSR | S_IRUGO,
51161 - &constraint_attrs[i].power_limit_attr,
51162 - show_constraint_power_limit_uw,
51163 - store_constraint_power_limit_uw);
51164 + &constraint_attrs[i].power_limit_attr);
51165 if (ret)
51166 goto err_alloc;
51167 ret = create_constraint_attribute(i, "time_window_us",
51168 - S_IWUSR | S_IRUGO,
51169 - &constraint_attrs[i].time_window_attr,
51170 - show_constraint_time_window_us,
51171 - store_constraint_time_window_us);
51172 + &constraint_attrs[i].time_window_attr);
51173 if (ret)
51174 goto err_alloc;
51175 - ret = create_constraint_attribute(i, "name", S_IRUGO,
51176 - &constraint_attrs[i].name_attr,
51177 - show_constraint_name,
51178 - NULL);
51179 + ret = create_constraint_attribute(i, "name",
51180 + &constraint_attrs[i].name_attr);
51181 if (ret)
51182 goto err_alloc;
51183 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51184 - &constraint_attrs[i].max_power_attr,
51185 - show_constraint_max_power_uw,
51186 - NULL);
51187 + ret = create_constraint_attribute(i, "max_power_uw",
51188 + &constraint_attrs[i].max_power_attr);
51189 if (ret)
51190 goto err_alloc;
51191 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51192 - &constraint_attrs[i].min_power_attr,
51193 - show_constraint_min_power_uw,
51194 - NULL);
51195 + ret = create_constraint_attribute(i, "min_power_uw",
51196 + &constraint_attrs[i].min_power_attr);
51197 if (ret)
51198 goto err_alloc;
51199 ret = create_constraint_attribute(i, "max_time_window_us",
51200 - S_IRUGO,
51201 - &constraint_attrs[i].max_time_window_attr,
51202 - show_constraint_max_time_window_us,
51203 - NULL);
51204 + &constraint_attrs[i].max_time_window_attr);
51205 if (ret)
51206 goto err_alloc;
51207 ret = create_constraint_attribute(i, "min_time_window_us",
51208 - S_IRUGO,
51209 - &constraint_attrs[i].min_time_window_attr,
51210 - show_constraint_min_time_window_us,
51211 - NULL);
51212 + &constraint_attrs[i].min_time_window_attr);
51213 if (ret)
51214 goto err_alloc;
51215
51216 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51217 power_zone->zone_dev_attrs[count++] =
51218 &dev_attr_max_energy_range_uj.attr;
51219 if (power_zone->ops->get_energy_uj) {
51220 + pax_open_kernel();
51221 if (power_zone->ops->reset_energy_uj)
51222 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51223 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51224 else
51225 - dev_attr_energy_uj.attr.mode = S_IRUGO;
51226 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51227 + pax_close_kernel();
51228 power_zone->zone_dev_attrs[count++] =
51229 &dev_attr_energy_uj.attr;
51230 }
51231 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51232 index 9c5d414..c7900ce 100644
51233 --- a/drivers/ptp/ptp_private.h
51234 +++ b/drivers/ptp/ptp_private.h
51235 @@ -51,7 +51,7 @@ struct ptp_clock {
51236 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51237 wait_queue_head_t tsev_wq;
51238 int defunct; /* tells readers to go away when clock is being removed */
51239 - struct device_attribute *pin_dev_attr;
51240 + device_attribute_no_const *pin_dev_attr;
51241 struct attribute **pin_attr;
51242 struct attribute_group pin_attr_group;
51243 };
51244 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51245 index 302e626..12579af 100644
51246 --- a/drivers/ptp/ptp_sysfs.c
51247 +++ b/drivers/ptp/ptp_sysfs.c
51248 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51249 goto no_pin_attr;
51250
51251 for (i = 0; i < n_pins; i++) {
51252 - struct device_attribute *da = &ptp->pin_dev_attr[i];
51253 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51254 sysfs_attr_init(&da->attr);
51255 da->attr.name = info->pin_config[i].name;
51256 da->attr.mode = 0644;
51257 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51258 index a3c3785..c901e3a 100644
51259 --- a/drivers/regulator/core.c
51260 +++ b/drivers/regulator/core.c
51261 @@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51262 {
51263 const struct regulation_constraints *constraints = NULL;
51264 const struct regulator_init_data *init_data;
51265 - static atomic_t regulator_no = ATOMIC_INIT(0);
51266 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51267 struct regulator_dev *rdev;
51268 struct device *dev;
51269 int ret, i;
51270 @@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51271 rdev->dev.of_node = of_node_get(config->of_node);
51272 rdev->dev.parent = dev;
51273 dev_set_name(&rdev->dev, "regulator.%d",
51274 - atomic_inc_return(&regulator_no) - 1);
51275 + atomic_inc_return_unchecked(&regulator_no) - 1);
51276 ret = device_register(&rdev->dev);
51277 if (ret != 0) {
51278 put_device(&rdev->dev);
51279 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51280 index 2fc4111..6aa88ca 100644
51281 --- a/drivers/regulator/max8660.c
51282 +++ b/drivers/regulator/max8660.c
51283 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51284 max8660->shadow_regs[MAX8660_OVER1] = 5;
51285 } else {
51286 /* Otherwise devices can be toggled via software */
51287 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
51288 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
51289 + pax_open_kernel();
51290 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51291 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51292 + pax_close_kernel();
51293 }
51294
51295 /*
51296 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51297 index dbedf17..18ff6b7 100644
51298 --- a/drivers/regulator/max8973-regulator.c
51299 +++ b/drivers/regulator/max8973-regulator.c
51300 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51301 if (!pdata || !pdata->enable_ext_control) {
51302 max->desc.enable_reg = MAX8973_VOUT;
51303 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51304 - max->ops.enable = regulator_enable_regmap;
51305 - max->ops.disable = regulator_disable_regmap;
51306 - max->ops.is_enabled = regulator_is_enabled_regmap;
51307 + pax_open_kernel();
51308 + *(void **)&max->ops.enable = regulator_enable_regmap;
51309 + *(void **)&max->ops.disable = regulator_disable_regmap;
51310 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51311 + pax_close_kernel();
51312 }
51313
51314 if (pdata) {
51315 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51316 index f374fa5..26f0683 100644
51317 --- a/drivers/regulator/mc13892-regulator.c
51318 +++ b/drivers/regulator/mc13892-regulator.c
51319 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51320 }
51321 mc13xxx_unlock(mc13892);
51322
51323 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51324 + pax_open_kernel();
51325 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51326 = mc13892_vcam_set_mode;
51327 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51328 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51329 = mc13892_vcam_get_mode;
51330 + pax_close_kernel();
51331
51332 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51333 ARRAY_SIZE(mc13892_regulators));
51334 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51335 index b0e4a3e..e5dc11e 100644
51336 --- a/drivers/rtc/rtc-cmos.c
51337 +++ b/drivers/rtc/rtc-cmos.c
51338 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51339 hpet_rtc_timer_init();
51340
51341 /* export at least the first block of NVRAM */
51342 - nvram.size = address_space - NVRAM_OFFSET;
51343 + pax_open_kernel();
51344 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51345 + pax_close_kernel();
51346 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51347 if (retval < 0) {
51348 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51349 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51350 index d049393..bb20be0 100644
51351 --- a/drivers/rtc/rtc-dev.c
51352 +++ b/drivers/rtc/rtc-dev.c
51353 @@ -16,6 +16,7 @@
51354 #include <linux/module.h>
51355 #include <linux/rtc.h>
51356 #include <linux/sched.h>
51357 +#include <linux/grsecurity.h>
51358 #include "rtc-core.h"
51359
51360 static dev_t rtc_devt;
51361 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51362 if (copy_from_user(&tm, uarg, sizeof(tm)))
51363 return -EFAULT;
51364
51365 + gr_log_timechange();
51366 +
51367 return rtc_set_time(rtc, &tm);
51368
51369 case RTC_PIE_ON:
51370 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51371 index f03d5ba..8325bf6 100644
51372 --- a/drivers/rtc/rtc-ds1307.c
51373 +++ b/drivers/rtc/rtc-ds1307.c
51374 @@ -107,7 +107,7 @@ struct ds1307 {
51375 u8 offset; /* register's offset */
51376 u8 regs[11];
51377 u16 nvram_offset;
51378 - struct bin_attribute *nvram;
51379 + bin_attribute_no_const *nvram;
51380 enum ds_type type;
51381 unsigned long flags;
51382 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51383 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51384 index 11880c1..b823aa4 100644
51385 --- a/drivers/rtc/rtc-m48t59.c
51386 +++ b/drivers/rtc/rtc-m48t59.c
51387 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51388 if (IS_ERR(m48t59->rtc))
51389 return PTR_ERR(m48t59->rtc);
51390
51391 - m48t59_nvram_attr.size = pdata->offset;
51392 + pax_open_kernel();
51393 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51394 + pax_close_kernel();
51395
51396 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51397 if (ret)
51398 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51399 index e693af6..2e525b6 100644
51400 --- a/drivers/scsi/bfa/bfa_fcpim.h
51401 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51402 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51403
51404 struct bfa_itn_s {
51405 bfa_isr_func_t isr;
51406 -};
51407 +} __no_const;
51408
51409 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51410 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51411 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51412 index 0f19455..ef7adb5 100644
51413 --- a/drivers/scsi/bfa/bfa_fcs.c
51414 +++ b/drivers/scsi/bfa/bfa_fcs.c
51415 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51416 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51417
51418 static struct bfa_fcs_mod_s fcs_modules[] = {
51419 - { bfa_fcs_port_attach, NULL, NULL },
51420 - { bfa_fcs_uf_attach, NULL, NULL },
51421 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51422 - bfa_fcs_fabric_modexit },
51423 + {
51424 + .attach = bfa_fcs_port_attach,
51425 + .modinit = NULL,
51426 + .modexit = NULL
51427 + },
51428 + {
51429 + .attach = bfa_fcs_uf_attach,
51430 + .modinit = NULL,
51431 + .modexit = NULL
51432 + },
51433 + {
51434 + .attach = bfa_fcs_fabric_attach,
51435 + .modinit = bfa_fcs_fabric_modinit,
51436 + .modexit = bfa_fcs_fabric_modexit
51437 + },
51438 };
51439
51440 /*
51441 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51442 index ff75ef8..2dfe00a 100644
51443 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51444 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51445 @@ -89,15 +89,26 @@ static struct {
51446 void (*offline) (struct bfa_fcs_lport_s *port);
51447 } __port_action[] = {
51448 {
51449 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51450 - bfa_fcs_lport_unknown_offline}, {
51451 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51452 - bfa_fcs_lport_fab_offline}, {
51453 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51454 - bfa_fcs_lport_n2n_offline}, {
51455 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51456 - bfa_fcs_lport_loop_offline},
51457 - };
51458 + .init = bfa_fcs_lport_unknown_init,
51459 + .online = bfa_fcs_lport_unknown_online,
51460 + .offline = bfa_fcs_lport_unknown_offline
51461 + },
51462 + {
51463 + .init = bfa_fcs_lport_fab_init,
51464 + .online = bfa_fcs_lport_fab_online,
51465 + .offline = bfa_fcs_lport_fab_offline
51466 + },
51467 + {
51468 + .init = bfa_fcs_lport_n2n_init,
51469 + .online = bfa_fcs_lport_n2n_online,
51470 + .offline = bfa_fcs_lport_n2n_offline
51471 + },
51472 + {
51473 + .init = bfa_fcs_lport_loop_init,
51474 + .online = bfa_fcs_lport_loop_online,
51475 + .offline = bfa_fcs_lport_loop_offline
51476 + },
51477 +};
51478
51479 /*
51480 * fcs_port_sm FCS logical port state machine
51481 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51482 index a38aafa0..fe8f03b 100644
51483 --- a/drivers/scsi/bfa/bfa_ioc.h
51484 +++ b/drivers/scsi/bfa/bfa_ioc.h
51485 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51486 bfa_ioc_disable_cbfn_t disable_cbfn;
51487 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51488 bfa_ioc_reset_cbfn_t reset_cbfn;
51489 -};
51490 +} __no_const;
51491
51492 /*
51493 * IOC event notification mechanism.
51494 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51495 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51496 enum bfi_ioc_state fwstate);
51497 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51498 -};
51499 +} __no_const;
51500
51501 /*
51502 * Queue element to wait for room in request queue. FIFO order is
51503 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51504 index a14c784..6de6790 100644
51505 --- a/drivers/scsi/bfa/bfa_modules.h
51506 +++ b/drivers/scsi/bfa/bfa_modules.h
51507 @@ -78,12 +78,12 @@ enum {
51508 \
51509 extern struct bfa_module_s hal_mod_ ## __mod; \
51510 struct bfa_module_s hal_mod_ ## __mod = { \
51511 - bfa_ ## __mod ## _meminfo, \
51512 - bfa_ ## __mod ## _attach, \
51513 - bfa_ ## __mod ## _detach, \
51514 - bfa_ ## __mod ## _start, \
51515 - bfa_ ## __mod ## _stop, \
51516 - bfa_ ## __mod ## _iocdisable, \
51517 + .meminfo = bfa_ ## __mod ## _meminfo, \
51518 + .attach = bfa_ ## __mod ## _attach, \
51519 + .detach = bfa_ ## __mod ## _detach, \
51520 + .start = bfa_ ## __mod ## _start, \
51521 + .stop = bfa_ ## __mod ## _stop, \
51522 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51523 }
51524
51525 #define BFA_CACHELINE_SZ (256)
51526 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51527 index 045c4e1..13de803 100644
51528 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51529 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51530 @@ -33,8 +33,8 @@
51531 */
51532 #include "libfcoe.h"
51533
51534 -static atomic_t ctlr_num;
51535 -static atomic_t fcf_num;
51536 +static atomic_unchecked_t ctlr_num;
51537 +static atomic_unchecked_t fcf_num;
51538
51539 /*
51540 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51541 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51542 if (!ctlr)
51543 goto out;
51544
51545 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51546 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51547 ctlr->f = f;
51548 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51549 INIT_LIST_HEAD(&ctlr->fcfs);
51550 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51551 fcf->dev.parent = &ctlr->dev;
51552 fcf->dev.bus = &fcoe_bus_type;
51553 fcf->dev.type = &fcoe_fcf_device_type;
51554 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51555 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51556 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51557
51558 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51559 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51560 {
51561 int error;
51562
51563 - atomic_set(&ctlr_num, 0);
51564 - atomic_set(&fcf_num, 0);
51565 + atomic_set_unchecked(&ctlr_num, 0);
51566 + atomic_set_unchecked(&fcf_num, 0);
51567
51568 error = bus_register(&fcoe_bus_type);
51569 if (error)
51570 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51571 index 6de80e3..a11e0ac 100644
51572 --- a/drivers/scsi/hosts.c
51573 +++ b/drivers/scsi/hosts.c
51574 @@ -42,7 +42,7 @@
51575 #include "scsi_logging.h"
51576
51577
51578 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51579 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51580
51581
51582 static void scsi_host_cls_release(struct device *dev)
51583 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51584 * subtract one because we increment first then return, but we need to
51585 * know what the next host number was before increment
51586 */
51587 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51588 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51589 shost->dma_channel = 0xff;
51590
51591 /* These three are default values which can be overridden */
51592 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51593 index 6b35d0d..2880305 100644
51594 --- a/drivers/scsi/hpsa.c
51595 +++ b/drivers/scsi/hpsa.c
51596 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51597 unsigned long flags;
51598
51599 if (h->transMethod & CFGTBL_Trans_io_accel1)
51600 - return h->access.command_completed(h, q);
51601 + return h->access->command_completed(h, q);
51602
51603 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51604 - return h->access.command_completed(h, q);
51605 + return h->access->command_completed(h, q);
51606
51607 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51608 a = rq->head[rq->current_entry];
51609 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51610 while (!list_empty(&h->reqQ)) {
51611 c = list_entry(h->reqQ.next, struct CommandList, list);
51612 /* can't do anything if fifo is full */
51613 - if ((h->access.fifo_full(h))) {
51614 + if ((h->access->fifo_full(h))) {
51615 h->fifo_recently_full = 1;
51616 dev_warn(&h->pdev->dev, "fifo full\n");
51617 break;
51618 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51619
51620 /* Tell the controller execute command */
51621 spin_unlock_irqrestore(&h->lock, *flags);
51622 - h->access.submit_command(h, c);
51623 + h->access->submit_command(h, c);
51624 spin_lock_irqsave(&h->lock, *flags);
51625 }
51626 }
51627 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51628
51629 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51630 {
51631 - return h->access.command_completed(h, q);
51632 + return h->access->command_completed(h, q);
51633 }
51634
51635 static inline bool interrupt_pending(struct ctlr_info *h)
51636 {
51637 - return h->access.intr_pending(h);
51638 + return h->access->intr_pending(h);
51639 }
51640
51641 static inline long interrupt_not_for_us(struct ctlr_info *h)
51642 {
51643 - return (h->access.intr_pending(h) == 0) ||
51644 + return (h->access->intr_pending(h) == 0) ||
51645 (h->interrupts_enabled == 0);
51646 }
51647
51648 @@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51649 if (prod_index < 0)
51650 return -ENODEV;
51651 h->product_name = products[prod_index].product_name;
51652 - h->access = *(products[prod_index].access);
51653 + h->access = products[prod_index].access;
51654
51655 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51656 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51657 @@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51658 unsigned long flags;
51659 u32 lockup_detected;
51660
51661 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51662 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51663 spin_lock_irqsave(&h->lock, flags);
51664 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51665 if (!lockup_detected) {
51666 @@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51667 }
51668
51669 /* make sure the board interrupts are off */
51670 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51671 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51672
51673 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51674 goto clean2;
51675 @@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51676 * fake ones to scoop up any residual completions.
51677 */
51678 spin_lock_irqsave(&h->lock, flags);
51679 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51680 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51681 spin_unlock_irqrestore(&h->lock, flags);
51682 free_irqs(h);
51683 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51684 @@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51685 dev_info(&h->pdev->dev, "Board READY.\n");
51686 dev_info(&h->pdev->dev,
51687 "Waiting for stale completions to drain.\n");
51688 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51689 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51690 msleep(10000);
51691 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51692 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51693
51694 rc = controller_reset_failed(h->cfgtable);
51695 if (rc)
51696 @@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51697 h->drv_req_rescan = 0;
51698
51699 /* Turn the interrupts on so we can service requests */
51700 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51701 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51702
51703 hpsa_hba_inquiry(h);
51704 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51705 @@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51706 * To write all data in the battery backed cache to disks
51707 */
51708 hpsa_flush_cache(h);
51709 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51710 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51711 hpsa_free_irqs_and_disable_msix(h);
51712 }
51713
51714 @@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51715 CFGTBL_Trans_enable_directed_msix |
51716 (trans_support & (CFGTBL_Trans_io_accel1 |
51717 CFGTBL_Trans_io_accel2));
51718 - struct access_method access = SA5_performant_access;
51719 + struct access_method *access = &SA5_performant_access;
51720
51721 /* This is a bit complicated. There are 8 registers on
51722 * the controller which we write to to tell it 8 different
51723 @@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51724 * perform the superfluous readl() after each command submission.
51725 */
51726 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51727 - access = SA5_performant_access_no_read;
51728 + access = &SA5_performant_access_no_read;
51729
51730 /* Controller spec: zero out this buffer. */
51731 for (i = 0; i < h->nreply_queues; i++)
51732 @@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51733 * enable outbound interrupt coalescing in accelerator mode;
51734 */
51735 if (trans_support & CFGTBL_Trans_io_accel1) {
51736 - access = SA5_ioaccel_mode1_access;
51737 + access = &SA5_ioaccel_mode1_access;
51738 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51739 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51740 } else {
51741 if (trans_support & CFGTBL_Trans_io_accel2) {
51742 - access = SA5_ioaccel_mode2_access;
51743 + access = &SA5_ioaccel_mode2_access;
51744 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51745 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51746 }
51747 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51748 index 24472ce..8782caf 100644
51749 --- a/drivers/scsi/hpsa.h
51750 +++ b/drivers/scsi/hpsa.h
51751 @@ -127,7 +127,7 @@ struct ctlr_info {
51752 unsigned int msix_vector;
51753 unsigned int msi_vector;
51754 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51755 - struct access_method access;
51756 + struct access_method *access;
51757 char hba_mode_enabled;
51758
51759 /* queue and queue Info */
51760 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51761 }
51762
51763 static struct access_method SA5_access = {
51764 - SA5_submit_command,
51765 - SA5_intr_mask,
51766 - SA5_fifo_full,
51767 - SA5_intr_pending,
51768 - SA5_completed,
51769 + .submit_command = SA5_submit_command,
51770 + .set_intr_mask = SA5_intr_mask,
51771 + .fifo_full = SA5_fifo_full,
51772 + .intr_pending = SA5_intr_pending,
51773 + .command_completed = SA5_completed,
51774 };
51775
51776 static struct access_method SA5_ioaccel_mode1_access = {
51777 - SA5_submit_command,
51778 - SA5_performant_intr_mask,
51779 - SA5_fifo_full,
51780 - SA5_ioaccel_mode1_intr_pending,
51781 - SA5_ioaccel_mode1_completed,
51782 + .submit_command = SA5_submit_command,
51783 + .set_intr_mask = SA5_performant_intr_mask,
51784 + .fifo_full = SA5_fifo_full,
51785 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51786 + .command_completed = SA5_ioaccel_mode1_completed,
51787 };
51788
51789 static struct access_method SA5_ioaccel_mode2_access = {
51790 - SA5_submit_command_ioaccel2,
51791 - SA5_performant_intr_mask,
51792 - SA5_fifo_full,
51793 - SA5_performant_intr_pending,
51794 - SA5_performant_completed,
51795 + .submit_command = SA5_submit_command_ioaccel2,
51796 + .set_intr_mask = SA5_performant_intr_mask,
51797 + .fifo_full = SA5_fifo_full,
51798 + .intr_pending = SA5_performant_intr_pending,
51799 + .command_completed = SA5_performant_completed,
51800 };
51801
51802 static struct access_method SA5_performant_access = {
51803 - SA5_submit_command,
51804 - SA5_performant_intr_mask,
51805 - SA5_fifo_full,
51806 - SA5_performant_intr_pending,
51807 - SA5_performant_completed,
51808 + .submit_command = SA5_submit_command,
51809 + .set_intr_mask = SA5_performant_intr_mask,
51810 + .fifo_full = SA5_fifo_full,
51811 + .intr_pending = SA5_performant_intr_pending,
51812 + .command_completed = SA5_performant_completed,
51813 };
51814
51815 static struct access_method SA5_performant_access_no_read = {
51816 - SA5_submit_command_no_read,
51817 - SA5_performant_intr_mask,
51818 - SA5_fifo_full,
51819 - SA5_performant_intr_pending,
51820 - SA5_performant_completed,
51821 + .submit_command = SA5_submit_command_no_read,
51822 + .set_intr_mask = SA5_performant_intr_mask,
51823 + .fifo_full = SA5_fifo_full,
51824 + .intr_pending = SA5_performant_intr_pending,
51825 + .command_completed = SA5_performant_completed,
51826 };
51827
51828 struct board_type {
51829 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51830 index 1b3a094..068e683 100644
51831 --- a/drivers/scsi/libfc/fc_exch.c
51832 +++ b/drivers/scsi/libfc/fc_exch.c
51833 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51834 u16 pool_max_index;
51835
51836 struct {
51837 - atomic_t no_free_exch;
51838 - atomic_t no_free_exch_xid;
51839 - atomic_t xid_not_found;
51840 - atomic_t xid_busy;
51841 - atomic_t seq_not_found;
51842 - atomic_t non_bls_resp;
51843 + atomic_unchecked_t no_free_exch;
51844 + atomic_unchecked_t no_free_exch_xid;
51845 + atomic_unchecked_t xid_not_found;
51846 + atomic_unchecked_t xid_busy;
51847 + atomic_unchecked_t seq_not_found;
51848 + atomic_unchecked_t non_bls_resp;
51849 } stats;
51850 };
51851
51852 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51853 /* allocate memory for exchange */
51854 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51855 if (!ep) {
51856 - atomic_inc(&mp->stats.no_free_exch);
51857 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51858 goto out;
51859 }
51860 memset(ep, 0, sizeof(*ep));
51861 @@ -874,7 +874,7 @@ out:
51862 return ep;
51863 err:
51864 spin_unlock_bh(&pool->lock);
51865 - atomic_inc(&mp->stats.no_free_exch_xid);
51866 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51867 mempool_free(ep, mp->ep_pool);
51868 return NULL;
51869 }
51870 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51871 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51872 ep = fc_exch_find(mp, xid);
51873 if (!ep) {
51874 - atomic_inc(&mp->stats.xid_not_found);
51875 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51876 reject = FC_RJT_OX_ID;
51877 goto out;
51878 }
51879 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51880 ep = fc_exch_find(mp, xid);
51881 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51882 if (ep) {
51883 - atomic_inc(&mp->stats.xid_busy);
51884 + atomic_inc_unchecked(&mp->stats.xid_busy);
51885 reject = FC_RJT_RX_ID;
51886 goto rel;
51887 }
51888 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51889 }
51890 xid = ep->xid; /* get our XID */
51891 } else if (!ep) {
51892 - atomic_inc(&mp->stats.xid_not_found);
51893 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51894 reject = FC_RJT_RX_ID; /* XID not found */
51895 goto out;
51896 }
51897 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51898 } else {
51899 sp = &ep->seq;
51900 if (sp->id != fh->fh_seq_id) {
51901 - atomic_inc(&mp->stats.seq_not_found);
51902 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51903 if (f_ctl & FC_FC_END_SEQ) {
51904 /*
51905 * Update sequence_id based on incoming last
51906 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51907
51908 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51909 if (!ep) {
51910 - atomic_inc(&mp->stats.xid_not_found);
51911 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51912 goto out;
51913 }
51914 if (ep->esb_stat & ESB_ST_COMPLETE) {
51915 - atomic_inc(&mp->stats.xid_not_found);
51916 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51917 goto rel;
51918 }
51919 if (ep->rxid == FC_XID_UNKNOWN)
51920 ep->rxid = ntohs(fh->fh_rx_id);
51921 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51922 - atomic_inc(&mp->stats.xid_not_found);
51923 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51924 goto rel;
51925 }
51926 if (ep->did != ntoh24(fh->fh_s_id) &&
51927 ep->did != FC_FID_FLOGI) {
51928 - atomic_inc(&mp->stats.xid_not_found);
51929 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51930 goto rel;
51931 }
51932 sof = fr_sof(fp);
51933 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51934 sp->ssb_stat |= SSB_ST_RESP;
51935 sp->id = fh->fh_seq_id;
51936 } else if (sp->id != fh->fh_seq_id) {
51937 - atomic_inc(&mp->stats.seq_not_found);
51938 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51939 goto rel;
51940 }
51941
51942 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51943 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51944
51945 if (!sp)
51946 - atomic_inc(&mp->stats.xid_not_found);
51947 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51948 else
51949 - atomic_inc(&mp->stats.non_bls_resp);
51950 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51951
51952 fc_frame_free(fp);
51953 }
51954 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51955
51956 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51957 mp = ema->mp;
51958 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51959 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51960 st->fc_no_free_exch_xid +=
51961 - atomic_read(&mp->stats.no_free_exch_xid);
51962 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51963 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51964 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51965 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51966 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51967 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51968 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51969 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51970 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51971 }
51972 }
51973 EXPORT_SYMBOL(fc_exch_update_stats);
51974 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51975 index 766098a..1c6c971 100644
51976 --- a/drivers/scsi/libsas/sas_ata.c
51977 +++ b/drivers/scsi/libsas/sas_ata.c
51978 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51979 .postreset = ata_std_postreset,
51980 .error_handler = ata_std_error_handler,
51981 .post_internal_cmd = sas_ata_post_internal,
51982 - .qc_defer = ata_std_qc_defer,
51983 + .qc_defer = ata_std_qc_defer,
51984 .qc_prep = ata_noop_qc_prep,
51985 .qc_issue = sas_ata_qc_issue,
51986 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51987 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51988 index 434e903..5a4a79b 100644
51989 --- a/drivers/scsi/lpfc/lpfc.h
51990 +++ b/drivers/scsi/lpfc/lpfc.h
51991 @@ -430,7 +430,7 @@ struct lpfc_vport {
51992 struct dentry *debug_nodelist;
51993 struct dentry *vport_debugfs_root;
51994 struct lpfc_debugfs_trc *disc_trc;
51995 - atomic_t disc_trc_cnt;
51996 + atomic_unchecked_t disc_trc_cnt;
51997 #endif
51998 uint8_t stat_data_enabled;
51999 uint8_t stat_data_blocked;
52000 @@ -880,8 +880,8 @@ struct lpfc_hba {
52001 struct timer_list fabric_block_timer;
52002 unsigned long bit_flags;
52003 #define FABRIC_COMANDS_BLOCKED 0
52004 - atomic_t num_rsrc_err;
52005 - atomic_t num_cmd_success;
52006 + atomic_unchecked_t num_rsrc_err;
52007 + atomic_unchecked_t num_cmd_success;
52008 unsigned long last_rsrc_error_time;
52009 unsigned long last_ramp_down_time;
52010 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52011 @@ -916,7 +916,7 @@ struct lpfc_hba {
52012
52013 struct dentry *debug_slow_ring_trc;
52014 struct lpfc_debugfs_trc *slow_ring_trc;
52015 - atomic_t slow_ring_trc_cnt;
52016 + atomic_unchecked_t slow_ring_trc_cnt;
52017 /* iDiag debugfs sub-directory */
52018 struct dentry *idiag_root;
52019 struct dentry *idiag_pci_cfg;
52020 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52021 index b0aedce..89c6ca6 100644
52022 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52023 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52024 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52025
52026 #include <linux/debugfs.h>
52027
52028 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52029 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52030 static unsigned long lpfc_debugfs_start_time = 0L;
52031
52032 /* iDiag */
52033 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52034 lpfc_debugfs_enable = 0;
52035
52036 len = 0;
52037 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52038 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52039 (lpfc_debugfs_max_disc_trc - 1);
52040 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52041 dtp = vport->disc_trc + i;
52042 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52043 lpfc_debugfs_enable = 0;
52044
52045 len = 0;
52046 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52047 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52048 (lpfc_debugfs_max_slow_ring_trc - 1);
52049 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52050 dtp = phba->slow_ring_trc + i;
52051 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52052 !vport || !vport->disc_trc)
52053 return;
52054
52055 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52056 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52057 (lpfc_debugfs_max_disc_trc - 1);
52058 dtp = vport->disc_trc + index;
52059 dtp->fmt = fmt;
52060 dtp->data1 = data1;
52061 dtp->data2 = data2;
52062 dtp->data3 = data3;
52063 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52064 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52065 dtp->jif = jiffies;
52066 #endif
52067 return;
52068 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52069 !phba || !phba->slow_ring_trc)
52070 return;
52071
52072 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52073 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52074 (lpfc_debugfs_max_slow_ring_trc - 1);
52075 dtp = phba->slow_ring_trc + index;
52076 dtp->fmt = fmt;
52077 dtp->data1 = data1;
52078 dtp->data2 = data2;
52079 dtp->data3 = data3;
52080 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52081 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52082 dtp->jif = jiffies;
52083 #endif
52084 return;
52085 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52086 "slow_ring buffer\n");
52087 goto debug_failed;
52088 }
52089 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52090 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52091 memset(phba->slow_ring_trc, 0,
52092 (sizeof(struct lpfc_debugfs_trc) *
52093 lpfc_debugfs_max_slow_ring_trc));
52094 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52095 "buffer\n");
52096 goto debug_failed;
52097 }
52098 - atomic_set(&vport->disc_trc_cnt, 0);
52099 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52100
52101 snprintf(name, sizeof(name), "discovery_trace");
52102 vport->debug_disc_trc =
52103 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52104 index a5769a9..718ecc7 100644
52105 --- a/drivers/scsi/lpfc/lpfc_init.c
52106 +++ b/drivers/scsi/lpfc/lpfc_init.c
52107 @@ -11299,8 +11299,10 @@ lpfc_init(void)
52108 "misc_register returned with status %d", error);
52109
52110 if (lpfc_enable_npiv) {
52111 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52112 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52113 + pax_open_kernel();
52114 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52115 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52116 + pax_close_kernel();
52117 }
52118 lpfc_transport_template =
52119 fc_attach_transport(&lpfc_transport_functions);
52120 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52121 index 7862c55..5aa65df 100644
52122 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52123 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52124 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52125 uint32_t evt_posted;
52126
52127 spin_lock_irqsave(&phba->hbalock, flags);
52128 - atomic_inc(&phba->num_rsrc_err);
52129 + atomic_inc_unchecked(&phba->num_rsrc_err);
52130 phba->last_rsrc_error_time = jiffies;
52131
52132 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52133 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52134 unsigned long num_rsrc_err, num_cmd_success;
52135 int i;
52136
52137 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52138 - num_cmd_success = atomic_read(&phba->num_cmd_success);
52139 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52140 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52141
52142 /*
52143 * The error and success command counters are global per
52144 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52145 }
52146 }
52147 lpfc_destroy_vport_work_array(phba, vports);
52148 - atomic_set(&phba->num_rsrc_err, 0);
52149 - atomic_set(&phba->num_cmd_success, 0);
52150 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
52151 + atomic_set_unchecked(&phba->num_cmd_success, 0);
52152 }
52153
52154 /**
52155 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52156 index dd46101..ca80eb9 100644
52157 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52158 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52159 @@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
52160 {
52161 struct scsi_device *sdev = to_scsi_device(dev);
52162 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52163 - static struct _raid_device *raid_device;
52164 + struct _raid_device *raid_device;
52165 unsigned long flags;
52166 Mpi2RaidVolPage0_t vol_pg0;
52167 Mpi2ConfigReply_t mpi_reply;
52168 @@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
52169 {
52170 struct scsi_device *sdev = to_scsi_device(dev);
52171 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52172 - static struct _raid_device *raid_device;
52173 + struct _raid_device *raid_device;
52174 unsigned long flags;
52175 Mpi2RaidVolPage0_t vol_pg0;
52176 Mpi2ConfigReply_t mpi_reply;
52177 @@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52178 Mpi2EventDataIrOperationStatus_t *event_data =
52179 (Mpi2EventDataIrOperationStatus_t *)
52180 fw_event->event_data;
52181 - static struct _raid_device *raid_device;
52182 + struct _raid_device *raid_device;
52183 unsigned long flags;
52184 u16 handle;
52185
52186 @@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52187 u64 sas_address;
52188 struct _sas_device *sas_device;
52189 struct _sas_node *expander_device;
52190 - static struct _raid_device *raid_device;
52191 + struct _raid_device *raid_device;
52192 u8 retry_count;
52193 unsigned long flags;
52194
52195 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52196 index 6f3275d..fa5e6b6 100644
52197 --- a/drivers/scsi/pmcraid.c
52198 +++ b/drivers/scsi/pmcraid.c
52199 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52200 res->scsi_dev = scsi_dev;
52201 scsi_dev->hostdata = res;
52202 res->change_detected = 0;
52203 - atomic_set(&res->read_failures, 0);
52204 - atomic_set(&res->write_failures, 0);
52205 + atomic_set_unchecked(&res->read_failures, 0);
52206 + atomic_set_unchecked(&res->write_failures, 0);
52207 rc = 0;
52208 }
52209 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52210 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52211
52212 /* If this was a SCSI read/write command keep count of errors */
52213 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52214 - atomic_inc(&res->read_failures);
52215 + atomic_inc_unchecked(&res->read_failures);
52216 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52217 - atomic_inc(&res->write_failures);
52218 + atomic_inc_unchecked(&res->write_failures);
52219
52220 if (!RES_IS_GSCSI(res->cfg_entry) &&
52221 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52222 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52223 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52224 * hrrq_id assigned here in queuecommand
52225 */
52226 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52227 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52228 pinstance->num_hrrq;
52229 cmd->cmd_done = pmcraid_io_done;
52230
52231 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52232 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52233 * hrrq_id assigned here in queuecommand
52234 */
52235 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52236 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52237 pinstance->num_hrrq;
52238
52239 if (request_size) {
52240 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52241
52242 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52243 /* add resources only after host is added into system */
52244 - if (!atomic_read(&pinstance->expose_resources))
52245 + if (!atomic_read_unchecked(&pinstance->expose_resources))
52246 return;
52247
52248 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52249 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52250 init_waitqueue_head(&pinstance->reset_wait_q);
52251
52252 atomic_set(&pinstance->outstanding_cmds, 0);
52253 - atomic_set(&pinstance->last_message_id, 0);
52254 - atomic_set(&pinstance->expose_resources, 0);
52255 + atomic_set_unchecked(&pinstance->last_message_id, 0);
52256 + atomic_set_unchecked(&pinstance->expose_resources, 0);
52257
52258 INIT_LIST_HEAD(&pinstance->free_res_q);
52259 INIT_LIST_HEAD(&pinstance->used_res_q);
52260 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52261 /* Schedule worker thread to handle CCN and take care of adding and
52262 * removing devices to OS
52263 */
52264 - atomic_set(&pinstance->expose_resources, 1);
52265 + atomic_set_unchecked(&pinstance->expose_resources, 1);
52266 schedule_work(&pinstance->worker_q);
52267 return rc;
52268
52269 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52270 index e1d150f..6c6df44 100644
52271 --- a/drivers/scsi/pmcraid.h
52272 +++ b/drivers/scsi/pmcraid.h
52273 @@ -748,7 +748,7 @@ struct pmcraid_instance {
52274 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52275
52276 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52277 - atomic_t last_message_id;
52278 + atomic_unchecked_t last_message_id;
52279
52280 /* configuration table */
52281 struct pmcraid_config_table *cfg_table;
52282 @@ -777,7 +777,7 @@ struct pmcraid_instance {
52283 atomic_t outstanding_cmds;
52284
52285 /* should add/delete resources to mid-layer now ?*/
52286 - atomic_t expose_resources;
52287 + atomic_unchecked_t expose_resources;
52288
52289
52290
52291 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52292 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52293 };
52294 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52295 - atomic_t read_failures; /* count of failed READ commands */
52296 - atomic_t write_failures; /* count of failed WRITE commands */
52297 + atomic_unchecked_t read_failures; /* count of failed READ commands */
52298 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52299
52300 /* To indicate add/delete/modify during CCN */
52301 u8 change_detected;
52302 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52303 index 16fe519..3b1ec82 100644
52304 --- a/drivers/scsi/qla2xxx/qla_attr.c
52305 +++ b/drivers/scsi/qla2xxx/qla_attr.c
52306 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52307 return 0;
52308 }
52309
52310 -struct fc_function_template qla2xxx_transport_functions = {
52311 +fc_function_template_no_const qla2xxx_transport_functions = {
52312
52313 .show_host_node_name = 1,
52314 .show_host_port_name = 1,
52315 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52316 .bsg_timeout = qla24xx_bsg_timeout,
52317 };
52318
52319 -struct fc_function_template qla2xxx_transport_vport_functions = {
52320 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
52321
52322 .show_host_node_name = 1,
52323 .show_host_port_name = 1,
52324 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52325 index d646540..5b13554 100644
52326 --- a/drivers/scsi/qla2xxx/qla_gbl.h
52327 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
52328 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52329 struct device_attribute;
52330 extern struct device_attribute *qla2x00_host_attrs[];
52331 struct fc_function_template;
52332 -extern struct fc_function_template qla2xxx_transport_functions;
52333 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52334 +extern fc_function_template_no_const qla2xxx_transport_functions;
52335 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52336 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52337 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52338 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52339 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52340 index be9698d..a328a41 100644
52341 --- a/drivers/scsi/qla2xxx/qla_os.c
52342 +++ b/drivers/scsi/qla2xxx/qla_os.c
52343 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52344 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52345 /* Ok, a 64bit DMA mask is applicable. */
52346 ha->flags.enable_64bit_addressing = 1;
52347 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52348 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52349 + pax_open_kernel();
52350 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52351 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52352 + pax_close_kernel();
52353 return;
52354 }
52355 }
52356 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52357 index 8f6d0fb..1b21097 100644
52358 --- a/drivers/scsi/qla4xxx/ql4_def.h
52359 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52360 @@ -305,7 +305,7 @@ struct ddb_entry {
52361 * (4000 only) */
52362 atomic_t relogin_timer; /* Max Time to wait for
52363 * relogin to complete */
52364 - atomic_t relogin_retry_count; /* Num of times relogin has been
52365 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52366 * retried */
52367 uint32_t default_time2wait; /* Default Min time between
52368 * relogins (+aens) */
52369 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52370 index 199fcf7..3c3a918 100644
52371 --- a/drivers/scsi/qla4xxx/ql4_os.c
52372 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52373 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52374 */
52375 if (!iscsi_is_session_online(cls_sess)) {
52376 /* Reset retry relogin timer */
52377 - atomic_inc(&ddb_entry->relogin_retry_count);
52378 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52379 DEBUG2(ql4_printk(KERN_INFO, ha,
52380 "%s: index[%d] relogin timed out-retrying"
52381 " relogin (%d), retry (%d)\n", __func__,
52382 ddb_entry->fw_ddb_index,
52383 - atomic_read(&ddb_entry->relogin_retry_count),
52384 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52385 ddb_entry->default_time2wait + 4));
52386 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52387 atomic_set(&ddb_entry->retry_relogin_timer,
52388 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52389
52390 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52391 atomic_set(&ddb_entry->relogin_timer, 0);
52392 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52393 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52394 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52395 ddb_entry->default_relogin_timeout =
52396 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52397 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52398 index d81f3cc..0093e5b 100644
52399 --- a/drivers/scsi/scsi.c
52400 +++ b/drivers/scsi/scsi.c
52401 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52402 struct Scsi_Host *host = cmd->device->host;
52403 int rtn = 0;
52404
52405 - atomic_inc(&cmd->device->iorequest_cnt);
52406 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52407
52408 /* check if the device is still usable */
52409 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52410 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52411 index aaea4b9..c64408d 100644
52412 --- a/drivers/scsi/scsi_lib.c
52413 +++ b/drivers/scsi/scsi_lib.c
52414 @@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52415 shost = sdev->host;
52416 scsi_init_cmd_errh(cmd);
52417 cmd->result = DID_NO_CONNECT << 16;
52418 - atomic_inc(&cmd->device->iorequest_cnt);
52419 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52420
52421 /*
52422 * SCSI request completion path will do scsi_device_unbusy(),
52423 @@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52424
52425 INIT_LIST_HEAD(&cmd->eh_entry);
52426
52427 - atomic_inc(&cmd->device->iodone_cnt);
52428 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52429 if (cmd->result)
52430 - atomic_inc(&cmd->device->ioerr_cnt);
52431 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52432
52433 disposition = scsi_decide_disposition(cmd);
52434 if (disposition != SUCCESS &&
52435 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52436 index 8b4105a..1f58363 100644
52437 --- a/drivers/scsi/scsi_sysfs.c
52438 +++ b/drivers/scsi/scsi_sysfs.c
52439 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52440 char *buf) \
52441 { \
52442 struct scsi_device *sdev = to_scsi_device(dev); \
52443 - unsigned long long count = atomic_read(&sdev->field); \
52444 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52445 return snprintf(buf, 20, "0x%llx\n", count); \
52446 } \
52447 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52448 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52449 index 5d6f348..18778a6b 100644
52450 --- a/drivers/scsi/scsi_transport_fc.c
52451 +++ b/drivers/scsi/scsi_transport_fc.c
52452 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52453 * Netlink Infrastructure
52454 */
52455
52456 -static atomic_t fc_event_seq;
52457 +static atomic_unchecked_t fc_event_seq;
52458
52459 /**
52460 * fc_get_event_number - Obtain the next sequential FC event number
52461 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52462 u32
52463 fc_get_event_number(void)
52464 {
52465 - return atomic_add_return(1, &fc_event_seq);
52466 + return atomic_add_return_unchecked(1, &fc_event_seq);
52467 }
52468 EXPORT_SYMBOL(fc_get_event_number);
52469
52470 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52471 {
52472 int error;
52473
52474 - atomic_set(&fc_event_seq, 0);
52475 + atomic_set_unchecked(&fc_event_seq, 0);
52476
52477 error = transport_class_register(&fc_host_class);
52478 if (error)
52479 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52480 char *cp;
52481
52482 *val = simple_strtoul(buf, &cp, 0);
52483 - if ((*cp && (*cp != '\n')) || (*val < 0))
52484 + if (*cp && (*cp != '\n'))
52485 return -EINVAL;
52486 /*
52487 * Check for overflow; dev_loss_tmo is u32
52488 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52489 index 67d43e3..8cee73c 100644
52490 --- a/drivers/scsi/scsi_transport_iscsi.c
52491 +++ b/drivers/scsi/scsi_transport_iscsi.c
52492 @@ -79,7 +79,7 @@ struct iscsi_internal {
52493 struct transport_container session_cont;
52494 };
52495
52496 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52497 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52498 static struct workqueue_struct *iscsi_eh_timer_workq;
52499
52500 static DEFINE_IDA(iscsi_sess_ida);
52501 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52502 int err;
52503
52504 ihost = shost->shost_data;
52505 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52506 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52507
52508 if (target_id == ISCSI_MAX_TARGET) {
52509 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52510 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52511 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52512 ISCSI_TRANSPORT_VERSION);
52513
52514 - atomic_set(&iscsi_session_nr, 0);
52515 + atomic_set_unchecked(&iscsi_session_nr, 0);
52516
52517 err = class_register(&iscsi_transport_class);
52518 if (err)
52519 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52520 index ae45bd9..c32a586 100644
52521 --- a/drivers/scsi/scsi_transport_srp.c
52522 +++ b/drivers/scsi/scsi_transport_srp.c
52523 @@ -35,7 +35,7 @@
52524 #include "scsi_priv.h"
52525
52526 struct srp_host_attrs {
52527 - atomic_t next_port_id;
52528 + atomic_unchecked_t next_port_id;
52529 };
52530 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52531
52532 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52533 struct Scsi_Host *shost = dev_to_shost(dev);
52534 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52535
52536 - atomic_set(&srp_host->next_port_id, 0);
52537 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52538 return 0;
52539 }
52540
52541 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52542 rport_fast_io_fail_timedout);
52543 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52544
52545 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52546 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52547 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52548
52549 transport_setup_device(&rport->dev);
52550 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52551 index 2c2041c..9d94085 100644
52552 --- a/drivers/scsi/sd.c
52553 +++ b/drivers/scsi/sd.c
52554 @@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52555 sdkp->disk = gd;
52556 sdkp->index = index;
52557 atomic_set(&sdkp->openers, 0);
52558 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52559 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52560
52561 if (!sdp->request_queue->rq_timeout) {
52562 if (sdp->type != TYPE_MOD)
52563 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52564 index 01cf888..59e0475 100644
52565 --- a/drivers/scsi/sg.c
52566 +++ b/drivers/scsi/sg.c
52567 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52568 sdp->disk->disk_name,
52569 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52570 NULL,
52571 - (char *)arg);
52572 + (char __user *)arg);
52573 case BLKTRACESTART:
52574 return blk_trace_startstop(sdp->device->request_queue, 1);
52575 case BLKTRACESTOP:
52576 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52577 index ca935df..ae8a3dc 100644
52578 --- a/drivers/spi/spi.c
52579 +++ b/drivers/spi/spi.c
52580 @@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52581 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52582
52583 /* portable code must never pass more than 32 bytes */
52584 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52585 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52586
52587 static u8 *buf;
52588
52589 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52590 index b41429f..2de5373 100644
52591 --- a/drivers/staging/android/timed_output.c
52592 +++ b/drivers/staging/android/timed_output.c
52593 @@ -25,7 +25,7 @@
52594 #include "timed_output.h"
52595
52596 static struct class *timed_output_class;
52597 -static atomic_t device_count;
52598 +static atomic_unchecked_t device_count;
52599
52600 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52601 char *buf)
52602 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52603 timed_output_class = class_create(THIS_MODULE, "timed_output");
52604 if (IS_ERR(timed_output_class))
52605 return PTR_ERR(timed_output_class);
52606 - atomic_set(&device_count, 0);
52607 + atomic_set_unchecked(&device_count, 0);
52608 timed_output_class->dev_groups = timed_output_groups;
52609 }
52610
52611 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52612 if (ret < 0)
52613 return ret;
52614
52615 - tdev->index = atomic_inc_return(&device_count);
52616 + tdev->index = atomic_inc_return_unchecked(&device_count);
52617 tdev->dev = device_create(timed_output_class, NULL,
52618 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52619 if (IS_ERR(tdev->dev))
52620 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52621 index 001348c..cfaac8a 100644
52622 --- a/drivers/staging/gdm724x/gdm_tty.c
52623 +++ b/drivers/staging/gdm724x/gdm_tty.c
52624 @@ -44,7 +44,7 @@
52625 #define gdm_tty_send_control(n, r, v, d, l) (\
52626 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52627
52628 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52629 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52630
52631 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52632 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52633 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52634 index 6b22106..6c6e641 100644
52635 --- a/drivers/staging/imx-drm/imx-drm-core.c
52636 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52637 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52638 if (imxdrm->pipes >= MAX_CRTC)
52639 return -EINVAL;
52640
52641 - if (imxdrm->drm->open_count)
52642 + if (local_read(&imxdrm->drm->open_count))
52643 return -EBUSY;
52644
52645 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52646 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52647 index bcce919..f30fcf9 100644
52648 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52649 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52650 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52651 return 0;
52652 }
52653
52654 -sfw_test_client_ops_t brw_test_client;
52655 -void brw_init_test_client(void)
52656 -{
52657 - brw_test_client.tso_init = brw_client_init;
52658 - brw_test_client.tso_fini = brw_client_fini;
52659 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52660 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52661 +sfw_test_client_ops_t brw_test_client = {
52662 + .tso_init = brw_client_init,
52663 + .tso_fini = brw_client_fini,
52664 + .tso_prep_rpc = brw_client_prep_rpc,
52665 + .tso_done_rpc = brw_client_done_rpc,
52666 };
52667
52668 srpc_service_t brw_test_service;
52669 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52670 index 7e83dff..1f9a545 100644
52671 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52672 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52673 @@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52674
52675 extern sfw_test_client_ops_t ping_test_client;
52676 extern srpc_service_t ping_test_service;
52677 -extern void ping_init_test_client(void);
52678 extern void ping_init_test_service(void);
52679
52680 extern sfw_test_client_ops_t brw_test_client;
52681 extern srpc_service_t brw_test_service;
52682 -extern void brw_init_test_client(void);
52683 extern void brw_init_test_service(void);
52684
52685
52686 @@ -1682,12 +1680,10 @@ sfw_startup (void)
52687 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52688 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52689
52690 - brw_init_test_client();
52691 brw_init_test_service();
52692 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52693 LASSERT (rc == 0);
52694
52695 - ping_init_test_client();
52696 ping_init_test_service();
52697 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52698 LASSERT (rc == 0);
52699 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52700 index 750cac4..e4d751f 100644
52701 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52702 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52703 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52704 return 0;
52705 }
52706
52707 -sfw_test_client_ops_t ping_test_client;
52708 -void ping_init_test_client(void)
52709 -{
52710 - ping_test_client.tso_init = ping_client_init;
52711 - ping_test_client.tso_fini = ping_client_fini;
52712 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52713 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52714 -}
52715 +sfw_test_client_ops_t ping_test_client = {
52716 + .tso_init = ping_client_init,
52717 + .tso_fini = ping_client_fini,
52718 + .tso_prep_rpc = ping_client_prep_rpc,
52719 + .tso_done_rpc = ping_client_done_rpc,
52720 +};
52721
52722 srpc_service_t ping_test_service;
52723 void ping_init_test_service(void)
52724 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52725 index 30b1812f..9e5bd0b 100644
52726 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52727 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52728 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52729 ldlm_completion_callback lcs_completion;
52730 ldlm_blocking_callback lcs_blocking;
52731 ldlm_glimpse_callback lcs_glimpse;
52732 -};
52733 +} __no_const;
52734
52735 /* ldlm_lockd.c */
52736 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52737 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52738 index 489bdd3..65058081 100644
52739 --- a/drivers/staging/lustre/lustre/include/obd.h
52740 +++ b/drivers/staging/lustre/lustre/include/obd.h
52741 @@ -1438,7 +1438,7 @@ struct md_ops {
52742 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52743 * wrapper function in include/linux/obd_class.h.
52744 */
52745 -};
52746 +} __no_const;
52747
52748 struct lsm_operations {
52749 void (*lsm_free)(struct lov_stripe_md *);
52750 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52751 index b798daa..b28ca8f 100644
52752 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52753 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52754 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52755 int added = (mode == LCK_NL);
52756 int overlaps = 0;
52757 int splitted = 0;
52758 - const struct ldlm_callback_suite null_cbs = { NULL };
52759 + const struct ldlm_callback_suite null_cbs = { };
52760
52761 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52762 *flags, new->l_policy_data.l_flock.owner,
52763 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52764 index 13a9266..3439390 100644
52765 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52766 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52767 @@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52768 void __user *buffer, size_t *lenp, loff_t *ppos)
52769 {
52770 int rc, max_delay_cs;
52771 - struct ctl_table dummy = *table;
52772 + ctl_table_no_const dummy = *table;
52773 long d;
52774
52775 dummy.data = &max_delay_cs;
52776 @@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52777 void __user *buffer, size_t *lenp, loff_t *ppos)
52778 {
52779 int rc, min_delay_cs;
52780 - struct ctl_table dummy = *table;
52781 + ctl_table_no_const dummy = *table;
52782 long d;
52783
52784 dummy.data = &min_delay_cs;
52785 @@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52786 void __user *buffer, size_t *lenp, loff_t *ppos)
52787 {
52788 int rc, backoff;
52789 - struct ctl_table dummy = *table;
52790 + ctl_table_no_const dummy = *table;
52791
52792 dummy.data = &backoff;
52793 dummy.proc_handler = &proc_dointvec;
52794 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52795 index 3396858..c0bd996 100644
52796 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52797 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52798 @@ -314,11 +314,11 @@ out:
52799
52800
52801 struct cfs_psdev_ops libcfs_psdev_ops = {
52802 - libcfs_psdev_open,
52803 - libcfs_psdev_release,
52804 - NULL,
52805 - NULL,
52806 - libcfs_ioctl
52807 + .p_open = libcfs_psdev_open,
52808 + .p_close = libcfs_psdev_release,
52809 + .p_read = NULL,
52810 + .p_write = NULL,
52811 + .p_ioctl = libcfs_ioctl
52812 };
52813
52814 extern int insert_proc(void);
52815 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52816 index efa2faf..03a9836 100644
52817 --- a/drivers/staging/lustre/lustre/llite/dir.c
52818 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52819 @@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52820 int mode;
52821 int err;
52822
52823 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52824 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52825 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52826 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52827 lump);
52828 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52829 index a0f4868..139f1fb 100644
52830 --- a/drivers/staging/octeon/ethernet-rx.c
52831 +++ b/drivers/staging/octeon/ethernet-rx.c
52832 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52833 /* Increment RX stats for virtual ports */
52834 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52835 #ifdef CONFIG_64BIT
52836 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52837 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52838 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52839 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52840 #else
52841 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52842 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52843 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52844 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52845 #endif
52846 }
52847 netif_receive_skb(skb);
52848 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52849 dev->name);
52850 */
52851 #ifdef CONFIG_64BIT
52852 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52853 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52854 #else
52855 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52856 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52857 #endif
52858 dev_kfree_skb_irq(skb);
52859 }
52860 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52861 index 2aa7235..ba3c205 100644
52862 --- a/drivers/staging/octeon/ethernet.c
52863 +++ b/drivers/staging/octeon/ethernet.c
52864 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52865 * since the RX tasklet also increments it.
52866 */
52867 #ifdef CONFIG_64BIT
52868 - atomic64_add(rx_status.dropped_packets,
52869 - (atomic64_t *)&priv->stats.rx_dropped);
52870 + atomic64_add_unchecked(rx_status.dropped_packets,
52871 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52872 #else
52873 - atomic_add(rx_status.dropped_packets,
52874 - (atomic_t *)&priv->stats.rx_dropped);
52875 + atomic_add_unchecked(rx_status.dropped_packets,
52876 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52877 #endif
52878 }
52879
52880 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52881 index 56d5c50..a14f4db 100644
52882 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52883 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52884 @@ -234,7 +234,7 @@ struct hal_ops {
52885
52886 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52887 void (*hal_reset_security_engine)(struct adapter *adapter);
52888 -};
52889 +} __no_const;
52890
52891 enum rt_eeprom_type {
52892 EEPROM_93C46,
52893 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52894 index dc23395..cf7e9b1 100644
52895 --- a/drivers/staging/rtl8712/rtl871x_io.h
52896 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52897 @@ -108,7 +108,7 @@ struct _io_ops {
52898 u8 *pmem);
52899 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52900 u8 *pmem);
52901 -};
52902 +} __no_const;
52903
52904 struct io_req {
52905 struct list_head list;
52906 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52907 index 164136b..7244df5 100644
52908 --- a/drivers/staging/vt6655/hostap.c
52909 +++ b/drivers/staging/vt6655/hostap.c
52910 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
52911 *
52912 */
52913
52914 +static net_device_ops_no_const apdev_netdev_ops;
52915 +
52916 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52917 {
52918 PSDevice apdev_priv;
52919 struct net_device *dev = pDevice->dev;
52920 int ret;
52921 - const struct net_device_ops apdev_netdev_ops = {
52922 - .ndo_start_xmit = pDevice->tx_80211,
52923 - };
52924
52925 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
52926
52927 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52928 *apdev_priv = *pDevice;
52929 eth_hw_addr_inherit(pDevice->apdev, dev);
52930
52931 + /* only half broken now */
52932 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52933 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52934
52935 pDevice->apdev->type = ARPHRD_IEEE80211;
52936 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52937 index e7e9372..161f530 100644
52938 --- a/drivers/target/sbp/sbp_target.c
52939 +++ b/drivers/target/sbp/sbp_target.c
52940 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52941
52942 #define SESSION_MAINTENANCE_INTERVAL HZ
52943
52944 -static atomic_t login_id = ATOMIC_INIT(0);
52945 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52946
52947 static void session_maintenance_work(struct work_struct *);
52948 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52949 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52950 login->lun = se_lun;
52951 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52952 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52953 - login->login_id = atomic_inc_return(&login_id);
52954 + login->login_id = atomic_inc_return_unchecked(&login_id);
52955
52956 login->tgt_agt = sbp_target_agent_register(login);
52957 if (IS_ERR(login->tgt_agt)) {
52958 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52959 index 98da901..bb443e8 100644
52960 --- a/drivers/target/target_core_device.c
52961 +++ b/drivers/target/target_core_device.c
52962 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52963 spin_lock_init(&dev->se_tmr_lock);
52964 spin_lock_init(&dev->qf_cmd_lock);
52965 sema_init(&dev->caw_sem, 1);
52966 - atomic_set(&dev->dev_ordered_id, 0);
52967 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52968 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52969 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52970 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52971 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52972 index 7fa62fc..abdd041 100644
52973 --- a/drivers/target/target_core_transport.c
52974 +++ b/drivers/target/target_core_transport.c
52975 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52976 * Used to determine when ORDERED commands should go from
52977 * Dormant to Active status.
52978 */
52979 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52980 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52981 smp_mb__after_atomic();
52982 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52983 cmd->se_ordered_id, cmd->sam_task_attr,
52984 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52985 index 4b2b999..cad9fa5 100644
52986 --- a/drivers/thermal/of-thermal.c
52987 +++ b/drivers/thermal/of-thermal.c
52988 @@ -30,6 +30,7 @@
52989 #include <linux/err.h>
52990 #include <linux/export.h>
52991 #include <linux/string.h>
52992 +#include <linux/mm.h>
52993
52994 #include "thermal_core.h"
52995
52996 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52997 tz->get_trend = get_trend;
52998 tz->sensor_data = data;
52999
53000 - tzd->ops->get_temp = of_thermal_get_temp;
53001 - tzd->ops->get_trend = of_thermal_get_trend;
53002 + pax_open_kernel();
53003 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53004 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53005 + pax_close_kernel();
53006 mutex_unlock(&tzd->lock);
53007
53008 return tzd;
53009 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53010 return;
53011
53012 mutex_lock(&tzd->lock);
53013 - tzd->ops->get_temp = NULL;
53014 - tzd->ops->get_trend = NULL;
53015 + pax_open_kernel();
53016 + *(void **)&tzd->ops->get_temp = NULL;
53017 + *(void **)&tzd->ops->get_trend = NULL;
53018 + pax_close_kernel();
53019
53020 tz->get_temp = NULL;
53021 tz->get_trend = NULL;
53022 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53023 index fd66f57..48e6376 100644
53024 --- a/drivers/tty/cyclades.c
53025 +++ b/drivers/tty/cyclades.c
53026 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53027 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53028 info->port.count);
53029 #endif
53030 - info->port.count++;
53031 + atomic_inc(&info->port.count);
53032 #ifdef CY_DEBUG_COUNT
53033 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53034 - current->pid, info->port.count);
53035 + current->pid, atomic_read(&info->port.count));
53036 #endif
53037
53038 /*
53039 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53040 for (j = 0; j < cy_card[i].nports; j++) {
53041 info = &cy_card[i].ports[j];
53042
53043 - if (info->port.count) {
53044 + if (atomic_read(&info->port.count)) {
53045 /* XXX is the ldisc num worth this? */
53046 struct tty_struct *tty;
53047 struct tty_ldisc *ld;
53048 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53049 index 4fcec1d..5a036f7 100644
53050 --- a/drivers/tty/hvc/hvc_console.c
53051 +++ b/drivers/tty/hvc/hvc_console.c
53052 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53053
53054 spin_lock_irqsave(&hp->port.lock, flags);
53055 /* Check and then increment for fast path open. */
53056 - if (hp->port.count++ > 0) {
53057 + if (atomic_inc_return(&hp->port.count) > 1) {
53058 spin_unlock_irqrestore(&hp->port.lock, flags);
53059 hvc_kick();
53060 return 0;
53061 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53062
53063 spin_lock_irqsave(&hp->port.lock, flags);
53064
53065 - if (--hp->port.count == 0) {
53066 + if (atomic_dec_return(&hp->port.count) == 0) {
53067 spin_unlock_irqrestore(&hp->port.lock, flags);
53068 /* We are done with the tty pointer now. */
53069 tty_port_tty_set(&hp->port, NULL);
53070 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53071 */
53072 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53073 } else {
53074 - if (hp->port.count < 0)
53075 + if (atomic_read(&hp->port.count) < 0)
53076 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53077 - hp->vtermno, hp->port.count);
53078 + hp->vtermno, atomic_read(&hp->port.count));
53079 spin_unlock_irqrestore(&hp->port.lock, flags);
53080 }
53081 }
53082 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53083 * open->hangup case this can be called after the final close so prevent
53084 * that from happening for now.
53085 */
53086 - if (hp->port.count <= 0) {
53087 + if (atomic_read(&hp->port.count) <= 0) {
53088 spin_unlock_irqrestore(&hp->port.lock, flags);
53089 return;
53090 }
53091
53092 - hp->port.count = 0;
53093 + atomic_set(&hp->port.count, 0);
53094 spin_unlock_irqrestore(&hp->port.lock, flags);
53095 tty_port_tty_set(&hp->port, NULL);
53096
53097 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53098 return -EPIPE;
53099
53100 /* FIXME what's this (unprotected) check for? */
53101 - if (hp->port.count <= 0)
53102 + if (atomic_read(&hp->port.count) <= 0)
53103 return -EIO;
53104
53105 spin_lock_irqsave(&hp->lock, flags);
53106 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53107 index 81e939e..95ead10 100644
53108 --- a/drivers/tty/hvc/hvcs.c
53109 +++ b/drivers/tty/hvc/hvcs.c
53110 @@ -83,6 +83,7 @@
53111 #include <asm/hvcserver.h>
53112 #include <asm/uaccess.h>
53113 #include <asm/vio.h>
53114 +#include <asm/local.h>
53115
53116 /*
53117 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53118 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53119
53120 spin_lock_irqsave(&hvcsd->lock, flags);
53121
53122 - if (hvcsd->port.count > 0) {
53123 + if (atomic_read(&hvcsd->port.count) > 0) {
53124 spin_unlock_irqrestore(&hvcsd->lock, flags);
53125 printk(KERN_INFO "HVCS: vterm state unchanged. "
53126 "The hvcs device node is still in use.\n");
53127 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53128 }
53129 }
53130
53131 - hvcsd->port.count = 0;
53132 + atomic_set(&hvcsd->port.count, 0);
53133 hvcsd->port.tty = tty;
53134 tty->driver_data = hvcsd;
53135
53136 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53137 unsigned long flags;
53138
53139 spin_lock_irqsave(&hvcsd->lock, flags);
53140 - hvcsd->port.count++;
53141 + atomic_inc(&hvcsd->port.count);
53142 hvcsd->todo_mask |= HVCS_SCHED_READ;
53143 spin_unlock_irqrestore(&hvcsd->lock, flags);
53144
53145 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53146 hvcsd = tty->driver_data;
53147
53148 spin_lock_irqsave(&hvcsd->lock, flags);
53149 - if (--hvcsd->port.count == 0) {
53150 + if (atomic_dec_and_test(&hvcsd->port.count)) {
53151
53152 vio_disable_interrupts(hvcsd->vdev);
53153
53154 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53155
53156 free_irq(irq, hvcsd);
53157 return;
53158 - } else if (hvcsd->port.count < 0) {
53159 + } else if (atomic_read(&hvcsd->port.count) < 0) {
53160 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53161 " is missmanaged.\n",
53162 - hvcsd->vdev->unit_address, hvcsd->port.count);
53163 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53164 }
53165
53166 spin_unlock_irqrestore(&hvcsd->lock, flags);
53167 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53168
53169 spin_lock_irqsave(&hvcsd->lock, flags);
53170 /* Preserve this so that we know how many kref refs to put */
53171 - temp_open_count = hvcsd->port.count;
53172 + temp_open_count = atomic_read(&hvcsd->port.count);
53173
53174 /*
53175 * Don't kref put inside the spinlock because the destruction
53176 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53177 tty->driver_data = NULL;
53178 hvcsd->port.tty = NULL;
53179
53180 - hvcsd->port.count = 0;
53181 + atomic_set(&hvcsd->port.count, 0);
53182
53183 /* This will drop any buffered data on the floor which is OK in a hangup
53184 * scenario. */
53185 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53186 * the middle of a write operation? This is a crummy place to do this
53187 * but we want to keep it all in the spinlock.
53188 */
53189 - if (hvcsd->port.count <= 0) {
53190 + if (atomic_read(&hvcsd->port.count) <= 0) {
53191 spin_unlock_irqrestore(&hvcsd->lock, flags);
53192 return -ENODEV;
53193 }
53194 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53195 {
53196 struct hvcs_struct *hvcsd = tty->driver_data;
53197
53198 - if (!hvcsd || hvcsd->port.count <= 0)
53199 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53200 return 0;
53201
53202 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53203 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53204 index 4190199..06d5bfa 100644
53205 --- a/drivers/tty/hvc/hvsi.c
53206 +++ b/drivers/tty/hvc/hvsi.c
53207 @@ -85,7 +85,7 @@ struct hvsi_struct {
53208 int n_outbuf;
53209 uint32_t vtermno;
53210 uint32_t virq;
53211 - atomic_t seqno; /* HVSI packet sequence number */
53212 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
53213 uint16_t mctrl;
53214 uint8_t state; /* HVSI protocol state */
53215 uint8_t flags;
53216 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53217
53218 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53219 packet.hdr.len = sizeof(struct hvsi_query_response);
53220 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53221 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53222 packet.verb = VSV_SEND_VERSION_NUMBER;
53223 packet.u.version = HVSI_VERSION;
53224 packet.query_seqno = query_seqno+1;
53225 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53226
53227 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53228 packet.hdr.len = sizeof(struct hvsi_query);
53229 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53230 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53231 packet.verb = verb;
53232
53233 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53234 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53235 int wrote;
53236
53237 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53238 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53239 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53240 packet.hdr.len = sizeof(struct hvsi_control);
53241 packet.verb = VSV_SET_MODEM_CTL;
53242 packet.mask = HVSI_TSDTR;
53243 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53244 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53245
53246 packet.hdr.type = VS_DATA_PACKET_HEADER;
53247 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53248 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53249 packet.hdr.len = count + sizeof(struct hvsi_header);
53250 memcpy(&packet.data, buf, count);
53251
53252 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53253 struct hvsi_control packet __ALIGNED__;
53254
53255 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53256 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53257 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53258 packet.hdr.len = 6;
53259 packet.verb = VSV_CLOSE_PROTOCOL;
53260
53261 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53262
53263 tty_port_tty_set(&hp->port, tty);
53264 spin_lock_irqsave(&hp->lock, flags);
53265 - hp->port.count++;
53266 + atomic_inc(&hp->port.count);
53267 atomic_set(&hp->seqno, 0);
53268 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53269 spin_unlock_irqrestore(&hp->lock, flags);
53270 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53271
53272 spin_lock_irqsave(&hp->lock, flags);
53273
53274 - if (--hp->port.count == 0) {
53275 + if (atomic_dec_return(&hp->port.count) == 0) {
53276 tty_port_tty_set(&hp->port, NULL);
53277 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53278
53279 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53280
53281 spin_lock_irqsave(&hp->lock, flags);
53282 }
53283 - } else if (hp->port.count < 0)
53284 + } else if (atomic_read(&hp->port.count) < 0)
53285 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53286 - hp - hvsi_ports, hp->port.count);
53287 + hp - hvsi_ports, atomic_read(&hp->port.count));
53288
53289 spin_unlock_irqrestore(&hp->lock, flags);
53290 }
53291 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53292 tty_port_tty_set(&hp->port, NULL);
53293
53294 spin_lock_irqsave(&hp->lock, flags);
53295 - hp->port.count = 0;
53296 + atomic_set(&hp->port.count, 0);
53297 hp->n_outbuf = 0;
53298 spin_unlock_irqrestore(&hp->lock, flags);
53299 }
53300 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53301 index 7ae6c29..05c6dba 100644
53302 --- a/drivers/tty/hvc/hvsi_lib.c
53303 +++ b/drivers/tty/hvc/hvsi_lib.c
53304 @@ -8,7 +8,7 @@
53305
53306 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53307 {
53308 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53309 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53310
53311 /* Assumes that always succeeds, works in practice */
53312 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53313 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53314
53315 /* Reset state */
53316 pv->established = 0;
53317 - atomic_set(&pv->seqno, 0);
53318 + atomic_set_unchecked(&pv->seqno, 0);
53319
53320 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53321
53322 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53323 index 345cebb..d5a1e9e 100644
53324 --- a/drivers/tty/ipwireless/tty.c
53325 +++ b/drivers/tty/ipwireless/tty.c
53326 @@ -28,6 +28,7 @@
53327 #include <linux/tty_driver.h>
53328 #include <linux/tty_flip.h>
53329 #include <linux/uaccess.h>
53330 +#include <asm/local.h>
53331
53332 #include "tty.h"
53333 #include "network.h"
53334 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53335 return -ENODEV;
53336
53337 mutex_lock(&tty->ipw_tty_mutex);
53338 - if (tty->port.count == 0)
53339 + if (atomic_read(&tty->port.count) == 0)
53340 tty->tx_bytes_queued = 0;
53341
53342 - tty->port.count++;
53343 + atomic_inc(&tty->port.count);
53344
53345 tty->port.tty = linux_tty;
53346 linux_tty->driver_data = tty;
53347 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53348
53349 static void do_ipw_close(struct ipw_tty *tty)
53350 {
53351 - tty->port.count--;
53352 -
53353 - if (tty->port.count == 0) {
53354 + if (atomic_dec_return(&tty->port.count) == 0) {
53355 struct tty_struct *linux_tty = tty->port.tty;
53356
53357 if (linux_tty != NULL) {
53358 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53359 return;
53360
53361 mutex_lock(&tty->ipw_tty_mutex);
53362 - if (tty->port.count == 0) {
53363 + if (atomic_read(&tty->port.count) == 0) {
53364 mutex_unlock(&tty->ipw_tty_mutex);
53365 return;
53366 }
53367 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53368
53369 mutex_lock(&tty->ipw_tty_mutex);
53370
53371 - if (!tty->port.count) {
53372 + if (!atomic_read(&tty->port.count)) {
53373 mutex_unlock(&tty->ipw_tty_mutex);
53374 return;
53375 }
53376 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53377 return -ENODEV;
53378
53379 mutex_lock(&tty->ipw_tty_mutex);
53380 - if (!tty->port.count) {
53381 + if (!atomic_read(&tty->port.count)) {
53382 mutex_unlock(&tty->ipw_tty_mutex);
53383 return -EINVAL;
53384 }
53385 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53386 if (!tty)
53387 return -ENODEV;
53388
53389 - if (!tty->port.count)
53390 + if (!atomic_read(&tty->port.count))
53391 return -EINVAL;
53392
53393 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53394 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53395 if (!tty)
53396 return 0;
53397
53398 - if (!tty->port.count)
53399 + if (!atomic_read(&tty->port.count))
53400 return 0;
53401
53402 return tty->tx_bytes_queued;
53403 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53404 if (!tty)
53405 return -ENODEV;
53406
53407 - if (!tty->port.count)
53408 + if (!atomic_read(&tty->port.count))
53409 return -EINVAL;
53410
53411 return get_control_lines(tty);
53412 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53413 if (!tty)
53414 return -ENODEV;
53415
53416 - if (!tty->port.count)
53417 + if (!atomic_read(&tty->port.count))
53418 return -EINVAL;
53419
53420 return set_control_lines(tty, set, clear);
53421 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53422 if (!tty)
53423 return -ENODEV;
53424
53425 - if (!tty->port.count)
53426 + if (!atomic_read(&tty->port.count))
53427 return -EINVAL;
53428
53429 /* FIXME: Exactly how is the tty object locked here .. */
53430 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53431 * are gone */
53432 mutex_lock(&ttyj->ipw_tty_mutex);
53433 }
53434 - while (ttyj->port.count)
53435 + while (atomic_read(&ttyj->port.count))
53436 do_ipw_close(ttyj);
53437 ipwireless_disassociate_network_ttys(network,
53438 ttyj->channel_idx);
53439 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53440 index 1deaca4..c8582d4 100644
53441 --- a/drivers/tty/moxa.c
53442 +++ b/drivers/tty/moxa.c
53443 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53444 }
53445
53446 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53447 - ch->port.count++;
53448 + atomic_inc(&ch->port.count);
53449 tty->driver_data = ch;
53450 tty_port_tty_set(&ch->port, tty);
53451 mutex_lock(&ch->port.mutex);
53452 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53453 index c434376..114ce13 100644
53454 --- a/drivers/tty/n_gsm.c
53455 +++ b/drivers/tty/n_gsm.c
53456 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53457 spin_lock_init(&dlci->lock);
53458 mutex_init(&dlci->mutex);
53459 dlci->fifo = &dlci->_fifo;
53460 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53461 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53462 kfree(dlci);
53463 return NULL;
53464 }
53465 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53466 struct gsm_dlci *dlci = tty->driver_data;
53467 struct tty_port *port = &dlci->port;
53468
53469 - port->count++;
53470 + atomic_inc(&port->count);
53471 tty_port_tty_set(port, tty);
53472
53473 dlci->modem_rx = 0;
53474 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53475 index f44f1ba..a8d5915 100644
53476 --- a/drivers/tty/n_tty.c
53477 +++ b/drivers/tty/n_tty.c
53478 @@ -115,7 +115,7 @@ struct n_tty_data {
53479 int minimum_to_wake;
53480
53481 /* consumer-published */
53482 - size_t read_tail;
53483 + size_t read_tail __intentional_overflow(-1);
53484 size_t line_start;
53485
53486 /* protected by output lock */
53487 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53488 {
53489 *ops = tty_ldisc_N_TTY;
53490 ops->owner = NULL;
53491 - ops->refcount = ops->flags = 0;
53492 + atomic_set(&ops->refcount, 0);
53493 + ops->flags = 0;
53494 }
53495 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53496 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53497 index 9bbdb1d..dc514ee 100644
53498 --- a/drivers/tty/pty.c
53499 +++ b/drivers/tty/pty.c
53500 @@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53501 panic("Couldn't register Unix98 pts driver");
53502
53503 /* Now create the /dev/ptmx special device */
53504 + pax_open_kernel();
53505 tty_default_fops(&ptmx_fops);
53506 - ptmx_fops.open = ptmx_open;
53507 + *(void **)&ptmx_fops.open = ptmx_open;
53508 + pax_close_kernel();
53509
53510 cdev_init(&ptmx_cdev, &ptmx_fops);
53511 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53512 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53513 index 383c4c7..d408e21 100644
53514 --- a/drivers/tty/rocket.c
53515 +++ b/drivers/tty/rocket.c
53516 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53517 tty->driver_data = info;
53518 tty_port_tty_set(port, tty);
53519
53520 - if (port->count++ == 0) {
53521 + if (atomic_inc_return(&port->count) == 1) {
53522 atomic_inc(&rp_num_ports_open);
53523
53524 #ifdef ROCKET_DEBUG_OPEN
53525 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53526 #endif
53527 }
53528 #ifdef ROCKET_DEBUG_OPEN
53529 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53530 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53531 #endif
53532
53533 /*
53534 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53535 spin_unlock_irqrestore(&info->port.lock, flags);
53536 return;
53537 }
53538 - if (info->port.count)
53539 + if (atomic_read(&info->port.count))
53540 atomic_dec(&rp_num_ports_open);
53541 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53542 spin_unlock_irqrestore(&info->port.lock, flags);
53543 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53544 index aa28209..e08fb85 100644
53545 --- a/drivers/tty/serial/ioc4_serial.c
53546 +++ b/drivers/tty/serial/ioc4_serial.c
53547 @@ -437,7 +437,7 @@ struct ioc4_soft {
53548 } is_intr_info[MAX_IOC4_INTR_ENTS];
53549
53550 /* Number of entries active in the above array */
53551 - atomic_t is_num_intrs;
53552 + atomic_unchecked_t is_num_intrs;
53553 } is_intr_type[IOC4_NUM_INTR_TYPES];
53554
53555 /* is_ir_lock must be held while
53556 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53557 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53558 || (type == IOC4_OTHER_INTR_TYPE)));
53559
53560 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53561 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53562 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53563
53564 /* Save off the lower level interrupt handler */
53565 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53566
53567 soft = arg;
53568 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53569 - num_intrs = (int)atomic_read(
53570 + num_intrs = (int)atomic_read_unchecked(
53571 &soft->is_intr_type[intr_type].is_num_intrs);
53572
53573 this_mir = this_ir = pending_intrs(soft, intr_type);
53574 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53575 index 6ec7501..265bcbf 100644
53576 --- a/drivers/tty/serial/kgdb_nmi.c
53577 +++ b/drivers/tty/serial/kgdb_nmi.c
53578 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53579 * I/O utilities that messages sent to the console will automatically
53580 * be displayed on the dbg_io.
53581 */
53582 - dbg_io_ops->is_console = true;
53583 + pax_open_kernel();
53584 + *(int *)&dbg_io_ops->is_console = true;
53585 + pax_close_kernel();
53586
53587 return 0;
53588 }
53589 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53590 index a260cde..6b2b5ce 100644
53591 --- a/drivers/tty/serial/kgdboc.c
53592 +++ b/drivers/tty/serial/kgdboc.c
53593 @@ -24,8 +24,9 @@
53594 #define MAX_CONFIG_LEN 40
53595
53596 static struct kgdb_io kgdboc_io_ops;
53597 +static struct kgdb_io kgdboc_io_ops_console;
53598
53599 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53600 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53601 static int configured = -1;
53602
53603 static char config[MAX_CONFIG_LEN];
53604 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53605 kgdboc_unregister_kbd();
53606 if (configured == 1)
53607 kgdb_unregister_io_module(&kgdboc_io_ops);
53608 + else if (configured == 2)
53609 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53610 }
53611
53612 static int configure_kgdboc(void)
53613 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53614 int err;
53615 char *cptr = config;
53616 struct console *cons;
53617 + int is_console = 0;
53618
53619 err = kgdboc_option_setup(config);
53620 if (err || !strlen(config) || isspace(config[0]))
53621 goto noconfig;
53622
53623 err = -ENODEV;
53624 - kgdboc_io_ops.is_console = 0;
53625 kgdb_tty_driver = NULL;
53626
53627 kgdboc_use_kms = 0;
53628 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53629 int idx;
53630 if (cons->device && cons->device(cons, &idx) == p &&
53631 idx == tty_line) {
53632 - kgdboc_io_ops.is_console = 1;
53633 + is_console = 1;
53634 break;
53635 }
53636 cons = cons->next;
53637 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53638 kgdb_tty_line = tty_line;
53639
53640 do_register:
53641 - err = kgdb_register_io_module(&kgdboc_io_ops);
53642 + if (is_console) {
53643 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53644 + configured = 2;
53645 + } else {
53646 + err = kgdb_register_io_module(&kgdboc_io_ops);
53647 + configured = 1;
53648 + }
53649 if (err)
53650 goto noconfig;
53651
53652 @@ -205,8 +214,6 @@ do_register:
53653 if (err)
53654 goto nmi_con_failed;
53655
53656 - configured = 1;
53657 -
53658 return 0;
53659
53660 nmi_con_failed:
53661 @@ -223,7 +230,7 @@ noconfig:
53662 static int __init init_kgdboc(void)
53663 {
53664 /* Already configured? */
53665 - if (configured == 1)
53666 + if (configured >= 1)
53667 return 0;
53668
53669 return configure_kgdboc();
53670 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53671 if (config[len - 1] == '\n')
53672 config[len - 1] = '\0';
53673
53674 - if (configured == 1)
53675 + if (configured >= 1)
53676 cleanup_kgdboc();
53677
53678 /* Go and configure with the new params. */
53679 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53680 .post_exception = kgdboc_post_exp_handler,
53681 };
53682
53683 +static struct kgdb_io kgdboc_io_ops_console = {
53684 + .name = "kgdboc",
53685 + .read_char = kgdboc_get_char,
53686 + .write_char = kgdboc_put_char,
53687 + .pre_exception = kgdboc_pre_exp_handler,
53688 + .post_exception = kgdboc_post_exp_handler,
53689 + .is_console = 1
53690 +};
53691 +
53692 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53693 /* This is only available if kgdboc is a built in for early debugging */
53694 static int __init kgdboc_early_init(char *opt)
53695 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53696 index 0da0b54..80ae306 100644
53697 --- a/drivers/tty/serial/msm_serial.c
53698 +++ b/drivers/tty/serial/msm_serial.c
53699 @@ -989,7 +989,7 @@ static struct uart_driver msm_uart_driver = {
53700 .cons = MSM_CONSOLE,
53701 };
53702
53703 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53704 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53705
53706 static const struct of_device_id msm_uartdm_table[] = {
53707 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53708 @@ -1008,7 +1008,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53709 int irq;
53710
53711 if (pdev->id == -1)
53712 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53713 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53714
53715 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53716 return -ENXIO;
53717 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53718 index c78f43a..22b1dab 100644
53719 --- a/drivers/tty/serial/samsung.c
53720 +++ b/drivers/tty/serial/samsung.c
53721 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53722 }
53723 }
53724
53725 +static int s3c64xx_serial_startup(struct uart_port *port);
53726 static int s3c24xx_serial_startup(struct uart_port *port)
53727 {
53728 struct s3c24xx_uart_port *ourport = to_ourport(port);
53729 int ret;
53730
53731 + /* Startup sequence is different for s3c64xx and higher SoC's */
53732 + if (s3c24xx_serial_has_interrupt_mask(port))
53733 + return s3c64xx_serial_startup(port);
53734 +
53735 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53736 port, (unsigned long long)port->mapbase, port->membase);
53737
53738 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53739 /* setup info for port */
53740 port->dev = &platdev->dev;
53741
53742 - /* Startup sequence is different for s3c64xx and higher SoC's */
53743 - if (s3c24xx_serial_has_interrupt_mask(port))
53744 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53745 -
53746 port->uartclk = 1;
53747
53748 if (cfg->uart_flags & UPF_CONS_FLOW) {
53749 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53750 index 29a7be4..0144e62 100644
53751 --- a/drivers/tty/serial/serial_core.c
53752 +++ b/drivers/tty/serial/serial_core.c
53753 @@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53754
53755 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53756
53757 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53758 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53759 return;
53760
53761 /*
53762 @@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53763 uart_flush_buffer(tty);
53764 uart_shutdown(tty, state);
53765 spin_lock_irqsave(&port->lock, flags);
53766 - port->count = 0;
53767 + atomic_set(&port->count, 0);
53768 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53769 spin_unlock_irqrestore(&port->lock, flags);
53770 tty_port_tty_set(port, NULL);
53771 @@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53772 goto end;
53773 }
53774
53775 - port->count++;
53776 + atomic_inc(&port->count);
53777 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53778 retval = -ENXIO;
53779 goto err_dec_count;
53780 @@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53781 end:
53782 return retval;
53783 err_dec_count:
53784 - port->count--;
53785 + atomic_inc(&port->count);
53786 mutex_unlock(&port->mutex);
53787 goto end;
53788 }
53789 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53790 index b799170..87dafd5 100644
53791 --- a/drivers/tty/synclink.c
53792 +++ b/drivers/tty/synclink.c
53793 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53794
53795 if (debug_level >= DEBUG_LEVEL_INFO)
53796 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53797 - __FILE__,__LINE__, info->device_name, info->port.count);
53798 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53799
53800 if (tty_port_close_start(&info->port, tty, filp) == 0)
53801 goto cleanup;
53802 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53803 cleanup:
53804 if (debug_level >= DEBUG_LEVEL_INFO)
53805 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53806 - tty->driver->name, info->port.count);
53807 + tty->driver->name, atomic_read(&info->port.count));
53808
53809 } /* end of mgsl_close() */
53810
53811 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53812
53813 mgsl_flush_buffer(tty);
53814 shutdown(info);
53815 -
53816 - info->port.count = 0;
53817 +
53818 + atomic_set(&info->port.count, 0);
53819 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53820 info->port.tty = NULL;
53821
53822 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53823
53824 if (debug_level >= DEBUG_LEVEL_INFO)
53825 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53826 - __FILE__,__LINE__, tty->driver->name, port->count );
53827 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53828
53829 spin_lock_irqsave(&info->irq_spinlock, flags);
53830 - port->count--;
53831 + atomic_dec(&port->count);
53832 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53833 port->blocked_open++;
53834
53835 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53836
53837 if (debug_level >= DEBUG_LEVEL_INFO)
53838 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53839 - __FILE__,__LINE__, tty->driver->name, port->count );
53840 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53841
53842 tty_unlock(tty);
53843 schedule();
53844 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53845
53846 /* FIXME: Racy on hangup during close wait */
53847 if (!tty_hung_up_p(filp))
53848 - port->count++;
53849 + atomic_inc(&port->count);
53850 port->blocked_open--;
53851
53852 if (debug_level >= DEBUG_LEVEL_INFO)
53853 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53854 - __FILE__,__LINE__, tty->driver->name, port->count );
53855 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53856
53857 if (!retval)
53858 port->flags |= ASYNC_NORMAL_ACTIVE;
53859 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53860
53861 if (debug_level >= DEBUG_LEVEL_INFO)
53862 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53863 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53864 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53865
53866 /* If port is closing, signal caller to try again */
53867 if (info->port.flags & ASYNC_CLOSING){
53868 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53869 spin_unlock_irqrestore(&info->netlock, flags);
53870 goto cleanup;
53871 }
53872 - info->port.count++;
53873 + atomic_inc(&info->port.count);
53874 spin_unlock_irqrestore(&info->netlock, flags);
53875
53876 - if (info->port.count == 1) {
53877 + if (atomic_read(&info->port.count) == 1) {
53878 /* 1st open on this device, init hardware */
53879 retval = startup(info);
53880 if (retval < 0)
53881 @@ -3442,8 +3442,8 @@ cleanup:
53882 if (retval) {
53883 if (tty->count == 1)
53884 info->port.tty = NULL; /* tty layer will release tty struct */
53885 - if(info->port.count)
53886 - info->port.count--;
53887 + if (atomic_read(&info->port.count))
53888 + atomic_dec(&info->port.count);
53889 }
53890
53891 return retval;
53892 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53893 unsigned short new_crctype;
53894
53895 /* return error if TTY interface open */
53896 - if (info->port.count)
53897 + if (atomic_read(&info->port.count))
53898 return -EBUSY;
53899
53900 switch (encoding)
53901 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53902
53903 /* arbitrate between network and tty opens */
53904 spin_lock_irqsave(&info->netlock, flags);
53905 - if (info->port.count != 0 || info->netcount != 0) {
53906 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53907 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53908 spin_unlock_irqrestore(&info->netlock, flags);
53909 return -EBUSY;
53910 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53911 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53912
53913 /* return error if TTY interface open */
53914 - if (info->port.count)
53915 + if (atomic_read(&info->port.count))
53916 return -EBUSY;
53917
53918 if (cmd != SIOCWANDEV)
53919 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53920 index 0e8c39b..e0cb171 100644
53921 --- a/drivers/tty/synclink_gt.c
53922 +++ b/drivers/tty/synclink_gt.c
53923 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53924 tty->driver_data = info;
53925 info->port.tty = tty;
53926
53927 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53928 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53929
53930 /* If port is closing, signal caller to try again */
53931 if (info->port.flags & ASYNC_CLOSING){
53932 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53933 mutex_unlock(&info->port.mutex);
53934 goto cleanup;
53935 }
53936 - info->port.count++;
53937 + atomic_inc(&info->port.count);
53938 spin_unlock_irqrestore(&info->netlock, flags);
53939
53940 - if (info->port.count == 1) {
53941 + if (atomic_read(&info->port.count) == 1) {
53942 /* 1st open on this device, init hardware */
53943 retval = startup(info);
53944 if (retval < 0) {
53945 @@ -715,8 +715,8 @@ cleanup:
53946 if (retval) {
53947 if (tty->count == 1)
53948 info->port.tty = NULL; /* tty layer will release tty struct */
53949 - if(info->port.count)
53950 - info->port.count--;
53951 + if(atomic_read(&info->port.count))
53952 + atomic_dec(&info->port.count);
53953 }
53954
53955 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53956 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53957
53958 if (sanity_check(info, tty->name, "close"))
53959 return;
53960 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53961 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53962
53963 if (tty_port_close_start(&info->port, tty, filp) == 0)
53964 goto cleanup;
53965 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53966 tty_port_close_end(&info->port, tty);
53967 info->port.tty = NULL;
53968 cleanup:
53969 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53970 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53971 }
53972
53973 static void hangup(struct tty_struct *tty)
53974 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53975 shutdown(info);
53976
53977 spin_lock_irqsave(&info->port.lock, flags);
53978 - info->port.count = 0;
53979 + atomic_set(&info->port.count, 0);
53980 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53981 info->port.tty = NULL;
53982 spin_unlock_irqrestore(&info->port.lock, flags);
53983 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53984 unsigned short new_crctype;
53985
53986 /* return error if TTY interface open */
53987 - if (info->port.count)
53988 + if (atomic_read(&info->port.count))
53989 return -EBUSY;
53990
53991 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53992 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53993
53994 /* arbitrate between network and tty opens */
53995 spin_lock_irqsave(&info->netlock, flags);
53996 - if (info->port.count != 0 || info->netcount != 0) {
53997 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53998 DBGINFO(("%s hdlc_open busy\n", dev->name));
53999 spin_unlock_irqrestore(&info->netlock, flags);
54000 return -EBUSY;
54001 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54002 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54003
54004 /* return error if TTY interface open */
54005 - if (info->port.count)
54006 + if (atomic_read(&info->port.count))
54007 return -EBUSY;
54008
54009 if (cmd != SIOCWANDEV)
54010 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54011 if (port == NULL)
54012 continue;
54013 spin_lock(&port->lock);
54014 - if ((port->port.count || port->netcount) &&
54015 + if ((atomic_read(&port->port.count) || port->netcount) &&
54016 port->pending_bh && !port->bh_running &&
54017 !port->bh_requested) {
54018 DBGISR(("%s bh queued\n", port->device_name));
54019 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54020 add_wait_queue(&port->open_wait, &wait);
54021
54022 spin_lock_irqsave(&info->lock, flags);
54023 - port->count--;
54024 + atomic_dec(&port->count);
54025 spin_unlock_irqrestore(&info->lock, flags);
54026 port->blocked_open++;
54027
54028 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54029 remove_wait_queue(&port->open_wait, &wait);
54030
54031 if (!tty_hung_up_p(filp))
54032 - port->count++;
54033 + atomic_inc(&port->count);
54034 port->blocked_open--;
54035
54036 if (!retval)
54037 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54038 index c3f9091..abe4601 100644
54039 --- a/drivers/tty/synclinkmp.c
54040 +++ b/drivers/tty/synclinkmp.c
54041 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54042
54043 if (debug_level >= DEBUG_LEVEL_INFO)
54044 printk("%s(%d):%s open(), old ref count = %d\n",
54045 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54046 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54047
54048 /* If port is closing, signal caller to try again */
54049 if (info->port.flags & ASYNC_CLOSING){
54050 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54051 spin_unlock_irqrestore(&info->netlock, flags);
54052 goto cleanup;
54053 }
54054 - info->port.count++;
54055 + atomic_inc(&info->port.count);
54056 spin_unlock_irqrestore(&info->netlock, flags);
54057
54058 - if (info->port.count == 1) {
54059 + if (atomic_read(&info->port.count) == 1) {
54060 /* 1st open on this device, init hardware */
54061 retval = startup(info);
54062 if (retval < 0)
54063 @@ -796,8 +796,8 @@ cleanup:
54064 if (retval) {
54065 if (tty->count == 1)
54066 info->port.tty = NULL; /* tty layer will release tty struct */
54067 - if(info->port.count)
54068 - info->port.count--;
54069 + if(atomic_read(&info->port.count))
54070 + atomic_dec(&info->port.count);
54071 }
54072
54073 return retval;
54074 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54075
54076 if (debug_level >= DEBUG_LEVEL_INFO)
54077 printk("%s(%d):%s close() entry, count=%d\n",
54078 - __FILE__,__LINE__, info->device_name, info->port.count);
54079 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54080
54081 if (tty_port_close_start(&info->port, tty, filp) == 0)
54082 goto cleanup;
54083 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54084 cleanup:
54085 if (debug_level >= DEBUG_LEVEL_INFO)
54086 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54087 - tty->driver->name, info->port.count);
54088 + tty->driver->name, atomic_read(&info->port.count));
54089 }
54090
54091 /* Called by tty_hangup() when a hangup is signaled.
54092 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54093 shutdown(info);
54094
54095 spin_lock_irqsave(&info->port.lock, flags);
54096 - info->port.count = 0;
54097 + atomic_set(&info->port.count, 0);
54098 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54099 info->port.tty = NULL;
54100 spin_unlock_irqrestore(&info->port.lock, flags);
54101 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54102 unsigned short new_crctype;
54103
54104 /* return error if TTY interface open */
54105 - if (info->port.count)
54106 + if (atomic_read(&info->port.count))
54107 return -EBUSY;
54108
54109 switch (encoding)
54110 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54111
54112 /* arbitrate between network and tty opens */
54113 spin_lock_irqsave(&info->netlock, flags);
54114 - if (info->port.count != 0 || info->netcount != 0) {
54115 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54116 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54117 spin_unlock_irqrestore(&info->netlock, flags);
54118 return -EBUSY;
54119 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54120 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54121
54122 /* return error if TTY interface open */
54123 - if (info->port.count)
54124 + if (atomic_read(&info->port.count))
54125 return -EBUSY;
54126
54127 if (cmd != SIOCWANDEV)
54128 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54129 * do not request bottom half processing if the
54130 * device is not open in a normal mode.
54131 */
54132 - if ( port && (port->port.count || port->netcount) &&
54133 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54134 port->pending_bh && !port->bh_running &&
54135 !port->bh_requested ) {
54136 if ( debug_level >= DEBUG_LEVEL_ISR )
54137 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54138
54139 if (debug_level >= DEBUG_LEVEL_INFO)
54140 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54141 - __FILE__,__LINE__, tty->driver->name, port->count );
54142 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54143
54144 spin_lock_irqsave(&info->lock, flags);
54145 - port->count--;
54146 + atomic_dec(&port->count);
54147 spin_unlock_irqrestore(&info->lock, flags);
54148 port->blocked_open++;
54149
54150 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54151
54152 if (debug_level >= DEBUG_LEVEL_INFO)
54153 printk("%s(%d):%s block_til_ready() count=%d\n",
54154 - __FILE__,__LINE__, tty->driver->name, port->count );
54155 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54156
54157 tty_unlock(tty);
54158 schedule();
54159 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54160 set_current_state(TASK_RUNNING);
54161 remove_wait_queue(&port->open_wait, &wait);
54162 if (!tty_hung_up_p(filp))
54163 - port->count++;
54164 + atomic_inc(&port->count);
54165 port->blocked_open--;
54166
54167 if (debug_level >= DEBUG_LEVEL_INFO)
54168 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54169 - __FILE__,__LINE__, tty->driver->name, port->count );
54170 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54171
54172 if (!retval)
54173 port->flags |= ASYNC_NORMAL_ACTIVE;
54174 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54175 index 42bad18..447d7a2 100644
54176 --- a/drivers/tty/sysrq.c
54177 +++ b/drivers/tty/sysrq.c
54178 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54179 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54180 size_t count, loff_t *ppos)
54181 {
54182 - if (count) {
54183 + if (count && capable(CAP_SYS_ADMIN)) {
54184 char c;
54185
54186 if (get_user(c, buf))
54187 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54188 index 8fbad34..0db0a39 100644
54189 --- a/drivers/tty/tty_io.c
54190 +++ b/drivers/tty/tty_io.c
54191 @@ -3464,7 +3464,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54192
54193 void tty_default_fops(struct file_operations *fops)
54194 {
54195 - *fops = tty_fops;
54196 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54197 }
54198
54199 /*
54200 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54201 index 2d822aa..a566234 100644
54202 --- a/drivers/tty/tty_ldisc.c
54203 +++ b/drivers/tty/tty_ldisc.c
54204 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54205 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54206 tty_ldiscs[disc] = new_ldisc;
54207 new_ldisc->num = disc;
54208 - new_ldisc->refcount = 0;
54209 + atomic_set(&new_ldisc->refcount, 0);
54210 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54211
54212 return ret;
54213 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54214 return -EINVAL;
54215
54216 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54217 - if (tty_ldiscs[disc]->refcount)
54218 + if (atomic_read(&tty_ldiscs[disc]->refcount))
54219 ret = -EBUSY;
54220 else
54221 tty_ldiscs[disc] = NULL;
54222 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54223 if (ldops) {
54224 ret = ERR_PTR(-EAGAIN);
54225 if (try_module_get(ldops->owner)) {
54226 - ldops->refcount++;
54227 + atomic_inc(&ldops->refcount);
54228 ret = ldops;
54229 }
54230 }
54231 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54232 unsigned long flags;
54233
54234 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54235 - ldops->refcount--;
54236 + atomic_dec(&ldops->refcount);
54237 module_put(ldops->owner);
54238 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54239 }
54240 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54241 index 1b93357..ea9f82c 100644
54242 --- a/drivers/tty/tty_port.c
54243 +++ b/drivers/tty/tty_port.c
54244 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54245 unsigned long flags;
54246
54247 spin_lock_irqsave(&port->lock, flags);
54248 - port->count = 0;
54249 + atomic_set(&port->count, 0);
54250 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54251 tty = port->tty;
54252 if (tty)
54253 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54254
54255 /* The port lock protects the port counts */
54256 spin_lock_irqsave(&port->lock, flags);
54257 - port->count--;
54258 + atomic_dec(&port->count);
54259 port->blocked_open++;
54260 spin_unlock_irqrestore(&port->lock, flags);
54261
54262 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54263 we must not mess that up further */
54264 spin_lock_irqsave(&port->lock, flags);
54265 if (!tty_hung_up_p(filp))
54266 - port->count++;
54267 + atomic_inc(&port->count);
54268 port->blocked_open--;
54269 if (retval == 0)
54270 port->flags |= ASYNC_NORMAL_ACTIVE;
54271 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54272 return 0;
54273 }
54274
54275 - if (tty->count == 1 && port->count != 1) {
54276 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54277 printk(KERN_WARNING
54278 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54279 - port->count);
54280 - port->count = 1;
54281 + atomic_read(&port->count));
54282 + atomic_set(&port->count, 1);
54283 }
54284 - if (--port->count < 0) {
54285 + if (atomic_dec_return(&port->count) < 0) {
54286 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54287 - port->count);
54288 - port->count = 0;
54289 + atomic_read(&port->count));
54290 + atomic_set(&port->count, 0);
54291 }
54292
54293 - if (port->count) {
54294 + if (atomic_read(&port->count)) {
54295 spin_unlock_irqrestore(&port->lock, flags);
54296 return 0;
54297 }
54298 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54299 struct file *filp)
54300 {
54301 spin_lock_irq(&port->lock);
54302 - ++port->count;
54303 + atomic_inc(&port->count);
54304 spin_unlock_irq(&port->lock);
54305 tty_port_tty_set(port, tty);
54306
54307 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54308 index d0e3a44..5f8b754 100644
54309 --- a/drivers/tty/vt/keyboard.c
54310 +++ b/drivers/tty/vt/keyboard.c
54311 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54312 kbd->kbdmode == VC_OFF) &&
54313 value != KVAL(K_SAK))
54314 return; /* SAK is allowed even in raw mode */
54315 +
54316 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54317 + {
54318 + void *func = fn_handler[value];
54319 + if (func == fn_show_state || func == fn_show_ptregs ||
54320 + func == fn_show_mem)
54321 + return;
54322 + }
54323 +#endif
54324 +
54325 fn_handler[value](vc);
54326 }
54327
54328 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54329 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54330 return -EFAULT;
54331
54332 - if (!capable(CAP_SYS_TTY_CONFIG))
54333 - perm = 0;
54334 -
54335 switch (cmd) {
54336 case KDGKBENT:
54337 /* Ensure another thread doesn't free it under us */
54338 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54339 spin_unlock_irqrestore(&kbd_event_lock, flags);
54340 return put_user(val, &user_kbe->kb_value);
54341 case KDSKBENT:
54342 + if (!capable(CAP_SYS_TTY_CONFIG))
54343 + perm = 0;
54344 +
54345 if (!perm)
54346 return -EPERM;
54347 if (!i && v == K_NOSUCHMAP) {
54348 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54349 int i, j, k;
54350 int ret;
54351
54352 - if (!capable(CAP_SYS_TTY_CONFIG))
54353 - perm = 0;
54354 -
54355 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54356 if (!kbs) {
54357 ret = -ENOMEM;
54358 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54359 kfree(kbs);
54360 return ((p && *p) ? -EOVERFLOW : 0);
54361 case KDSKBSENT:
54362 + if (!capable(CAP_SYS_TTY_CONFIG))
54363 + perm = 0;
54364 +
54365 if (!perm) {
54366 ret = -EPERM;
54367 goto reterr;
54368 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54369 index a673e5b..36e5d32 100644
54370 --- a/drivers/uio/uio.c
54371 +++ b/drivers/uio/uio.c
54372 @@ -25,6 +25,7 @@
54373 #include <linux/kobject.h>
54374 #include <linux/cdev.h>
54375 #include <linux/uio_driver.h>
54376 +#include <asm/local.h>
54377
54378 #define UIO_MAX_DEVICES (1U << MINORBITS)
54379
54380 @@ -32,7 +33,7 @@ struct uio_device {
54381 struct module *owner;
54382 struct device *dev;
54383 int minor;
54384 - atomic_t event;
54385 + atomic_unchecked_t event;
54386 struct fasync_struct *async_queue;
54387 wait_queue_head_t wait;
54388 struct uio_info *info;
54389 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54390 struct device_attribute *attr, char *buf)
54391 {
54392 struct uio_device *idev = dev_get_drvdata(dev);
54393 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54394 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54395 }
54396 static DEVICE_ATTR_RO(event);
54397
54398 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54399 {
54400 struct uio_device *idev = info->uio_dev;
54401
54402 - atomic_inc(&idev->event);
54403 + atomic_inc_unchecked(&idev->event);
54404 wake_up_interruptible(&idev->wait);
54405 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54406 }
54407 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54408 }
54409
54410 listener->dev = idev;
54411 - listener->event_count = atomic_read(&idev->event);
54412 + listener->event_count = atomic_read_unchecked(&idev->event);
54413 filep->private_data = listener;
54414
54415 if (idev->info->open) {
54416 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54417 return -EIO;
54418
54419 poll_wait(filep, &idev->wait, wait);
54420 - if (listener->event_count != atomic_read(&idev->event))
54421 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54422 return POLLIN | POLLRDNORM;
54423 return 0;
54424 }
54425 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54426 do {
54427 set_current_state(TASK_INTERRUPTIBLE);
54428
54429 - event_count = atomic_read(&idev->event);
54430 + event_count = atomic_read_unchecked(&idev->event);
54431 if (event_count != listener->event_count) {
54432 if (copy_to_user(buf, &event_count, count))
54433 retval = -EFAULT;
54434 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54435 static int uio_find_mem_index(struct vm_area_struct *vma)
54436 {
54437 struct uio_device *idev = vma->vm_private_data;
54438 + unsigned long size;
54439
54440 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54441 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54442 + size = idev->info->mem[vma->vm_pgoff].size;
54443 + if (size == 0)
54444 + return -1;
54445 + if (vma->vm_end - vma->vm_start > size)
54446 return -1;
54447 return (int)vma->vm_pgoff;
54448 }
54449 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54450 idev->owner = owner;
54451 idev->info = info;
54452 init_waitqueue_head(&idev->wait);
54453 - atomic_set(&idev->event, 0);
54454 + atomic_set_unchecked(&idev->event, 0);
54455
54456 ret = uio_get_minor(idev);
54457 if (ret)
54458 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54459 index 813d4d3..a71934f 100644
54460 --- a/drivers/usb/atm/cxacru.c
54461 +++ b/drivers/usb/atm/cxacru.c
54462 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54463 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54464 if (ret < 2)
54465 return -EINVAL;
54466 - if (index < 0 || index > 0x7f)
54467 + if (index > 0x7f)
54468 return -EINVAL;
54469 pos += tmp;
54470
54471 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54472 index dada014..1d0d517 100644
54473 --- a/drivers/usb/atm/usbatm.c
54474 +++ b/drivers/usb/atm/usbatm.c
54475 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54476 if (printk_ratelimit())
54477 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54478 __func__, vpi, vci);
54479 - atomic_inc(&vcc->stats->rx_err);
54480 + atomic_inc_unchecked(&vcc->stats->rx_err);
54481 return;
54482 }
54483
54484 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54485 if (length > ATM_MAX_AAL5_PDU) {
54486 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54487 __func__, length, vcc);
54488 - atomic_inc(&vcc->stats->rx_err);
54489 + atomic_inc_unchecked(&vcc->stats->rx_err);
54490 goto out;
54491 }
54492
54493 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54494 if (sarb->len < pdu_length) {
54495 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54496 __func__, pdu_length, sarb->len, vcc);
54497 - atomic_inc(&vcc->stats->rx_err);
54498 + atomic_inc_unchecked(&vcc->stats->rx_err);
54499 goto out;
54500 }
54501
54502 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54503 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54504 __func__, vcc);
54505 - atomic_inc(&vcc->stats->rx_err);
54506 + atomic_inc_unchecked(&vcc->stats->rx_err);
54507 goto out;
54508 }
54509
54510 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54511 if (printk_ratelimit())
54512 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54513 __func__, length);
54514 - atomic_inc(&vcc->stats->rx_drop);
54515 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54516 goto out;
54517 }
54518
54519 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54520
54521 vcc->push(vcc, skb);
54522
54523 - atomic_inc(&vcc->stats->rx);
54524 + atomic_inc_unchecked(&vcc->stats->rx);
54525 out:
54526 skb_trim(sarb, 0);
54527 }
54528 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54529 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54530
54531 usbatm_pop(vcc, skb);
54532 - atomic_inc(&vcc->stats->tx);
54533 + atomic_inc_unchecked(&vcc->stats->tx);
54534
54535 skb = skb_dequeue(&instance->sndqueue);
54536 }
54537 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54538 if (!left--)
54539 return sprintf(page,
54540 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54541 - atomic_read(&atm_dev->stats.aal5.tx),
54542 - atomic_read(&atm_dev->stats.aal5.tx_err),
54543 - atomic_read(&atm_dev->stats.aal5.rx),
54544 - atomic_read(&atm_dev->stats.aal5.rx_err),
54545 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54546 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54547 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54548 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54549 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54550 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54551
54552 if (!left--) {
54553 if (instance->disconnected)
54554 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54555 index 2a3bbdf..91d72cf 100644
54556 --- a/drivers/usb/core/devices.c
54557 +++ b/drivers/usb/core/devices.c
54558 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54559 * time it gets called.
54560 */
54561 static struct device_connect_event {
54562 - atomic_t count;
54563 + atomic_unchecked_t count;
54564 wait_queue_head_t wait;
54565 } device_event = {
54566 .count = ATOMIC_INIT(1),
54567 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54568
54569 void usbfs_conn_disc_event(void)
54570 {
54571 - atomic_add(2, &device_event.count);
54572 + atomic_add_unchecked(2, &device_event.count);
54573 wake_up(&device_event.wait);
54574 }
54575
54576 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54577
54578 poll_wait(file, &device_event.wait, wait);
54579
54580 - event_count = atomic_read(&device_event.count);
54581 + event_count = atomic_read_unchecked(&device_event.count);
54582 if (file->f_version != event_count) {
54583 file->f_version = event_count;
54584 return POLLIN | POLLRDNORM;
54585 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54586 index 0b59731..46ee7d1 100644
54587 --- a/drivers/usb/core/devio.c
54588 +++ b/drivers/usb/core/devio.c
54589 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54590 struct usb_dev_state *ps = file->private_data;
54591 struct usb_device *dev = ps->dev;
54592 ssize_t ret = 0;
54593 - unsigned len;
54594 + size_t len;
54595 loff_t pos;
54596 int i;
54597
54598 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54599 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54600 struct usb_config_descriptor *config =
54601 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54602 - unsigned int length = le16_to_cpu(config->wTotalLength);
54603 + size_t length = le16_to_cpu(config->wTotalLength);
54604
54605 if (*ppos < pos + length) {
54606
54607 /* The descriptor may claim to be longer than it
54608 * really is. Here is the actual allocated length. */
54609 - unsigned alloclen =
54610 + size_t alloclen =
54611 le16_to_cpu(dev->config[i].desc.wTotalLength);
54612
54613 - len = length - (*ppos - pos);
54614 + len = length + pos - *ppos;
54615 if (len > nbytes)
54616 len = nbytes;
54617
54618 /* Simply don't write (skip over) unallocated parts */
54619 if (alloclen > (*ppos - pos)) {
54620 - alloclen -= (*ppos - pos);
54621 + alloclen = alloclen + pos - *ppos;
54622 if (copy_to_user(buf,
54623 dev->rawdescriptors[i] + (*ppos - pos),
54624 min(len, alloclen))) {
54625 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54626 index 487abcf..06226dc 100644
54627 --- a/drivers/usb/core/hcd.c
54628 +++ b/drivers/usb/core/hcd.c
54629 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54630 */
54631 usb_get_urb(urb);
54632 atomic_inc(&urb->use_count);
54633 - atomic_inc(&urb->dev->urbnum);
54634 + atomic_inc_unchecked(&urb->dev->urbnum);
54635 usbmon_urb_submit(&hcd->self, urb);
54636
54637 /* NOTE requirements on root-hub callers (usbfs and the hub
54638 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54639 urb->hcpriv = NULL;
54640 INIT_LIST_HEAD(&urb->urb_list);
54641 atomic_dec(&urb->use_count);
54642 - atomic_dec(&urb->dev->urbnum);
54643 + atomic_dec_unchecked(&urb->dev->urbnum);
54644 if (atomic_read(&urb->reject))
54645 wake_up(&usb_kill_urb_queue);
54646 usb_put_urb(urb);
54647 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54648 index dc84915..cdb6624 100644
54649 --- a/drivers/usb/core/hub.c
54650 +++ b/drivers/usb/core/hub.c
54651 @@ -27,6 +27,7 @@
54652 #include <linux/freezer.h>
54653 #include <linux/random.h>
54654 #include <linux/pm_qos.h>
54655 +#include <linux/grsecurity.h>
54656
54657 #include <asm/uaccess.h>
54658 #include <asm/byteorder.h>
54659 @@ -4662,6 +4663,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54660 goto done;
54661 return;
54662 }
54663 +
54664 + if (gr_handle_new_usb())
54665 + goto done;
54666 +
54667 if (hub_is_superspeed(hub->hdev))
54668 unit_load = 150;
54669 else
54670 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54671 index 0c8a7fc..c45b40a 100644
54672 --- a/drivers/usb/core/message.c
54673 +++ b/drivers/usb/core/message.c
54674 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54675 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54676 * error number.
54677 */
54678 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54679 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54680 __u8 requesttype, __u16 value, __u16 index, void *data,
54681 __u16 size, int timeout)
54682 {
54683 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54684 * If successful, 0. Otherwise a negative error number. The number of actual
54685 * bytes transferred will be stored in the @actual_length parameter.
54686 */
54687 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54688 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54689 void *data, int len, int *actual_length, int timeout)
54690 {
54691 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54692 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54693 * bytes transferred will be stored in the @actual_length parameter.
54694 *
54695 */
54696 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54697 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54698 void *data, int len, int *actual_length, int timeout)
54699 {
54700 struct urb *urb;
54701 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54702 index 1236c60..d47a51c 100644
54703 --- a/drivers/usb/core/sysfs.c
54704 +++ b/drivers/usb/core/sysfs.c
54705 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54706 struct usb_device *udev;
54707
54708 udev = to_usb_device(dev);
54709 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54710 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54711 }
54712 static DEVICE_ATTR_RO(urbnum);
54713
54714 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54715 index 2dd2362..1135437 100644
54716 --- a/drivers/usb/core/usb.c
54717 +++ b/drivers/usb/core/usb.c
54718 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54719 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54720 dev->state = USB_STATE_ATTACHED;
54721 dev->lpm_disable_count = 1;
54722 - atomic_set(&dev->urbnum, 0);
54723 + atomic_set_unchecked(&dev->urbnum, 0);
54724
54725 INIT_LIST_HEAD(&dev->ep0.urb_list);
54726 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54727 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
54728 index 490a6ca..1f8364d 100644
54729 --- a/drivers/usb/dwc3/gadget.c
54730 +++ b/drivers/usb/dwc3/gadget.c
54731 @@ -615,8 +615,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
54732 if (!usb_endpoint_xfer_isoc(desc))
54733 return 0;
54734
54735 - memset(&trb_link, 0, sizeof(trb_link));
54736 -
54737 /* Link TRB for ISOC. The HWO bit is never reset */
54738 trb_st_hw = &dep->trb_pool[0];
54739
54740 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54741 index 8cfc319..4868255 100644
54742 --- a/drivers/usb/early/ehci-dbgp.c
54743 +++ b/drivers/usb/early/ehci-dbgp.c
54744 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54745
54746 #ifdef CONFIG_KGDB
54747 static struct kgdb_io kgdbdbgp_io_ops;
54748 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54749 +static struct kgdb_io kgdbdbgp_io_ops_console;
54750 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54751 #else
54752 #define dbgp_kgdb_mode (0)
54753 #endif
54754 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54755 .write_char = kgdbdbgp_write_char,
54756 };
54757
54758 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54759 + .name = "kgdbdbgp",
54760 + .read_char = kgdbdbgp_read_char,
54761 + .write_char = kgdbdbgp_write_char,
54762 + .is_console = 1
54763 +};
54764 +
54765 static int kgdbdbgp_wait_time;
54766
54767 static int __init kgdbdbgp_parse_config(char *str)
54768 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54769 ptr++;
54770 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54771 }
54772 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54773 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54774 + if (early_dbgp_console.index != -1)
54775 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54776 + else
54777 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54778
54779 return 0;
54780 }
54781 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54782 index 2b4c82d..06a8ee6 100644
54783 --- a/drivers/usb/gadget/function/f_uac1.c
54784 +++ b/drivers/usb/gadget/function/f_uac1.c
54785 @@ -13,6 +13,7 @@
54786 #include <linux/kernel.h>
54787 #include <linux/device.h>
54788 #include <linux/atomic.h>
54789 +#include <linux/module.h>
54790
54791 #include "u_uac1.h"
54792
54793 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54794 index ad0aca8..8ff84865 100644
54795 --- a/drivers/usb/gadget/function/u_serial.c
54796 +++ b/drivers/usb/gadget/function/u_serial.c
54797 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54798 spin_lock_irq(&port->port_lock);
54799
54800 /* already open? Great. */
54801 - if (port->port.count) {
54802 + if (atomic_read(&port->port.count)) {
54803 status = 0;
54804 - port->port.count++;
54805 + atomic_inc(&port->port.count);
54806
54807 /* currently opening/closing? wait ... */
54808 } else if (port->openclose) {
54809 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54810 tty->driver_data = port;
54811 port->port.tty = tty;
54812
54813 - port->port.count = 1;
54814 + atomic_set(&port->port.count, 1);
54815 port->openclose = false;
54816
54817 /* if connected, start the I/O stream */
54818 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54819
54820 spin_lock_irq(&port->port_lock);
54821
54822 - if (port->port.count != 1) {
54823 - if (port->port.count == 0)
54824 + if (atomic_read(&port->port.count) != 1) {
54825 + if (atomic_read(&port->port.count) == 0)
54826 WARN_ON(1);
54827 else
54828 - --port->port.count;
54829 + atomic_dec(&port->port.count);
54830 goto exit;
54831 }
54832
54833 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54834 * and sleep if necessary
54835 */
54836 port->openclose = true;
54837 - port->port.count = 0;
54838 + atomic_set(&port->port.count, 0);
54839
54840 gser = port->port_usb;
54841 if (gser && gser->disconnect)
54842 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54843 int cond;
54844
54845 spin_lock_irq(&port->port_lock);
54846 - cond = (port->port.count == 0) && !port->openclose;
54847 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54848 spin_unlock_irq(&port->port_lock);
54849 return cond;
54850 }
54851 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54852 /* if it's already open, start I/O ... and notify the serial
54853 * protocol about open/close status (connect/disconnect).
54854 */
54855 - if (port->port.count) {
54856 + if (atomic_read(&port->port.count)) {
54857 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54858 gs_start_io(port);
54859 if (gser->connect)
54860 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54861
54862 port->port_usb = NULL;
54863 gser->ioport = NULL;
54864 - if (port->port.count > 0 || port->openclose) {
54865 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54866 wake_up_interruptible(&port->drain_wait);
54867 if (port->port.tty)
54868 tty_hangup(port->port.tty);
54869 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54870
54871 /* finally, free any unused/unusable I/O buffers */
54872 spin_lock_irqsave(&port->port_lock, flags);
54873 - if (port->port.count == 0 && !port->openclose)
54874 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54875 gs_buf_free(&port->port_write_buf);
54876 gs_free_requests(gser->out, &port->read_pool, NULL);
54877 gs_free_requests(gser->out, &port->read_queue, NULL);
54878 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54879 index 7a55fea..cc0ed4f 100644
54880 --- a/drivers/usb/gadget/function/u_uac1.c
54881 +++ b/drivers/usb/gadget/function/u_uac1.c
54882 @@ -16,6 +16,7 @@
54883 #include <linux/ctype.h>
54884 #include <linux/random.h>
54885 #include <linux/syscalls.h>
54886 +#include <linux/module.h>
54887
54888 #include "u_uac1.h"
54889
54890 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54891 index 6130b75..3b60008 100644
54892 --- a/drivers/usb/host/ehci-hub.c
54893 +++ b/drivers/usb/host/ehci-hub.c
54894 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54895 urb->transfer_flags = URB_DIR_IN;
54896 usb_get_urb(urb);
54897 atomic_inc(&urb->use_count);
54898 - atomic_inc(&urb->dev->urbnum);
54899 + atomic_inc_unchecked(&urb->dev->urbnum);
54900 urb->setup_dma = dma_map_single(
54901 hcd->self.controller,
54902 urb->setup_packet,
54903 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54904 urb->status = -EINPROGRESS;
54905 usb_get_urb(urb);
54906 atomic_inc(&urb->use_count);
54907 - atomic_inc(&urb->dev->urbnum);
54908 + atomic_inc_unchecked(&urb->dev->urbnum);
54909 retval = submit_single_step_set_feature(hcd, urb, 0);
54910 if (!retval && !wait_for_completion_timeout(&done,
54911 msecs_to_jiffies(2000))) {
54912 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54913 index d0d8fad..668ef7b 100644
54914 --- a/drivers/usb/host/hwa-hc.c
54915 +++ b/drivers/usb/host/hwa-hc.c
54916 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54917 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54918 struct wahc *wa = &hwahc->wa;
54919 struct device *dev = &wa->usb_iface->dev;
54920 - u8 mas_le[UWB_NUM_MAS/8];
54921 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54922 +
54923 + if (mas_le == NULL)
54924 + return -ENOMEM;
54925
54926 /* Set the stream index */
54927 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54928 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54929 WUSB_REQ_SET_WUSB_MAS,
54930 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54931 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54932 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54933 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54934 if (result < 0)
54935 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54936 out:
54937 + kfree(mas_le);
54938 +
54939 return result;
54940 }
54941
54942 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54943 index b3d245e..99549ed 100644
54944 --- a/drivers/usb/misc/appledisplay.c
54945 +++ b/drivers/usb/misc/appledisplay.c
54946 @@ -84,7 +84,7 @@ struct appledisplay {
54947 struct mutex sysfslock; /* concurrent read and write */
54948 };
54949
54950 -static atomic_t count_displays = ATOMIC_INIT(0);
54951 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54952 static struct workqueue_struct *wq;
54953
54954 static void appledisplay_complete(struct urb *urb)
54955 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54956
54957 /* Register backlight device */
54958 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54959 - atomic_inc_return(&count_displays) - 1);
54960 + atomic_inc_return_unchecked(&count_displays) - 1);
54961 memset(&props, 0, sizeof(struct backlight_properties));
54962 props.type = BACKLIGHT_RAW;
54963 props.max_brightness = 0xff;
54964 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54965 index 8d7fc48..01c4986 100644
54966 --- a/drivers/usb/serial/console.c
54967 +++ b/drivers/usb/serial/console.c
54968 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54969
54970 info->port = port;
54971
54972 - ++port->port.count;
54973 + atomic_inc(&port->port.count);
54974 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54975 if (serial->type->set_termios) {
54976 /*
54977 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54978 }
54979 /* Now that any required fake tty operations are completed restore
54980 * the tty port count */
54981 - --port->port.count;
54982 + atomic_dec(&port->port.count);
54983 /* The console is special in terms of closing the device so
54984 * indicate this port is now acting as a system console. */
54985 port->port.console = 1;
54986 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54987 free_tty:
54988 kfree(tty);
54989 reset_open_count:
54990 - port->port.count = 0;
54991 + atomic_set(&port->port.count, 0);
54992 usb_autopm_put_interface(serial->interface);
54993 error_get_interface:
54994 usb_serial_put(serial);
54995 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54996 static void usb_console_write(struct console *co,
54997 const char *buf, unsigned count)
54998 {
54999 - static struct usbcons_info *info = &usbcons_info;
55000 + struct usbcons_info *info = &usbcons_info;
55001 struct usb_serial_port *port = info->port;
55002 struct usb_serial *serial;
55003 int retval = -ENODEV;
55004 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55005 index 307e339..6aa97cb 100644
55006 --- a/drivers/usb/storage/usb.h
55007 +++ b/drivers/usb/storage/usb.h
55008 @@ -63,7 +63,7 @@ struct us_unusual_dev {
55009 __u8 useProtocol;
55010 __u8 useTransport;
55011 int (*initFunction)(struct us_data *);
55012 -};
55013 +} __do_const;
55014
55015
55016 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55017 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
55018 index a863a98..d272795 100644
55019 --- a/drivers/usb/usbip/vhci.h
55020 +++ b/drivers/usb/usbip/vhci.h
55021 @@ -83,7 +83,7 @@ struct vhci_hcd {
55022 unsigned resuming:1;
55023 unsigned long re_timeout;
55024
55025 - atomic_t seqnum;
55026 + atomic_unchecked_t seqnum;
55027
55028 /*
55029 * NOTE:
55030 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
55031 index c02374b..32d47a9 100644
55032 --- a/drivers/usb/usbip/vhci_hcd.c
55033 +++ b/drivers/usb/usbip/vhci_hcd.c
55034 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
55035
55036 spin_lock(&vdev->priv_lock);
55037
55038 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
55039 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55040 if (priv->seqnum == 0xffff)
55041 dev_info(&urb->dev->dev, "seqnum max\n");
55042
55043 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
55044 return -ENOMEM;
55045 }
55046
55047 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
55048 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55049 if (unlink->seqnum == 0xffff)
55050 pr_info("seqnum max\n");
55051
55052 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
55053 vdev->rhport = rhport;
55054 }
55055
55056 - atomic_set(&vhci->seqnum, 0);
55057 + atomic_set_unchecked(&vhci->seqnum, 0);
55058 spin_lock_init(&vhci->lock);
55059
55060 hcd->power_budget = 0; /* no limit */
55061 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
55062 index 00e4a54..d676f85 100644
55063 --- a/drivers/usb/usbip/vhci_rx.c
55064 +++ b/drivers/usb/usbip/vhci_rx.c
55065 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
55066 if (!urb) {
55067 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
55068 pr_info("max seqnum %d\n",
55069 - atomic_read(&the_controller->seqnum));
55070 + atomic_read_unchecked(&the_controller->seqnum));
55071 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
55072 return;
55073 }
55074 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55075 index f2a8d29..7bc3fe7 100644
55076 --- a/drivers/usb/wusbcore/wa-hc.h
55077 +++ b/drivers/usb/wusbcore/wa-hc.h
55078 @@ -240,7 +240,7 @@ struct wahc {
55079 spinlock_t xfer_list_lock;
55080 struct work_struct xfer_enqueue_work;
55081 struct work_struct xfer_error_work;
55082 - atomic_t xfer_id_count;
55083 + atomic_unchecked_t xfer_id_count;
55084
55085 kernel_ulong_t quirks;
55086 };
55087 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55088 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55089 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55090 wa->dto_in_use = 0;
55091 - atomic_set(&wa->xfer_id_count, 1);
55092 + atomic_set_unchecked(&wa->xfer_id_count, 1);
55093 /* init the buf in URBs */
55094 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55095 usb_init_urb(&(wa->buf_in_urbs[index]));
55096 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55097 index e279015..c2d0dae 100644
55098 --- a/drivers/usb/wusbcore/wa-xfer.c
55099 +++ b/drivers/usb/wusbcore/wa-xfer.c
55100 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55101 */
55102 static void wa_xfer_id_init(struct wa_xfer *xfer)
55103 {
55104 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55105 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55106 }
55107
55108 /* Return the xfer's ID. */
55109 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55110 index f018d8d..ccab63f 100644
55111 --- a/drivers/vfio/vfio.c
55112 +++ b/drivers/vfio/vfio.c
55113 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55114 return 0;
55115
55116 /* TODO Prevent device auto probing */
55117 - WARN("Device %s added to live group %d!\n", dev_name(dev),
55118 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55119 iommu_group_id(group->iommu_group));
55120
55121 return 0;
55122 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55123 index 5174eba..451e6bc 100644
55124 --- a/drivers/vhost/vringh.c
55125 +++ b/drivers/vhost/vringh.c
55126 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55127 /* Userspace access helpers: in this case, addresses are really userspace. */
55128 static inline int getu16_user(u16 *val, const u16 *p)
55129 {
55130 - return get_user(*val, (__force u16 __user *)p);
55131 + return get_user(*val, (u16 __force_user *)p);
55132 }
55133
55134 static inline int putu16_user(u16 *p, u16 val)
55135 {
55136 - return put_user(val, (__force u16 __user *)p);
55137 + return put_user(val, (u16 __force_user *)p);
55138 }
55139
55140 static inline int copydesc_user(void *dst, const void *src, size_t len)
55141 {
55142 - return copy_from_user(dst, (__force void __user *)src, len) ?
55143 + return copy_from_user(dst, (void __force_user *)src, len) ?
55144 -EFAULT : 0;
55145 }
55146
55147 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55148 const struct vring_used_elem *src,
55149 unsigned int num)
55150 {
55151 - return copy_to_user((__force void __user *)dst, src,
55152 + return copy_to_user((void __force_user *)dst, src,
55153 sizeof(*dst) * num) ? -EFAULT : 0;
55154 }
55155
55156 static inline int xfer_from_user(void *src, void *dst, size_t len)
55157 {
55158 - return copy_from_user(dst, (__force void __user *)src, len) ?
55159 + return copy_from_user(dst, (void __force_user *)src, len) ?
55160 -EFAULT : 0;
55161 }
55162
55163 static inline int xfer_to_user(void *dst, void *src, size_t len)
55164 {
55165 - return copy_to_user((__force void __user *)dst, src, len) ?
55166 + return copy_to_user((void __force_user *)dst, src, len) ?
55167 -EFAULT : 0;
55168 }
55169
55170 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55171 vrh->last_used_idx = 0;
55172 vrh->vring.num = num;
55173 /* vring expects kernel addresses, but only used via accessors. */
55174 - vrh->vring.desc = (__force struct vring_desc *)desc;
55175 - vrh->vring.avail = (__force struct vring_avail *)avail;
55176 - vrh->vring.used = (__force struct vring_used *)used;
55177 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55178 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55179 + vrh->vring.used = (__force_kernel struct vring_used *)used;
55180 return 0;
55181 }
55182 EXPORT_SYMBOL(vringh_init_user);
55183 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55184
55185 static inline int putu16_kern(u16 *p, u16 val)
55186 {
55187 - ACCESS_ONCE(*p) = val;
55188 + ACCESS_ONCE_RW(*p) = val;
55189 return 0;
55190 }
55191
55192 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55193 index 84a110a..96312c3 100644
55194 --- a/drivers/video/backlight/kb3886_bl.c
55195 +++ b/drivers/video/backlight/kb3886_bl.c
55196 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55197 static unsigned long kb3886bl_flags;
55198 #define KB3886BL_SUSPENDED 0x01
55199
55200 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55201 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55202 {
55203 .ident = "Sahara Touch-iT",
55204 .matches = {
55205 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55206 index 1b0b233..6f34c2c 100644
55207 --- a/drivers/video/fbdev/arcfb.c
55208 +++ b/drivers/video/fbdev/arcfb.c
55209 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55210 return -ENOSPC;
55211
55212 err = 0;
55213 - if ((count + p) > fbmemlength) {
55214 + if (count > (fbmemlength - p)) {
55215 count = fbmemlength - p;
55216 err = -ENOSPC;
55217 }
55218 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55219 index ff60701..814b973 100644
55220 --- a/drivers/video/fbdev/aty/aty128fb.c
55221 +++ b/drivers/video/fbdev/aty/aty128fb.c
55222 @@ -149,7 +149,7 @@ enum {
55223 };
55224
55225 /* Must match above enum */
55226 -static char * const r128_family[] = {
55227 +static const char * const r128_family[] = {
55228 "AGP",
55229 "PCI",
55230 "PRO AGP",
55231 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55232 index 37ec09b..98f8862 100644
55233 --- a/drivers/video/fbdev/aty/atyfb_base.c
55234 +++ b/drivers/video/fbdev/aty/atyfb_base.c
55235 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55236 par->accel_flags = var->accel_flags; /* hack */
55237
55238 if (var->accel_flags) {
55239 - info->fbops->fb_sync = atyfb_sync;
55240 + pax_open_kernel();
55241 + *(void **)&info->fbops->fb_sync = atyfb_sync;
55242 + pax_close_kernel();
55243 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55244 } else {
55245 - info->fbops->fb_sync = NULL;
55246 + pax_open_kernel();
55247 + *(void **)&info->fbops->fb_sync = NULL;
55248 + pax_close_kernel();
55249 info->flags |= FBINFO_HWACCEL_DISABLED;
55250 }
55251
55252 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55253 index 2fa0317..4983f2a 100644
55254 --- a/drivers/video/fbdev/aty/mach64_cursor.c
55255 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
55256 @@ -8,6 +8,7 @@
55257 #include "../core/fb_draw.h"
55258
55259 #include <asm/io.h>
55260 +#include <asm/pgtable.h>
55261
55262 #ifdef __sparc__
55263 #include <asm/fbio.h>
55264 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55265 info->sprite.buf_align = 16; /* and 64 lines tall. */
55266 info->sprite.flags = FB_PIXMAP_IO;
55267
55268 - info->fbops->fb_cursor = atyfb_cursor;
55269 + pax_open_kernel();
55270 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55271 + pax_close_kernel();
55272
55273 return 0;
55274 }
55275 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55276 index 900aa4e..6d49418 100644
55277 --- a/drivers/video/fbdev/core/fb_defio.c
55278 +++ b/drivers/video/fbdev/core/fb_defio.c
55279 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55280
55281 BUG_ON(!fbdefio);
55282 mutex_init(&fbdefio->lock);
55283 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55284 + pax_open_kernel();
55285 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55286 + pax_close_kernel();
55287 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55288 INIT_LIST_HEAD(&fbdefio->pagelist);
55289 if (fbdefio->delay == 0) /* set a default of 1 s */
55290 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55291 page->mapping = NULL;
55292 }
55293
55294 - info->fbops->fb_mmap = NULL;
55295 + *(void **)&info->fbops->fb_mmap = NULL;
55296 mutex_destroy(&fbdefio->lock);
55297 }
55298 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55299 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55300 index b5e85f6..290f8c7 100644
55301 --- a/drivers/video/fbdev/core/fbmem.c
55302 +++ b/drivers/video/fbdev/core/fbmem.c
55303 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55304 __u32 data;
55305 int err;
55306
55307 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55308 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55309
55310 data = (__u32) (unsigned long) fix->smem_start;
55311 err |= put_user(data, &fix32->smem_start);
55312 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55313 index 4254336..282567e 100644
55314 --- a/drivers/video/fbdev/hyperv_fb.c
55315 +++ b/drivers/video/fbdev/hyperv_fb.c
55316 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55317 static inline int synthvid_send(struct hv_device *hdev,
55318 struct synthvid_msg *msg)
55319 {
55320 - static atomic64_t request_id = ATOMIC64_INIT(0);
55321 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55322 int ret;
55323
55324 msg->pipe_hdr.type = PIPE_MSG_DATA;
55325 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55326
55327 ret = vmbus_sendpacket(hdev->channel, msg,
55328 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55329 - atomic64_inc_return(&request_id),
55330 + atomic64_inc_return_unchecked(&request_id),
55331 VM_PKT_DATA_INBAND, 0);
55332
55333 if (ret)
55334 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55335 index 7672d2e..b56437f 100644
55336 --- a/drivers/video/fbdev/i810/i810_accel.c
55337 +++ b/drivers/video/fbdev/i810/i810_accel.c
55338 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55339 }
55340 }
55341 printk("ringbuffer lockup!!!\n");
55342 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55343 i810_report_error(mmio);
55344 par->dev_flags |= LOCKUP;
55345 info->pixmap.scan_align = 1;
55346 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55347 index a01147f..5d896f8 100644
55348 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55349 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55350 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55351
55352 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55353 struct matrox_switch matrox_mystique = {
55354 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55355 + .preinit = MGA1064_preinit,
55356 + .reset = MGA1064_reset,
55357 + .init = MGA1064_init,
55358 + .restore = MGA1064_restore,
55359 };
55360 EXPORT_SYMBOL(matrox_mystique);
55361 #endif
55362
55363 #ifdef CONFIG_FB_MATROX_G
55364 struct matrox_switch matrox_G100 = {
55365 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55366 + .preinit = MGAG100_preinit,
55367 + .reset = MGAG100_reset,
55368 + .init = MGAG100_init,
55369 + .restore = MGAG100_restore,
55370 };
55371 EXPORT_SYMBOL(matrox_G100);
55372 #endif
55373 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55374 index 195ad7c..09743fc 100644
55375 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55376 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55377 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55378 }
55379
55380 struct matrox_switch matrox_millennium = {
55381 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55382 + .preinit = Ti3026_preinit,
55383 + .reset = Ti3026_reset,
55384 + .init = Ti3026_init,
55385 + .restore = Ti3026_restore
55386 };
55387 EXPORT_SYMBOL(matrox_millennium);
55388 #endif
55389 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55390 index fe92eed..106e085 100644
55391 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55392 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55393 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55394 struct mb862xxfb_par *par = info->par;
55395
55396 if (info->var.bits_per_pixel == 32) {
55397 - info->fbops->fb_fillrect = cfb_fillrect;
55398 - info->fbops->fb_copyarea = cfb_copyarea;
55399 - info->fbops->fb_imageblit = cfb_imageblit;
55400 + pax_open_kernel();
55401 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55402 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55403 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55404 + pax_close_kernel();
55405 } else {
55406 outreg(disp, GC_L0EM, 3);
55407 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55408 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55409 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55410 + pax_open_kernel();
55411 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55412 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55413 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55414 + pax_close_kernel();
55415 }
55416 outreg(draw, GDC_REG_DRAW_BASE, 0);
55417 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55418 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55419 index def0412..fed6529 100644
55420 --- a/drivers/video/fbdev/nvidia/nvidia.c
55421 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55422 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55423 info->fix.line_length = (info->var.xres_virtual *
55424 info->var.bits_per_pixel) >> 3;
55425 if (info->var.accel_flags) {
55426 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55427 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55428 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55429 - info->fbops->fb_sync = nvidiafb_sync;
55430 + pax_open_kernel();
55431 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55432 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55433 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55434 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55435 + pax_close_kernel();
55436 info->pixmap.scan_align = 4;
55437 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55438 info->flags |= FBINFO_READS_FAST;
55439 NVResetGraphics(info);
55440 } else {
55441 - info->fbops->fb_imageblit = cfb_imageblit;
55442 - info->fbops->fb_fillrect = cfb_fillrect;
55443 - info->fbops->fb_copyarea = cfb_copyarea;
55444 - info->fbops->fb_sync = NULL;
55445 + pax_open_kernel();
55446 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55447 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55448 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55449 + *(void **)&info->fbops->fb_sync = NULL;
55450 + pax_close_kernel();
55451 info->pixmap.scan_align = 1;
55452 info->flags |= FBINFO_HWACCEL_DISABLED;
55453 info->flags &= ~FBINFO_READS_FAST;
55454 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55455 info->pixmap.size = 8 * 1024;
55456 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55457
55458 - if (!hwcur)
55459 - info->fbops->fb_cursor = NULL;
55460 + if (!hwcur) {
55461 + pax_open_kernel();
55462 + *(void **)&info->fbops->fb_cursor = NULL;
55463 + pax_close_kernel();
55464 + }
55465
55466 info->var.accel_flags = (!noaccel);
55467
55468 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55469 index 2412a0d..294215b 100644
55470 --- a/drivers/video/fbdev/omap2/dss/display.c
55471 +++ b/drivers/video/fbdev/omap2/dss/display.c
55472 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55473 if (dssdev->name == NULL)
55474 dssdev->name = dssdev->alias;
55475
55476 + pax_open_kernel();
55477 if (drv && drv->get_resolution == NULL)
55478 - drv->get_resolution = omapdss_default_get_resolution;
55479 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55480 if (drv && drv->get_recommended_bpp == NULL)
55481 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55482 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55483 if (drv && drv->get_timings == NULL)
55484 - drv->get_timings = omapdss_default_get_timings;
55485 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55486 + pax_close_kernel();
55487
55488 mutex_lock(&panel_list_mutex);
55489 list_add_tail(&dssdev->panel_list, &panel_list);
55490 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55491 index 83433cb..71e9b98 100644
55492 --- a/drivers/video/fbdev/s1d13xxxfb.c
55493 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55494 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55495
55496 switch(prod_id) {
55497 case S1D13506_PROD_ID: /* activate acceleration */
55498 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55499 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55500 + pax_open_kernel();
55501 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55502 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55503 + pax_close_kernel();
55504 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55505 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55506 break;
55507 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55508 index 2bcc84a..29dd1ea 100644
55509 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55510 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55511 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55512 }
55513
55514 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55515 - lcdc_sys_write_index,
55516 - lcdc_sys_write_data,
55517 - lcdc_sys_read_data,
55518 + .write_index = lcdc_sys_write_index,
55519 + .write_data = lcdc_sys_write_data,
55520 + .read_data = lcdc_sys_read_data,
55521 };
55522
55523 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55524 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55525 index d513ed6..90b0de9 100644
55526 --- a/drivers/video/fbdev/smscufx.c
55527 +++ b/drivers/video/fbdev/smscufx.c
55528 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55529 fb_deferred_io_cleanup(info);
55530 kfree(info->fbdefio);
55531 info->fbdefio = NULL;
55532 - info->fbops->fb_mmap = ufx_ops_mmap;
55533 + pax_open_kernel();
55534 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55535 + pax_close_kernel();
55536 }
55537
55538 pr_debug("released /dev/fb%d user=%d count=%d",
55539 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55540 index 77b890e..458e666 100644
55541 --- a/drivers/video/fbdev/udlfb.c
55542 +++ b/drivers/video/fbdev/udlfb.c
55543 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55544 dlfb_urb_completion(urb);
55545
55546 error:
55547 - atomic_add(bytes_sent, &dev->bytes_sent);
55548 - atomic_add(bytes_identical, &dev->bytes_identical);
55549 - atomic_add(width*height*2, &dev->bytes_rendered);
55550 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55551 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55552 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55553 end_cycles = get_cycles();
55554 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55555 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55556 >> 10)), /* Kcycles */
55557 &dev->cpu_kcycles_used);
55558
55559 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55560 dlfb_urb_completion(urb);
55561
55562 error:
55563 - atomic_add(bytes_sent, &dev->bytes_sent);
55564 - atomic_add(bytes_identical, &dev->bytes_identical);
55565 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55566 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55567 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55568 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55569 end_cycles = get_cycles();
55570 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55571 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55572 >> 10)), /* Kcycles */
55573 &dev->cpu_kcycles_used);
55574 }
55575 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55576 fb_deferred_io_cleanup(info);
55577 kfree(info->fbdefio);
55578 info->fbdefio = NULL;
55579 - info->fbops->fb_mmap = dlfb_ops_mmap;
55580 + pax_open_kernel();
55581 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55582 + pax_close_kernel();
55583 }
55584
55585 pr_warn("released /dev/fb%d user=%d count=%d\n",
55586 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55587 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55588 struct dlfb_data *dev = fb_info->par;
55589 return snprintf(buf, PAGE_SIZE, "%u\n",
55590 - atomic_read(&dev->bytes_rendered));
55591 + atomic_read_unchecked(&dev->bytes_rendered));
55592 }
55593
55594 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55595 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55596 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55597 struct dlfb_data *dev = fb_info->par;
55598 return snprintf(buf, PAGE_SIZE, "%u\n",
55599 - atomic_read(&dev->bytes_identical));
55600 + atomic_read_unchecked(&dev->bytes_identical));
55601 }
55602
55603 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55604 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55605 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55606 struct dlfb_data *dev = fb_info->par;
55607 return snprintf(buf, PAGE_SIZE, "%u\n",
55608 - atomic_read(&dev->bytes_sent));
55609 + atomic_read_unchecked(&dev->bytes_sent));
55610 }
55611
55612 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55613 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55614 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55615 struct dlfb_data *dev = fb_info->par;
55616 return snprintf(buf, PAGE_SIZE, "%u\n",
55617 - atomic_read(&dev->cpu_kcycles_used));
55618 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55619 }
55620
55621 static ssize_t edid_show(
55622 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55623 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55624 struct dlfb_data *dev = fb_info->par;
55625
55626 - atomic_set(&dev->bytes_rendered, 0);
55627 - atomic_set(&dev->bytes_identical, 0);
55628 - atomic_set(&dev->bytes_sent, 0);
55629 - atomic_set(&dev->cpu_kcycles_used, 0);
55630 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55631 + atomic_set_unchecked(&dev->bytes_identical, 0);
55632 + atomic_set_unchecked(&dev->bytes_sent, 0);
55633 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55634
55635 return count;
55636 }
55637 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55638 index 509d452..7c9d2de 100644
55639 --- a/drivers/video/fbdev/uvesafb.c
55640 +++ b/drivers/video/fbdev/uvesafb.c
55641 @@ -19,6 +19,7 @@
55642 #include <linux/io.h>
55643 #include <linux/mutex.h>
55644 #include <linux/slab.h>
55645 +#include <linux/moduleloader.h>
55646 #include <video/edid.h>
55647 #include <video/uvesafb.h>
55648 #ifdef CONFIG_X86
55649 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55650 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55651 par->pmi_setpal = par->ypan = 0;
55652 } else {
55653 +
55654 +#ifdef CONFIG_PAX_KERNEXEC
55655 +#ifdef CONFIG_MODULES
55656 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55657 +#endif
55658 + if (!par->pmi_code) {
55659 + par->pmi_setpal = par->ypan = 0;
55660 + return 0;
55661 + }
55662 +#endif
55663 +
55664 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55665 + task->t.regs.edi);
55666 +
55667 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55668 + pax_open_kernel();
55669 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55670 + pax_close_kernel();
55671 +
55672 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55673 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55674 +#else
55675 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55676 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55677 +#endif
55678 +
55679 printk(KERN_INFO "uvesafb: protected mode interface info at "
55680 "%04x:%04x\n",
55681 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55682 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55683 par->ypan = ypan;
55684
55685 if (par->pmi_setpal || par->ypan) {
55686 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55687 if (__supported_pte_mask & _PAGE_NX) {
55688 par->pmi_setpal = par->ypan = 0;
55689 printk(KERN_WARNING "uvesafb: NX protection is active, "
55690 "better not use the PMI.\n");
55691 - } else {
55692 + } else
55693 +#endif
55694 uvesafb_vbe_getpmi(task, par);
55695 - }
55696 }
55697 #else
55698 /* The protected mode interface is not available on non-x86. */
55699 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55700 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55701
55702 /* Disable blanking if the user requested so. */
55703 - if (!blank)
55704 - info->fbops->fb_blank = NULL;
55705 + if (!blank) {
55706 + pax_open_kernel();
55707 + *(void **)&info->fbops->fb_blank = NULL;
55708 + pax_close_kernel();
55709 + }
55710
55711 /*
55712 * Find out how much IO memory is required for the mode with
55713 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55714 info->flags = FBINFO_FLAG_DEFAULT |
55715 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55716
55717 - if (!par->ypan)
55718 - info->fbops->fb_pan_display = NULL;
55719 + if (!par->ypan) {
55720 + pax_open_kernel();
55721 + *(void **)&info->fbops->fb_pan_display = NULL;
55722 + pax_close_kernel();
55723 + }
55724 }
55725
55726 static void uvesafb_init_mtrr(struct fb_info *info)
55727 @@ -1787,6 +1817,11 @@ out_mode:
55728 out:
55729 kfree(par->vbe_modes);
55730
55731 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55732 + if (par->pmi_code)
55733 + module_free_exec(NULL, par->pmi_code);
55734 +#endif
55735 +
55736 framebuffer_release(info);
55737 return err;
55738 }
55739 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55740 kfree(par->vbe_state_orig);
55741 kfree(par->vbe_state_saved);
55742
55743 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55744 + if (par->pmi_code)
55745 + module_free_exec(NULL, par->pmi_code);
55746 +#endif
55747 +
55748 framebuffer_release(info);
55749 }
55750 return 0;
55751 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55752 index 6170e7f..dd63031 100644
55753 --- a/drivers/video/fbdev/vesafb.c
55754 +++ b/drivers/video/fbdev/vesafb.c
55755 @@ -9,6 +9,7 @@
55756 */
55757
55758 #include <linux/module.h>
55759 +#include <linux/moduleloader.h>
55760 #include <linux/kernel.h>
55761 #include <linux/errno.h>
55762 #include <linux/string.h>
55763 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55764 static int vram_total; /* Set total amount of memory */
55765 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55766 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55767 -static void (*pmi_start)(void) __read_mostly;
55768 -static void (*pmi_pal) (void) __read_mostly;
55769 +static void (*pmi_start)(void) __read_only;
55770 +static void (*pmi_pal) (void) __read_only;
55771 static int depth __read_mostly;
55772 static int vga_compat __read_mostly;
55773 /* --------------------------------------------------------------------- */
55774 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55775 unsigned int size_remap;
55776 unsigned int size_total;
55777 char *option = NULL;
55778 + void *pmi_code = NULL;
55779
55780 /* ignore error return of fb_get_options */
55781 fb_get_options("vesafb", &option);
55782 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55783 size_remap = size_total;
55784 vesafb_fix.smem_len = size_remap;
55785
55786 -#ifndef __i386__
55787 - screen_info.vesapm_seg = 0;
55788 -#endif
55789 -
55790 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55791 printk(KERN_WARNING
55792 "vesafb: cannot reserve video memory at 0x%lx\n",
55793 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55794 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55795 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55796
55797 +#ifdef __i386__
55798 +
55799 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55800 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55801 + if (!pmi_code)
55802 +#elif !defined(CONFIG_PAX_KERNEXEC)
55803 + if (0)
55804 +#endif
55805 +
55806 +#endif
55807 + screen_info.vesapm_seg = 0;
55808 +
55809 if (screen_info.vesapm_seg) {
55810 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55811 - screen_info.vesapm_seg,screen_info.vesapm_off);
55812 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55813 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55814 }
55815
55816 if (screen_info.vesapm_seg < 0xc000)
55817 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55818
55819 if (ypan || pmi_setpal) {
55820 unsigned short *pmi_base;
55821 +
55822 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55823 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55824 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55825 +
55826 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55827 + pax_open_kernel();
55828 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55829 +#else
55830 + pmi_code = pmi_base;
55831 +#endif
55832 +
55833 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55834 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55835 +
55836 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55837 + pmi_start = ktva_ktla(pmi_start);
55838 + pmi_pal = ktva_ktla(pmi_pal);
55839 + pax_close_kernel();
55840 +#endif
55841 +
55842 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55843 if (pmi_base[3]) {
55844 printk(KERN_INFO "vesafb: pmi: ports = ");
55845 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55846 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55847 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55848
55849 - if (!ypan)
55850 - info->fbops->fb_pan_display = NULL;
55851 + if (!ypan) {
55852 + pax_open_kernel();
55853 + *(void **)&info->fbops->fb_pan_display = NULL;
55854 + pax_close_kernel();
55855 + }
55856
55857 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55858 err = -ENOMEM;
55859 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55860 fb_info(info, "%s frame buffer device\n", info->fix.id);
55861 return 0;
55862 err:
55863 +
55864 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55865 + module_free_exec(NULL, pmi_code);
55866 +#endif
55867 +
55868 if (info->screen_base)
55869 iounmap(info->screen_base);
55870 framebuffer_release(info);
55871 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55872 index 88714ae..16c2e11 100644
55873 --- a/drivers/video/fbdev/via/via_clock.h
55874 +++ b/drivers/video/fbdev/via/via_clock.h
55875 @@ -56,7 +56,7 @@ struct via_clock {
55876
55877 void (*set_engine_pll_state)(u8 state);
55878 void (*set_engine_pll)(struct via_pll_config config);
55879 -};
55880 +} __no_const;
55881
55882
55883 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55884 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55885 index 3c14e43..2630570 100644
55886 --- a/drivers/video/logo/logo_linux_clut224.ppm
55887 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55888 @@ -2,1603 +2,1123 @@ P3
55889 # Standard 224-color Linux logo
55890 80 80
55891 255
55892 - 0 0 0 0 0 0 0 0 0 0 0 0
55893 - 0 0 0 0 0 0 0 0 0 0 0 0
55894 - 0 0 0 0 0 0 0 0 0 0 0 0
55895 - 0 0 0 0 0 0 0 0 0 0 0 0
55896 - 0 0 0 0 0 0 0 0 0 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 6 6 6 6 6 6 10 10 10 10 10 10
55902 - 10 10 10 6 6 6 6 6 6 6 6 6
55903 - 0 0 0 0 0 0 0 0 0 0 0 0
55904 - 0 0 0 0 0 0 0 0 0 0 0 0
55905 - 0 0 0 0 0 0 0 0 0 0 0 0
55906 - 0 0 0 0 0 0 0 0 0 0 0 0
55907 - 0 0 0 0 0 0 0 0 0 0 0 0
55908 - 0 0 0 0 0 0 0 0 0 0 0 0
55909 - 0 0 0 0 0 0 0 0 0 0 0 0
55910 - 0 0 0 0 0 0 0 0 0 0 0 0
55911 - 0 0 0 0 0 0 0 0 0 0 0 0
55912 - 0 0 0 0 0 0 0 0 0 0 0 0
55913 - 0 0 0 0 0 0 0 0 0 0 0 0
55914 - 0 0 0 0 0 0 0 0 0 0 0 0
55915 - 0 0 0 0 0 0 0 0 0 0 0 0
55916 - 0 0 0 0 0 0 0 0 0 0 0 0
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 6 6 6 10 10 10 14 14 14
55921 - 22 22 22 26 26 26 30 30 30 34 34 34
55922 - 30 30 30 30 30 30 26 26 26 18 18 18
55923 - 14 14 14 10 10 10 6 6 6 0 0 0
55924 - 0 0 0 0 0 0 0 0 0 0 0 0
55925 - 0 0 0 0 0 0 0 0 0 0 0 0
55926 - 0 0 0 0 0 0 0 0 0 0 0 0
55927 - 0 0 0 0 0 0 0 0 0 0 0 0
55928 - 0 0 0 0 0 0 0 0 0 0 0 0
55929 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0 0
55936 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 26 26 26 42 42 42
55941 - 54 54 54 66 66 66 78 78 78 78 78 78
55942 - 78 78 78 74 74 74 66 66 66 54 54 54
55943 - 42 42 42 26 26 26 18 18 18 10 10 10
55944 - 6 6 6 0 0 0 0 0 0 0 0 0
55945 - 0 0 0 0 0 0 0 0 0 0 0 0
55946 - 0 0 0 0 0 0 0 0 0 0 0 0
55947 - 0 0 0 0 0 0 0 0 0 0 0 0
55948 - 0 0 0 0 0 0 0 0 0 0 0 0
55949 - 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
55960 - 22 22 22 42 42 42 66 66 66 86 86 86
55961 - 66 66 66 38 38 38 38 38 38 22 22 22
55962 - 26 26 26 34 34 34 54 54 54 66 66 66
55963 - 86 86 86 70 70 70 46 46 46 26 26 26
55964 - 14 14 14 6 6 6 0 0 0 0 0 0
55965 - 0 0 0 0 0 0 0 0 0 0 0 0
55966 - 0 0 0 0 0 0 0 0 0 0 0 0
55967 - 0 0 0 0 0 0 0 0 0 0 0 0
55968 - 0 0 0 0 0 0 0 0 0 0 0 0
55969 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 10 10 10 26 26 26
55980 - 50 50 50 82 82 82 58 58 58 6 6 6
55981 - 2 2 6 2 2 6 2 2 6 2 2 6
55982 - 2 2 6 2 2 6 2 2 6 2 2 6
55983 - 6 6 6 54 54 54 86 86 86 66 66 66
55984 - 38 38 38 18 18 18 6 6 6 0 0 0
55985 - 0 0 0 0 0 0 0 0 0 0 0 0
55986 - 0 0 0 0 0 0 0 0 0 0 0 0
55987 - 0 0 0 0 0 0 0 0 0 0 0 0
55988 - 0 0 0 0 0 0 0 0 0 0 0 0
55989 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
56000 - 78 78 78 34 34 34 2 2 6 2 2 6
56001 - 2 2 6 2 2 6 2 2 6 2 2 6
56002 - 2 2 6 2 2 6 2 2 6 2 2 6
56003 - 2 2 6 2 2 6 6 6 6 70 70 70
56004 - 78 78 78 46 46 46 22 22 22 6 6 6
56005 - 0 0 0 0 0 0 0 0 0 0 0 0
56006 - 0 0 0 0 0 0 0 0 0 0 0 0
56007 - 0 0 0 0 0 0 0 0 0 0 0 0
56008 - 0 0 0 0 0 0 0 0 0 0 0 0
56009 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
56020 - 26 26 26 2 2 6 2 2 6 2 2 6
56021 - 2 2 6 2 2 6 2 2 6 2 2 6
56022 - 2 2 6 2 2 6 2 2 6 14 14 14
56023 - 46 46 46 34 34 34 6 6 6 2 2 6
56024 - 42 42 42 78 78 78 42 42 42 18 18 18
56025 - 6 6 6 0 0 0 0 0 0 0 0 0
56026 - 0 0 0 0 0 0 0 0 0 0 0 0
56027 - 0 0 0 0 0 0 0 0 0 0 0 0
56028 - 0 0 0 0 0 0 0 0 0 0 0 0
56029 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
56040 - 2 2 6 2 2 6 2 2 6 2 2 6
56041 - 2 2 6 2 2 6 2 2 6 2 2 6
56042 - 2 2 6 2 2 6 2 2 6 26 26 26
56043 - 86 86 86 101 101 101 46 46 46 10 10 10
56044 - 2 2 6 58 58 58 70 70 70 34 34 34
56045 - 10 10 10 0 0 0 0 0 0 0 0 0
56046 - 0 0 0 0 0 0 0 0 0 0 0 0
56047 - 0 0 0 0 0 0 0 0 0 0 0 0
56048 - 0 0 0 0 0 0 0 0 0 0 0 0
56049 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
56060 - 2 2 6 2 2 6 2 2 6 2 2 6
56061 - 2 2 6 2 2 6 2 2 6 2 2 6
56062 - 2 2 6 2 2 6 2 2 6 30 30 30
56063 - 94 94 94 94 94 94 58 58 58 26 26 26
56064 - 2 2 6 6 6 6 78 78 78 54 54 54
56065 - 22 22 22 6 6 6 0 0 0 0 0 0
56066 - 0 0 0 0 0 0 0 0 0 0 0 0
56067 - 0 0 0 0 0 0 0 0 0 0 0 0
56068 - 0 0 0 0 0 0 0 0 0 0 0 0
56069 - 0 0 0 0 0 0 0 0 0 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 6 6 6
56079 - 22 22 22 62 62 62 62 62 62 2 2 6
56080 - 2 2 6 2 2 6 2 2 6 2 2 6
56081 - 2 2 6 2 2 6 2 2 6 2 2 6
56082 - 2 2 6 2 2 6 2 2 6 26 26 26
56083 - 54 54 54 38 38 38 18 18 18 10 10 10
56084 - 2 2 6 2 2 6 34 34 34 82 82 82
56085 - 38 38 38 14 14 14 0 0 0 0 0 0
56086 - 0 0 0 0 0 0 0 0 0 0 0 0
56087 - 0 0 0 0 0 0 0 0 0 0 0 0
56088 - 0 0 0 0 0 0 0 0 0 0 0 0
56089 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 6 6 6
56099 - 30 30 30 78 78 78 30 30 30 2 2 6
56100 - 2 2 6 2 2 6 2 2 6 2 2 6
56101 - 2 2 6 2 2 6 2 2 6 2 2 6
56102 - 2 2 6 2 2 6 2 2 6 10 10 10
56103 - 10 10 10 2 2 6 2 2 6 2 2 6
56104 - 2 2 6 2 2 6 2 2 6 78 78 78
56105 - 50 50 50 18 18 18 6 6 6 0 0 0
56106 - 0 0 0 0 0 0 0 0 0 0 0 0
56107 - 0 0 0 0 0 0 0 0 0 0 0 0
56108 - 0 0 0 0 0 0 0 0 0 0 0 0
56109 - 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
56119 - 38 38 38 86 86 86 14 14 14 2 2 6
56120 - 2 2 6 2 2 6 2 2 6 2 2 6
56121 - 2 2 6 2 2 6 2 2 6 2 2 6
56122 - 2 2 6 2 2 6 2 2 6 2 2 6
56123 - 2 2 6 2 2 6 2 2 6 2 2 6
56124 - 2 2 6 2 2 6 2 2 6 54 54 54
56125 - 66 66 66 26 26 26 6 6 6 0 0 0
56126 - 0 0 0 0 0 0 0 0 0 0 0 0
56127 - 0 0 0 0 0 0 0 0 0 0 0 0
56128 - 0 0 0 0 0 0 0 0 0 0 0 0
56129 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 14 14 14
56139 - 42 42 42 82 82 82 2 2 6 2 2 6
56140 - 2 2 6 6 6 6 10 10 10 2 2 6
56141 - 2 2 6 2 2 6 2 2 6 2 2 6
56142 - 2 2 6 2 2 6 2 2 6 6 6 6
56143 - 14 14 14 10 10 10 2 2 6 2 2 6
56144 - 2 2 6 2 2 6 2 2 6 18 18 18
56145 - 82 82 82 34 34 34 10 10 10 0 0 0
56146 - 0 0 0 0 0 0 0 0 0 0 0 0
56147 - 0 0 0 0 0 0 0 0 0 0 0 0
56148 - 0 0 0 0 0 0 0 0 0 0 0 0
56149 - 0 0 0 0 0 0 0 0 0 0 0 0
56150 - 0 0 0 0 0 0 0 0 0 0 0 0
56151 - 0 0 0 0 0 0 0 0 0 0 0 0
56152 - 0 0 0 0 0 0 0 0 0 0 0 0
56153 - 0 0 1 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 14 14 14
56159 - 46 46 46 86 86 86 2 2 6 2 2 6
56160 - 6 6 6 6 6 6 22 22 22 34 34 34
56161 - 6 6 6 2 2 6 2 2 6 2 2 6
56162 - 2 2 6 2 2 6 18 18 18 34 34 34
56163 - 10 10 10 50 50 50 22 22 22 2 2 6
56164 - 2 2 6 2 2 6 2 2 6 10 10 10
56165 - 86 86 86 42 42 42 14 14 14 0 0 0
56166 - 0 0 0 0 0 0 0 0 0 0 0 0
56167 - 0 0 0 0 0 0 0 0 0 0 0 0
56168 - 0 0 0 0 0 0 0 0 0 0 0 0
56169 - 0 0 0 0 0 0 0 0 0 0 0 0
56170 - 0 0 0 0 0 0 0 0 0 0 0 0
56171 - 0 0 0 0 0 0 0 0 0 0 0 0
56172 - 0 0 0 0 0 0 0 0 0 0 0 0
56173 - 0 0 1 0 0 1 0 0 1 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 14 14 14
56179 - 46 46 46 86 86 86 2 2 6 2 2 6
56180 - 38 38 38 116 116 116 94 94 94 22 22 22
56181 - 22 22 22 2 2 6 2 2 6 2 2 6
56182 - 14 14 14 86 86 86 138 138 138 162 162 162
56183 -154 154 154 38 38 38 26 26 26 6 6 6
56184 - 2 2 6 2 2 6 2 2 6 2 2 6
56185 - 86 86 86 46 46 46 14 14 14 0 0 0
56186 - 0 0 0 0 0 0 0 0 0 0 0 0
56187 - 0 0 0 0 0 0 0 0 0 0 0 0
56188 - 0 0 0 0 0 0 0 0 0 0 0 0
56189 - 0 0 0 0 0 0 0 0 0 0 0 0
56190 - 0 0 0 0 0 0 0 0 0 0 0 0
56191 - 0 0 0 0 0 0 0 0 0 0 0 0
56192 - 0 0 0 0 0 0 0 0 0 0 0 0
56193 - 0 0 0 0 0 0 0 0 0 0 0 0
56194 - 0 0 0 0 0 0 0 0 0 0 0 0
56195 - 0 0 0 0 0 0 0 0 0 0 0 0
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 14 14 14
56199 - 46 46 46 86 86 86 2 2 6 14 14 14
56200 -134 134 134 198 198 198 195 195 195 116 116 116
56201 - 10 10 10 2 2 6 2 2 6 6 6 6
56202 -101 98 89 187 187 187 210 210 210 218 218 218
56203 -214 214 214 134 134 134 14 14 14 6 6 6
56204 - 2 2 6 2 2 6 2 2 6 2 2 6
56205 - 86 86 86 50 50 50 18 18 18 6 6 6
56206 - 0 0 0 0 0 0 0 0 0 0 0 0
56207 - 0 0 0 0 0 0 0 0 0 0 0 0
56208 - 0 0 0 0 0 0 0 0 0 0 0 0
56209 - 0 0 0 0 0 0 0 0 0 0 0 0
56210 - 0 0 0 0 0 0 0 0 0 0 0 0
56211 - 0 0 0 0 0 0 0 0 0 0 0 0
56212 - 0 0 0 0 0 0 0 0 1 0 0 0
56213 - 0 0 1 0 0 1 0 0 1 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 14 14 14
56219 - 46 46 46 86 86 86 2 2 6 54 54 54
56220 -218 218 218 195 195 195 226 226 226 246 246 246
56221 - 58 58 58 2 2 6 2 2 6 30 30 30
56222 -210 210 210 253 253 253 174 174 174 123 123 123
56223 -221 221 221 234 234 234 74 74 74 2 2 6
56224 - 2 2 6 2 2 6 2 2 6 2 2 6
56225 - 70 70 70 58 58 58 22 22 22 6 6 6
56226 - 0 0 0 0 0 0 0 0 0 0 0 0
56227 - 0 0 0 0 0 0 0 0 0 0 0 0
56228 - 0 0 0 0 0 0 0 0 0 0 0 0
56229 - 0 0 0 0 0 0 0 0 0 0 0 0
56230 - 0 0 0 0 0 0 0 0 0 0 0 0
56231 - 0 0 0 0 0 0 0 0 0 0 0 0
56232 - 0 0 0 0 0 0 0 0 0 0 0 0
56233 - 0 0 0 0 0 0 0 0 0 0 0 0
56234 - 0 0 0 0 0 0 0 0 0 0 0 0
56235 - 0 0 0 0 0 0 0 0 0 0 0 0
56236 - 0 0 0 0 0 0 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 14 14 14
56239 - 46 46 46 82 82 82 2 2 6 106 106 106
56240 -170 170 170 26 26 26 86 86 86 226 226 226
56241 -123 123 123 10 10 10 14 14 14 46 46 46
56242 -231 231 231 190 190 190 6 6 6 70 70 70
56243 - 90 90 90 238 238 238 158 158 158 2 2 6
56244 - 2 2 6 2 2 6 2 2 6 2 2 6
56245 - 70 70 70 58 58 58 22 22 22 6 6 6
56246 - 0 0 0 0 0 0 0 0 0 0 0 0
56247 - 0 0 0 0 0 0 0 0 0 0 0 0
56248 - 0 0 0 0 0 0 0 0 0 0 0 0
56249 - 0 0 0 0 0 0 0 0 0 0 0 0
56250 - 0 0 0 0 0 0 0 0 0 0 0 0
56251 - 0 0 0 0 0 0 0 0 0 0 0 0
56252 - 0 0 0 0 0 0 0 0 1 0 0 0
56253 - 0 0 1 0 0 1 0 0 1 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 14 14 14
56259 - 42 42 42 86 86 86 6 6 6 116 116 116
56260 -106 106 106 6 6 6 70 70 70 149 149 149
56261 -128 128 128 18 18 18 38 38 38 54 54 54
56262 -221 221 221 106 106 106 2 2 6 14 14 14
56263 - 46 46 46 190 190 190 198 198 198 2 2 6
56264 - 2 2 6 2 2 6 2 2 6 2 2 6
56265 - 74 74 74 62 62 62 22 22 22 6 6 6
56266 - 0 0 0 0 0 0 0 0 0 0 0 0
56267 - 0 0 0 0 0 0 0 0 0 0 0 0
56268 - 0 0 0 0 0 0 0 0 0 0 0 0
56269 - 0 0 0 0 0 0 0 0 0 0 0 0
56270 - 0 0 0 0 0 0 0 0 0 0 0 0
56271 - 0 0 0 0 0 0 0 0 0 0 0 0
56272 - 0 0 0 0 0 0 0 0 1 0 0 0
56273 - 0 0 1 0 0 0 0 0 1 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 14 14 14
56279 - 42 42 42 94 94 94 14 14 14 101 101 101
56280 -128 128 128 2 2 6 18 18 18 116 116 116
56281 -118 98 46 121 92 8 121 92 8 98 78 10
56282 -162 162 162 106 106 106 2 2 6 2 2 6
56283 - 2 2 6 195 195 195 195 195 195 6 6 6
56284 - 2 2 6 2 2 6 2 2 6 2 2 6
56285 - 74 74 74 62 62 62 22 22 22 6 6 6
56286 - 0 0 0 0 0 0 0 0 0 0 0 0
56287 - 0 0 0 0 0 0 0 0 0 0 0 0
56288 - 0 0 0 0 0 0 0 0 0 0 0 0
56289 - 0 0 0 0 0 0 0 0 0 0 0 0
56290 - 0 0 0 0 0 0 0 0 0 0 0 0
56291 - 0 0 0 0 0 0 0 0 0 0 0 0
56292 - 0 0 0 0 0 0 0 0 1 0 0 1
56293 - 0 0 1 0 0 0 0 0 1 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 10 10 10
56299 - 38 38 38 90 90 90 14 14 14 58 58 58
56300 -210 210 210 26 26 26 54 38 6 154 114 10
56301 -226 170 11 236 186 11 225 175 15 184 144 12
56302 -215 174 15 175 146 61 37 26 9 2 2 6
56303 - 70 70 70 246 246 246 138 138 138 2 2 6
56304 - 2 2 6 2 2 6 2 2 6 2 2 6
56305 - 70 70 70 66 66 66 26 26 26 6 6 6
56306 - 0 0 0 0 0 0 0 0 0 0 0 0
56307 - 0 0 0 0 0 0 0 0 0 0 0 0
56308 - 0 0 0 0 0 0 0 0 0 0 0 0
56309 - 0 0 0 0 0 0 0 0 0 0 0 0
56310 - 0 0 0 0 0 0 0 0 0 0 0 0
56311 - 0 0 0 0 0 0 0 0 0 0 0 0
56312 - 0 0 0 0 0 0 0 0 0 0 0 0
56313 - 0 0 0 0 0 0 0 0 0 0 0 0
56314 - 0 0 0 0 0 0 0 0 0 0 0 0
56315 - 0 0 0 0 0 0 0 0 0 0 0 0
56316 - 0 0 0 0 0 0 0 0 0 0 0 0
56317 - 0 0 0 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 10 10 10
56319 - 38 38 38 86 86 86 14 14 14 10 10 10
56320 -195 195 195 188 164 115 192 133 9 225 175 15
56321 -239 182 13 234 190 10 232 195 16 232 200 30
56322 -245 207 45 241 208 19 232 195 16 184 144 12
56323 -218 194 134 211 206 186 42 42 42 2 2 6
56324 - 2 2 6 2 2 6 2 2 6 2 2 6
56325 - 50 50 50 74 74 74 30 30 30 6 6 6
56326 - 0 0 0 0 0 0 0 0 0 0 0 0
56327 - 0 0 0 0 0 0 0 0 0 0 0 0
56328 - 0 0 0 0 0 0 0 0 0 0 0 0
56329 - 0 0 0 0 0 0 0 0 0 0 0 0
56330 - 0 0 0 0 0 0 0 0 0 0 0 0
56331 - 0 0 0 0 0 0 0 0 0 0 0 0
56332 - 0 0 0 0 0 0 0 0 0 0 0 0
56333 - 0 0 0 0 0 0 0 0 0 0 0 0
56334 - 0 0 0 0 0 0 0 0 0 0 0 0
56335 - 0 0 0 0 0 0 0 0 0 0 0 0
56336 - 0 0 0 0 0 0 0 0 0 0 0 0
56337 - 0 0 0 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 10 10 10
56339 - 34 34 34 86 86 86 14 14 14 2 2 6
56340 -121 87 25 192 133 9 219 162 10 239 182 13
56341 -236 186 11 232 195 16 241 208 19 244 214 54
56342 -246 218 60 246 218 38 246 215 20 241 208 19
56343 -241 208 19 226 184 13 121 87 25 2 2 6
56344 - 2 2 6 2 2 6 2 2 6 2 2 6
56345 - 50 50 50 82 82 82 34 34 34 10 10 10
56346 - 0 0 0 0 0 0 0 0 0 0 0 0
56347 - 0 0 0 0 0 0 0 0 0 0 0 0
56348 - 0 0 0 0 0 0 0 0 0 0 0 0
56349 - 0 0 0 0 0 0 0 0 0 0 0 0
56350 - 0 0 0 0 0 0 0 0 0 0 0 0
56351 - 0 0 0 0 0 0 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 10 10 10
56359 - 34 34 34 82 82 82 30 30 30 61 42 6
56360 -180 123 7 206 145 10 230 174 11 239 182 13
56361 -234 190 10 238 202 15 241 208 19 246 218 74
56362 -246 218 38 246 215 20 246 215 20 246 215 20
56363 -226 184 13 215 174 15 184 144 12 6 6 6
56364 - 2 2 6 2 2 6 2 2 6 2 2 6
56365 - 26 26 26 94 94 94 42 42 42 14 14 14
56366 - 0 0 0 0 0 0 0 0 0 0 0 0
56367 - 0 0 0 0 0 0 0 0 0 0 0 0
56368 - 0 0 0 0 0 0 0 0 0 0 0 0
56369 - 0 0 0 0 0 0 0 0 0 0 0 0
56370 - 0 0 0 0 0 0 0 0 0 0 0 0
56371 - 0 0 0 0 0 0 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 0 0 0 0 0 0 0 0 0
56376 - 0 0 0 0 0 0 0 0 0 0 0 0
56377 - 0 0 0 0 0 0 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 10 10 10
56379 - 30 30 30 78 78 78 50 50 50 104 69 6
56380 -192 133 9 216 158 10 236 178 12 236 186 11
56381 -232 195 16 241 208 19 244 214 54 245 215 43
56382 -246 215 20 246 215 20 241 208 19 198 155 10
56383 -200 144 11 216 158 10 156 118 10 2 2 6
56384 - 2 2 6 2 2 6 2 2 6 2 2 6
56385 - 6 6 6 90 90 90 54 54 54 18 18 18
56386 - 6 6 6 0 0 0 0 0 0 0 0 0
56387 - 0 0 0 0 0 0 0 0 0 0 0 0
56388 - 0 0 0 0 0 0 0 0 0 0 0 0
56389 - 0 0 0 0 0 0 0 0 0 0 0 0
56390 - 0 0 0 0 0 0 0 0 0 0 0 0
56391 - 0 0 0 0 0 0 0 0 0 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 0 0 0 0 0 0 0 0 0 0 0 0
56396 - 0 0 0 0 0 0 0 0 0 0 0 0
56397 - 0 0 0 0 0 0 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 10 10 10
56399 - 30 30 30 78 78 78 46 46 46 22 22 22
56400 -137 92 6 210 162 10 239 182 13 238 190 10
56401 -238 202 15 241 208 19 246 215 20 246 215 20
56402 -241 208 19 203 166 17 185 133 11 210 150 10
56403 -216 158 10 210 150 10 102 78 10 2 2 6
56404 - 6 6 6 54 54 54 14 14 14 2 2 6
56405 - 2 2 6 62 62 62 74 74 74 30 30 30
56406 - 10 10 10 0 0 0 0 0 0 0 0 0
56407 - 0 0 0 0 0 0 0 0 0 0 0 0
56408 - 0 0 0 0 0 0 0 0 0 0 0 0
56409 - 0 0 0 0 0 0 0 0 0 0 0 0
56410 - 0 0 0 0 0 0 0 0 0 0 0 0
56411 - 0 0 0 0 0 0 0 0 0 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 10 10 10
56419 - 34 34 34 78 78 78 50 50 50 6 6 6
56420 - 94 70 30 139 102 15 190 146 13 226 184 13
56421 -232 200 30 232 195 16 215 174 15 190 146 13
56422 -168 122 10 192 133 9 210 150 10 213 154 11
56423 -202 150 34 182 157 106 101 98 89 2 2 6
56424 - 2 2 6 78 78 78 116 116 116 58 58 58
56425 - 2 2 6 22 22 22 90 90 90 46 46 46
56426 - 18 18 18 6 6 6 0 0 0 0 0 0
56427 - 0 0 0 0 0 0 0 0 0 0 0 0
56428 - 0 0 0 0 0 0 0 0 0 0 0 0
56429 - 0 0 0 0 0 0 0 0 0 0 0 0
56430 - 0 0 0 0 0 0 0 0 0 0 0 0
56431 - 0 0 0 0 0 0 0 0 0 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 10 10 10
56439 - 38 38 38 86 86 86 50 50 50 6 6 6
56440 -128 128 128 174 154 114 156 107 11 168 122 10
56441 -198 155 10 184 144 12 197 138 11 200 144 11
56442 -206 145 10 206 145 10 197 138 11 188 164 115
56443 -195 195 195 198 198 198 174 174 174 14 14 14
56444 - 2 2 6 22 22 22 116 116 116 116 116 116
56445 - 22 22 22 2 2 6 74 74 74 70 70 70
56446 - 30 30 30 10 10 10 0 0 0 0 0 0
56447 - 0 0 0 0 0 0 0 0 0 0 0 0
56448 - 0 0 0 0 0 0 0 0 0 0 0 0
56449 - 0 0 0 0 0 0 0 0 0 0 0 0
56450 - 0 0 0 0 0 0 0 0 0 0 0 0
56451 - 0 0 0 0 0 0 0 0 0 0 0 0
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 6 6 6 18 18 18
56459 - 50 50 50 101 101 101 26 26 26 10 10 10
56460 -138 138 138 190 190 190 174 154 114 156 107 11
56461 -197 138 11 200 144 11 197 138 11 192 133 9
56462 -180 123 7 190 142 34 190 178 144 187 187 187
56463 -202 202 202 221 221 221 214 214 214 66 66 66
56464 - 2 2 6 2 2 6 50 50 50 62 62 62
56465 - 6 6 6 2 2 6 10 10 10 90 90 90
56466 - 50 50 50 18 18 18 6 6 6 0 0 0
56467 - 0 0 0 0 0 0 0 0 0 0 0 0
56468 - 0 0 0 0 0 0 0 0 0 0 0 0
56469 - 0 0 0 0 0 0 0 0 0 0 0 0
56470 - 0 0 0 0 0 0 0 0 0 0 0 0
56471 - 0 0 0 0 0 0 0 0 0 0 0 0
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 10 10 10 34 34 34
56479 - 74 74 74 74 74 74 2 2 6 6 6 6
56480 -144 144 144 198 198 198 190 190 190 178 166 146
56481 -154 121 60 156 107 11 156 107 11 168 124 44
56482 -174 154 114 187 187 187 190 190 190 210 210 210
56483 -246 246 246 253 253 253 253 253 253 182 182 182
56484 - 6 6 6 2 2 6 2 2 6 2 2 6
56485 - 2 2 6 2 2 6 2 2 6 62 62 62
56486 - 74 74 74 34 34 34 14 14 14 0 0 0
56487 - 0 0 0 0 0 0 0 0 0 0 0 0
56488 - 0 0 0 0 0 0 0 0 0 0 0 0
56489 - 0 0 0 0 0 0 0 0 0 0 0 0
56490 - 0 0 0 0 0 0 0 0 0 0 0 0
56491 - 0 0 0 0 0 0 0 0 0 0 0 0
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 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 10 10 10 22 22 22 54 54 54
56499 - 94 94 94 18 18 18 2 2 6 46 46 46
56500 -234 234 234 221 221 221 190 190 190 190 190 190
56501 -190 190 190 187 187 187 187 187 187 190 190 190
56502 -190 190 190 195 195 195 214 214 214 242 242 242
56503 -253 253 253 253 253 253 253 253 253 253 253 253
56504 - 82 82 82 2 2 6 2 2 6 2 2 6
56505 - 2 2 6 2 2 6 2 2 6 14 14 14
56506 - 86 86 86 54 54 54 22 22 22 6 6 6
56507 - 0 0 0 0 0 0 0 0 0 0 0 0
56508 - 0 0 0 0 0 0 0 0 0 0 0 0
56509 - 0 0 0 0 0 0 0 0 0 0 0 0
56510 - 0 0 0 0 0 0 0 0 0 0 0 0
56511 - 0 0 0 0 0 0 0 0 0 0 0 0
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 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 - 6 6 6 18 18 18 46 46 46 90 90 90
56519 - 46 46 46 18 18 18 6 6 6 182 182 182
56520 -253 253 253 246 246 246 206 206 206 190 190 190
56521 -190 190 190 190 190 190 190 190 190 190 190 190
56522 -206 206 206 231 231 231 250 250 250 253 253 253
56523 -253 253 253 253 253 253 253 253 253 253 253 253
56524 -202 202 202 14 14 14 2 2 6 2 2 6
56525 - 2 2 6 2 2 6 2 2 6 2 2 6
56526 - 42 42 42 86 86 86 42 42 42 18 18 18
56527 - 6 6 6 0 0 0 0 0 0 0 0 0
56528 - 0 0 0 0 0 0 0 0 0 0 0 0
56529 - 0 0 0 0 0 0 0 0 0 0 0 0
56530 - 0 0 0 0 0 0 0 0 0 0 0 0
56531 - 0 0 0 0 0 0 0 0 0 0 0 0
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 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 6 6 6
56538 - 14 14 14 38 38 38 74 74 74 66 66 66
56539 - 2 2 6 6 6 6 90 90 90 250 250 250
56540 -253 253 253 253 253 253 238 238 238 198 198 198
56541 -190 190 190 190 190 190 195 195 195 221 221 221
56542 -246 246 246 253 253 253 253 253 253 253 253 253
56543 -253 253 253 253 253 253 253 253 253 253 253 253
56544 -253 253 253 82 82 82 2 2 6 2 2 6
56545 - 2 2 6 2 2 6 2 2 6 2 2 6
56546 - 2 2 6 78 78 78 70 70 70 34 34 34
56547 - 14 14 14 6 6 6 0 0 0 0 0 0
56548 - 0 0 0 0 0 0 0 0 0 0 0 0
56549 - 0 0 0 0 0 0 0 0 0 0 0 0
56550 - 0 0 0 0 0 0 0 0 0 0 0 0
56551 - 0 0 0 0 0 0 0 0 0 0 0 0
56552 - 0 0 0 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 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 14 14 14
56558 - 34 34 34 66 66 66 78 78 78 6 6 6
56559 - 2 2 6 18 18 18 218 218 218 253 253 253
56560 -253 253 253 253 253 253 253 253 253 246 246 246
56561 -226 226 226 231 231 231 246 246 246 253 253 253
56562 -253 253 253 253 253 253 253 253 253 253 253 253
56563 -253 253 253 253 253 253 253 253 253 253 253 253
56564 -253 253 253 178 178 178 2 2 6 2 2 6
56565 - 2 2 6 2 2 6 2 2 6 2 2 6
56566 - 2 2 6 18 18 18 90 90 90 62 62 62
56567 - 30 30 30 10 10 10 0 0 0 0 0 0
56568 - 0 0 0 0 0 0 0 0 0 0 0 0
56569 - 0 0 0 0 0 0 0 0 0 0 0 0
56570 - 0 0 0 0 0 0 0 0 0 0 0 0
56571 - 0 0 0 0 0 0 0 0 0 0 0 0
56572 - 0 0 0 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 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 10 10 10 26 26 26
56578 - 58 58 58 90 90 90 18 18 18 2 2 6
56579 - 2 2 6 110 110 110 253 253 253 253 253 253
56580 -253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 253 253 253
56584 -253 253 253 231 231 231 18 18 18 2 2 6
56585 - 2 2 6 2 2 6 2 2 6 2 2 6
56586 - 2 2 6 2 2 6 18 18 18 94 94 94
56587 - 54 54 54 26 26 26 10 10 10 0 0 0
56588 - 0 0 0 0 0 0 0 0 0 0 0 0
56589 - 0 0 0 0 0 0 0 0 0 0 0 0
56590 - 0 0 0 0 0 0 0 0 0 0 0 0
56591 - 0 0 0 0 0 0 0 0 0 0 0 0
56592 - 0 0 0 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 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 6 6 6 22 22 22 50 50 50
56598 - 90 90 90 26 26 26 2 2 6 2 2 6
56599 - 14 14 14 195 195 195 250 250 250 253 253 253
56600 -253 253 253 253 253 253 253 253 253 253 253 253
56601 -253 253 253 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 253 253 253 253 253 253
56604 -250 250 250 242 242 242 54 54 54 2 2 6
56605 - 2 2 6 2 2 6 2 2 6 2 2 6
56606 - 2 2 6 2 2 6 2 2 6 38 38 38
56607 - 86 86 86 50 50 50 22 22 22 6 6 6
56608 - 0 0 0 0 0 0 0 0 0 0 0 0
56609 - 0 0 0 0 0 0 0 0 0 0 0 0
56610 - 0 0 0 0 0 0 0 0 0 0 0 0
56611 - 0 0 0 0 0 0 0 0 0 0 0 0
56612 - 0 0 0 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 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 - 6 6 6 14 14 14 38 38 38 82 82 82
56618 - 34 34 34 2 2 6 2 2 6 2 2 6
56619 - 42 42 42 195 195 195 246 246 246 253 253 253
56620 -253 253 253 253 253 253 253 253 253 250 250 250
56621 -242 242 242 242 242 242 250 250 250 253 253 253
56622 -253 253 253 253 253 253 253 253 253 253 253 253
56623 -253 253 253 250 250 250 246 246 246 238 238 238
56624 -226 226 226 231 231 231 101 101 101 6 6 6
56625 - 2 2 6 2 2 6 2 2 6 2 2 6
56626 - 2 2 6 2 2 6 2 2 6 2 2 6
56627 - 38 38 38 82 82 82 42 42 42 14 14 14
56628 - 6 6 6 0 0 0 0 0 0 0 0 0
56629 - 0 0 0 0 0 0 0 0 0 0 0 0
56630 - 0 0 0 0 0 0 0 0 0 0 0 0
56631 - 0 0 0 0 0 0 0 0 0 0 0 0
56632 - 0 0 0 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 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 - 10 10 10 26 26 26 62 62 62 66 66 66
56638 - 2 2 6 2 2 6 2 2 6 6 6 6
56639 - 70 70 70 170 170 170 206 206 206 234 234 234
56640 -246 246 246 250 250 250 250 250 250 238 238 238
56641 -226 226 226 231 231 231 238 238 238 250 250 250
56642 -250 250 250 250 250 250 246 246 246 231 231 231
56643 -214 214 214 206 206 206 202 202 202 202 202 202
56644 -198 198 198 202 202 202 182 182 182 18 18 18
56645 - 2 2 6 2 2 6 2 2 6 2 2 6
56646 - 2 2 6 2 2 6 2 2 6 2 2 6
56647 - 2 2 6 62 62 62 66 66 66 30 30 30
56648 - 10 10 10 0 0 0 0 0 0 0 0 0
56649 - 0 0 0 0 0 0 0 0 0 0 0 0
56650 - 0 0 0 0 0 0 0 0 0 0 0 0
56651 - 0 0 0 0 0 0 0 0 0 0 0 0
56652 - 0 0 0 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
56658 - 2 2 6 2 2 6 2 2 6 10 10 10
56659 - 94 94 94 182 182 182 218 218 218 242 242 242
56660 -250 250 250 253 253 253 253 253 253 250 250 250
56661 -234 234 234 253 253 253 253 253 253 253 253 253
56662 -253 253 253 253 253 253 253 253 253 246 246 246
56663 -238 238 238 226 226 226 210 210 210 202 202 202
56664 -195 195 195 195 195 195 210 210 210 158 158 158
56665 - 6 6 6 14 14 14 50 50 50 14 14 14
56666 - 2 2 6 2 2 6 2 2 6 2 2 6
56667 - 2 2 6 6 6 6 86 86 86 46 46 46
56668 - 18 18 18 6 6 6 0 0 0 0 0 0
56669 - 0 0 0 0 0 0 0 0 0 0 0 0
56670 - 0 0 0 0 0 0 0 0 0 0 0 0
56671 - 0 0 0 0 0 0 0 0 0 0 0 0
56672 - 0 0 0 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 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 6 6 6
56677 - 22 22 22 54 54 54 70 70 70 2 2 6
56678 - 2 2 6 10 10 10 2 2 6 22 22 22
56679 -166 166 166 231 231 231 250 250 250 253 253 253
56680 -253 253 253 253 253 253 253 253 253 250 250 250
56681 -242 242 242 253 253 253 253 253 253 253 253 253
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 253 253 253 246 246 246
56684 -231 231 231 206 206 206 198 198 198 226 226 226
56685 - 94 94 94 2 2 6 6 6 6 38 38 38
56686 - 30 30 30 2 2 6 2 2 6 2 2 6
56687 - 2 2 6 2 2 6 62 62 62 66 66 66
56688 - 26 26 26 10 10 10 0 0 0 0 0 0
56689 - 0 0 0 0 0 0 0 0 0 0 0 0
56690 - 0 0 0 0 0 0 0 0 0 0 0 0
56691 - 0 0 0 0 0 0 0 0 0 0 0 0
56692 - 0 0 0 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 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 10 10 10
56697 - 30 30 30 74 74 74 50 50 50 2 2 6
56698 - 26 26 26 26 26 26 2 2 6 106 106 106
56699 -238 238 238 253 253 253 253 253 253 253 253 253
56700 -253 253 253 253 253 253 253 253 253 253 253 253
56701 -253 253 253 253 253 253 253 253 253 253 253 253
56702 -253 253 253 253 253 253 253 253 253 253 253 253
56703 -253 253 253 253 253 253 253 253 253 253 253 253
56704 -253 253 253 246 246 246 218 218 218 202 202 202
56705 -210 210 210 14 14 14 2 2 6 2 2 6
56706 - 30 30 30 22 22 22 2 2 6 2 2 6
56707 - 2 2 6 2 2 6 18 18 18 86 86 86
56708 - 42 42 42 14 14 14 0 0 0 0 0 0
56709 - 0 0 0 0 0 0 0 0 0 0 0 0
56710 - 0 0 0 0 0 0 0 0 0 0 0 0
56711 - 0 0 0 0 0 0 0 0 0 0 0 0
56712 - 0 0 0 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 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 14 14 14
56717 - 42 42 42 90 90 90 22 22 22 2 2 6
56718 - 42 42 42 2 2 6 18 18 18 218 218 218
56719 -253 253 253 253 253 253 253 253 253 253 253 253
56720 -253 253 253 253 253 253 253 253 253 253 253 253
56721 -253 253 253 253 253 253 253 253 253 253 253 253
56722 -253 253 253 253 253 253 253 253 253 253 253 253
56723 -253 253 253 253 253 253 253 253 253 253 253 253
56724 -253 253 253 253 253 253 250 250 250 221 221 221
56725 -218 218 218 101 101 101 2 2 6 14 14 14
56726 - 18 18 18 38 38 38 10 10 10 2 2 6
56727 - 2 2 6 2 2 6 2 2 6 78 78 78
56728 - 58 58 58 22 22 22 6 6 6 0 0 0
56729 - 0 0 0 0 0 0 0 0 0 0 0 0
56730 - 0 0 0 0 0 0 0 0 0 0 0 0
56731 - 0 0 0 0 0 0 0 0 0 0 0 0
56732 - 0 0 0 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 6 6 6 18 18 18
56737 - 54 54 54 82 82 82 2 2 6 26 26 26
56738 - 22 22 22 2 2 6 123 123 123 253 253 253
56739 -253 253 253 253 253 253 253 253 253 253 253 253
56740 -253 253 253 253 253 253 253 253 253 253 253 253
56741 -253 253 253 253 253 253 253 253 253 253 253 253
56742 -253 253 253 253 253 253 253 253 253 253 253 253
56743 -253 253 253 253 253 253 253 253 253 253 253 253
56744 -253 253 253 253 253 253 253 253 253 250 250 250
56745 -238 238 238 198 198 198 6 6 6 38 38 38
56746 - 58 58 58 26 26 26 38 38 38 2 2 6
56747 - 2 2 6 2 2 6 2 2 6 46 46 46
56748 - 78 78 78 30 30 30 10 10 10 0 0 0
56749 - 0 0 0 0 0 0 0 0 0 0 0 0
56750 - 0 0 0 0 0 0 0 0 0 0 0 0
56751 - 0 0 0 0 0 0 0 0 0 0 0 0
56752 - 0 0 0 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 10 10 10 30 30 30
56757 - 74 74 74 58 58 58 2 2 6 42 42 42
56758 - 2 2 6 22 22 22 231 231 231 253 253 253
56759 -253 253 253 253 253 253 253 253 253 253 253 253
56760 -253 253 253 253 253 253 253 253 253 250 250 250
56761 -253 253 253 253 253 253 253 253 253 253 253 253
56762 -253 253 253 253 253 253 253 253 253 253 253 253
56763 -253 253 253 253 253 253 253 253 253 253 253 253
56764 -253 253 253 253 253 253 253 253 253 253 253 253
56765 -253 253 253 246 246 246 46 46 46 38 38 38
56766 - 42 42 42 14 14 14 38 38 38 14 14 14
56767 - 2 2 6 2 2 6 2 2 6 6 6 6
56768 - 86 86 86 46 46 46 14 14 14 0 0 0
56769 - 0 0 0 0 0 0 0 0 0 0 0 0
56770 - 0 0 0 0 0 0 0 0 0 0 0 0
56771 - 0 0 0 0 0 0 0 0 0 0 0 0
56772 - 0 0 0 0 0 0 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 6 6 6 14 14 14 42 42 42
56777 - 90 90 90 18 18 18 18 18 18 26 26 26
56778 - 2 2 6 116 116 116 253 253 253 253 253 253
56779 -253 253 253 253 253 253 253 253 253 253 253 253
56780 -253 253 253 253 253 253 250 250 250 238 238 238
56781 -253 253 253 253 253 253 253 253 253 253 253 253
56782 -253 253 253 253 253 253 253 253 253 253 253 253
56783 -253 253 253 253 253 253 253 253 253 253 253 253
56784 -253 253 253 253 253 253 253 253 253 253 253 253
56785 -253 253 253 253 253 253 94 94 94 6 6 6
56786 - 2 2 6 2 2 6 10 10 10 34 34 34
56787 - 2 2 6 2 2 6 2 2 6 2 2 6
56788 - 74 74 74 58 58 58 22 22 22 6 6 6
56789 - 0 0 0 0 0 0 0 0 0 0 0 0
56790 - 0 0 0 0 0 0 0 0 0 0 0 0
56791 - 0 0 0 0 0 0 0 0 0 0 0 0
56792 - 0 0 0 0 0 0 0 0 0 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 10 10 10 26 26 26 66 66 66
56797 - 82 82 82 2 2 6 38 38 38 6 6 6
56798 - 14 14 14 210 210 210 253 253 253 253 253 253
56799 -253 253 253 253 253 253 253 253 253 253 253 253
56800 -253 253 253 253 253 253 246 246 246 242 242 242
56801 -253 253 253 253 253 253 253 253 253 253 253 253
56802 -253 253 253 253 253 253 253 253 253 253 253 253
56803 -253 253 253 253 253 253 253 253 253 253 253 253
56804 -253 253 253 253 253 253 253 253 253 253 253 253
56805 -253 253 253 253 253 253 144 144 144 2 2 6
56806 - 2 2 6 2 2 6 2 2 6 46 46 46
56807 - 2 2 6 2 2 6 2 2 6 2 2 6
56808 - 42 42 42 74 74 74 30 30 30 10 10 10
56809 - 0 0 0 0 0 0 0 0 0 0 0 0
56810 - 0 0 0 0 0 0 0 0 0 0 0 0
56811 - 0 0 0 0 0 0 0 0 0 0 0 0
56812 - 0 0 0 0 0 0 0 0 0 0 0 0
56813 - 0 0 0 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 6 6 6 14 14 14 42 42 42 90 90 90
56817 - 26 26 26 6 6 6 42 42 42 2 2 6
56818 - 74 74 74 250 250 250 253 253 253 253 253 253
56819 -253 253 253 253 253 253 253 253 253 253 253 253
56820 -253 253 253 253 253 253 242 242 242 242 242 242
56821 -253 253 253 253 253 253 253 253 253 253 253 253
56822 -253 253 253 253 253 253 253 253 253 253 253 253
56823 -253 253 253 253 253 253 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 182 182 182 2 2 6
56826 - 2 2 6 2 2 6 2 2 6 46 46 46
56827 - 2 2 6 2 2 6 2 2 6 2 2 6
56828 - 10 10 10 86 86 86 38 38 38 10 10 10
56829 - 0 0 0 0 0 0 0 0 0 0 0 0
56830 - 0 0 0 0 0 0 0 0 0 0 0 0
56831 - 0 0 0 0 0 0 0 0 0 0 0 0
56832 - 0 0 0 0 0 0 0 0 0 0 0 0
56833 - 0 0 0 0 0 0 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 10 10 10 26 26 26 66 66 66 82 82 82
56837 - 2 2 6 22 22 22 18 18 18 2 2 6
56838 -149 149 149 253 253 253 253 253 253 253 253 253
56839 -253 253 253 253 253 253 253 253 253 253 253 253
56840 -253 253 253 253 253 253 234 234 234 242 242 242
56841 -253 253 253 253 253 253 253 253 253 253 253 253
56842 -253 253 253 253 253 253 253 253 253 253 253 253
56843 -253 253 253 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 206 206 206 2 2 6
56846 - 2 2 6 2 2 6 2 2 6 38 38 38
56847 - 2 2 6 2 2 6 2 2 6 2 2 6
56848 - 6 6 6 86 86 86 46 46 46 14 14 14
56849 - 0 0 0 0 0 0 0 0 0 0 0 0
56850 - 0 0 0 0 0 0 0 0 0 0 0 0
56851 - 0 0 0 0 0 0 0 0 0 0 0 0
56852 - 0 0 0 0 0 0 0 0 0 0 0 0
56853 - 0 0 0 0 0 0 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 6 6 6
56856 - 18 18 18 46 46 46 86 86 86 18 18 18
56857 - 2 2 6 34 34 34 10 10 10 6 6 6
56858 -210 210 210 253 253 253 253 253 253 253 253 253
56859 -253 253 253 253 253 253 253 253 253 253 253 253
56860 -253 253 253 253 253 253 234 234 234 242 242 242
56861 -253 253 253 253 253 253 253 253 253 253 253 253
56862 -253 253 253 253 253 253 253 253 253 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 221 221 221 6 6 6
56866 - 2 2 6 2 2 6 6 6 6 30 30 30
56867 - 2 2 6 2 2 6 2 2 6 2 2 6
56868 - 2 2 6 82 82 82 54 54 54 18 18 18
56869 - 6 6 6 0 0 0 0 0 0 0 0 0
56870 - 0 0 0 0 0 0 0 0 0 0 0 0
56871 - 0 0 0 0 0 0 0 0 0 0 0 0
56872 - 0 0 0 0 0 0 0 0 0 0 0 0
56873 - 0 0 0 0 0 0 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 10 10 10
56876 - 26 26 26 66 66 66 62 62 62 2 2 6
56877 - 2 2 6 38 38 38 10 10 10 26 26 26
56878 -238 238 238 253 253 253 253 253 253 253 253 253
56879 -253 253 253 253 253 253 253 253 253 253 253 253
56880 -253 253 253 253 253 253 231 231 231 238 238 238
56881 -253 253 253 253 253 253 253 253 253 253 253 253
56882 -253 253 253 253 253 253 253 253 253 253 253 253
56883 -253 253 253 253 253 253 253 253 253 253 253 253
56884 -253 253 253 253 253 253 253 253 253 253 253 253
56885 -253 253 253 253 253 253 231 231 231 6 6 6
56886 - 2 2 6 2 2 6 10 10 10 30 30 30
56887 - 2 2 6 2 2 6 2 2 6 2 2 6
56888 - 2 2 6 66 66 66 58 58 58 22 22 22
56889 - 6 6 6 0 0 0 0 0 0 0 0 0
56890 - 0 0 0 0 0 0 0 0 0 0 0 0
56891 - 0 0 0 0 0 0 0 0 0 0 0 0
56892 - 0 0 0 0 0 0 0 0 0 0 0 0
56893 - 0 0 0 0 0 0 0 0 0 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 10 10 10
56896 - 38 38 38 78 78 78 6 6 6 2 2 6
56897 - 2 2 6 46 46 46 14 14 14 42 42 42
56898 -246 246 246 253 253 253 253 253 253 253 253 253
56899 -253 253 253 253 253 253 253 253 253 253 253 253
56900 -253 253 253 253 253 253 231 231 231 242 242 242
56901 -253 253 253 253 253 253 253 253 253 253 253 253
56902 -253 253 253 253 253 253 253 253 253 253 253 253
56903 -253 253 253 253 253 253 253 253 253 253 253 253
56904 -253 253 253 253 253 253 253 253 253 253 253 253
56905 -253 253 253 253 253 253 234 234 234 10 10 10
56906 - 2 2 6 2 2 6 22 22 22 14 14 14
56907 - 2 2 6 2 2 6 2 2 6 2 2 6
56908 - 2 2 6 66 66 66 62 62 62 22 22 22
56909 - 6 6 6 0 0 0 0 0 0 0 0 0
56910 - 0 0 0 0 0 0 0 0 0 0 0 0
56911 - 0 0 0 0 0 0 0 0 0 0 0 0
56912 - 0 0 0 0 0 0 0 0 0 0 0 0
56913 - 0 0 0 0 0 0 0 0 0 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 6 6 6 18 18 18
56916 - 50 50 50 74 74 74 2 2 6 2 2 6
56917 - 14 14 14 70 70 70 34 34 34 62 62 62
56918 -250 250 250 253 253 253 253 253 253 253 253 253
56919 -253 253 253 253 253 253 253 253 253 253 253 253
56920 -253 253 253 253 253 253 231 231 231 246 246 246
56921 -253 253 253 253 253 253 253 253 253 253 253 253
56922 -253 253 253 253 253 253 253 253 253 253 253 253
56923 -253 253 253 253 253 253 253 253 253 253 253 253
56924 -253 253 253 253 253 253 253 253 253 253 253 253
56925 -253 253 253 253 253 253 234 234 234 14 14 14
56926 - 2 2 6 2 2 6 30 30 30 2 2 6
56927 - 2 2 6 2 2 6 2 2 6 2 2 6
56928 - 2 2 6 66 66 66 62 62 62 22 22 22
56929 - 6 6 6 0 0 0 0 0 0 0 0 0
56930 - 0 0 0 0 0 0 0 0 0 0 0 0
56931 - 0 0 0 0 0 0 0 0 0 0 0 0
56932 - 0 0 0 0 0 0 0 0 0 0 0 0
56933 - 0 0 0 0 0 0 0 0 0 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 6 6 6 18 18 18
56936 - 54 54 54 62 62 62 2 2 6 2 2 6
56937 - 2 2 6 30 30 30 46 46 46 70 70 70
56938 -250 250 250 253 253 253 253 253 253 253 253 253
56939 -253 253 253 253 253 253 253 253 253 253 253 253
56940 -253 253 253 253 253 253 231 231 231 246 246 246
56941 -253 253 253 253 253 253 253 253 253 253 253 253
56942 -253 253 253 253 253 253 253 253 253 253 253 253
56943 -253 253 253 253 253 253 253 253 253 253 253 253
56944 -253 253 253 253 253 253 253 253 253 253 253 253
56945 -253 253 253 253 253 253 226 226 226 10 10 10
56946 - 2 2 6 6 6 6 30 30 30 2 2 6
56947 - 2 2 6 2 2 6 2 2 6 2 2 6
56948 - 2 2 6 66 66 66 58 58 58 22 22 22
56949 - 6 6 6 0 0 0 0 0 0 0 0 0
56950 - 0 0 0 0 0 0 0 0 0 0 0 0
56951 - 0 0 0 0 0 0 0 0 0 0 0 0
56952 - 0 0 0 0 0 0 0 0 0 0 0 0
56953 - 0 0 0 0 0 0 0 0 0 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 6 6 6 22 22 22
56956 - 58 58 58 62 62 62 2 2 6 2 2 6
56957 - 2 2 6 2 2 6 30 30 30 78 78 78
56958 -250 250 250 253 253 253 253 253 253 253 253 253
56959 -253 253 253 253 253 253 253 253 253 253 253 253
56960 -253 253 253 253 253 253 231 231 231 246 246 246
56961 -253 253 253 253 253 253 253 253 253 253 253 253
56962 -253 253 253 253 253 253 253 253 253 253 253 253
56963 -253 253 253 253 253 253 253 253 253 253 253 253
56964 -253 253 253 253 253 253 253 253 253 253 253 253
56965 -253 253 253 253 253 253 206 206 206 2 2 6
56966 - 22 22 22 34 34 34 18 14 6 22 22 22
56967 - 26 26 26 18 18 18 6 6 6 2 2 6
56968 - 2 2 6 82 82 82 54 54 54 18 18 18
56969 - 6 6 6 0 0 0 0 0 0 0 0 0
56970 - 0 0 0 0 0 0 0 0 0 0 0 0
56971 - 0 0 0 0 0 0 0 0 0 0 0 0
56972 - 0 0 0 0 0 0 0 0 0 0 0 0
56973 - 0 0 0 0 0 0 0 0 0 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 6 6 6 26 26 26
56976 - 62 62 62 106 106 106 74 54 14 185 133 11
56977 -210 162 10 121 92 8 6 6 6 62 62 62
56978 -238 238 238 253 253 253 253 253 253 253 253 253
56979 -253 253 253 253 253 253 253 253 253 253 253 253
56980 -253 253 253 253 253 253 231 231 231 246 246 246
56981 -253 253 253 253 253 253 253 253 253 253 253 253
56982 -253 253 253 253 253 253 253 253 253 253 253 253
56983 -253 253 253 253 253 253 253 253 253 253 253 253
56984 -253 253 253 253 253 253 253 253 253 253 253 253
56985 -253 253 253 253 253 253 158 158 158 18 18 18
56986 - 14 14 14 2 2 6 2 2 6 2 2 6
56987 - 6 6 6 18 18 18 66 66 66 38 38 38
56988 - 6 6 6 94 94 94 50 50 50 18 18 18
56989 - 6 6 6 0 0 0 0 0 0 0 0 0
56990 - 0 0 0 0 0 0 0 0 0 0 0 0
56991 - 0 0 0 0 0 0 0 0 0 0 0 0
56992 - 0 0 0 0 0 0 0 0 0 0 0 0
56993 - 0 0 0 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 6 6 6
56995 - 10 10 10 10 10 10 18 18 18 38 38 38
56996 - 78 78 78 142 134 106 216 158 10 242 186 14
56997 -246 190 14 246 190 14 156 118 10 10 10 10
56998 - 90 90 90 238 238 238 253 253 253 253 253 253
56999 -253 253 253 253 253 253 253 253 253 253 253 253
57000 -253 253 253 253 253 253 231 231 231 250 250 250
57001 -253 253 253 253 253 253 253 253 253 253 253 253
57002 -253 253 253 253 253 253 253 253 253 253 253 253
57003 -253 253 253 253 253 253 253 253 253 253 253 253
57004 -253 253 253 253 253 253 253 253 253 246 230 190
57005 -238 204 91 238 204 91 181 142 44 37 26 9
57006 - 2 2 6 2 2 6 2 2 6 2 2 6
57007 - 2 2 6 2 2 6 38 38 38 46 46 46
57008 - 26 26 26 106 106 106 54 54 54 18 18 18
57009 - 6 6 6 0 0 0 0 0 0 0 0 0
57010 - 0 0 0 0 0 0 0 0 0 0 0 0
57011 - 0 0 0 0 0 0 0 0 0 0 0 0
57012 - 0 0 0 0 0 0 0 0 0 0 0 0
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 6 6 6 14 14 14 22 22 22
57015 - 30 30 30 38 38 38 50 50 50 70 70 70
57016 -106 106 106 190 142 34 226 170 11 242 186 14
57017 -246 190 14 246 190 14 246 190 14 154 114 10
57018 - 6 6 6 74 74 74 226 226 226 253 253 253
57019 -253 253 253 253 253 253 253 253 253 253 253 253
57020 -253 253 253 253 253 253 231 231 231 250 250 250
57021 -253 253 253 253 253 253 253 253 253 253 253 253
57022 -253 253 253 253 253 253 253 253 253 253 253 253
57023 -253 253 253 253 253 253 253 253 253 253 253 253
57024 -253 253 253 253 253 253 253 253 253 228 184 62
57025 -241 196 14 241 208 19 232 195 16 38 30 10
57026 - 2 2 6 2 2 6 2 2 6 2 2 6
57027 - 2 2 6 6 6 6 30 30 30 26 26 26
57028 -203 166 17 154 142 90 66 66 66 26 26 26
57029 - 6 6 6 0 0 0 0 0 0 0 0 0
57030 - 0 0 0 0 0 0 0 0 0 0 0 0
57031 - 0 0 0 0 0 0 0 0 0 0 0 0
57032 - 0 0 0 0 0 0 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 6 6 6 18 18 18 38 38 38 58 58 58
57035 - 78 78 78 86 86 86 101 101 101 123 123 123
57036 -175 146 61 210 150 10 234 174 13 246 186 14
57037 -246 190 14 246 190 14 246 190 14 238 190 10
57038 -102 78 10 2 2 6 46 46 46 198 198 198
57039 -253 253 253 253 253 253 253 253 253 253 253 253
57040 -253 253 253 253 253 253 234 234 234 242 242 242
57041 -253 253 253 253 253 253 253 253 253 253 253 253
57042 -253 253 253 253 253 253 253 253 253 253 253 253
57043 -253 253 253 253 253 253 253 253 253 253 253 253
57044 -253 253 253 253 253 253 253 253 253 224 178 62
57045 -242 186 14 241 196 14 210 166 10 22 18 6
57046 - 2 2 6 2 2 6 2 2 6 2 2 6
57047 - 2 2 6 2 2 6 6 6 6 121 92 8
57048 -238 202 15 232 195 16 82 82 82 34 34 34
57049 - 10 10 10 0 0 0 0 0 0 0 0 0
57050 - 0 0 0 0 0 0 0 0 0 0 0 0
57051 - 0 0 0 0 0 0 0 0 0 0 0 0
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 14 14 14 38 38 38 70 70 70 154 122 46
57055 -190 142 34 200 144 11 197 138 11 197 138 11
57056 -213 154 11 226 170 11 242 186 14 246 190 14
57057 -246 190 14 246 190 14 246 190 14 246 190 14
57058 -225 175 15 46 32 6 2 2 6 22 22 22
57059 -158 158 158 250 250 250 253 253 253 253 253 253
57060 -253 253 253 253 253 253 253 253 253 253 253 253
57061 -253 253 253 253 253 253 253 253 253 253 253 253
57062 -253 253 253 253 253 253 253 253 253 253 253 253
57063 -253 253 253 253 253 253 253 253 253 253 253 253
57064 -253 253 253 250 250 250 242 242 242 224 178 62
57065 -239 182 13 236 186 11 213 154 11 46 32 6
57066 - 2 2 6 2 2 6 2 2 6 2 2 6
57067 - 2 2 6 2 2 6 61 42 6 225 175 15
57068 -238 190 10 236 186 11 112 100 78 42 42 42
57069 - 14 14 14 0 0 0 0 0 0 0 0 0
57070 - 0 0 0 0 0 0 0 0 0 0 0 0
57071 - 0 0 0 0 0 0 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 6 6 6
57074 - 22 22 22 54 54 54 154 122 46 213 154 11
57075 -226 170 11 230 174 11 226 170 11 226 170 11
57076 -236 178 12 242 186 14 246 190 14 246 190 14
57077 -246 190 14 246 190 14 246 190 14 246 190 14
57078 -241 196 14 184 144 12 10 10 10 2 2 6
57079 - 6 6 6 116 116 116 242 242 242 253 253 253
57080 -253 253 253 253 253 253 253 253 253 253 253 253
57081 -253 253 253 253 253 253 253 253 253 253 253 253
57082 -253 253 253 253 253 253 253 253 253 253 253 253
57083 -253 253 253 253 253 253 253 253 253 253 253 253
57084 -253 253 253 231 231 231 198 198 198 214 170 54
57085 -236 178 12 236 178 12 210 150 10 137 92 6
57086 - 18 14 6 2 2 6 2 2 6 2 2 6
57087 - 6 6 6 70 47 6 200 144 11 236 178 12
57088 -239 182 13 239 182 13 124 112 88 58 58 58
57089 - 22 22 22 6 6 6 0 0 0 0 0 0
57090 - 0 0 0 0 0 0 0 0 0 0 0 0
57091 - 0 0 0 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 10 10 10
57094 - 30 30 30 70 70 70 180 133 36 226 170 11
57095 -239 182 13 242 186 14 242 186 14 246 186 14
57096 -246 190 14 246 190 14 246 190 14 246 190 14
57097 -246 190 14 246 190 14 246 190 14 246 190 14
57098 -246 190 14 232 195 16 98 70 6 2 2 6
57099 - 2 2 6 2 2 6 66 66 66 221 221 221
57100 -253 253 253 253 253 253 253 253 253 253 253 253
57101 -253 253 253 253 253 253 253 253 253 253 253 253
57102 -253 253 253 253 253 253 253 253 253 253 253 253
57103 -253 253 253 253 253 253 253 253 253 253 253 253
57104 -253 253 253 206 206 206 198 198 198 214 166 58
57105 -230 174 11 230 174 11 216 158 10 192 133 9
57106 -163 110 8 116 81 8 102 78 10 116 81 8
57107 -167 114 7 197 138 11 226 170 11 239 182 13
57108 -242 186 14 242 186 14 162 146 94 78 78 78
57109 - 34 34 34 14 14 14 6 6 6 0 0 0
57110 - 0 0 0 0 0 0 0 0 0 0 0 0
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 6 6 6
57114 - 30 30 30 78 78 78 190 142 34 226 170 11
57115 -239 182 13 246 190 14 246 190 14 246 190 14
57116 -246 190 14 246 190 14 246 190 14 246 190 14
57117 -246 190 14 246 190 14 246 190 14 246 190 14
57118 -246 190 14 241 196 14 203 166 17 22 18 6
57119 - 2 2 6 2 2 6 2 2 6 38 38 38
57120 -218 218 218 253 253 253 253 253 253 253 253 253
57121 -253 253 253 253 253 253 253 253 253 253 253 253
57122 -253 253 253 253 253 253 253 253 253 253 253 253
57123 -253 253 253 253 253 253 253 253 253 253 253 253
57124 -250 250 250 206 206 206 198 198 198 202 162 69
57125 -226 170 11 236 178 12 224 166 10 210 150 10
57126 -200 144 11 197 138 11 192 133 9 197 138 11
57127 -210 150 10 226 170 11 242 186 14 246 190 14
57128 -246 190 14 246 186 14 225 175 15 124 112 88
57129 - 62 62 62 30 30 30 14 14 14 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 10 10 10
57134 - 30 30 30 78 78 78 174 135 50 224 166 10
57135 -239 182 13 246 190 14 246 190 14 246 190 14
57136 -246 190 14 246 190 14 246 190 14 246 190 14
57137 -246 190 14 246 190 14 246 190 14 246 190 14
57138 -246 190 14 246 190 14 241 196 14 139 102 15
57139 - 2 2 6 2 2 6 2 2 6 2 2 6
57140 - 78 78 78 250 250 250 253 253 253 253 253 253
57141 -253 253 253 253 253 253 253 253 253 253 253 253
57142 -253 253 253 253 253 253 253 253 253 253 253 253
57143 -253 253 253 253 253 253 253 253 253 253 253 253
57144 -250 250 250 214 214 214 198 198 198 190 150 46
57145 -219 162 10 236 178 12 234 174 13 224 166 10
57146 -216 158 10 213 154 11 213 154 11 216 158 10
57147 -226 170 11 239 182 13 246 190 14 246 190 14
57148 -246 190 14 246 190 14 242 186 14 206 162 42
57149 -101 101 101 58 58 58 30 30 30 14 14 14
57150 - 6 6 6 0 0 0 0 0 0 0 0 0
57151 - 0 0 0 0 0 0 0 0 0 0 0 0
57152 - 0 0 0 0 0 0 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 10 10 10
57154 - 30 30 30 74 74 74 174 135 50 216 158 10
57155 -236 178 12 246 190 14 246 190 14 246 190 14
57156 -246 190 14 246 190 14 246 190 14 246 190 14
57157 -246 190 14 246 190 14 246 190 14 246 190 14
57158 -246 190 14 246 190 14 241 196 14 226 184 13
57159 - 61 42 6 2 2 6 2 2 6 2 2 6
57160 - 22 22 22 238 238 238 253 253 253 253 253 253
57161 -253 253 253 253 253 253 253 253 253 253 253 253
57162 -253 253 253 253 253 253 253 253 253 253 253 253
57163 -253 253 253 253 253 253 253 253 253 253 253 253
57164 -253 253 253 226 226 226 187 187 187 180 133 36
57165 -216 158 10 236 178 12 239 182 13 236 178 12
57166 -230 174 11 226 170 11 226 170 11 230 174 11
57167 -236 178 12 242 186 14 246 190 14 246 190 14
57168 -246 190 14 246 190 14 246 186 14 239 182 13
57169 -206 162 42 106 106 106 66 66 66 34 34 34
57170 - 14 14 14 6 6 6 0 0 0 0 0 0
57171 - 0 0 0 0 0 0 0 0 0 0 0 0
57172 - 0 0 0 0 0 0 0 0 0 0 0 0
57173 - 0 0 0 0 0 0 0 0 0 6 6 6
57174 - 26 26 26 70 70 70 163 133 67 213 154 11
57175 -236 178 12 246 190 14 246 190 14 246 190 14
57176 -246 190 14 246 190 14 246 190 14 246 190 14
57177 -246 190 14 246 190 14 246 190 14 246 190 14
57178 -246 190 14 246 190 14 246 190 14 241 196 14
57179 -190 146 13 18 14 6 2 2 6 2 2 6
57180 - 46 46 46 246 246 246 253 253 253 253 253 253
57181 -253 253 253 253 253 253 253 253 253 253 253 253
57182 -253 253 253 253 253 253 253 253 253 253 253 253
57183 -253 253 253 253 253 253 253 253 253 253 253 253
57184 -253 253 253 221 221 221 86 86 86 156 107 11
57185 -216 158 10 236 178 12 242 186 14 246 186 14
57186 -242 186 14 239 182 13 239 182 13 242 186 14
57187 -242 186 14 246 186 14 246 190 14 246 190 14
57188 -246 190 14 246 190 14 246 190 14 246 190 14
57189 -242 186 14 225 175 15 142 122 72 66 66 66
57190 - 30 30 30 10 10 10 0 0 0 0 0 0
57191 - 0 0 0 0 0 0 0 0 0 0 0 0
57192 - 0 0 0 0 0 0 0 0 0 0 0 0
57193 - 0 0 0 0 0 0 0 0 0 6 6 6
57194 - 26 26 26 70 70 70 163 133 67 210 150 10
57195 -236 178 12 246 190 14 246 190 14 246 190 14
57196 -246 190 14 246 190 14 246 190 14 246 190 14
57197 -246 190 14 246 190 14 246 190 14 246 190 14
57198 -246 190 14 246 190 14 246 190 14 246 190 14
57199 -232 195 16 121 92 8 34 34 34 106 106 106
57200 -221 221 221 253 253 253 253 253 253 253 253 253
57201 -253 253 253 253 253 253 253 253 253 253 253 253
57202 -253 253 253 253 253 253 253 253 253 253 253 253
57203 -253 253 253 253 253 253 253 253 253 253 253 253
57204 -242 242 242 82 82 82 18 14 6 163 110 8
57205 -216 158 10 236 178 12 242 186 14 246 190 14
57206 -246 190 14 246 190 14 246 190 14 246 190 14
57207 -246 190 14 246 190 14 246 190 14 246 190 14
57208 -246 190 14 246 190 14 246 190 14 246 190 14
57209 -246 190 14 246 190 14 242 186 14 163 133 67
57210 - 46 46 46 18 18 18 6 6 6 0 0 0
57211 - 0 0 0 0 0 0 0 0 0 0 0 0
57212 - 0 0 0 0 0 0 0 0 0 0 0 0
57213 - 0 0 0 0 0 0 0 0 0 10 10 10
57214 - 30 30 30 78 78 78 163 133 67 210 150 10
57215 -236 178 12 246 186 14 246 190 14 246 190 14
57216 -246 190 14 246 190 14 246 190 14 246 190 14
57217 -246 190 14 246 190 14 246 190 14 246 190 14
57218 -246 190 14 246 190 14 246 190 14 246 190 14
57219 -241 196 14 215 174 15 190 178 144 253 253 253
57220 -253 253 253 253 253 253 253 253 253 253 253 253
57221 -253 253 253 253 253 253 253 253 253 253 253 253
57222 -253 253 253 253 253 253 253 253 253 253 253 253
57223 -253 253 253 253 253 253 253 253 253 218 218 218
57224 - 58 58 58 2 2 6 22 18 6 167 114 7
57225 -216 158 10 236 178 12 246 186 14 246 190 14
57226 -246 190 14 246 190 14 246 190 14 246 190 14
57227 -246 190 14 246 190 14 246 190 14 246 190 14
57228 -246 190 14 246 190 14 246 190 14 246 190 14
57229 -246 190 14 246 186 14 242 186 14 190 150 46
57230 - 54 54 54 22 22 22 6 6 6 0 0 0
57231 - 0 0 0 0 0 0 0 0 0 0 0 0
57232 - 0 0 0 0 0 0 0 0 0 0 0 0
57233 - 0 0 0 0 0 0 0 0 0 14 14 14
57234 - 38 38 38 86 86 86 180 133 36 213 154 11
57235 -236 178 12 246 186 14 246 190 14 246 190 14
57236 -246 190 14 246 190 14 246 190 14 246 190 14
57237 -246 190 14 246 190 14 246 190 14 246 190 14
57238 -246 190 14 246 190 14 246 190 14 246 190 14
57239 -246 190 14 232 195 16 190 146 13 214 214 214
57240 -253 253 253 253 253 253 253 253 253 253 253 253
57241 -253 253 253 253 253 253 253 253 253 253 253 253
57242 -253 253 253 253 253 253 253 253 253 253 253 253
57243 -253 253 253 250 250 250 170 170 170 26 26 26
57244 - 2 2 6 2 2 6 37 26 9 163 110 8
57245 -219 162 10 239 182 13 246 186 14 246 190 14
57246 -246 190 14 246 190 14 246 190 14 246 190 14
57247 -246 190 14 246 190 14 246 190 14 246 190 14
57248 -246 190 14 246 190 14 246 190 14 246 190 14
57249 -246 186 14 236 178 12 224 166 10 142 122 72
57250 - 46 46 46 18 18 18 6 6 6 0 0 0
57251 - 0 0 0 0 0 0 0 0 0 0 0 0
57252 - 0 0 0 0 0 0 0 0 0 0 0 0
57253 - 0 0 0 0 0 0 6 6 6 18 18 18
57254 - 50 50 50 109 106 95 192 133 9 224 166 10
57255 -242 186 14 246 190 14 246 190 14 246 190 14
57256 -246 190 14 246 190 14 246 190 14 246 190 14
57257 -246 190 14 246 190 14 246 190 14 246 190 14
57258 -246 190 14 246 190 14 246 190 14 246 190 14
57259 -242 186 14 226 184 13 210 162 10 142 110 46
57260 -226 226 226 253 253 253 253 253 253 253 253 253
57261 -253 253 253 253 253 253 253 253 253 253 253 253
57262 -253 253 253 253 253 253 253 253 253 253 253 253
57263 -198 198 198 66 66 66 2 2 6 2 2 6
57264 - 2 2 6 2 2 6 50 34 6 156 107 11
57265 -219 162 10 239 182 13 246 186 14 246 190 14
57266 -246 190 14 246 190 14 246 190 14 246 190 14
57267 -246 190 14 246 190 14 246 190 14 246 190 14
57268 -246 190 14 246 190 14 246 190 14 242 186 14
57269 -234 174 13 213 154 11 154 122 46 66 66 66
57270 - 30 30 30 10 10 10 0 0 0 0 0 0
57271 - 0 0 0 0 0 0 0 0 0 0 0 0
57272 - 0 0 0 0 0 0 0 0 0 0 0 0
57273 - 0 0 0 0 0 0 6 6 6 22 22 22
57274 - 58 58 58 154 121 60 206 145 10 234 174 13
57275 -242 186 14 246 186 14 246 190 14 246 190 14
57276 -246 190 14 246 190 14 246 190 14 246 190 14
57277 -246 190 14 246 190 14 246 190 14 246 190 14
57278 -246 190 14 246 190 14 246 190 14 246 190 14
57279 -246 186 14 236 178 12 210 162 10 163 110 8
57280 - 61 42 6 138 138 138 218 218 218 250 250 250
57281 -253 253 253 253 253 253 253 253 253 250 250 250
57282 -242 242 242 210 210 210 144 144 144 66 66 66
57283 - 6 6 6 2 2 6 2 2 6 2 2 6
57284 - 2 2 6 2 2 6 61 42 6 163 110 8
57285 -216 158 10 236 178 12 246 190 14 246 190 14
57286 -246 190 14 246 190 14 246 190 14 246 190 14
57287 -246 190 14 246 190 14 246 190 14 246 190 14
57288 -246 190 14 239 182 13 230 174 11 216 158 10
57289 -190 142 34 124 112 88 70 70 70 38 38 38
57290 - 18 18 18 6 6 6 0 0 0 0 0 0
57291 - 0 0 0 0 0 0 0 0 0 0 0 0
57292 - 0 0 0 0 0 0 0 0 0 0 0 0
57293 - 0 0 0 0 0 0 6 6 6 22 22 22
57294 - 62 62 62 168 124 44 206 145 10 224 166 10
57295 -236 178 12 239 182 13 242 186 14 242 186 14
57296 -246 186 14 246 190 14 246 190 14 246 190 14
57297 -246 190 14 246 190 14 246 190 14 246 190 14
57298 -246 190 14 246 190 14 246 190 14 246 190 14
57299 -246 190 14 236 178 12 216 158 10 175 118 6
57300 - 80 54 7 2 2 6 6 6 6 30 30 30
57301 - 54 54 54 62 62 62 50 50 50 38 38 38
57302 - 14 14 14 2 2 6 2 2 6 2 2 6
57303 - 2 2 6 2 2 6 2 2 6 2 2 6
57304 - 2 2 6 6 6 6 80 54 7 167 114 7
57305 -213 154 11 236 178 12 246 190 14 246 190 14
57306 -246 190 14 246 190 14 246 190 14 246 190 14
57307 -246 190 14 242 186 14 239 182 13 239 182 13
57308 -230 174 11 210 150 10 174 135 50 124 112 88
57309 - 82 82 82 54 54 54 34 34 34 18 18 18
57310 - 6 6 6 0 0 0 0 0 0 0 0 0
57311 - 0 0 0 0 0 0 0 0 0 0 0 0
57312 - 0 0 0 0 0 0 0 0 0 0 0 0
57313 - 0 0 0 0 0 0 6 6 6 18 18 18
57314 - 50 50 50 158 118 36 192 133 9 200 144 11
57315 -216 158 10 219 162 10 224 166 10 226 170 11
57316 -230 174 11 236 178 12 239 182 13 239 182 13
57317 -242 186 14 246 186 14 246 190 14 246 190 14
57318 -246 190 14 246 190 14 246 190 14 246 190 14
57319 -246 186 14 230 174 11 210 150 10 163 110 8
57320 -104 69 6 10 10 10 2 2 6 2 2 6
57321 - 2 2 6 2 2 6 2 2 6 2 2 6
57322 - 2 2 6 2 2 6 2 2 6 2 2 6
57323 - 2 2 6 2 2 6 2 2 6 2 2 6
57324 - 2 2 6 6 6 6 91 60 6 167 114 7
57325 -206 145 10 230 174 11 242 186 14 246 190 14
57326 -246 190 14 246 190 14 246 186 14 242 186 14
57327 -239 182 13 230 174 11 224 166 10 213 154 11
57328 -180 133 36 124 112 88 86 86 86 58 58 58
57329 - 38 38 38 22 22 22 10 10 10 6 6 6
57330 - 0 0 0 0 0 0 0 0 0 0 0 0
57331 - 0 0 0 0 0 0 0 0 0 0 0 0
57332 - 0 0 0 0 0 0 0 0 0 0 0 0
57333 - 0 0 0 0 0 0 0 0 0 14 14 14
57334 - 34 34 34 70 70 70 138 110 50 158 118 36
57335 -167 114 7 180 123 7 192 133 9 197 138 11
57336 -200 144 11 206 145 10 213 154 11 219 162 10
57337 -224 166 10 230 174 11 239 182 13 242 186 14
57338 -246 186 14 246 186 14 246 186 14 246 186 14
57339 -239 182 13 216 158 10 185 133 11 152 99 6
57340 -104 69 6 18 14 6 2 2 6 2 2 6
57341 - 2 2 6 2 2 6 2 2 6 2 2 6
57342 - 2 2 6 2 2 6 2 2 6 2 2 6
57343 - 2 2 6 2 2 6 2 2 6 2 2 6
57344 - 2 2 6 6 6 6 80 54 7 152 99 6
57345 -192 133 9 219 162 10 236 178 12 239 182 13
57346 -246 186 14 242 186 14 239 182 13 236 178 12
57347 -224 166 10 206 145 10 192 133 9 154 121 60
57348 - 94 94 94 62 62 62 42 42 42 22 22 22
57349 - 14 14 14 6 6 6 0 0 0 0 0 0
57350 - 0 0 0 0 0 0 0 0 0 0 0 0
57351 - 0 0 0 0 0 0 0 0 0 0 0 0
57352 - 0 0 0 0 0 0 0 0 0 0 0 0
57353 - 0 0 0 0 0 0 0 0 0 6 6 6
57354 - 18 18 18 34 34 34 58 58 58 78 78 78
57355 -101 98 89 124 112 88 142 110 46 156 107 11
57356 -163 110 8 167 114 7 175 118 6 180 123 7
57357 -185 133 11 197 138 11 210 150 10 219 162 10
57358 -226 170 11 236 178 12 236 178 12 234 174 13
57359 -219 162 10 197 138 11 163 110 8 130 83 6
57360 - 91 60 6 10 10 10 2 2 6 2 2 6
57361 - 18 18 18 38 38 38 38 38 38 38 38 38
57362 - 38 38 38 38 38 38 38 38 38 38 38 38
57363 - 38 38 38 38 38 38 26 26 26 2 2 6
57364 - 2 2 6 6 6 6 70 47 6 137 92 6
57365 -175 118 6 200 144 11 219 162 10 230 174 11
57366 -234 174 13 230 174 11 219 162 10 210 150 10
57367 -192 133 9 163 110 8 124 112 88 82 82 82
57368 - 50 50 50 30 30 30 14 14 14 6 6 6
57369 - 0 0 0 0 0 0 0 0 0 0 0 0
57370 - 0 0 0 0 0 0 0 0 0 0 0 0
57371 - 0 0 0 0 0 0 0 0 0 0 0 0
57372 - 0 0 0 0 0 0 0 0 0 0 0 0
57373 - 0 0 0 0 0 0 0 0 0 0 0 0
57374 - 6 6 6 14 14 14 22 22 22 34 34 34
57375 - 42 42 42 58 58 58 74 74 74 86 86 86
57376 -101 98 89 122 102 70 130 98 46 121 87 25
57377 -137 92 6 152 99 6 163 110 8 180 123 7
57378 -185 133 11 197 138 11 206 145 10 200 144 11
57379 -180 123 7 156 107 11 130 83 6 104 69 6
57380 - 50 34 6 54 54 54 110 110 110 101 98 89
57381 - 86 86 86 82 82 82 78 78 78 78 78 78
57382 - 78 78 78 78 78 78 78 78 78 78 78 78
57383 - 78 78 78 82 82 82 86 86 86 94 94 94
57384 -106 106 106 101 101 101 86 66 34 124 80 6
57385 -156 107 11 180 123 7 192 133 9 200 144 11
57386 -206 145 10 200 144 11 192 133 9 175 118 6
57387 -139 102 15 109 106 95 70 70 70 42 42 42
57388 - 22 22 22 10 10 10 0 0 0 0 0 0
57389 - 0 0 0 0 0 0 0 0 0 0 0 0
57390 - 0 0 0 0 0 0 0 0 0 0 0 0
57391 - 0 0 0 0 0 0 0 0 0 0 0 0
57392 - 0 0 0 0 0 0 0 0 0 0 0 0
57393 - 0 0 0 0 0 0 0 0 0 0 0 0
57394 - 0 0 0 0 0 0 6 6 6 10 10 10
57395 - 14 14 14 22 22 22 30 30 30 38 38 38
57396 - 50 50 50 62 62 62 74 74 74 90 90 90
57397 -101 98 89 112 100 78 121 87 25 124 80 6
57398 -137 92 6 152 99 6 152 99 6 152 99 6
57399 -138 86 6 124 80 6 98 70 6 86 66 30
57400 -101 98 89 82 82 82 58 58 58 46 46 46
57401 - 38 38 38 34 34 34 34 34 34 34 34 34
57402 - 34 34 34 34 34 34 34 34 34 34 34 34
57403 - 34 34 34 34 34 34 38 38 38 42 42 42
57404 - 54 54 54 82 82 82 94 86 76 91 60 6
57405 -134 86 6 156 107 11 167 114 7 175 118 6
57406 -175 118 6 167 114 7 152 99 6 121 87 25
57407 -101 98 89 62 62 62 34 34 34 18 18 18
57408 - 6 6 6 0 0 0 0 0 0 0 0 0
57409 - 0 0 0 0 0 0 0 0 0 0 0 0
57410 - 0 0 0 0 0 0 0 0 0 0 0 0
57411 - 0 0 0 0 0 0 0 0 0 0 0 0
57412 - 0 0 0 0 0 0 0 0 0 0 0 0
57413 - 0 0 0 0 0 0 0 0 0 0 0 0
57414 - 0 0 0 0 0 0 0 0 0 0 0 0
57415 - 0 0 0 6 6 6 6 6 6 10 10 10
57416 - 18 18 18 22 22 22 30 30 30 42 42 42
57417 - 50 50 50 66 66 66 86 86 86 101 98 89
57418 -106 86 58 98 70 6 104 69 6 104 69 6
57419 -104 69 6 91 60 6 82 62 34 90 90 90
57420 - 62 62 62 38 38 38 22 22 22 14 14 14
57421 - 10 10 10 10 10 10 10 10 10 10 10 10
57422 - 10 10 10 10 10 10 6 6 6 10 10 10
57423 - 10 10 10 10 10 10 10 10 10 14 14 14
57424 - 22 22 22 42 42 42 70 70 70 89 81 66
57425 - 80 54 7 104 69 6 124 80 6 137 92 6
57426 -134 86 6 116 81 8 100 82 52 86 86 86
57427 - 58 58 58 30 30 30 14 14 14 6 6 6
57428 - 0 0 0 0 0 0 0 0 0 0 0 0
57429 - 0 0 0 0 0 0 0 0 0 0 0 0
57430 - 0 0 0 0 0 0 0 0 0 0 0 0
57431 - 0 0 0 0 0 0 0 0 0 0 0 0
57432 - 0 0 0 0 0 0 0 0 0 0 0 0
57433 - 0 0 0 0 0 0 0 0 0 0 0 0
57434 - 0 0 0 0 0 0 0 0 0 0 0 0
57435 - 0 0 0 0 0 0 0 0 0 0 0 0
57436 - 0 0 0 6 6 6 10 10 10 14 14 14
57437 - 18 18 18 26 26 26 38 38 38 54 54 54
57438 - 70 70 70 86 86 86 94 86 76 89 81 66
57439 - 89 81 66 86 86 86 74 74 74 50 50 50
57440 - 30 30 30 14 14 14 6 6 6 0 0 0
57441 - 0 0 0 0 0 0 0 0 0 0 0 0
57442 - 0 0 0 0 0 0 0 0 0 0 0 0
57443 - 0 0 0 0 0 0 0 0 0 0 0 0
57444 - 6 6 6 18 18 18 34 34 34 58 58 58
57445 - 82 82 82 89 81 66 89 81 66 89 81 66
57446 - 94 86 66 94 86 76 74 74 74 50 50 50
57447 - 26 26 26 14 14 14 6 6 6 0 0 0
57448 - 0 0 0 0 0 0 0 0 0 0 0 0
57449 - 0 0 0 0 0 0 0 0 0 0 0 0
57450 - 0 0 0 0 0 0 0 0 0 0 0 0
57451 - 0 0 0 0 0 0 0 0 0 0 0 0
57452 - 0 0 0 0 0 0 0 0 0 0 0 0
57453 - 0 0 0 0 0 0 0 0 0 0 0 0
57454 - 0 0 0 0 0 0 0 0 0 0 0 0
57455 - 0 0 0 0 0 0 0 0 0 0 0 0
57456 - 0 0 0 0 0 0 0 0 0 0 0 0
57457 - 6 6 6 6 6 6 14 14 14 18 18 18
57458 - 30 30 30 38 38 38 46 46 46 54 54 54
57459 - 50 50 50 42 42 42 30 30 30 18 18 18
57460 - 10 10 10 0 0 0 0 0 0 0 0 0
57461 - 0 0 0 0 0 0 0 0 0 0 0 0
57462 - 0 0 0 0 0 0 0 0 0 0 0 0
57463 - 0 0 0 0 0 0 0 0 0 0 0 0
57464 - 0 0 0 6 6 6 14 14 14 26 26 26
57465 - 38 38 38 50 50 50 58 58 58 58 58 58
57466 - 54 54 54 42 42 42 30 30 30 18 18 18
57467 - 10 10 10 0 0 0 0 0 0 0 0 0
57468 - 0 0 0 0 0 0 0 0 0 0 0 0
57469 - 0 0 0 0 0 0 0 0 0 0 0 0
57470 - 0 0 0 0 0 0 0 0 0 0 0 0
57471 - 0 0 0 0 0 0 0 0 0 0 0 0
57472 - 0 0 0 0 0 0 0 0 0 0 0 0
57473 - 0 0 0 0 0 0 0 0 0 0 0 0
57474 - 0 0 0 0 0 0 0 0 0 0 0 0
57475 - 0 0 0 0 0 0 0 0 0 0 0 0
57476 - 0 0 0 0 0 0 0 0 0 0 0 0
57477 - 0 0 0 0 0 0 0 0 0 6 6 6
57478 - 6 6 6 10 10 10 14 14 14 18 18 18
57479 - 18 18 18 14 14 14 10 10 10 6 6 6
57480 - 0 0 0 0 0 0 0 0 0 0 0 0
57481 - 0 0 0 0 0 0 0 0 0 0 0 0
57482 - 0 0 0 0 0 0 0 0 0 0 0 0
57483 - 0 0 0 0 0 0 0 0 0 0 0 0
57484 - 0 0 0 0 0 0 0 0 0 6 6 6
57485 - 14 14 14 18 18 18 22 22 22 22 22 22
57486 - 18 18 18 14 14 14 10 10 10 6 6 6
57487 - 0 0 0 0 0 0 0 0 0 0 0 0
57488 - 0 0 0 0 0 0 0 0 0 0 0 0
57489 - 0 0 0 0 0 0 0 0 0 0 0 0
57490 - 0 0 0 0 0 0 0 0 0 0 0 0
57491 - 0 0 0 0 0 0 0 0 0 0 0 0
57492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57505 +4 4 4 4 4 4
57506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57519 +4 4 4 4 4 4
57520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57533 +4 4 4 4 4 4
57534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57547 +4 4 4 4 4 4
57548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57552 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
57555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57561 +4 4 4 4 4 4
57562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57566 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
57569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57575 +4 4 4 4 4 4
57576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57580 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57581 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57585 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57586 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57587 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57589 +4 4 4 4 4 4
57590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57594 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57595 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57596 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57599 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57600 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57601 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57602 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57603 +4 4 4 4 4 4
57604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57608 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57609 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57610 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57613 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57614 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57615 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57616 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57617 +4 4 4 4 4 4
57618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57621 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57622 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57623 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57624 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57626 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57627 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57628 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57629 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57630 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57631 +4 4 4 4 4 4
57632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57635 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57636 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57637 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57638 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57639 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57640 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57641 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57642 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57643 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57644 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57645 +4 4 4 4 4 4
57646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57649 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57650 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57651 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57652 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57653 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57654 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57655 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57656 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57657 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57658 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57659 +4 4 4 4 4 4
57660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57662 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57663 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57664 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57665 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57666 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57667 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57668 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57669 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57670 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57671 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57672 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57673 +4 4 4 4 4 4
57674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57676 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57677 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57678 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57679 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57680 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57681 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57682 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57683 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57684 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57685 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57686 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57687 +4 4 4 4 4 4
57688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57690 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57691 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57692 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57693 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57694 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57695 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57696 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57697 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57698 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57699 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57700 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57701 +4 4 4 4 4 4
57702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57704 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57705 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57706 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57707 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57708 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57709 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57710 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57711 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57712 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57713 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57714 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57715 +4 4 4 4 4 4
57716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57717 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57718 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57719 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57720 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57721 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57722 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57723 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57724 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57725 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57726 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57727 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57728 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57729 +4 4 4 4 4 4
57730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57731 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57732 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57733 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57734 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57735 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57736 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57737 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57738 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57739 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57740 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57741 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57742 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57743 +0 0 0 4 4 4
57744 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57745 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57746 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57747 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57748 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57749 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57750 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57751 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57752 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57753 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57754 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57755 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57756 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57757 +2 0 0 0 0 0
57758 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57759 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57760 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57761 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57762 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57763 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57764 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57765 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57766 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57767 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57768 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57769 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57770 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57771 +37 38 37 0 0 0
57772 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57773 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57774 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57775 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57776 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57777 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57778 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57779 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57780 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57781 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57782 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57783 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57784 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57785 +85 115 134 4 0 0
57786 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57787 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57788 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57789 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57790 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57791 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57792 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57793 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57794 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57795 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57796 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57797 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57798 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57799 +60 73 81 4 0 0
57800 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57801 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57802 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57803 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57804 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57805 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57806 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57807 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57808 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57809 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57810 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57811 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57812 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57813 +16 19 21 4 0 0
57814 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57815 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57816 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57817 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57818 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57819 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57820 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57821 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57822 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57823 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57824 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57825 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57826 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57827 +4 0 0 4 3 3
57828 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57829 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57830 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57832 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57833 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57834 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57835 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57836 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57837 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57838 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57839 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57840 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57841 +3 2 2 4 4 4
57842 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57843 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57844 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57845 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57846 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57847 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57848 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57849 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57850 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57851 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57852 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57853 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57854 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57855 +4 4 4 4 4 4
57856 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57857 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57858 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57859 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57860 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57861 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57862 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57863 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57864 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57865 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57866 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57867 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57868 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57869 +4 4 4 4 4 4
57870 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57871 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57872 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57873 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57874 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57875 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57876 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57877 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57878 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57879 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57880 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57881 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57882 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57883 +5 5 5 5 5 5
57884 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57885 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57886 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57887 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57888 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57889 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57890 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57891 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57892 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57893 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57894 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57895 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57896 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57897 +5 5 5 4 4 4
57898 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57899 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57900 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57901 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57902 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57903 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57904 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57905 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57906 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57907 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57908 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57909 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57911 +4 4 4 4 4 4
57912 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57913 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57914 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57915 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57916 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57917 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57918 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57919 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57920 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57921 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57922 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57923 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57925 +4 4 4 4 4 4
57926 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57927 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57928 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57929 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57930 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57931 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57932 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57933 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57934 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57935 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57936 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57939 +4 4 4 4 4 4
57940 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57941 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57942 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57943 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57944 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57945 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57946 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57947 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57948 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57949 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57950 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57953 +4 4 4 4 4 4
57954 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57955 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57956 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57957 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57958 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57959 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57960 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57961 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57962 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57963 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57964 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57967 +4 4 4 4 4 4
57968 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57969 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57970 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57971 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57972 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57973 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57974 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57975 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57976 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57977 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57978 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57981 +4 4 4 4 4 4
57982 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57983 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57984 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57985 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57986 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57987 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57988 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57989 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57990 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57991 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57992 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57995 +4 4 4 4 4 4
57996 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57997 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57998 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57999 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58000 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58001 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58002 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58003 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58004 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58005 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58006 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58009 +4 4 4 4 4 4
58010 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58011 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58012 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58013 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58014 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58015 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58016 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58017 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58018 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58019 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58020 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58023 +4 4 4 4 4 4
58024 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58025 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58026 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58027 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58028 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58029 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58030 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58031 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58032 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58033 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58034 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58037 +4 4 4 4 4 4
58038 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58039 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58040 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58041 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58042 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58043 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58044 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58045 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58046 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58047 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58048 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58051 +4 4 4 4 4 4
58052 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58053 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58054 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58055 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58056 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58057 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58058 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58059 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58060 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58061 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58062 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58065 +4 4 4 4 4 4
58066 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58067 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58068 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58069 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58070 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58071 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58072 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58073 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58074 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58075 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58076 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58079 +4 4 4 4 4 4
58080 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58081 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58082 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58083 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58084 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58085 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58086 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58087 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58088 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58089 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58090 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58093 +4 4 4 4 4 4
58094 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58095 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58096 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58097 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58098 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58099 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58100 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58101 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58102 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58103 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58104 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58107 +4 4 4 4 4 4
58108 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58109 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58110 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58111 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58112 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58113 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58114 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58115 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58116 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58117 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58118 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58121 +4 4 4 4 4 4
58122 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58123 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58124 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58125 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58126 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58127 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58128 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58129 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58130 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58131 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58132 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58135 +4 4 4 4 4 4
58136 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58137 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58138 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58139 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58140 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58141 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58142 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58143 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58144 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58145 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58146 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58149 +4 4 4 4 4 4
58150 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58151 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58152 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58153 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58154 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58155 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58156 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58157 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58158 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58159 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58160 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58163 +4 4 4 4 4 4
58164 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58165 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58166 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58167 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58168 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58169 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58170 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58171 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58172 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58173 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58174 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58177 +4 4 4 4 4 4
58178 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58179 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58180 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58181 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58182 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58183 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58184 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58185 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58186 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58187 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58188 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58191 +4 4 4 4 4 4
58192 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58193 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58194 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58195 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58196 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58197 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58198 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58199 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58200 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58201 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58202 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58205 +4 4 4 4 4 4
58206 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58207 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58208 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58209 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58210 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58211 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58212 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58213 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58214 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58215 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58216 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58219 +4 4 4 4 4 4
58220 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58221 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58222 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58223 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58224 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58225 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58226 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58227 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58228 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58229 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58230 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58233 +4 4 4 4 4 4
58234 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58235 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58236 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58238 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58239 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58240 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58241 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58242 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58243 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58244 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58247 +4 4 4 4 4 4
58248 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58249 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58250 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58251 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58252 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58253 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58254 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58255 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58256 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58257 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58258 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58261 +4 4 4 4 4 4
58262 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58263 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58264 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58265 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58266 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58267 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58268 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58269 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58270 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58271 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58272 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58275 +4 4 4 4 4 4
58276 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58277 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58278 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58279 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58280 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58281 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58282 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58284 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58285 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58286 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58289 +4 4 4 4 4 4
58290 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58291 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58292 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58293 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58294 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58295 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58296 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58297 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58298 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58299 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58300 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58303 +4 4 4 4 4 4
58304 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58305 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58306 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58307 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58308 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58309 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58310 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58311 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58312 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58313 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58317 +4 4 4 4 4 4
58318 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58319 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58320 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58321 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58322 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58323 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58324 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58325 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58326 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58327 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58331 +4 4 4 4 4 4
58332 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58333 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58334 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58335 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58336 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58337 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58338 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58339 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58340 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58341 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58345 +4 4 4 4 4 4
58346 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58347 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58348 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58349 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58350 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58351 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58352 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58353 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58354 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58355 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58359 +4 4 4 4 4 4
58360 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58361 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58362 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58363 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58364 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58365 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58366 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58367 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58368 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58373 +4 4 4 4 4 4
58374 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58375 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58376 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58377 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58378 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58379 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58380 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58381 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58382 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58387 +4 4 4 4 4 4
58388 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58389 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58390 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58391 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58392 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58393 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58394 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58395 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58396 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58401 +4 4 4 4 4 4
58402 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58403 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58404 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58405 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58406 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58407 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58408 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58409 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58415 +4 4 4 4 4 4
58416 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58417 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58418 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58419 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58420 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58421 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58422 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58423 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58429 +4 4 4 4 4 4
58430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58431 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58432 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58433 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58434 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58435 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58436 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58437 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58443 +4 4 4 4 4 4
58444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58445 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58446 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58447 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58448 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58449 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58450 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58451 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58457 +4 4 4 4 4 4
58458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58459 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58460 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58461 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58462 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58463 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58464 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58465 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58471 +4 4 4 4 4 4
58472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58474 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58475 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58476 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58477 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58478 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58479 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58485 +4 4 4 4 4 4
58486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58489 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58490 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58491 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58492 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58499 +4 4 4 4 4 4
58500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58503 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58504 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58505 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58506 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58513 +4 4 4 4 4 4
58514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58517 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58518 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58519 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58520 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58527 +4 4 4 4 4 4
58528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58531 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58532 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58533 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58534 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58541 +4 4 4 4 4 4
58542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58546 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58547 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58548 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58555 +4 4 4 4 4 4
58556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58560 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58561 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58562 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58569 +4 4 4 4 4 4
58570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58574 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58575 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58576 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58583 +4 4 4 4 4 4
58584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58588 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58589 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58597 +4 4 4 4 4 4
58598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58602 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58603 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58611 +4 4 4 4 4 4
58612 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58613 index fef20db..d28b1ab 100644
58614 --- a/drivers/xen/xenfs/xenstored.c
58615 +++ b/drivers/xen/xenfs/xenstored.c
58616 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58617 static int xsd_kva_open(struct inode *inode, struct file *file)
58618 {
58619 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58620 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58621 + NULL);
58622 +#else
58623 xen_store_interface);
58624 +#endif
58625 +
58626 if (!file->private_data)
58627 return -ENOMEM;
58628 return 0;
58629 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58630 index cc1cfae..41158ad 100644
58631 --- a/fs/9p/vfs_addr.c
58632 +++ b/fs/9p/vfs_addr.c
58633 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58634
58635 retval = v9fs_file_write_internal(inode,
58636 v9inode->writeback_fid,
58637 - (__force const char __user *)buffer,
58638 + (const char __force_user *)buffer,
58639 len, &offset, 0);
58640 if (retval > 0)
58641 retval = 0;
58642 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58643 index 7fa4f7a..a7ebf8c 100644
58644 --- a/fs/9p/vfs_inode.c
58645 +++ b/fs/9p/vfs_inode.c
58646 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58647 void
58648 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58649 {
58650 - char *s = nd_get_link(nd);
58651 + const char *s = nd_get_link(nd);
58652
58653 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58654 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58655 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58656 index 370b24c..ff0be7b 100644
58657 --- a/fs/Kconfig.binfmt
58658 +++ b/fs/Kconfig.binfmt
58659 @@ -103,7 +103,7 @@ config HAVE_AOUT
58660
58661 config BINFMT_AOUT
58662 tristate "Kernel support for a.out and ECOFF binaries"
58663 - depends on HAVE_AOUT
58664 + depends on HAVE_AOUT && BROKEN
58665 ---help---
58666 A.out (Assembler.OUTput) is a set of formats for libraries and
58667 executables used in the earliest versions of UNIX. Linux used
58668 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58669 index 2946712..f737435 100644
58670 --- a/fs/afs/inode.c
58671 +++ b/fs/afs/inode.c
58672 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58673 struct afs_vnode *vnode;
58674 struct super_block *sb;
58675 struct inode *inode;
58676 - static atomic_t afs_autocell_ino;
58677 + static atomic_unchecked_t afs_autocell_ino;
58678
58679 _enter("{%x:%u},%*.*s,",
58680 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58681 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58682 data.fid.unique = 0;
58683 data.fid.vnode = 0;
58684
58685 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58686 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58687 afs_iget5_autocell_test, afs_iget5_set,
58688 &data);
58689 if (!inode) {
58690 diff --git a/fs/aio.c b/fs/aio.c
58691 index 7337500..2058af6 100644
58692 --- a/fs/aio.c
58693 +++ b/fs/aio.c
58694 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58695 size += sizeof(struct io_event) * nr_events;
58696
58697 nr_pages = PFN_UP(size);
58698 - if (nr_pages < 0)
58699 + if (nr_pages <= 0)
58700 return -EINVAL;
58701
58702 file = aio_private_file(ctx, nr_pages);
58703 diff --git a/fs/attr.c b/fs/attr.c
58704 index 6530ced..4a827e2 100644
58705 --- a/fs/attr.c
58706 +++ b/fs/attr.c
58707 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58708 unsigned long limit;
58709
58710 limit = rlimit(RLIMIT_FSIZE);
58711 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58712 if (limit != RLIM_INFINITY && offset > limit)
58713 goto out_sig;
58714 if (offset > inode->i_sb->s_maxbytes)
58715 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58716 index 116fd38..c04182da 100644
58717 --- a/fs/autofs4/waitq.c
58718 +++ b/fs/autofs4/waitq.c
58719 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58720 {
58721 unsigned long sigpipe, flags;
58722 mm_segment_t fs;
58723 - const char *data = (const char *)addr;
58724 + const char __user *data = (const char __force_user *)addr;
58725 ssize_t wr = 0;
58726
58727 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58728 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58729 return 1;
58730 }
58731
58732 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58733 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58734 +#endif
58735 +
58736 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58737 enum autofs_notify notify)
58738 {
58739 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58740
58741 /* If this is a direct mount request create a dummy name */
58742 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58743 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58744 + /* this name does get written to userland via autofs4_write() */
58745 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58746 +#else
58747 qstr.len = sprintf(name, "%p", dentry);
58748 +#endif
58749 else {
58750 qstr.len = autofs4_getpath(sbi, dentry, &name);
58751 if (!qstr.len) {
58752 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58753 index 2722387..56059b5 100644
58754 --- a/fs/befs/endian.h
58755 +++ b/fs/befs/endian.h
58756 @@ -11,7 +11,7 @@
58757
58758 #include <asm/byteorder.h>
58759
58760 -static inline u64
58761 +static inline u64 __intentional_overflow(-1)
58762 fs64_to_cpu(const struct super_block *sb, fs64 n)
58763 {
58764 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58765 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58766 return (__force fs64)cpu_to_be64(n);
58767 }
58768
58769 -static inline u32
58770 +static inline u32 __intentional_overflow(-1)
58771 fs32_to_cpu(const struct super_block *sb, fs32 n)
58772 {
58773 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58774 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58775 return (__force fs32)cpu_to_be32(n);
58776 }
58777
58778 -static inline u16
58779 +static inline u16 __intentional_overflow(-1)
58780 fs16_to_cpu(const struct super_block *sb, fs16 n)
58781 {
58782 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58783 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58784 index ca0ba15..0fa3257 100644
58785 --- a/fs/binfmt_aout.c
58786 +++ b/fs/binfmt_aout.c
58787 @@ -16,6 +16,7 @@
58788 #include <linux/string.h>
58789 #include <linux/fs.h>
58790 #include <linux/file.h>
58791 +#include <linux/security.h>
58792 #include <linux/stat.h>
58793 #include <linux/fcntl.h>
58794 #include <linux/ptrace.h>
58795 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58796 #endif
58797 # define START_STACK(u) ((void __user *)u.start_stack)
58798
58799 + memset(&dump, 0, sizeof(dump));
58800 +
58801 fs = get_fs();
58802 set_fs(KERNEL_DS);
58803 has_dumped = 1;
58804 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58805
58806 /* If the size of the dump file exceeds the rlimit, then see what would happen
58807 if we wrote the stack, but not the data area. */
58808 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58809 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58810 dump.u_dsize = 0;
58811
58812 /* Make sure we have enough room to write the stack and data areas. */
58813 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58814 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58815 dump.u_ssize = 0;
58816
58817 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58818 rlim = rlimit(RLIMIT_DATA);
58819 if (rlim >= RLIM_INFINITY)
58820 rlim = ~0;
58821 +
58822 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58823 if (ex.a_data + ex.a_bss > rlim)
58824 return -ENOMEM;
58825
58826 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58827
58828 install_exec_creds(bprm);
58829
58830 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58831 + current->mm->pax_flags = 0UL;
58832 +#endif
58833 +
58834 +#ifdef CONFIG_PAX_PAGEEXEC
58835 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58836 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58837 +
58838 +#ifdef CONFIG_PAX_EMUTRAMP
58839 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58840 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58841 +#endif
58842 +
58843 +#ifdef CONFIG_PAX_MPROTECT
58844 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58845 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58846 +#endif
58847 +
58848 + }
58849 +#endif
58850 +
58851 if (N_MAGIC(ex) == OMAGIC) {
58852 unsigned long text_addr, map_size;
58853 loff_t pos;
58854 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58855 }
58856
58857 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58858 - PROT_READ | PROT_WRITE | PROT_EXEC,
58859 + PROT_READ | PROT_WRITE,
58860 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58861 fd_offset + ex.a_text);
58862 if (error != N_DATADDR(ex)) {
58863 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58864 index 3892c1a..4e27c04 100644
58865 --- a/fs/binfmt_elf.c
58866 +++ b/fs/binfmt_elf.c
58867 @@ -34,6 +34,7 @@
58868 #include <linux/utsname.h>
58869 #include <linux/coredump.h>
58870 #include <linux/sched.h>
58871 +#include <linux/xattr.h>
58872 #include <asm/uaccess.h>
58873 #include <asm/param.h>
58874 #include <asm/page.h>
58875 @@ -47,7 +48,7 @@
58876
58877 static int load_elf_binary(struct linux_binprm *bprm);
58878 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58879 - int, int, unsigned long);
58880 + int, int, unsigned long) __intentional_overflow(-1);
58881
58882 #ifdef CONFIG_USELIB
58883 static int load_elf_library(struct file *);
58884 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58885 #define elf_core_dump NULL
58886 #endif
58887
58888 +#ifdef CONFIG_PAX_MPROTECT
58889 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58890 +#endif
58891 +
58892 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58893 +static void elf_handle_mmap(struct file *file);
58894 +#endif
58895 +
58896 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58897 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58898 #else
58899 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58900 .load_binary = load_elf_binary,
58901 .load_shlib = load_elf_library,
58902 .core_dump = elf_core_dump,
58903 +
58904 +#ifdef CONFIG_PAX_MPROTECT
58905 + .handle_mprotect= elf_handle_mprotect,
58906 +#endif
58907 +
58908 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58909 + .handle_mmap = elf_handle_mmap,
58910 +#endif
58911 +
58912 .min_coredump = ELF_EXEC_PAGESIZE,
58913 };
58914
58915 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58916
58917 static int set_brk(unsigned long start, unsigned long end)
58918 {
58919 + unsigned long e = end;
58920 +
58921 start = ELF_PAGEALIGN(start);
58922 end = ELF_PAGEALIGN(end);
58923 if (end > start) {
58924 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58925 if (BAD_ADDR(addr))
58926 return addr;
58927 }
58928 - current->mm->start_brk = current->mm->brk = end;
58929 + current->mm->start_brk = current->mm->brk = e;
58930 return 0;
58931 }
58932
58933 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58934 elf_addr_t __user *u_rand_bytes;
58935 const char *k_platform = ELF_PLATFORM;
58936 const char *k_base_platform = ELF_BASE_PLATFORM;
58937 - unsigned char k_rand_bytes[16];
58938 + u32 k_rand_bytes[4];
58939 int items;
58940 elf_addr_t *elf_info;
58941 int ei_index = 0;
58942 const struct cred *cred = current_cred();
58943 struct vm_area_struct *vma;
58944 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58945
58946 /*
58947 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58948 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58949 * Generate 16 random bytes for userspace PRNG seeding.
58950 */
58951 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58952 - u_rand_bytes = (elf_addr_t __user *)
58953 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58954 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58955 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58956 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58957 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58958 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58959 + u_rand_bytes = (elf_addr_t __user *) p;
58960 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58961 return -EFAULT;
58962
58963 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58964 return -EFAULT;
58965 current->mm->env_end = p;
58966
58967 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58968 +
58969 /* Put the elf_info on the stack in the right place. */
58970 sp = (elf_addr_t __user *)envp + 1;
58971 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58972 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58973 return -EFAULT;
58974 return 0;
58975 }
58976 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58977 an ELF header */
58978
58979 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58980 - struct file *interpreter, unsigned long *interp_map_addr,
58981 - unsigned long no_base)
58982 + struct file *interpreter, unsigned long no_base)
58983 {
58984 struct elf_phdr *elf_phdata;
58985 struct elf_phdr *eppnt;
58986 - unsigned long load_addr = 0;
58987 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58988 int load_addr_set = 0;
58989 unsigned long last_bss = 0, elf_bss = 0;
58990 - unsigned long error = ~0UL;
58991 + unsigned long error = -EINVAL;
58992 unsigned long total_size;
58993 int retval, i, size;
58994
58995 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58996 goto out_close;
58997 }
58998
58999 +#ifdef CONFIG_PAX_SEGMEXEC
59000 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59001 + pax_task_size = SEGMEXEC_TASK_SIZE;
59002 +#endif
59003 +
59004 eppnt = elf_phdata;
59005 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59006 if (eppnt->p_type == PT_LOAD) {
59007 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59008 map_addr = elf_map(interpreter, load_addr + vaddr,
59009 eppnt, elf_prot, elf_type, total_size);
59010 total_size = 0;
59011 - if (!*interp_map_addr)
59012 - *interp_map_addr = map_addr;
59013 error = map_addr;
59014 if (BAD_ADDR(map_addr))
59015 goto out_close;
59016 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59017 k = load_addr + eppnt->p_vaddr;
59018 if (BAD_ADDR(k) ||
59019 eppnt->p_filesz > eppnt->p_memsz ||
59020 - eppnt->p_memsz > TASK_SIZE ||
59021 - TASK_SIZE - eppnt->p_memsz < k) {
59022 + eppnt->p_memsz > pax_task_size ||
59023 + pax_task_size - eppnt->p_memsz < k) {
59024 error = -ENOMEM;
59025 goto out_close;
59026 }
59027 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59028 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59029
59030 /* Map the last of the bss segment */
59031 - error = vm_brk(elf_bss, last_bss - elf_bss);
59032 - if (BAD_ADDR(error))
59033 - goto out_close;
59034 + if (last_bss > elf_bss) {
59035 + error = vm_brk(elf_bss, last_bss - elf_bss);
59036 + if (BAD_ADDR(error))
59037 + goto out_close;
59038 + }
59039 }
59040
59041 error = load_addr;
59042 @@ -543,6 +574,336 @@ out:
59043 return error;
59044 }
59045
59046 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59047 +#ifdef CONFIG_PAX_SOFTMODE
59048 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59049 +{
59050 + unsigned long pax_flags = 0UL;
59051 +
59052 +#ifdef CONFIG_PAX_PAGEEXEC
59053 + if (elf_phdata->p_flags & PF_PAGEEXEC)
59054 + pax_flags |= MF_PAX_PAGEEXEC;
59055 +#endif
59056 +
59057 +#ifdef CONFIG_PAX_SEGMEXEC
59058 + if (elf_phdata->p_flags & PF_SEGMEXEC)
59059 + pax_flags |= MF_PAX_SEGMEXEC;
59060 +#endif
59061 +
59062 +#ifdef CONFIG_PAX_EMUTRAMP
59063 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59064 + pax_flags |= MF_PAX_EMUTRAMP;
59065 +#endif
59066 +
59067 +#ifdef CONFIG_PAX_MPROTECT
59068 + if (elf_phdata->p_flags & PF_MPROTECT)
59069 + pax_flags |= MF_PAX_MPROTECT;
59070 +#endif
59071 +
59072 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59073 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59074 + pax_flags |= MF_PAX_RANDMMAP;
59075 +#endif
59076 +
59077 + return pax_flags;
59078 +}
59079 +#endif
59080 +
59081 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59082 +{
59083 + unsigned long pax_flags = 0UL;
59084 +
59085 +#ifdef CONFIG_PAX_PAGEEXEC
59086 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59087 + pax_flags |= MF_PAX_PAGEEXEC;
59088 +#endif
59089 +
59090 +#ifdef CONFIG_PAX_SEGMEXEC
59091 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59092 + pax_flags |= MF_PAX_SEGMEXEC;
59093 +#endif
59094 +
59095 +#ifdef CONFIG_PAX_EMUTRAMP
59096 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59097 + pax_flags |= MF_PAX_EMUTRAMP;
59098 +#endif
59099 +
59100 +#ifdef CONFIG_PAX_MPROTECT
59101 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59102 + pax_flags |= MF_PAX_MPROTECT;
59103 +#endif
59104 +
59105 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59106 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59107 + pax_flags |= MF_PAX_RANDMMAP;
59108 +#endif
59109 +
59110 + return pax_flags;
59111 +}
59112 +#endif
59113 +
59114 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59115 +#ifdef CONFIG_PAX_SOFTMODE
59116 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59117 +{
59118 + unsigned long pax_flags = 0UL;
59119 +
59120 +#ifdef CONFIG_PAX_PAGEEXEC
59121 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59122 + pax_flags |= MF_PAX_PAGEEXEC;
59123 +#endif
59124 +
59125 +#ifdef CONFIG_PAX_SEGMEXEC
59126 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59127 + pax_flags |= MF_PAX_SEGMEXEC;
59128 +#endif
59129 +
59130 +#ifdef CONFIG_PAX_EMUTRAMP
59131 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59132 + pax_flags |= MF_PAX_EMUTRAMP;
59133 +#endif
59134 +
59135 +#ifdef CONFIG_PAX_MPROTECT
59136 + if (pax_flags_softmode & MF_PAX_MPROTECT)
59137 + pax_flags |= MF_PAX_MPROTECT;
59138 +#endif
59139 +
59140 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59141 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59142 + pax_flags |= MF_PAX_RANDMMAP;
59143 +#endif
59144 +
59145 + return pax_flags;
59146 +}
59147 +#endif
59148 +
59149 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59150 +{
59151 + unsigned long pax_flags = 0UL;
59152 +
59153 +#ifdef CONFIG_PAX_PAGEEXEC
59154 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59155 + pax_flags |= MF_PAX_PAGEEXEC;
59156 +#endif
59157 +
59158 +#ifdef CONFIG_PAX_SEGMEXEC
59159 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59160 + pax_flags |= MF_PAX_SEGMEXEC;
59161 +#endif
59162 +
59163 +#ifdef CONFIG_PAX_EMUTRAMP
59164 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59165 + pax_flags |= MF_PAX_EMUTRAMP;
59166 +#endif
59167 +
59168 +#ifdef CONFIG_PAX_MPROTECT
59169 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59170 + pax_flags |= MF_PAX_MPROTECT;
59171 +#endif
59172 +
59173 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59174 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59175 + pax_flags |= MF_PAX_RANDMMAP;
59176 +#endif
59177 +
59178 + return pax_flags;
59179 +}
59180 +#endif
59181 +
59182 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59183 +static unsigned long pax_parse_defaults(void)
59184 +{
59185 + unsigned long pax_flags = 0UL;
59186 +
59187 +#ifdef CONFIG_PAX_SOFTMODE
59188 + if (pax_softmode)
59189 + return pax_flags;
59190 +#endif
59191 +
59192 +#ifdef CONFIG_PAX_PAGEEXEC
59193 + pax_flags |= MF_PAX_PAGEEXEC;
59194 +#endif
59195 +
59196 +#ifdef CONFIG_PAX_SEGMEXEC
59197 + pax_flags |= MF_PAX_SEGMEXEC;
59198 +#endif
59199 +
59200 +#ifdef CONFIG_PAX_MPROTECT
59201 + pax_flags |= MF_PAX_MPROTECT;
59202 +#endif
59203 +
59204 +#ifdef CONFIG_PAX_RANDMMAP
59205 + if (randomize_va_space)
59206 + pax_flags |= MF_PAX_RANDMMAP;
59207 +#endif
59208 +
59209 + return pax_flags;
59210 +}
59211 +
59212 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59213 +{
59214 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59215 +
59216 +#ifdef CONFIG_PAX_EI_PAX
59217 +
59218 +#ifdef CONFIG_PAX_SOFTMODE
59219 + if (pax_softmode)
59220 + return pax_flags;
59221 +#endif
59222 +
59223 + pax_flags = 0UL;
59224 +
59225 +#ifdef CONFIG_PAX_PAGEEXEC
59226 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59227 + pax_flags |= MF_PAX_PAGEEXEC;
59228 +#endif
59229 +
59230 +#ifdef CONFIG_PAX_SEGMEXEC
59231 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59232 + pax_flags |= MF_PAX_SEGMEXEC;
59233 +#endif
59234 +
59235 +#ifdef CONFIG_PAX_EMUTRAMP
59236 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59237 + pax_flags |= MF_PAX_EMUTRAMP;
59238 +#endif
59239 +
59240 +#ifdef CONFIG_PAX_MPROTECT
59241 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59242 + pax_flags |= MF_PAX_MPROTECT;
59243 +#endif
59244 +
59245 +#ifdef CONFIG_PAX_ASLR
59246 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59247 + pax_flags |= MF_PAX_RANDMMAP;
59248 +#endif
59249 +
59250 +#endif
59251 +
59252 + return pax_flags;
59253 +
59254 +}
59255 +
59256 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59257 +{
59258 +
59259 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59260 + unsigned long i;
59261 +
59262 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59263 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59264 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59265 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59266 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59267 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59268 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59269 + return PAX_PARSE_FLAGS_FALLBACK;
59270 +
59271 +#ifdef CONFIG_PAX_SOFTMODE
59272 + if (pax_softmode)
59273 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59274 + else
59275 +#endif
59276 +
59277 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59278 + break;
59279 + }
59280 +#endif
59281 +
59282 + return PAX_PARSE_FLAGS_FALLBACK;
59283 +}
59284 +
59285 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59286 +{
59287 +
59288 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59289 + ssize_t xattr_size, i;
59290 + unsigned char xattr_value[sizeof("pemrs") - 1];
59291 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59292 +
59293 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59294 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59295 + return PAX_PARSE_FLAGS_FALLBACK;
59296 +
59297 + for (i = 0; i < xattr_size; i++)
59298 + switch (xattr_value[i]) {
59299 + default:
59300 + return PAX_PARSE_FLAGS_FALLBACK;
59301 +
59302 +#define parse_flag(option1, option2, flag) \
59303 + case option1: \
59304 + if (pax_flags_hardmode & MF_PAX_##flag) \
59305 + return PAX_PARSE_FLAGS_FALLBACK;\
59306 + pax_flags_hardmode |= MF_PAX_##flag; \
59307 + break; \
59308 + case option2: \
59309 + if (pax_flags_softmode & MF_PAX_##flag) \
59310 + return PAX_PARSE_FLAGS_FALLBACK;\
59311 + pax_flags_softmode |= MF_PAX_##flag; \
59312 + break;
59313 +
59314 + parse_flag('p', 'P', PAGEEXEC);
59315 + parse_flag('e', 'E', EMUTRAMP);
59316 + parse_flag('m', 'M', MPROTECT);
59317 + parse_flag('r', 'R', RANDMMAP);
59318 + parse_flag('s', 'S', SEGMEXEC);
59319 +
59320 +#undef parse_flag
59321 + }
59322 +
59323 + if (pax_flags_hardmode & pax_flags_softmode)
59324 + return PAX_PARSE_FLAGS_FALLBACK;
59325 +
59326 +#ifdef CONFIG_PAX_SOFTMODE
59327 + if (pax_softmode)
59328 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59329 + else
59330 +#endif
59331 +
59332 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59333 +#else
59334 + return PAX_PARSE_FLAGS_FALLBACK;
59335 +#endif
59336 +
59337 +}
59338 +
59339 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59340 +{
59341 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59342 +
59343 + pax_flags = pax_parse_defaults();
59344 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59345 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59346 + xattr_pax_flags = pax_parse_xattr_pax(file);
59347 +
59348 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59349 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59350 + pt_pax_flags != xattr_pax_flags)
59351 + return -EINVAL;
59352 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59353 + pax_flags = xattr_pax_flags;
59354 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59355 + pax_flags = pt_pax_flags;
59356 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59357 + pax_flags = ei_pax_flags;
59358 +
59359 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59360 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59361 + if ((__supported_pte_mask & _PAGE_NX))
59362 + pax_flags &= ~MF_PAX_SEGMEXEC;
59363 + else
59364 + pax_flags &= ~MF_PAX_PAGEEXEC;
59365 + }
59366 +#endif
59367 +
59368 + if (0 > pax_check_flags(&pax_flags))
59369 + return -EINVAL;
59370 +
59371 + current->mm->pax_flags = pax_flags;
59372 + return 0;
59373 +}
59374 +#endif
59375 +
59376 /*
59377 * These are the functions used to load ELF style executables and shared
59378 * libraries. There is no binary dependent code anywhere else.
59379 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59380 {
59381 unsigned int random_variable = 0;
59382
59383 +#ifdef CONFIG_PAX_RANDUSTACK
59384 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59385 + return stack_top - current->mm->delta_stack;
59386 +#endif
59387 +
59388 if ((current->flags & PF_RANDOMIZE) &&
59389 !(current->personality & ADDR_NO_RANDOMIZE)) {
59390 random_variable = get_random_int() & STACK_RND_MASK;
59391 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59392 unsigned long load_addr = 0, load_bias = 0;
59393 int load_addr_set = 0;
59394 char * elf_interpreter = NULL;
59395 - unsigned long error;
59396 + unsigned long error = 0;
59397 struct elf_phdr *elf_ppnt, *elf_phdata;
59398 unsigned long elf_bss, elf_brk;
59399 int retval, i;
59400 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59401 struct elfhdr elf_ex;
59402 struct elfhdr interp_elf_ex;
59403 } *loc;
59404 + unsigned long pax_task_size;
59405
59406 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59407 if (!loc) {
59408 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59409 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59410 may depend on the personality. */
59411 SET_PERSONALITY(loc->elf_ex);
59412 +
59413 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59414 + current->mm->pax_flags = 0UL;
59415 +#endif
59416 +
59417 +#ifdef CONFIG_PAX_DLRESOLVE
59418 + current->mm->call_dl_resolve = 0UL;
59419 +#endif
59420 +
59421 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59422 + current->mm->call_syscall = 0UL;
59423 +#endif
59424 +
59425 +#ifdef CONFIG_PAX_ASLR
59426 + current->mm->delta_mmap = 0UL;
59427 + current->mm->delta_stack = 0UL;
59428 +#endif
59429 +
59430 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59431 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59432 + send_sig(SIGKILL, current, 0);
59433 + goto out_free_dentry;
59434 + }
59435 +#endif
59436 +
59437 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59438 + pax_set_initial_flags(bprm);
59439 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59440 + if (pax_set_initial_flags_func)
59441 + (pax_set_initial_flags_func)(bprm);
59442 +#endif
59443 +
59444 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59445 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59446 + current->mm->context.user_cs_limit = PAGE_SIZE;
59447 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59448 + }
59449 +#endif
59450 +
59451 +#ifdef CONFIG_PAX_SEGMEXEC
59452 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59453 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59454 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59455 + pax_task_size = SEGMEXEC_TASK_SIZE;
59456 + current->mm->def_flags |= VM_NOHUGEPAGE;
59457 + } else
59458 +#endif
59459 +
59460 + pax_task_size = TASK_SIZE;
59461 +
59462 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59463 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59464 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59465 + put_cpu();
59466 + }
59467 +#endif
59468 +
59469 +#ifdef CONFIG_PAX_ASLR
59470 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59471 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59472 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59473 + }
59474 +#endif
59475 +
59476 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59477 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59478 + executable_stack = EXSTACK_DISABLE_X;
59479 + current->personality &= ~READ_IMPLIES_EXEC;
59480 + } else
59481 +#endif
59482 +
59483 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59484 current->personality |= READ_IMPLIES_EXEC;
59485
59486 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59487 #else
59488 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59489 #endif
59490 +
59491 +#ifdef CONFIG_PAX_RANDMMAP
59492 + /* PaX: randomize base address at the default exe base if requested */
59493 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59494 +#ifdef CONFIG_SPARC64
59495 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59496 +#else
59497 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59498 +#endif
59499 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59500 + elf_flags |= MAP_FIXED;
59501 + }
59502 +#endif
59503 +
59504 }
59505
59506 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59507 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59508 * allowed task size. Note that p_filesz must always be
59509 * <= p_memsz so it is only necessary to check p_memsz.
59510 */
59511 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59512 - elf_ppnt->p_memsz > TASK_SIZE ||
59513 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59514 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59515 + elf_ppnt->p_memsz > pax_task_size ||
59516 + pax_task_size - elf_ppnt->p_memsz < k) {
59517 /* set_brk can never work. Avoid overflows. */
59518 send_sig(SIGKILL, current, 0);
59519 retval = -EINVAL;
59520 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59521 goto out_free_dentry;
59522 }
59523 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59524 - send_sig(SIGSEGV, current, 0);
59525 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59526 - goto out_free_dentry;
59527 + /*
59528 + * This bss-zeroing can fail if the ELF
59529 + * file specifies odd protections. So
59530 + * we don't check the return value
59531 + */
59532 }
59533
59534 +#ifdef CONFIG_PAX_RANDMMAP
59535 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59536 + unsigned long start, size, flags;
59537 + vm_flags_t vm_flags;
59538 +
59539 + start = ELF_PAGEALIGN(elf_brk);
59540 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59541 + flags = MAP_FIXED | MAP_PRIVATE;
59542 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59543 +
59544 + down_write(&current->mm->mmap_sem);
59545 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59546 + retval = -ENOMEM;
59547 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59548 +// if (current->personality & ADDR_NO_RANDOMIZE)
59549 +// vm_flags |= VM_READ | VM_MAYREAD;
59550 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59551 + retval = IS_ERR_VALUE(start) ? start : 0;
59552 + }
59553 + up_write(&current->mm->mmap_sem);
59554 + if (retval == 0)
59555 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59556 + if (retval < 0) {
59557 + send_sig(SIGKILL, current, 0);
59558 + goto out_free_dentry;
59559 + }
59560 + }
59561 +#endif
59562 +
59563 if (elf_interpreter) {
59564 - unsigned long interp_map_addr = 0;
59565 -
59566 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59567 interpreter,
59568 - &interp_map_addr,
59569 load_bias);
59570 if (!IS_ERR((void *)elf_entry)) {
59571 /*
59572 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59573 * Decide what to dump of a segment, part, all or none.
59574 */
59575 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59576 - unsigned long mm_flags)
59577 + unsigned long mm_flags, long signr)
59578 {
59579 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59580
59581 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59582 if (vma->vm_file == NULL)
59583 return 0;
59584
59585 - if (FILTER(MAPPED_PRIVATE))
59586 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59587 goto whole;
59588
59589 /*
59590 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59591 {
59592 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59593 int i = 0;
59594 - do
59595 + do {
59596 i += 2;
59597 - while (auxv[i - 2] != AT_NULL);
59598 + } while (auxv[i - 2] != AT_NULL);
59599 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59600 }
59601
59602 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59603 {
59604 mm_segment_t old_fs = get_fs();
59605 set_fs(KERNEL_DS);
59606 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59607 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59608 set_fs(old_fs);
59609 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59610 }
59611 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59612 }
59613
59614 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59615 - unsigned long mm_flags)
59616 + struct coredump_params *cprm)
59617 {
59618 struct vm_area_struct *vma;
59619 size_t size = 0;
59620
59621 for (vma = first_vma(current, gate_vma); vma != NULL;
59622 vma = next_vma(vma, gate_vma))
59623 - size += vma_dump_size(vma, mm_flags);
59624 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59625 return size;
59626 }
59627
59628 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59629
59630 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59631
59632 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59633 + offset += elf_core_vma_data_size(gate_vma, cprm);
59634 offset += elf_core_extra_data_size();
59635 e_shoff = offset;
59636
59637 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59638 phdr.p_offset = offset;
59639 phdr.p_vaddr = vma->vm_start;
59640 phdr.p_paddr = 0;
59641 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59642 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59643 phdr.p_memsz = vma->vm_end - vma->vm_start;
59644 offset += phdr.p_filesz;
59645 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59646 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59647 unsigned long addr;
59648 unsigned long end;
59649
59650 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59651 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59652
59653 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59654 struct page *page;
59655 @@ -2210,6 +2690,167 @@ out:
59656
59657 #endif /* CONFIG_ELF_CORE */
59658
59659 +#ifdef CONFIG_PAX_MPROTECT
59660 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59661 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59662 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59663 + *
59664 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59665 + * basis because we want to allow the common case and not the special ones.
59666 + */
59667 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59668 +{
59669 + struct elfhdr elf_h;
59670 + struct elf_phdr elf_p;
59671 + unsigned long i;
59672 + unsigned long oldflags;
59673 + bool is_textrel_rw, is_textrel_rx, is_relro;
59674 +
59675 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59676 + return;
59677 +
59678 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59679 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59680 +
59681 +#ifdef CONFIG_PAX_ELFRELOCS
59682 + /* possible TEXTREL */
59683 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59684 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59685 +#else
59686 + is_textrel_rw = false;
59687 + is_textrel_rx = false;
59688 +#endif
59689 +
59690 + /* possible RELRO */
59691 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59692 +
59693 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59694 + return;
59695 +
59696 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59697 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59698 +
59699 +#ifdef CONFIG_PAX_ETEXECRELOCS
59700 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59701 +#else
59702 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59703 +#endif
59704 +
59705 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59706 + !elf_check_arch(&elf_h) ||
59707 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59708 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59709 + return;
59710 +
59711 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59712 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59713 + return;
59714 + switch (elf_p.p_type) {
59715 + case PT_DYNAMIC:
59716 + if (!is_textrel_rw && !is_textrel_rx)
59717 + continue;
59718 + i = 0UL;
59719 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59720 + elf_dyn dyn;
59721 +
59722 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59723 + break;
59724 + if (dyn.d_tag == DT_NULL)
59725 + break;
59726 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59727 + gr_log_textrel(vma);
59728 + if (is_textrel_rw)
59729 + vma->vm_flags |= VM_MAYWRITE;
59730 + else
59731 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59732 + vma->vm_flags &= ~VM_MAYWRITE;
59733 + break;
59734 + }
59735 + i++;
59736 + }
59737 + is_textrel_rw = false;
59738 + is_textrel_rx = false;
59739 + continue;
59740 +
59741 + case PT_GNU_RELRO:
59742 + if (!is_relro)
59743 + continue;
59744 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59745 + vma->vm_flags &= ~VM_MAYWRITE;
59746 + is_relro = false;
59747 + continue;
59748 +
59749 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59750 + case PT_PAX_FLAGS: {
59751 + const char *msg_mprotect = "", *msg_emutramp = "";
59752 + char *buffer_lib, *buffer_exe;
59753 +
59754 + if (elf_p.p_flags & PF_NOMPROTECT)
59755 + msg_mprotect = "MPROTECT disabled";
59756 +
59757 +#ifdef CONFIG_PAX_EMUTRAMP
59758 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59759 + msg_emutramp = "EMUTRAMP enabled";
59760 +#endif
59761 +
59762 + if (!msg_mprotect[0] && !msg_emutramp[0])
59763 + continue;
59764 +
59765 + if (!printk_ratelimit())
59766 + continue;
59767 +
59768 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59769 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59770 + if (buffer_lib && buffer_exe) {
59771 + char *path_lib, *path_exe;
59772 +
59773 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59774 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59775 +
59776 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59777 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59778 +
59779 + }
59780 + free_page((unsigned long)buffer_exe);
59781 + free_page((unsigned long)buffer_lib);
59782 + continue;
59783 + }
59784 +#endif
59785 +
59786 + }
59787 + }
59788 +}
59789 +#endif
59790 +
59791 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59792 +
59793 +extern int grsec_enable_log_rwxmaps;
59794 +
59795 +static void elf_handle_mmap(struct file *file)
59796 +{
59797 + struct elfhdr elf_h;
59798 + struct elf_phdr elf_p;
59799 + unsigned long i;
59800 +
59801 + if (!grsec_enable_log_rwxmaps)
59802 + return;
59803 +
59804 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59805 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59806 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59807 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59808 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59809 + return;
59810 +
59811 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59812 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59813 + return;
59814 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59815 + gr_log_ptgnustack(file);
59816 + }
59817 +}
59818 +#endif
59819 +
59820 static int __init init_elf_binfmt(void)
59821 {
59822 register_binfmt(&elf_format);
59823 diff --git a/fs/block_dev.c b/fs/block_dev.c
59824 index 6d72746..536d1db 100644
59825 --- a/fs/block_dev.c
59826 +++ b/fs/block_dev.c
59827 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59828 else if (bdev->bd_contains == bdev)
59829 return true; /* is a whole device which isn't held */
59830
59831 - else if (whole->bd_holder == bd_may_claim)
59832 + else if (whole->bd_holder == (void *)bd_may_claim)
59833 return true; /* is a partition of a device that is being partitioned */
59834 else if (whole->bd_holder != NULL)
59835 return false; /* is a partition of a held device */
59836 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59837 index 44ee5d2..8b23e53 100644
59838 --- a/fs/btrfs/ctree.c
59839 +++ b/fs/btrfs/ctree.c
59840 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59841 free_extent_buffer(buf);
59842 add_root_to_dirty_list(root);
59843 } else {
59844 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59845 - parent_start = parent->start;
59846 - else
59847 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59848 + if (parent)
59849 + parent_start = parent->start;
59850 + else
59851 + parent_start = 0;
59852 + } else
59853 parent_start = 0;
59854
59855 WARN_ON(trans->transid != btrfs_header_generation(parent));
59856 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59857 index a2e90f8..5135e5f 100644
59858 --- a/fs/btrfs/delayed-inode.c
59859 +++ b/fs/btrfs/delayed-inode.c
59860 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59861
59862 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59863 {
59864 - int seq = atomic_inc_return(&delayed_root->items_seq);
59865 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59866 if ((atomic_dec_return(&delayed_root->items) <
59867 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59868 waitqueue_active(&delayed_root->wait))
59869 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59870
59871 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59872 {
59873 - int val = atomic_read(&delayed_root->items_seq);
59874 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59875
59876 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59877 return 1;
59878 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59879 int seq;
59880 int ret;
59881
59882 - seq = atomic_read(&delayed_root->items_seq);
59883 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59884
59885 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59886 if (ret)
59887 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59888 index f70119f..ab5894d 100644
59889 --- a/fs/btrfs/delayed-inode.h
59890 +++ b/fs/btrfs/delayed-inode.h
59891 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59892 */
59893 struct list_head prepare_list;
59894 atomic_t items; /* for delayed items */
59895 - atomic_t items_seq; /* for delayed items */
59896 + atomic_unchecked_t items_seq; /* for delayed items */
59897 int nodes; /* for delayed nodes */
59898 wait_queue_head_t wait;
59899 };
59900 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59901 struct btrfs_delayed_root *delayed_root)
59902 {
59903 atomic_set(&delayed_root->items, 0);
59904 - atomic_set(&delayed_root->items_seq, 0);
59905 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59906 delayed_root->nodes = 0;
59907 spin_lock_init(&delayed_root->lock);
59908 init_waitqueue_head(&delayed_root->wait);
59909 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59910 index 8a8e298..9f904ad 100644
59911 --- a/fs/btrfs/ioctl.c
59912 +++ b/fs/btrfs/ioctl.c
59913 @@ -3939,9 +3939,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59914 for (i = 0; i < num_types; i++) {
59915 struct btrfs_space_info *tmp;
59916
59917 + /* Don't copy in more than we allocated */
59918 if (!slot_count)
59919 break;
59920
59921 + slot_count--;
59922 +
59923 info = NULL;
59924 rcu_read_lock();
59925 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59926 @@ -3963,10 +3966,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59927 memcpy(dest, &space, sizeof(space));
59928 dest++;
59929 space_args.total_spaces++;
59930 - slot_count--;
59931 }
59932 - if (!slot_count)
59933 - break;
59934 }
59935 up_read(&info->groups_sem);
59936 }
59937 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59938 index c4124de..d7613eb6 100644
59939 --- a/fs/btrfs/super.c
59940 +++ b/fs/btrfs/super.c
59941 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59942 function, line, errstr);
59943 return;
59944 }
59945 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59946 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59947 /* Wake up anybody who may be waiting on this transaction */
59948 wake_up(&root->fs_info->transaction_wait);
59949 wake_up(&root->fs_info->transaction_blocked_wait);
59950 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59951 index 12e5355..cdf30c6 100644
59952 --- a/fs/btrfs/sysfs.c
59953 +++ b/fs/btrfs/sysfs.c
59954 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59955 for (set = 0; set < FEAT_MAX; set++) {
59956 int i;
59957 struct attribute *attrs[2];
59958 - struct attribute_group agroup = {
59959 + attribute_group_no_const agroup = {
59960 .name = "features",
59961 .attrs = attrs,
59962 };
59963 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59964 index e2e798a..f454c18 100644
59965 --- a/fs/btrfs/tree-log.h
59966 +++ b/fs/btrfs/tree-log.h
59967 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59968 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59969 struct btrfs_trans_handle *trans)
59970 {
59971 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59972 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59973 }
59974
59975 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59976 diff --git a/fs/buffer.c b/fs/buffer.c
59977 index 3588a80..3d038a9 100644
59978 --- a/fs/buffer.c
59979 +++ b/fs/buffer.c
59980 @@ -2318,6 +2318,11 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
59981 err = 0;
59982
59983 balance_dirty_pages_ratelimited(mapping);
59984 +
59985 + if (unlikely(fatal_signal_pending(current))) {
59986 + err = -EINTR;
59987 + goto out;
59988 + }
59989 }
59990
59991 /* page covers the boundary, find the boundary offset */
59992 @@ -3424,7 +3429,7 @@ void __init buffer_init(void)
59993 bh_cachep = kmem_cache_create("buffer_head",
59994 sizeof(struct buffer_head), 0,
59995 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59996 - SLAB_MEM_SPREAD),
59997 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59998 NULL);
59999
60000 /*
60001 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60002 index fbb08e9..0fda764 100644
60003 --- a/fs/cachefiles/bind.c
60004 +++ b/fs/cachefiles/bind.c
60005 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60006 args);
60007
60008 /* start by checking things over */
60009 - ASSERT(cache->fstop_percent >= 0 &&
60010 - cache->fstop_percent < cache->fcull_percent &&
60011 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
60012 cache->fcull_percent < cache->frun_percent &&
60013 cache->frun_percent < 100);
60014
60015 - ASSERT(cache->bstop_percent >= 0 &&
60016 - cache->bstop_percent < cache->bcull_percent &&
60017 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
60018 cache->bcull_percent < cache->brun_percent &&
60019 cache->brun_percent < 100);
60020
60021 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60022 index ce1b115..4a6852c 100644
60023 --- a/fs/cachefiles/daemon.c
60024 +++ b/fs/cachefiles/daemon.c
60025 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60026 if (n > buflen)
60027 return -EMSGSIZE;
60028
60029 - if (copy_to_user(_buffer, buffer, n) != 0)
60030 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60031 return -EFAULT;
60032
60033 return n;
60034 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60035 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60036 return -EIO;
60037
60038 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
60039 + if (datalen > PAGE_SIZE - 1)
60040 return -EOPNOTSUPP;
60041
60042 /* drag the command string into the kernel so we can parse it */
60043 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60044 if (args[0] != '%' || args[1] != '\0')
60045 return -EINVAL;
60046
60047 - if (fstop < 0 || fstop >= cache->fcull_percent)
60048 + if (fstop >= cache->fcull_percent)
60049 return cachefiles_daemon_range_error(cache, args);
60050
60051 cache->fstop_percent = fstop;
60052 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60053 if (args[0] != '%' || args[1] != '\0')
60054 return -EINVAL;
60055
60056 - if (bstop < 0 || bstop >= cache->bcull_percent)
60057 + if (bstop >= cache->bcull_percent)
60058 return cachefiles_daemon_range_error(cache, args);
60059
60060 cache->bstop_percent = bstop;
60061 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60062 index 8c52472..c4e3a69 100644
60063 --- a/fs/cachefiles/internal.h
60064 +++ b/fs/cachefiles/internal.h
60065 @@ -66,7 +66,7 @@ struct cachefiles_cache {
60066 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60067 struct rb_root active_nodes; /* active nodes (can't be culled) */
60068 rwlock_t active_lock; /* lock for active_nodes */
60069 - atomic_t gravecounter; /* graveyard uniquifier */
60070 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60071 unsigned frun_percent; /* when to stop culling (% files) */
60072 unsigned fcull_percent; /* when to start culling (% files) */
60073 unsigned fstop_percent; /* when to stop allocating (% files) */
60074 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60075 * proc.c
60076 */
60077 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60078 -extern atomic_t cachefiles_lookup_histogram[HZ];
60079 -extern atomic_t cachefiles_mkdir_histogram[HZ];
60080 -extern atomic_t cachefiles_create_histogram[HZ];
60081 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60082 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60083 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60084
60085 extern int __init cachefiles_proc_init(void);
60086 extern void cachefiles_proc_cleanup(void);
60087 static inline
60088 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60089 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60090 {
60091 unsigned long jif = jiffies - start_jif;
60092 if (jif >= HZ)
60093 jif = HZ - 1;
60094 - atomic_inc(&histogram[jif]);
60095 + atomic_inc_unchecked(&histogram[jif]);
60096 }
60097
60098 #else
60099 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60100 index dad7d95..07475af 100644
60101 --- a/fs/cachefiles/namei.c
60102 +++ b/fs/cachefiles/namei.c
60103 @@ -312,7 +312,7 @@ try_again:
60104 /* first step is to make up a grave dentry in the graveyard */
60105 sprintf(nbuffer, "%08x%08x",
60106 (uint32_t) get_seconds(),
60107 - (uint32_t) atomic_inc_return(&cache->gravecounter));
60108 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60109
60110 /* do the multiway lock magic */
60111 trap = lock_rename(cache->graveyard, dir);
60112 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60113 index eccd339..4c1d995 100644
60114 --- a/fs/cachefiles/proc.c
60115 +++ b/fs/cachefiles/proc.c
60116 @@ -14,9 +14,9 @@
60117 #include <linux/seq_file.h>
60118 #include "internal.h"
60119
60120 -atomic_t cachefiles_lookup_histogram[HZ];
60121 -atomic_t cachefiles_mkdir_histogram[HZ];
60122 -atomic_t cachefiles_create_histogram[HZ];
60123 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60124 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60125 +atomic_unchecked_t cachefiles_create_histogram[HZ];
60126
60127 /*
60128 * display the latency histogram
60129 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60130 return 0;
60131 default:
60132 index = (unsigned long) v - 3;
60133 - x = atomic_read(&cachefiles_lookup_histogram[index]);
60134 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
60135 - z = atomic_read(&cachefiles_create_histogram[index]);
60136 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60137 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60138 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60139 if (x == 0 && y == 0 && z == 0)
60140 return 0;
60141
60142 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60143 index 25e745b..220e604 100644
60144 --- a/fs/cachefiles/rdwr.c
60145 +++ b/fs/cachefiles/rdwr.c
60146 @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60147 old_fs = get_fs();
60148 set_fs(KERNEL_DS);
60149 ret = file->f_op->write(
60150 - file, (const void __user *) data, len, &pos);
60151 + file, (const void __force_user *) data, len, &pos);
60152 set_fs(old_fs);
60153 kunmap(page);
60154 file_end_write(file);
60155 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60156 index c29d6ae..719b9bb 100644
60157 --- a/fs/ceph/dir.c
60158 +++ b/fs/ceph/dir.c
60159 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60160 struct dentry *dentry, *last;
60161 struct ceph_dentry_info *di;
60162 int err = 0;
60163 + char d_name[DNAME_INLINE_LEN];
60164 + const unsigned char *name;
60165
60166 /* claim ref on last dentry we returned */
60167 last = fi->dentry;
60168 @@ -192,7 +194,12 @@ more:
60169
60170 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60171 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60172 - if (!dir_emit(ctx, dentry->d_name.name,
60173 + name = dentry->d_name.name;
60174 + if (name == dentry->d_iname) {
60175 + memcpy(d_name, name, dentry->d_name.len);
60176 + name = d_name;
60177 + }
60178 + if (!dir_emit(ctx, name,
60179 dentry->d_name.len,
60180 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60181 dentry->d_inode->i_mode >> 12)) {
60182 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60183 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60184 struct ceph_mds_client *mdsc = fsc->mdsc;
60185 unsigned frag = fpos_frag(ctx->pos);
60186 - int off = fpos_off(ctx->pos);
60187 + unsigned int off = fpos_off(ctx->pos);
60188 int err;
60189 u32 ftype;
60190 struct ceph_mds_reply_info_parsed *rinfo;
60191 diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
60192 index a822a6e..4644256 100644
60193 --- a/fs/ceph/ioctl.c
60194 +++ b/fs/ceph/ioctl.c
60195 @@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
60196 /* validate striping parameters */
60197 if ((l->object_size & ~PAGE_MASK) ||
60198 (l->stripe_unit & ~PAGE_MASK) ||
60199 - (l->stripe_unit != 0 &&
60200 + ((unsigned)l->stripe_unit != 0 &&
60201 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
60202 return -EINVAL;
60203
60204 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60205 index f6e1237..796ffd1 100644
60206 --- a/fs/ceph/super.c
60207 +++ b/fs/ceph/super.c
60208 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60209 /*
60210 * construct our own bdi so we can control readahead, etc.
60211 */
60212 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60213 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60214
60215 static int ceph_register_bdi(struct super_block *sb,
60216 struct ceph_fs_client *fsc)
60217 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60218 default_backing_dev_info.ra_pages;
60219
60220 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60221 - atomic_long_inc_return(&bdi_seq));
60222 + atomic_long_inc_return_unchecked(&bdi_seq));
60223 if (!err)
60224 sb->s_bdi = &fsc->backing_dev_info;
60225 return err;
60226 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60227 index 44ec726..bcb06a3 100644
60228 --- a/fs/cifs/cifs_debug.c
60229 +++ b/fs/cifs/cifs_debug.c
60230 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60231
60232 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60233 #ifdef CONFIG_CIFS_STATS2
60234 - atomic_set(&totBufAllocCount, 0);
60235 - atomic_set(&totSmBufAllocCount, 0);
60236 + atomic_set_unchecked(&totBufAllocCount, 0);
60237 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60238 #endif /* CONFIG_CIFS_STATS2 */
60239 spin_lock(&cifs_tcp_ses_lock);
60240 list_for_each(tmp1, &cifs_tcp_ses_list) {
60241 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60242 tcon = list_entry(tmp3,
60243 struct cifs_tcon,
60244 tcon_list);
60245 - atomic_set(&tcon->num_smbs_sent, 0);
60246 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60247 if (server->ops->clear_stats)
60248 server->ops->clear_stats(tcon);
60249 }
60250 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60251 smBufAllocCount.counter, cifs_min_small);
60252 #ifdef CONFIG_CIFS_STATS2
60253 seq_printf(m, "Total Large %d Small %d Allocations\n",
60254 - atomic_read(&totBufAllocCount),
60255 - atomic_read(&totSmBufAllocCount));
60256 + atomic_read_unchecked(&totBufAllocCount),
60257 + atomic_read_unchecked(&totSmBufAllocCount));
60258 #endif /* CONFIG_CIFS_STATS2 */
60259
60260 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60261 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60262 if (tcon->need_reconnect)
60263 seq_puts(m, "\tDISCONNECTED ");
60264 seq_printf(m, "\nSMBs: %d",
60265 - atomic_read(&tcon->num_smbs_sent));
60266 + atomic_read_unchecked(&tcon->num_smbs_sent));
60267 if (server->ops->print_stats)
60268 server->ops->print_stats(m, tcon);
60269 }
60270 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60271 index 889b984..fcb8431 100644
60272 --- a/fs/cifs/cifsfs.c
60273 +++ b/fs/cifs/cifsfs.c
60274 @@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60275 */
60276 cifs_req_cachep = kmem_cache_create("cifs_request",
60277 CIFSMaxBufSize + max_hdr_size, 0,
60278 - SLAB_HWCACHE_ALIGN, NULL);
60279 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60280 if (cifs_req_cachep == NULL)
60281 return -ENOMEM;
60282
60283 @@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60284 efficient to alloc 1 per page off the slab compared to 17K (5page)
60285 alloc of large cifs buffers even when page debugging is on */
60286 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60287 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60288 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60289 NULL);
60290 if (cifs_sm_req_cachep == NULL) {
60291 mempool_destroy(cifs_req_poolp);
60292 @@ -1204,8 +1204,8 @@ init_cifs(void)
60293 atomic_set(&bufAllocCount, 0);
60294 atomic_set(&smBufAllocCount, 0);
60295 #ifdef CONFIG_CIFS_STATS2
60296 - atomic_set(&totBufAllocCount, 0);
60297 - atomic_set(&totSmBufAllocCount, 0);
60298 + atomic_set_unchecked(&totBufAllocCount, 0);
60299 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60300 #endif /* CONFIG_CIFS_STATS2 */
60301
60302 atomic_set(&midCount, 0);
60303 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60304 index 25b8392..01e46dc 100644
60305 --- a/fs/cifs/cifsglob.h
60306 +++ b/fs/cifs/cifsglob.h
60307 @@ -821,35 +821,35 @@ struct cifs_tcon {
60308 __u16 Flags; /* optional support bits */
60309 enum statusEnum tidStatus;
60310 #ifdef CONFIG_CIFS_STATS
60311 - atomic_t num_smbs_sent;
60312 + atomic_unchecked_t num_smbs_sent;
60313 union {
60314 struct {
60315 - atomic_t num_writes;
60316 - atomic_t num_reads;
60317 - atomic_t num_flushes;
60318 - atomic_t num_oplock_brks;
60319 - atomic_t num_opens;
60320 - atomic_t num_closes;
60321 - atomic_t num_deletes;
60322 - atomic_t num_mkdirs;
60323 - atomic_t num_posixopens;
60324 - atomic_t num_posixmkdirs;
60325 - atomic_t num_rmdirs;
60326 - atomic_t num_renames;
60327 - atomic_t num_t2renames;
60328 - atomic_t num_ffirst;
60329 - atomic_t num_fnext;
60330 - atomic_t num_fclose;
60331 - atomic_t num_hardlinks;
60332 - atomic_t num_symlinks;
60333 - atomic_t num_locks;
60334 - atomic_t num_acl_get;
60335 - atomic_t num_acl_set;
60336 + atomic_unchecked_t num_writes;
60337 + atomic_unchecked_t num_reads;
60338 + atomic_unchecked_t num_flushes;
60339 + atomic_unchecked_t num_oplock_brks;
60340 + atomic_unchecked_t num_opens;
60341 + atomic_unchecked_t num_closes;
60342 + atomic_unchecked_t num_deletes;
60343 + atomic_unchecked_t num_mkdirs;
60344 + atomic_unchecked_t num_posixopens;
60345 + atomic_unchecked_t num_posixmkdirs;
60346 + atomic_unchecked_t num_rmdirs;
60347 + atomic_unchecked_t num_renames;
60348 + atomic_unchecked_t num_t2renames;
60349 + atomic_unchecked_t num_ffirst;
60350 + atomic_unchecked_t num_fnext;
60351 + atomic_unchecked_t num_fclose;
60352 + atomic_unchecked_t num_hardlinks;
60353 + atomic_unchecked_t num_symlinks;
60354 + atomic_unchecked_t num_locks;
60355 + atomic_unchecked_t num_acl_get;
60356 + atomic_unchecked_t num_acl_set;
60357 } cifs_stats;
60358 #ifdef CONFIG_CIFS_SMB2
60359 struct {
60360 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60361 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60362 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60363 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60364 } smb2_stats;
60365 #endif /* CONFIG_CIFS_SMB2 */
60366 } stats;
60367 @@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60368 }
60369
60370 #ifdef CONFIG_CIFS_STATS
60371 -#define cifs_stats_inc atomic_inc
60372 +#define cifs_stats_inc atomic_inc_unchecked
60373
60374 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60375 unsigned int bytes)
60376 @@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60377 /* Various Debug counters */
60378 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60379 #ifdef CONFIG_CIFS_STATS2
60380 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60381 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60382 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60383 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60384 #endif
60385 GLOBAL_EXTERN atomic_t smBufAllocCount;
60386 GLOBAL_EXTERN atomic_t midCount;
60387 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60388 index 5f29354..359bc0d 100644
60389 --- a/fs/cifs/file.c
60390 +++ b/fs/cifs/file.c
60391 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60392 index = mapping->writeback_index; /* Start from prev offset */
60393 end = -1;
60394 } else {
60395 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60396 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60397 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60398 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60399 range_whole = true;
60400 + index = 0;
60401 + end = ULONG_MAX;
60402 + } else {
60403 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60404 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60405 + }
60406 scanned = true;
60407 }
60408 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60409 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60410 index b7415d5..3984ec0 100644
60411 --- a/fs/cifs/misc.c
60412 +++ b/fs/cifs/misc.c
60413 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60414 memset(ret_buf, 0, buf_size + 3);
60415 atomic_inc(&bufAllocCount);
60416 #ifdef CONFIG_CIFS_STATS2
60417 - atomic_inc(&totBufAllocCount);
60418 + atomic_inc_unchecked(&totBufAllocCount);
60419 #endif /* CONFIG_CIFS_STATS2 */
60420 }
60421
60422 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60423 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60424 atomic_inc(&smBufAllocCount);
60425 #ifdef CONFIG_CIFS_STATS2
60426 - atomic_inc(&totSmBufAllocCount);
60427 + atomic_inc_unchecked(&totSmBufAllocCount);
60428 #endif /* CONFIG_CIFS_STATS2 */
60429
60430 }
60431 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60432 index 52131d8..fd79e97 100644
60433 --- a/fs/cifs/smb1ops.c
60434 +++ b/fs/cifs/smb1ops.c
60435 @@ -626,27 +626,27 @@ static void
60436 cifs_clear_stats(struct cifs_tcon *tcon)
60437 {
60438 #ifdef CONFIG_CIFS_STATS
60439 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60440 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60441 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60442 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60443 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60444 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60445 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60446 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60447 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60448 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60449 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60450 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60451 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60452 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60453 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60454 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60455 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60456 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60457 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60458 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60459 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60460 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60461 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60462 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60463 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60464 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60465 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60466 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60467 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60468 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60469 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60470 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60471 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60472 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60473 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60474 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60475 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60476 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60477 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60478 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60479 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60480 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60481 #endif
60482 }
60483
60484 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60485 {
60486 #ifdef CONFIG_CIFS_STATS
60487 seq_printf(m, " Oplocks breaks: %d",
60488 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60489 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60490 seq_printf(m, "\nReads: %d Bytes: %llu",
60491 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60492 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60493 (long long)(tcon->bytes_read));
60494 seq_printf(m, "\nWrites: %d Bytes: %llu",
60495 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60496 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60497 (long long)(tcon->bytes_written));
60498 seq_printf(m, "\nFlushes: %d",
60499 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60500 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60501 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60502 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60503 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60504 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60505 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60506 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60507 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60508 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60509 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60510 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60511 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60512 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60513 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60514 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60515 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60516 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60517 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60518 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60519 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60520 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60521 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60522 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60523 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60524 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60525 seq_printf(m, "\nRenames: %d T2 Renames %d",
60526 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60527 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60528 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60529 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60530 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60531 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60532 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60533 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60534 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60535 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60536 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60537 #endif
60538 }
60539
60540 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60541 index f522193..586121b 100644
60542 --- a/fs/cifs/smb2ops.c
60543 +++ b/fs/cifs/smb2ops.c
60544 @@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60545 #ifdef CONFIG_CIFS_STATS
60546 int i;
60547 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60548 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60549 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60550 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60551 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60552 }
60553 #endif
60554 }
60555 @@ -455,65 +455,65 @@ static void
60556 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60557 {
60558 #ifdef CONFIG_CIFS_STATS
60559 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60560 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60561 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60562 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60563 seq_printf(m, "\nNegotiates: %d sent %d failed",
60564 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60565 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60566 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60567 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60568 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60569 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60570 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60571 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60572 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60573 seq_printf(m, "\nLogoffs: %d sent %d failed",
60574 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60575 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60576 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60577 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60578 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60579 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60580 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60581 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60582 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60583 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60584 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60585 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60586 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60587 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60588 seq_printf(m, "\nCreates: %d sent %d failed",
60589 - atomic_read(&sent[SMB2_CREATE_HE]),
60590 - atomic_read(&failed[SMB2_CREATE_HE]));
60591 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60592 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60593 seq_printf(m, "\nCloses: %d sent %d failed",
60594 - atomic_read(&sent[SMB2_CLOSE_HE]),
60595 - atomic_read(&failed[SMB2_CLOSE_HE]));
60596 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60597 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60598 seq_printf(m, "\nFlushes: %d sent %d failed",
60599 - atomic_read(&sent[SMB2_FLUSH_HE]),
60600 - atomic_read(&failed[SMB2_FLUSH_HE]));
60601 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60602 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60603 seq_printf(m, "\nReads: %d sent %d failed",
60604 - atomic_read(&sent[SMB2_READ_HE]),
60605 - atomic_read(&failed[SMB2_READ_HE]));
60606 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60607 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60608 seq_printf(m, "\nWrites: %d sent %d failed",
60609 - atomic_read(&sent[SMB2_WRITE_HE]),
60610 - atomic_read(&failed[SMB2_WRITE_HE]));
60611 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60612 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60613 seq_printf(m, "\nLocks: %d sent %d failed",
60614 - atomic_read(&sent[SMB2_LOCK_HE]),
60615 - atomic_read(&failed[SMB2_LOCK_HE]));
60616 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60617 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60618 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60619 - atomic_read(&sent[SMB2_IOCTL_HE]),
60620 - atomic_read(&failed[SMB2_IOCTL_HE]));
60621 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60622 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60623 seq_printf(m, "\nCancels: %d sent %d failed",
60624 - atomic_read(&sent[SMB2_CANCEL_HE]),
60625 - atomic_read(&failed[SMB2_CANCEL_HE]));
60626 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60627 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60628 seq_printf(m, "\nEchos: %d sent %d failed",
60629 - atomic_read(&sent[SMB2_ECHO_HE]),
60630 - atomic_read(&failed[SMB2_ECHO_HE]));
60631 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60632 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60633 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60634 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60635 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60636 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60637 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60638 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60639 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60640 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60641 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60642 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60643 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60644 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60645 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60646 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60647 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60648 seq_printf(m, "\nSetInfos: %d sent %d failed",
60649 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60650 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60651 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60652 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60653 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60654 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60655 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60656 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60657 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60658 #endif
60659 }
60660
60661 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60662 index 74b3a66..0c709f3 100644
60663 --- a/fs/cifs/smb2pdu.c
60664 +++ b/fs/cifs/smb2pdu.c
60665 @@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60666 default:
60667 cifs_dbg(VFS, "info level %u isn't supported\n",
60668 srch_inf->info_level);
60669 - rc = -EINVAL;
60670 - goto qdir_exit;
60671 + return -EINVAL;
60672 }
60673
60674 req->FileIndex = cpu_to_le32(index);
60675 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60676 index 278f8fd..e69c52d 100644
60677 --- a/fs/coda/cache.c
60678 +++ b/fs/coda/cache.c
60679 @@ -24,7 +24,7 @@
60680 #include "coda_linux.h"
60681 #include "coda_cache.h"
60682
60683 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60684 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60685
60686 /* replace or extend an acl cache hit */
60687 void coda_cache_enter(struct inode *inode, int mask)
60688 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60689 struct coda_inode_info *cii = ITOC(inode);
60690
60691 spin_lock(&cii->c_lock);
60692 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60693 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60694 if (!uid_eq(cii->c_uid, current_fsuid())) {
60695 cii->c_uid = current_fsuid();
60696 cii->c_cached_perm = mask;
60697 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60698 {
60699 struct coda_inode_info *cii = ITOC(inode);
60700 spin_lock(&cii->c_lock);
60701 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60702 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60703 spin_unlock(&cii->c_lock);
60704 }
60705
60706 /* remove all acl caches */
60707 void coda_cache_clear_all(struct super_block *sb)
60708 {
60709 - atomic_inc(&permission_epoch);
60710 + atomic_inc_unchecked(&permission_epoch);
60711 }
60712
60713
60714 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60715 spin_lock(&cii->c_lock);
60716 hit = (mask & cii->c_cached_perm) == mask &&
60717 uid_eq(cii->c_uid, current_fsuid()) &&
60718 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60719 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60720 spin_unlock(&cii->c_lock);
60721
60722 return hit;
60723 diff --git a/fs/compat.c b/fs/compat.c
60724 index 66d3d3c..9c10175 100644
60725 --- a/fs/compat.c
60726 +++ b/fs/compat.c
60727 @@ -54,7 +54,7 @@
60728 #include <asm/ioctls.h>
60729 #include "internal.h"
60730
60731 -int compat_log = 1;
60732 +int compat_log = 0;
60733
60734 int compat_printk(const char *fmt, ...)
60735 {
60736 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60737
60738 set_fs(KERNEL_DS);
60739 /* The __user pointer cast is valid because of the set_fs() */
60740 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60741 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60742 set_fs(oldfs);
60743 /* truncating is ok because it's a user address */
60744 if (!ret)
60745 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60746 goto out;
60747
60748 ret = -EINVAL;
60749 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60750 + if (nr_segs > UIO_MAXIOV)
60751 goto out;
60752 if (nr_segs > fast_segs) {
60753 ret = -ENOMEM;
60754 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60755 struct compat_readdir_callback {
60756 struct dir_context ctx;
60757 struct compat_old_linux_dirent __user *dirent;
60758 + struct file * file;
60759 int result;
60760 };
60761
60762 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60763 buf->result = -EOVERFLOW;
60764 return -EOVERFLOW;
60765 }
60766 +
60767 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60768 + return 0;
60769 +
60770 buf->result++;
60771 dirent = buf->dirent;
60772 if (!access_ok(VERIFY_WRITE, dirent,
60773 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60774 if (!f.file)
60775 return -EBADF;
60776
60777 + buf.file = f.file;
60778 error = iterate_dir(f.file, &buf.ctx);
60779 if (buf.result)
60780 error = buf.result;
60781 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
60782 struct dir_context ctx;
60783 struct compat_linux_dirent __user *current_dir;
60784 struct compat_linux_dirent __user *previous;
60785 + struct file * file;
60786 int count;
60787 int error;
60788 };
60789 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60790 buf->error = -EOVERFLOW;
60791 return -EOVERFLOW;
60792 }
60793 +
60794 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60795 + return 0;
60796 +
60797 dirent = buf->previous;
60798 if (dirent) {
60799 if (__put_user(offset, &dirent->d_off))
60800 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60801 if (!f.file)
60802 return -EBADF;
60803
60804 + buf.file = f.file;
60805 error = iterate_dir(f.file, &buf.ctx);
60806 if (error >= 0)
60807 error = buf.error;
60808 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60809 struct dir_context ctx;
60810 struct linux_dirent64 __user *current_dir;
60811 struct linux_dirent64 __user *previous;
60812 + struct file * file;
60813 int count;
60814 int error;
60815 };
60816 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60817 buf->error = -EINVAL; /* only used if we fail.. */
60818 if (reclen > buf->count)
60819 return -EINVAL;
60820 +
60821 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60822 + return 0;
60823 +
60824 dirent = buf->previous;
60825
60826 if (dirent) {
60827 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60828 if (!f.file)
60829 return -EBADF;
60830
60831 + buf.file = f.file;
60832 error = iterate_dir(f.file, &buf.ctx);
60833 if (error >= 0)
60834 error = buf.error;
60835 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60836 index 4d24d17..4f8c09e 100644
60837 --- a/fs/compat_binfmt_elf.c
60838 +++ b/fs/compat_binfmt_elf.c
60839 @@ -30,11 +30,13 @@
60840 #undef elf_phdr
60841 #undef elf_shdr
60842 #undef elf_note
60843 +#undef elf_dyn
60844 #undef elf_addr_t
60845 #define elfhdr elf32_hdr
60846 #define elf_phdr elf32_phdr
60847 #define elf_shdr elf32_shdr
60848 #define elf_note elf32_note
60849 +#define elf_dyn Elf32_Dyn
60850 #define elf_addr_t Elf32_Addr
60851
60852 /*
60853 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60854 index afec645..9c65620 100644
60855 --- a/fs/compat_ioctl.c
60856 +++ b/fs/compat_ioctl.c
60857 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60858 return -EFAULT;
60859 if (__get_user(udata, &ss32->iomem_base))
60860 return -EFAULT;
60861 - ss.iomem_base = compat_ptr(udata);
60862 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60863 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60864 __get_user(ss.port_high, &ss32->port_high))
60865 return -EFAULT;
60866 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60867 for (i = 0; i < nmsgs; i++) {
60868 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60869 return -EFAULT;
60870 - if (get_user(datap, &umsgs[i].buf) ||
60871 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60872 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60873 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60874 return -EFAULT;
60875 }
60876 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60877 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60878 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60879 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60880 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60881 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60882 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60883 return -EFAULT;
60884
60885 return ioctl_preallocate(file, p);
60886 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60887 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60888 {
60889 unsigned int a, b;
60890 - a = *(unsigned int *)p;
60891 - b = *(unsigned int *)q;
60892 + a = *(const unsigned int *)p;
60893 + b = *(const unsigned int *)q;
60894 if (a > b)
60895 return 1;
60896 if (a < b)
60897 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60898 index 668dcab..daebcd6 100644
60899 --- a/fs/configfs/dir.c
60900 +++ b/fs/configfs/dir.c
60901 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60902 }
60903 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60904 struct configfs_dirent *next;
60905 - const char *name;
60906 + const unsigned char * name;
60907 + char d_name[sizeof(next->s_dentry->d_iname)];
60908 int len;
60909 struct inode *inode = NULL;
60910
60911 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60912 continue;
60913
60914 name = configfs_get_name(next);
60915 - len = strlen(name);
60916 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60917 + len = next->s_dentry->d_name.len;
60918 + memcpy(d_name, name, len);
60919 + name = d_name;
60920 + } else
60921 + len = strlen(name);
60922
60923 /*
60924 * We'll have a dentry and an inode for
60925 diff --git a/fs/coredump.c b/fs/coredump.c
60926 index a93f7e6..d58bcbe 100644
60927 --- a/fs/coredump.c
60928 +++ b/fs/coredump.c
60929 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
60930 struct pipe_inode_info *pipe = file->private_data;
60931
60932 pipe_lock(pipe);
60933 - pipe->readers++;
60934 - pipe->writers--;
60935 + atomic_inc(&pipe->readers);
60936 + atomic_dec(&pipe->writers);
60937 wake_up_interruptible_sync(&pipe->wait);
60938 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60939 pipe_unlock(pipe);
60940 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
60941 * We actually want wait_event_freezable() but then we need
60942 * to clear TIF_SIGPENDING and improve dump_interrupted().
60943 */
60944 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60945 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60946
60947 pipe_lock(pipe);
60948 - pipe->readers--;
60949 - pipe->writers++;
60950 + atomic_dec(&pipe->readers);
60951 + atomic_inc(&pipe->writers);
60952 pipe_unlock(pipe);
60953 }
60954
60955 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
60956 struct files_struct *displaced;
60957 bool need_nonrelative = false;
60958 bool core_dumped = false;
60959 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60960 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60961 + long signr = siginfo->si_signo;
60962 + int dumpable;
60963 struct coredump_params cprm = {
60964 .siginfo = siginfo,
60965 .regs = signal_pt_regs(),
60966 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
60967 .mm_flags = mm->flags,
60968 };
60969
60970 - audit_core_dumps(siginfo->si_signo);
60971 + audit_core_dumps(signr);
60972 +
60973 + dumpable = __get_dumpable(cprm.mm_flags);
60974 +
60975 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60976 + gr_handle_brute_attach(dumpable);
60977
60978 binfmt = mm->binfmt;
60979 if (!binfmt || !binfmt->core_dump)
60980 goto fail;
60981 - if (!__get_dumpable(cprm.mm_flags))
60982 + if (!dumpable)
60983 goto fail;
60984
60985 cred = prepare_creds();
60986 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
60987 need_nonrelative = true;
60988 }
60989
60990 - retval = coredump_wait(siginfo->si_signo, &core_state);
60991 + retval = coredump_wait(signr, &core_state);
60992 if (retval < 0)
60993 goto fail_creds;
60994
60995 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
60996 }
60997 cprm.limit = RLIM_INFINITY;
60998
60999 - dump_count = atomic_inc_return(&core_dump_count);
61000 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
61001 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61002 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61003 task_tgid_vnr(current), current->comm);
61004 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61005 } else {
61006 struct inode *inode;
61007
61008 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61009 +
61010 if (cprm.limit < binfmt->min_coredump)
61011 goto fail_unlock;
61012
61013 @@ -673,7 +682,7 @@ close_fail:
61014 filp_close(cprm.file, NULL);
61015 fail_dropcount:
61016 if (ispipe)
61017 - atomic_dec(&core_dump_count);
61018 + atomic_dec_unchecked(&core_dump_count);
61019 fail_unlock:
61020 kfree(cn.corename);
61021 coredump_finish(mm, core_dumped);
61022 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61023 struct file *file = cprm->file;
61024 loff_t pos = file->f_pos;
61025 ssize_t n;
61026 +
61027 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61028 if (cprm->written + nr > cprm->limit)
61029 return 0;
61030 while (nr) {
61031 diff --git a/fs/dcache.c b/fs/dcache.c
61032 index cb25a1a..8060de0 100644
61033 --- a/fs/dcache.c
61034 +++ b/fs/dcache.c
61035 @@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
61036 * dentry_iput drops the locks, at which point nobody (except
61037 * transient RCU lookups) can reach this dentry.
61038 */
61039 - BUG_ON((int)dentry->d_lockref.count > 0);
61040 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
61041 this_cpu_dec(nr_dentry);
61042 if (dentry->d_op && dentry->d_op->d_release)
61043 dentry->d_op->d_release(dentry);
61044 @@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
61045 struct dentry *parent = dentry->d_parent;
61046 if (IS_ROOT(dentry))
61047 return NULL;
61048 - if (unlikely((int)dentry->d_lockref.count < 0))
61049 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
61050 return NULL;
61051 if (likely(spin_trylock(&parent->d_lock)))
61052 return parent;
61053 @@ -608,7 +608,7 @@ repeat:
61054 dentry->d_flags |= DCACHE_REFERENCED;
61055 dentry_lru_add(dentry);
61056
61057 - dentry->d_lockref.count--;
61058 + __lockref_dec(&dentry->d_lockref);
61059 spin_unlock(&dentry->d_lock);
61060 return;
61061
61062 @@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
61063 * We also need to leave mountpoints alone,
61064 * directory or not.
61065 */
61066 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
61067 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
61068 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
61069 spin_unlock(&dentry->d_lock);
61070 return -EBUSY;
61071 @@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
61072 /* This must be called with d_lock held */
61073 static inline void __dget_dlock(struct dentry *dentry)
61074 {
61075 - dentry->d_lockref.count++;
61076 + __lockref_inc(&dentry->d_lockref);
61077 }
61078
61079 static inline void __dget(struct dentry *dentry)
61080 @@ -720,8 +720,8 @@ repeat:
61081 goto repeat;
61082 }
61083 rcu_read_unlock();
61084 - BUG_ON(!ret->d_lockref.count);
61085 - ret->d_lockref.count++;
61086 + BUG_ON(!__lockref_read(&ret->d_lockref));
61087 + __lockref_inc(&ret->d_lockref);
61088 spin_unlock(&ret->d_lock);
61089 return ret;
61090 }
61091 @@ -798,7 +798,7 @@ restart:
61092 spin_lock(&inode->i_lock);
61093 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
61094 spin_lock(&dentry->d_lock);
61095 - if (!dentry->d_lockref.count) {
61096 + if (!__lockref_read(&dentry->d_lockref)) {
61097 /*
61098 * inform the fs via d_prune that this dentry
61099 * is about to be unhashed and destroyed.
61100 @@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
61101 * We found an inuse dentry which was not removed from
61102 * the LRU because of laziness during lookup. Do not free it.
61103 */
61104 - if ((int)dentry->d_lockref.count > 0) {
61105 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
61106 spin_unlock(&dentry->d_lock);
61107 if (parent)
61108 spin_unlock(&parent->d_lock);
61109 @@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
61110 dentry = parent;
61111 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
61112 parent = lock_parent(dentry);
61113 - if (dentry->d_lockref.count != 1) {
61114 - dentry->d_lockref.count--;
61115 + if (__lockref_read(&dentry->d_lockref) != 1) {
61116 + __lockref_inc(&dentry->d_lockref);
61117 spin_unlock(&dentry->d_lock);
61118 if (parent)
61119 spin_unlock(&parent->d_lock);
61120 @@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
61121 * counts, just remove them from the LRU. Otherwise give them
61122 * another pass through the LRU.
61123 */
61124 - if (dentry->d_lockref.count) {
61125 + if (__lockref_read(&dentry->d_lockref) > 0) {
61126 d_lru_isolate(dentry);
61127 spin_unlock(&dentry->d_lock);
61128 return LRU_REMOVED;
61129 @@ -1255,7 +1255,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
61130 } else {
61131 if (dentry->d_flags & DCACHE_LRU_LIST)
61132 d_lru_del(dentry);
61133 - if (!dentry->d_lockref.count) {
61134 + if (!__lockref_read(&dentry->d_lockref)) {
61135 d_shrink_add(dentry, &data->dispose);
61136 data->found++;
61137 }
61138 @@ -1303,7 +1303,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61139 return D_WALK_CONTINUE;
61140
61141 /* root with refcount 1 is fine */
61142 - if (dentry == _data && dentry->d_lockref.count == 1)
61143 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
61144 return D_WALK_CONTINUE;
61145
61146 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
61147 @@ -1312,7 +1312,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61148 dentry->d_inode ?
61149 dentry->d_inode->i_ino : 0UL,
61150 dentry,
61151 - dentry->d_lockref.count,
61152 + __lockref_read(&dentry->d_lockref),
61153 dentry->d_sb->s_type->name,
61154 dentry->d_sb->s_id);
61155 WARN_ON(1);
61156 @@ -1438,7 +1438,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61157 */
61158 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61159 if (name->len > DNAME_INLINE_LEN-1) {
61160 - dname = kmalloc(name->len + 1, GFP_KERNEL);
61161 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61162 if (!dname) {
61163 kmem_cache_free(dentry_cache, dentry);
61164 return NULL;
61165 @@ -1456,7 +1456,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61166 smp_wmb();
61167 dentry->d_name.name = dname;
61168
61169 - dentry->d_lockref.count = 1;
61170 + __lockref_set(&dentry->d_lockref, 1);
61171 dentry->d_flags = 0;
61172 spin_lock_init(&dentry->d_lock);
61173 seqcount_init(&dentry->d_seq);
61174 @@ -2196,7 +2196,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
61175 goto next;
61176 }
61177
61178 - dentry->d_lockref.count++;
61179 + __lockref_inc(&dentry->d_lockref);
61180 found = dentry;
61181 spin_unlock(&dentry->d_lock);
61182 break;
61183 @@ -2295,7 +2295,7 @@ again:
61184 spin_lock(&dentry->d_lock);
61185 inode = dentry->d_inode;
61186 isdir = S_ISDIR(inode->i_mode);
61187 - if (dentry->d_lockref.count == 1) {
61188 + if (__lockref_read(&dentry->d_lockref) == 1) {
61189 if (!spin_trylock(&inode->i_lock)) {
61190 spin_unlock(&dentry->d_lock);
61191 cpu_relax();
61192 @@ -2675,11 +2675,13 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
61193 if (!IS_ROOT(new)) {
61194 spin_unlock(&inode->i_lock);
61195 dput(new);
61196 + iput(inode);
61197 return ERR_PTR(-EIO);
61198 }
61199 if (d_ancestor(new, dentry)) {
61200 spin_unlock(&inode->i_lock);
61201 dput(new);
61202 + iput(inode);
61203 return ERR_PTR(-EIO);
61204 }
61205 write_seqlock(&rename_lock);
61206 @@ -3300,7 +3302,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
61207
61208 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
61209 dentry->d_flags |= DCACHE_GENOCIDE;
61210 - dentry->d_lockref.count--;
61211 + __lockref_dec(&dentry->d_lockref);
61212 }
61213 }
61214 return D_WALK_CONTINUE;
61215 @@ -3416,7 +3418,8 @@ void __init vfs_caches_init(unsigned long mempages)
61216 mempages -= reserve;
61217
61218 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61219 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61220 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61221 + SLAB_NO_SANITIZE, NULL);
61222
61223 dcache_init();
61224 inode_init();
61225 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61226 index 1e3b99d..6512101 100644
61227 --- a/fs/debugfs/inode.c
61228 +++ b/fs/debugfs/inode.c
61229 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61230 */
61231 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61232 {
61233 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61234 + return __create_file(name, S_IFDIR | S_IRWXU,
61235 +#else
61236 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61237 +#endif
61238 parent, NULL, NULL);
61239 }
61240 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61241 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61242 index d4a9431..77f9b2e 100644
61243 --- a/fs/ecryptfs/inode.c
61244 +++ b/fs/ecryptfs/inode.c
61245 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61246 old_fs = get_fs();
61247 set_fs(get_ds());
61248 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61249 - (char __user *)lower_buf,
61250 + (char __force_user *)lower_buf,
61251 PATH_MAX);
61252 set_fs(old_fs);
61253 if (rc < 0)
61254 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61255 index e4141f2..d8263e8 100644
61256 --- a/fs/ecryptfs/miscdev.c
61257 +++ b/fs/ecryptfs/miscdev.c
61258 @@ -304,7 +304,7 @@ check_list:
61259 goto out_unlock_msg_ctx;
61260 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61261 if (msg_ctx->msg) {
61262 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61263 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61264 goto out_unlock_msg_ctx;
61265 i += packet_length_size;
61266 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61267 diff --git a/fs/exec.c b/fs/exec.c
61268 index a2b42a9..1e924b3 100644
61269 --- a/fs/exec.c
61270 +++ b/fs/exec.c
61271 @@ -56,8 +56,20 @@
61272 #include <linux/pipe_fs_i.h>
61273 #include <linux/oom.h>
61274 #include <linux/compat.h>
61275 +#include <linux/random.h>
61276 +#include <linux/seq_file.h>
61277 +#include <linux/coredump.h>
61278 +#include <linux/mman.h>
61279 +
61280 +#ifdef CONFIG_PAX_REFCOUNT
61281 +#include <linux/kallsyms.h>
61282 +#include <linux/kdebug.h>
61283 +#endif
61284 +
61285 +#include <trace/events/fs.h>
61286
61287 #include <asm/uaccess.h>
61288 +#include <asm/sections.h>
61289 #include <asm/mmu_context.h>
61290 #include <asm/tlb.h>
61291
61292 @@ -66,19 +78,34 @@
61293
61294 #include <trace/events/sched.h>
61295
61296 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61297 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61298 +{
61299 + 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");
61300 +}
61301 +#endif
61302 +
61303 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61304 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61305 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61306 +#endif
61307 +
61308 int suid_dumpable = 0;
61309
61310 static LIST_HEAD(formats);
61311 static DEFINE_RWLOCK(binfmt_lock);
61312
61313 +extern int gr_process_kernel_exec_ban(void);
61314 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61315 +
61316 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61317 {
61318 BUG_ON(!fmt);
61319 if (WARN_ON(!fmt->load_binary))
61320 return;
61321 write_lock(&binfmt_lock);
61322 - insert ? list_add(&fmt->lh, &formats) :
61323 - list_add_tail(&fmt->lh, &formats);
61324 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61325 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61326 write_unlock(&binfmt_lock);
61327 }
61328
61329 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61330 void unregister_binfmt(struct linux_binfmt * fmt)
61331 {
61332 write_lock(&binfmt_lock);
61333 - list_del(&fmt->lh);
61334 + pax_list_del((struct list_head *)&fmt->lh);
61335 write_unlock(&binfmt_lock);
61336 }
61337
61338 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61339 int write)
61340 {
61341 struct page *page;
61342 - int ret;
61343
61344 -#ifdef CONFIG_STACK_GROWSUP
61345 - if (write) {
61346 - ret = expand_downwards(bprm->vma, pos);
61347 - if (ret < 0)
61348 - return NULL;
61349 - }
61350 -#endif
61351 - ret = get_user_pages(current, bprm->mm, pos,
61352 - 1, write, 1, &page, NULL);
61353 - if (ret <= 0)
61354 + if (0 > expand_downwards(bprm->vma, pos))
61355 + return NULL;
61356 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61357 return NULL;
61358
61359 if (write) {
61360 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61361 if (size <= ARG_MAX)
61362 return page;
61363
61364 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61365 + // only allow 512KB for argv+env on suid/sgid binaries
61366 + // to prevent easy ASLR exhaustion
61367 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61368 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61369 + (size > (512 * 1024))) {
61370 + put_page(page);
61371 + return NULL;
61372 + }
61373 +#endif
61374 +
61375 /*
61376 * Limit to 1/4-th the stack size for the argv+env strings.
61377 * This ensures that:
61378 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61379 vma->vm_end = STACK_TOP_MAX;
61380 vma->vm_start = vma->vm_end - PAGE_SIZE;
61381 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61382 +
61383 +#ifdef CONFIG_PAX_SEGMEXEC
61384 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61385 +#endif
61386 +
61387 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61388 INIT_LIST_HEAD(&vma->anon_vma_chain);
61389
61390 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61391 mm->stack_vm = mm->total_vm = 1;
61392 up_write(&mm->mmap_sem);
61393 bprm->p = vma->vm_end - sizeof(void *);
61394 +
61395 +#ifdef CONFIG_PAX_RANDUSTACK
61396 + if (randomize_va_space)
61397 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61398 +#endif
61399 +
61400 return 0;
61401 err:
61402 up_write(&mm->mmap_sem);
61403 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61404 } ptr;
61405 };
61406
61407 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61408 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61409 {
61410 const char __user *native;
61411
61412 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61413 compat_uptr_t compat;
61414
61415 if (get_user(compat, argv.ptr.compat + nr))
61416 - return ERR_PTR(-EFAULT);
61417 + return (const char __force_user *)ERR_PTR(-EFAULT);
61418
61419 return compat_ptr(compat);
61420 }
61421 #endif
61422
61423 if (get_user(native, argv.ptr.native + nr))
61424 - return ERR_PTR(-EFAULT);
61425 + return (const char __force_user *)ERR_PTR(-EFAULT);
61426
61427 return native;
61428 }
61429 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61430 if (!p)
61431 break;
61432
61433 - if (IS_ERR(p))
61434 + if (IS_ERR((const char __force_kernel *)p))
61435 return -EFAULT;
61436
61437 if (i >= max)
61438 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61439
61440 ret = -EFAULT;
61441 str = get_user_arg_ptr(argv, argc);
61442 - if (IS_ERR(str))
61443 + if (IS_ERR((const char __force_kernel *)str))
61444 goto out;
61445
61446 len = strnlen_user(str, MAX_ARG_STRLEN);
61447 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61448 int r;
61449 mm_segment_t oldfs = get_fs();
61450 struct user_arg_ptr argv = {
61451 - .ptr.native = (const char __user *const __user *)__argv,
61452 + .ptr.native = (const char __user * const __force_user *)__argv,
61453 };
61454
61455 set_fs(KERNEL_DS);
61456 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61457 unsigned long new_end = old_end - shift;
61458 struct mmu_gather tlb;
61459
61460 - BUG_ON(new_start > new_end);
61461 + if (new_start >= new_end || new_start < mmap_min_addr)
61462 + return -ENOMEM;
61463
61464 /*
61465 * ensure there are no vmas between where we want to go
61466 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61467 if (vma != find_vma(mm, new_start))
61468 return -EFAULT;
61469
61470 +#ifdef CONFIG_PAX_SEGMEXEC
61471 + BUG_ON(pax_find_mirror_vma(vma));
61472 +#endif
61473 +
61474 /*
61475 * cover the whole range: [new_start, old_end)
61476 */
61477 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61478 stack_top = arch_align_stack(stack_top);
61479 stack_top = PAGE_ALIGN(stack_top);
61480
61481 - if (unlikely(stack_top < mmap_min_addr) ||
61482 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61483 - return -ENOMEM;
61484 -
61485 stack_shift = vma->vm_end - stack_top;
61486
61487 bprm->p -= stack_shift;
61488 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61489 bprm->exec -= stack_shift;
61490
61491 down_write(&mm->mmap_sem);
61492 +
61493 + /* Move stack pages down in memory. */
61494 + if (stack_shift) {
61495 + ret = shift_arg_pages(vma, stack_shift);
61496 + if (ret)
61497 + goto out_unlock;
61498 + }
61499 +
61500 vm_flags = VM_STACK_FLAGS;
61501
61502 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61503 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61504 + vm_flags &= ~VM_EXEC;
61505 +
61506 +#ifdef CONFIG_PAX_MPROTECT
61507 + if (mm->pax_flags & MF_PAX_MPROTECT)
61508 + vm_flags &= ~VM_MAYEXEC;
61509 +#endif
61510 +
61511 + }
61512 +#endif
61513 +
61514 /*
61515 * Adjust stack execute permissions; explicitly enable for
61516 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61517 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61518 goto out_unlock;
61519 BUG_ON(prev != vma);
61520
61521 - /* Move stack pages down in memory. */
61522 - if (stack_shift) {
61523 - ret = shift_arg_pages(vma, stack_shift);
61524 - if (ret)
61525 - goto out_unlock;
61526 - }
61527 -
61528 /* mprotect_fixup is overkill to remove the temporary stack flags */
61529 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61530
61531 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61532 #endif
61533 current->mm->start_stack = bprm->p;
61534 ret = expand_stack(vma, stack_base);
61535 +
61536 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61537 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61538 + unsigned long size;
61539 + vm_flags_t vm_flags;
61540 +
61541 + size = STACK_TOP - vma->vm_end;
61542 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61543 +
61544 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61545 +
61546 +#ifdef CONFIG_X86
61547 + if (!ret) {
61548 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61549 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61550 + }
61551 +#endif
61552 +
61553 + }
61554 +#endif
61555 +
61556 if (ret)
61557 ret = -EFAULT;
61558
61559 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61560
61561 fsnotify_open(file);
61562
61563 + trace_open_exec(name->name);
61564 +
61565 err = deny_write_access(file);
61566 if (err)
61567 goto exit;
61568 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61569 old_fs = get_fs();
61570 set_fs(get_ds());
61571 /* The cast to a user pointer is valid due to the set_fs() */
61572 - result = vfs_read(file, (void __user *)addr, count, &pos);
61573 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61574 set_fs(old_fs);
61575 return result;
61576 }
61577 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61578 tsk->mm = mm;
61579 tsk->active_mm = mm;
61580 activate_mm(active_mm, mm);
61581 + populate_stack();
61582 tsk->mm->vmacache_seqnum = 0;
61583 vmacache_flush(tsk);
61584 task_unlock(tsk);
61585 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61586 }
61587 rcu_read_unlock();
61588
61589 - if (p->fs->users > n_fs)
61590 + if (atomic_read(&p->fs->users) > n_fs)
61591 bprm->unsafe |= LSM_UNSAFE_SHARE;
61592 else
61593 p->fs->in_exec = 1;
61594 @@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61595 return ret;
61596 }
61597
61598 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61599 +static DEFINE_PER_CPU(u64, exec_counter);
61600 +static int __init init_exec_counters(void)
61601 +{
61602 + unsigned int cpu;
61603 +
61604 + for_each_possible_cpu(cpu) {
61605 + per_cpu(exec_counter, cpu) = (u64)cpu;
61606 + }
61607 +
61608 + return 0;
61609 +}
61610 +early_initcall(init_exec_counters);
61611 +static inline void increment_exec_counter(void)
61612 +{
61613 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61614 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61615 +}
61616 +#else
61617 +static inline void increment_exec_counter(void) {}
61618 +#endif
61619 +
61620 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61621 + struct user_arg_ptr argv);
61622 +
61623 /*
61624 * sys_execve() executes a new program.
61625 */
61626 @@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61627 struct user_arg_ptr argv,
61628 struct user_arg_ptr envp)
61629 {
61630 +#ifdef CONFIG_GRKERNSEC
61631 + struct file *old_exec_file;
61632 + struct acl_subject_label *old_acl;
61633 + struct rlimit old_rlim[RLIM_NLIMITS];
61634 +#endif
61635 struct linux_binprm *bprm;
61636 struct file *file;
61637 struct files_struct *displaced;
61638 @@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61639 if (IS_ERR(filename))
61640 return PTR_ERR(filename);
61641
61642 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61643 +
61644 /*
61645 * We move the actual failure in case of RLIMIT_NPROC excess from
61646 * set*uid() to execve() because too many poorly written programs
61647 @@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61648 if (IS_ERR(file))
61649 goto out_unmark;
61650
61651 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61652 + retval = -EPERM;
61653 + goto out_unmark;
61654 + }
61655 +
61656 sched_exec();
61657
61658 bprm->file = file;
61659 bprm->filename = bprm->interp = filename->name;
61660
61661 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61662 + retval = -EACCES;
61663 + goto out_unmark;
61664 + }
61665 +
61666 retval = bprm_mm_init(bprm);
61667 if (retval)
61668 goto out_unmark;
61669 @@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61670 if (retval < 0)
61671 goto out;
61672
61673 +#ifdef CONFIG_GRKERNSEC
61674 + old_acl = current->acl;
61675 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61676 + old_exec_file = current->exec_file;
61677 + get_file(file);
61678 + current->exec_file = file;
61679 +#endif
61680 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61681 + /* limit suid stack to 8MB
61682 + * we saved the old limits above and will restore them if this exec fails
61683 + */
61684 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61685 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61686 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61687 +#endif
61688 +
61689 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61690 + retval = -EPERM;
61691 + goto out_fail;
61692 + }
61693 +
61694 + if (!gr_tpe_allow(file)) {
61695 + retval = -EACCES;
61696 + goto out_fail;
61697 + }
61698 +
61699 + if (gr_check_crash_exec(file)) {
61700 + retval = -EACCES;
61701 + goto out_fail;
61702 + }
61703 +
61704 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61705 + bprm->unsafe);
61706 + if (retval < 0)
61707 + goto out_fail;
61708 +
61709 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61710 if (retval < 0)
61711 - goto out;
61712 + goto out_fail;
61713
61714 bprm->exec = bprm->p;
61715 retval = copy_strings(bprm->envc, envp, bprm);
61716 if (retval < 0)
61717 - goto out;
61718 + goto out_fail;
61719
61720 retval = copy_strings(bprm->argc, argv, bprm);
61721 if (retval < 0)
61722 - goto out;
61723 + goto out_fail;
61724 +
61725 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61726 +
61727 + gr_handle_exec_args(bprm, argv);
61728
61729 retval = exec_binprm(bprm);
61730 if (retval < 0)
61731 - goto out;
61732 + goto out_fail;
61733 +#ifdef CONFIG_GRKERNSEC
61734 + if (old_exec_file)
61735 + fput(old_exec_file);
61736 +#endif
61737
61738 /* execve succeeded */
61739 +
61740 + increment_exec_counter();
61741 current->fs->in_exec = 0;
61742 current->in_execve = 0;
61743 acct_update_integrals(current);
61744 @@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61745 put_files_struct(displaced);
61746 return retval;
61747
61748 +out_fail:
61749 +#ifdef CONFIG_GRKERNSEC
61750 + current->acl = old_acl;
61751 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61752 + fput(current->exec_file);
61753 + current->exec_file = old_exec_file;
61754 +#endif
61755 +
61756 out:
61757 if (bprm->mm) {
61758 acct_arg_size(bprm, 0);
61759 @@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61760 return compat_do_execve(getname(filename), argv, envp);
61761 }
61762 #endif
61763 +
61764 +int pax_check_flags(unsigned long *flags)
61765 +{
61766 + int retval = 0;
61767 +
61768 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61769 + if (*flags & MF_PAX_SEGMEXEC)
61770 + {
61771 + *flags &= ~MF_PAX_SEGMEXEC;
61772 + retval = -EINVAL;
61773 + }
61774 +#endif
61775 +
61776 + if ((*flags & MF_PAX_PAGEEXEC)
61777 +
61778 +#ifdef CONFIG_PAX_PAGEEXEC
61779 + && (*flags & MF_PAX_SEGMEXEC)
61780 +#endif
61781 +
61782 + )
61783 + {
61784 + *flags &= ~MF_PAX_PAGEEXEC;
61785 + retval = -EINVAL;
61786 + }
61787 +
61788 + if ((*flags & MF_PAX_MPROTECT)
61789 +
61790 +#ifdef CONFIG_PAX_MPROTECT
61791 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61792 +#endif
61793 +
61794 + )
61795 + {
61796 + *flags &= ~MF_PAX_MPROTECT;
61797 + retval = -EINVAL;
61798 + }
61799 +
61800 + if ((*flags & MF_PAX_EMUTRAMP)
61801 +
61802 +#ifdef CONFIG_PAX_EMUTRAMP
61803 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61804 +#endif
61805 +
61806 + )
61807 + {
61808 + *flags &= ~MF_PAX_EMUTRAMP;
61809 + retval = -EINVAL;
61810 + }
61811 +
61812 + return retval;
61813 +}
61814 +
61815 +EXPORT_SYMBOL(pax_check_flags);
61816 +
61817 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61818 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61819 +{
61820 + char *pathname = d_path(path, buf, buflen);
61821 +
61822 + if (IS_ERR(pathname))
61823 + goto toolong;
61824 +
61825 + pathname = mangle_path(buf, pathname, "\t\n\\");
61826 + if (!pathname)
61827 + goto toolong;
61828 +
61829 + *pathname = 0;
61830 + return buf;
61831 +
61832 +toolong:
61833 + return "<path too long>";
61834 +}
61835 +EXPORT_SYMBOL(pax_get_path);
61836 +
61837 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61838 +{
61839 + struct task_struct *tsk = current;
61840 + struct mm_struct *mm = current->mm;
61841 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61842 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61843 + char *path_exec = NULL;
61844 + char *path_fault = NULL;
61845 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61846 + siginfo_t info = { };
61847 +
61848 + if (buffer_exec && buffer_fault) {
61849 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61850 +
61851 + down_read(&mm->mmap_sem);
61852 + vma = mm->mmap;
61853 + while (vma && (!vma_exec || !vma_fault)) {
61854 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61855 + vma_exec = vma;
61856 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61857 + vma_fault = vma;
61858 + vma = vma->vm_next;
61859 + }
61860 + if (vma_exec)
61861 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61862 + if (vma_fault) {
61863 + start = vma_fault->vm_start;
61864 + end = vma_fault->vm_end;
61865 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61866 + if (vma_fault->vm_file)
61867 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61868 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61869 + path_fault = "<heap>";
61870 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61871 + path_fault = "<stack>";
61872 + else
61873 + path_fault = "<anonymous mapping>";
61874 + }
61875 + up_read(&mm->mmap_sem);
61876 + }
61877 + if (tsk->signal->curr_ip)
61878 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61879 + else
61880 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61881 + 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),
61882 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61883 + free_page((unsigned long)buffer_exec);
61884 + free_page((unsigned long)buffer_fault);
61885 + pax_report_insns(regs, pc, sp);
61886 + info.si_signo = SIGKILL;
61887 + info.si_errno = 0;
61888 + info.si_code = SI_KERNEL;
61889 + info.si_pid = 0;
61890 + info.si_uid = 0;
61891 + do_coredump(&info);
61892 +}
61893 +#endif
61894 +
61895 +#ifdef CONFIG_PAX_REFCOUNT
61896 +void pax_report_refcount_overflow(struct pt_regs *regs)
61897 +{
61898 + if (current->signal->curr_ip)
61899 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61900 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61901 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61902 + else
61903 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61904 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61905 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61906 + preempt_disable();
61907 + show_regs(regs);
61908 + preempt_enable();
61909 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61910 +}
61911 +#endif
61912 +
61913 +#ifdef CONFIG_PAX_USERCOPY
61914 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61915 +static noinline int check_stack_object(const void *obj, unsigned long len)
61916 +{
61917 + const void * const stack = task_stack_page(current);
61918 + const void * const stackend = stack + THREAD_SIZE;
61919 +
61920 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61921 + const void *frame = NULL;
61922 + const void *oldframe;
61923 +#endif
61924 +
61925 + if (obj + len < obj)
61926 + return -1;
61927 +
61928 + if (obj + len <= stack || stackend <= obj)
61929 + return 0;
61930 +
61931 + if (obj < stack || stackend < obj + len)
61932 + return -1;
61933 +
61934 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61935 + oldframe = __builtin_frame_address(1);
61936 + if (oldframe)
61937 + frame = __builtin_frame_address(2);
61938 + /*
61939 + low ----------------------------------------------> high
61940 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61941 + ^----------------^
61942 + allow copies only within here
61943 + */
61944 + while (stack <= frame && frame < stackend) {
61945 + /* if obj + len extends past the last frame, this
61946 + check won't pass and the next frame will be 0,
61947 + causing us to bail out and correctly report
61948 + the copy as invalid
61949 + */
61950 + if (obj + len <= frame)
61951 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61952 + oldframe = frame;
61953 + frame = *(const void * const *)frame;
61954 + }
61955 + return -1;
61956 +#else
61957 + return 1;
61958 +#endif
61959 +}
61960 +
61961 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61962 +{
61963 + if (current->signal->curr_ip)
61964 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61965 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61966 + else
61967 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61968 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61969 + dump_stack();
61970 + gr_handle_kernel_exploit();
61971 + do_group_exit(SIGKILL);
61972 +}
61973 +#endif
61974 +
61975 +#ifdef CONFIG_PAX_USERCOPY
61976 +
61977 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61978 +{
61979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61980 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61981 +#ifdef CONFIG_MODULES
61982 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61983 +#else
61984 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61985 +#endif
61986 +
61987 +#else
61988 + unsigned long textlow = (unsigned long)_stext;
61989 + unsigned long texthigh = (unsigned long)_etext;
61990 +
61991 +#ifdef CONFIG_X86_64
61992 + /* check against linear mapping as well */
61993 + if (high > (unsigned long)__va(__pa(textlow)) &&
61994 + low < (unsigned long)__va(__pa(texthigh)))
61995 + return true;
61996 +#endif
61997 +
61998 +#endif
61999 +
62000 + if (high <= textlow || low >= texthigh)
62001 + return false;
62002 + else
62003 + return true;
62004 +}
62005 +#endif
62006 +
62007 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62008 +{
62009 +#ifdef CONFIG_PAX_USERCOPY
62010 + const char *type;
62011 +#endif
62012 +
62013 +#ifndef CONFIG_STACK_GROWSUP
62014 + unsigned long stackstart = (unsigned long)task_stack_page(current);
62015 + unsigned long currentsp = (unsigned long)&stackstart;
62016 + if (unlikely((currentsp < stackstart + 512 ||
62017 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62018 + BUG();
62019 +#endif
62020 +
62021 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
62022 + if (const_size)
62023 + return;
62024 +#endif
62025 +
62026 +#ifdef CONFIG_PAX_USERCOPY
62027 + if (!n)
62028 + return;
62029 +
62030 + type = check_heap_object(ptr, n);
62031 + if (!type) {
62032 + int ret = check_stack_object(ptr, n);
62033 + if (ret == 1 || ret == 2)
62034 + return;
62035 + if (ret == 0) {
62036 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62037 + type = "<kernel text>";
62038 + else
62039 + return;
62040 + } else
62041 + type = "<process stack>";
62042 + }
62043 +
62044 + pax_report_usercopy(ptr, n, to_user, type);
62045 +#endif
62046 +
62047 +}
62048 +EXPORT_SYMBOL(__check_object_size);
62049 +
62050 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62051 +void pax_track_stack(void)
62052 +{
62053 + unsigned long sp = (unsigned long)&sp;
62054 + if (sp < current_thread_info()->lowest_stack &&
62055 + sp > (unsigned long)task_stack_page(current))
62056 + current_thread_info()->lowest_stack = sp;
62057 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62058 + BUG();
62059 +}
62060 +EXPORT_SYMBOL(pax_track_stack);
62061 +#endif
62062 +
62063 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
62064 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62065 +{
62066 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62067 + dump_stack();
62068 + do_group_exit(SIGKILL);
62069 +}
62070 +EXPORT_SYMBOL(report_size_overflow);
62071 +#endif
62072 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62073 index 9f9992b..8b59411 100644
62074 --- a/fs/ext2/balloc.c
62075 +++ b/fs/ext2/balloc.c
62076 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62077
62078 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62079 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62080 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62081 + if (free_blocks < root_blocks + 1 &&
62082 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62083 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62084 - !in_group_p (sbi->s_resgid))) {
62085 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62086 return 0;
62087 }
62088 return 1;
62089 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62090 index 9142614..97484fa 100644
62091 --- a/fs/ext2/xattr.c
62092 +++ b/fs/ext2/xattr.c
62093 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62094 struct buffer_head *bh = NULL;
62095 struct ext2_xattr_entry *entry;
62096 char *end;
62097 - size_t rest = buffer_size;
62098 + size_t rest = buffer_size, total_size = 0;
62099 int error;
62100
62101 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62102 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62103 buffer += size;
62104 }
62105 rest -= size;
62106 + total_size += size;
62107 }
62108 }
62109 - error = buffer_size - rest; /* total size */
62110 + error = total_size;
62111
62112 cleanup:
62113 brelse(bh);
62114 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62115 index 158b5d4..2432610 100644
62116 --- a/fs/ext3/balloc.c
62117 +++ b/fs/ext3/balloc.c
62118 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62119
62120 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62121 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62122 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62123 + if (free_blocks < root_blocks + 1 &&
62124 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62125 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62126 - !in_group_p (sbi->s_resgid))) {
62127 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62128 return 0;
62129 }
62130 return 1;
62131 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62132 index c6874be..f8a6ae8 100644
62133 --- a/fs/ext3/xattr.c
62134 +++ b/fs/ext3/xattr.c
62135 @@ -330,7 +330,7 @@ static int
62136 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62137 char *buffer, size_t buffer_size)
62138 {
62139 - size_t rest = buffer_size;
62140 + size_t rest = buffer_size, total_size = 0;
62141
62142 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62143 const struct xattr_handler *handler =
62144 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62145 buffer += size;
62146 }
62147 rest -= size;
62148 + total_size += size;
62149 }
62150 }
62151 - return buffer_size - rest;
62152 + return total_size;
62153 }
62154
62155 static int
62156 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62157 index 581ef40..cec52d7 100644
62158 --- a/fs/ext4/balloc.c
62159 +++ b/fs/ext4/balloc.c
62160 @@ -553,8 +553,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62161 /* Hm, nope. Are (enough) root reserved clusters available? */
62162 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62163 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62164 - capable(CAP_SYS_RESOURCE) ||
62165 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62166 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62167 + capable_nolog(CAP_SYS_RESOURCE)) {
62168
62169 if (free_clusters >= (nclusters + dirty_clusters +
62170 resv_clusters))
62171 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62172 index b0c225c..0e69bd7 100644
62173 --- a/fs/ext4/ext4.h
62174 +++ b/fs/ext4/ext4.h
62175 @@ -1275,19 +1275,19 @@ struct ext4_sb_info {
62176 unsigned long s_mb_last_start;
62177
62178 /* stats for buddy allocator */
62179 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62180 - atomic_t s_bal_success; /* we found long enough chunks */
62181 - atomic_t s_bal_allocated; /* in blocks */
62182 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62183 - atomic_t s_bal_goals; /* goal hits */
62184 - atomic_t s_bal_breaks; /* too long searches */
62185 - atomic_t s_bal_2orders; /* 2^order hits */
62186 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62187 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62188 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62189 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62190 + atomic_unchecked_t s_bal_goals; /* goal hits */
62191 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62192 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62193 spinlock_t s_bal_lock;
62194 unsigned long s_mb_buddies_generated;
62195 unsigned long long s_mb_generation_time;
62196 - atomic_t s_mb_lost_chunks;
62197 - atomic_t s_mb_preallocated;
62198 - atomic_t s_mb_discarded;
62199 + atomic_unchecked_t s_mb_lost_chunks;
62200 + atomic_unchecked_t s_mb_preallocated;
62201 + atomic_unchecked_t s_mb_discarded;
62202 atomic_t s_lock_busy;
62203
62204 /* locality groups */
62205 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62206 index 8b0f9ef..cb9f620 100644
62207 --- a/fs/ext4/mballoc.c
62208 +++ b/fs/ext4/mballoc.c
62209 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62210 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62211
62212 if (EXT4_SB(sb)->s_mb_stats)
62213 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62214 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62215
62216 break;
62217 }
62218 @@ -2211,7 +2211,7 @@ repeat:
62219 ac->ac_status = AC_STATUS_CONTINUE;
62220 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62221 cr = 3;
62222 - atomic_inc(&sbi->s_mb_lost_chunks);
62223 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62224 goto repeat;
62225 }
62226 }
62227 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62228 if (sbi->s_mb_stats) {
62229 ext4_msg(sb, KERN_INFO,
62230 "mballoc: %u blocks %u reqs (%u success)",
62231 - atomic_read(&sbi->s_bal_allocated),
62232 - atomic_read(&sbi->s_bal_reqs),
62233 - atomic_read(&sbi->s_bal_success));
62234 + atomic_read_unchecked(&sbi->s_bal_allocated),
62235 + atomic_read_unchecked(&sbi->s_bal_reqs),
62236 + atomic_read_unchecked(&sbi->s_bal_success));
62237 ext4_msg(sb, KERN_INFO,
62238 "mballoc: %u extents scanned, %u goal hits, "
62239 "%u 2^N hits, %u breaks, %u lost",
62240 - atomic_read(&sbi->s_bal_ex_scanned),
62241 - atomic_read(&sbi->s_bal_goals),
62242 - atomic_read(&sbi->s_bal_2orders),
62243 - atomic_read(&sbi->s_bal_breaks),
62244 - atomic_read(&sbi->s_mb_lost_chunks));
62245 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62246 + atomic_read_unchecked(&sbi->s_bal_goals),
62247 + atomic_read_unchecked(&sbi->s_bal_2orders),
62248 + atomic_read_unchecked(&sbi->s_bal_breaks),
62249 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62250 ext4_msg(sb, KERN_INFO,
62251 "mballoc: %lu generated and it took %Lu",
62252 sbi->s_mb_buddies_generated,
62253 sbi->s_mb_generation_time);
62254 ext4_msg(sb, KERN_INFO,
62255 "mballoc: %u preallocated, %u discarded",
62256 - atomic_read(&sbi->s_mb_preallocated),
62257 - atomic_read(&sbi->s_mb_discarded));
62258 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62259 + atomic_read_unchecked(&sbi->s_mb_discarded));
62260 }
62261
62262 free_percpu(sbi->s_locality_groups);
62263 @@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62264 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62265
62266 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62267 - atomic_inc(&sbi->s_bal_reqs);
62268 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62269 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62270 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62271 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62272 - atomic_inc(&sbi->s_bal_success);
62273 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62274 + atomic_inc_unchecked(&sbi->s_bal_success);
62275 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62276 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62277 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62278 - atomic_inc(&sbi->s_bal_goals);
62279 + atomic_inc_unchecked(&sbi->s_bal_goals);
62280 if (ac->ac_found > sbi->s_mb_max_to_scan)
62281 - atomic_inc(&sbi->s_bal_breaks);
62282 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62283 }
62284
62285 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62286 @@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62287 trace_ext4_mb_new_inode_pa(ac, pa);
62288
62289 ext4_mb_use_inode_pa(ac, pa);
62290 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62291 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62292
62293 ei = EXT4_I(ac->ac_inode);
62294 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62295 @@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62296 trace_ext4_mb_new_group_pa(ac, pa);
62297
62298 ext4_mb_use_group_pa(ac, pa);
62299 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62300 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62301
62302 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62303 lg = ac->ac_lg;
62304 @@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62305 * from the bitmap and continue.
62306 */
62307 }
62308 - atomic_add(free, &sbi->s_mb_discarded);
62309 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62310
62311 return err;
62312 }
62313 @@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62314 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62315 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62316 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62317 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62318 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62319 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62320
62321 return 0;
62322 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62323 index 32bce84..112d969 100644
62324 --- a/fs/ext4/mmp.c
62325 +++ b/fs/ext4/mmp.c
62326 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62327 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62328 const char *function, unsigned int line, const char *msg)
62329 {
62330 - __ext4_warning(sb, function, line, msg);
62331 + __ext4_warning(sb, function, line, "%s", msg);
62332 __ext4_warning(sb, function, line,
62333 "MMP failure info: last update time: %llu, last update "
62334 "node: %s, last update device: %s\n",
62335 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62336 index 0b28b36..b85d0f53 100644
62337 --- a/fs/ext4/super.c
62338 +++ b/fs/ext4/super.c
62339 @@ -1276,7 +1276,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62340 }
62341
62342 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62343 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62344 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62345 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62346
62347 #ifdef CONFIG_QUOTA
62348 @@ -2460,7 +2460,7 @@ struct ext4_attr {
62349 int offset;
62350 int deprecated_val;
62351 } u;
62352 -};
62353 +} __do_const;
62354
62355 static int parse_strtoull(const char *buf,
62356 unsigned long long max, unsigned long long *value)
62357 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62358 index e738733..9843a6c 100644
62359 --- a/fs/ext4/xattr.c
62360 +++ b/fs/ext4/xattr.c
62361 @@ -386,7 +386,7 @@ static int
62362 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62363 char *buffer, size_t buffer_size)
62364 {
62365 - size_t rest = buffer_size;
62366 + size_t rest = buffer_size, total_size = 0;
62367
62368 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62369 const struct xattr_handler *handler =
62370 @@ -403,9 +403,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62371 buffer += size;
62372 }
62373 rest -= size;
62374 + total_size += size;
62375 }
62376 }
62377 - return buffer_size - rest;
62378 + return total_size;
62379 }
62380
62381 static int
62382 diff --git a/fs/fcntl.c b/fs/fcntl.c
62383 index 22d1c3d..600cf7e 100644
62384 --- a/fs/fcntl.c
62385 +++ b/fs/fcntl.c
62386 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62387 if (err)
62388 return err;
62389
62390 + if (gr_handle_chroot_fowner(pid, type))
62391 + return -ENOENT;
62392 + if (gr_check_protected_task_fowner(pid, type))
62393 + return -EACCES;
62394 +
62395 f_modown(filp, pid, type, force);
62396 return 0;
62397 }
62398 diff --git a/fs/fhandle.c b/fs/fhandle.c
62399 index 999ff5c..ac037c9 100644
62400 --- a/fs/fhandle.c
62401 +++ b/fs/fhandle.c
62402 @@ -8,6 +8,7 @@
62403 #include <linux/fs_struct.h>
62404 #include <linux/fsnotify.h>
62405 #include <linux/personality.h>
62406 +#include <linux/grsecurity.h>
62407 #include <asm/uaccess.h>
62408 #include "internal.h"
62409 #include "mount.h"
62410 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62411 } else
62412 retval = 0;
62413 /* copy the mount id */
62414 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62415 - sizeof(*mnt_id)) ||
62416 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62417 copy_to_user(ufh, handle,
62418 sizeof(struct file_handle) + handle_bytes))
62419 retval = -EFAULT;
62420 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62421 * the directory. Ideally we would like CAP_DAC_SEARCH.
62422 * But we don't have that
62423 */
62424 - if (!capable(CAP_DAC_READ_SEARCH)) {
62425 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62426 retval = -EPERM;
62427 goto out_err;
62428 }
62429 diff --git a/fs/file.c b/fs/file.c
62430 index 66923fe..2849783 100644
62431 --- a/fs/file.c
62432 +++ b/fs/file.c
62433 @@ -16,6 +16,7 @@
62434 #include <linux/slab.h>
62435 #include <linux/vmalloc.h>
62436 #include <linux/file.h>
62437 +#include <linux/security.h>
62438 #include <linux/fdtable.h>
62439 #include <linux/bitops.h>
62440 #include <linux/interrupt.h>
62441 @@ -139,7 +140,7 @@ out:
62442 * Return <0 error code on error; 1 on successful completion.
62443 * The files->file_lock should be held on entry, and will be held on exit.
62444 */
62445 -static int expand_fdtable(struct files_struct *files, int nr)
62446 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62447 __releases(files->file_lock)
62448 __acquires(files->file_lock)
62449 {
62450 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62451 * expanded and execution may have blocked.
62452 * The files->file_lock should be held on entry, and will be held on exit.
62453 */
62454 -static int expand_files(struct files_struct *files, int nr)
62455 +static int expand_files(struct files_struct *files, unsigned int nr)
62456 {
62457 struct fdtable *fdt;
62458
62459 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62460 if (!file)
62461 return __close_fd(files, fd);
62462
62463 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62464 if (fd >= rlimit(RLIMIT_NOFILE))
62465 return -EBADF;
62466
62467 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62468 if (unlikely(oldfd == newfd))
62469 return -EINVAL;
62470
62471 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62472 if (newfd >= rlimit(RLIMIT_NOFILE))
62473 return -EBADF;
62474
62475 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62476 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62477 {
62478 int err;
62479 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62480 if (from >= rlimit(RLIMIT_NOFILE))
62481 return -EINVAL;
62482 err = alloc_fd(from, flags);
62483 diff --git a/fs/filesystems.c b/fs/filesystems.c
62484 index 5797d45..7d7d79a 100644
62485 --- a/fs/filesystems.c
62486 +++ b/fs/filesystems.c
62487 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62488 int len = dot ? dot - name : strlen(name);
62489
62490 fs = __get_fs_type(name, len);
62491 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62492 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62493 +#else
62494 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62495 +#endif
62496 fs = __get_fs_type(name, len);
62497
62498 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62499 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62500 index 7dca743..543d620 100644
62501 --- a/fs/fs_struct.c
62502 +++ b/fs/fs_struct.c
62503 @@ -4,6 +4,7 @@
62504 #include <linux/path.h>
62505 #include <linux/slab.h>
62506 #include <linux/fs_struct.h>
62507 +#include <linux/grsecurity.h>
62508 #include "internal.h"
62509
62510 /*
62511 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62512 write_seqcount_begin(&fs->seq);
62513 old_root = fs->root;
62514 fs->root = *path;
62515 + gr_set_chroot_entries(current, path);
62516 write_seqcount_end(&fs->seq);
62517 spin_unlock(&fs->lock);
62518 if (old_root.dentry)
62519 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62520 int hits = 0;
62521 spin_lock(&fs->lock);
62522 write_seqcount_begin(&fs->seq);
62523 + /* this root replacement is only done by pivot_root,
62524 + leave grsec's chroot tagging alone for this task
62525 + so that a pivoted root isn't treated as a chroot
62526 + */
62527 hits += replace_path(&fs->root, old_root, new_root);
62528 hits += replace_path(&fs->pwd, old_root, new_root);
62529 write_seqcount_end(&fs->seq);
62530 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62531 task_lock(tsk);
62532 spin_lock(&fs->lock);
62533 tsk->fs = NULL;
62534 - kill = !--fs->users;
62535 + gr_clear_chroot_entries(tsk);
62536 + kill = !atomic_dec_return(&fs->users);
62537 spin_unlock(&fs->lock);
62538 task_unlock(tsk);
62539 if (kill)
62540 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62541 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62542 /* We don't need to lock fs - think why ;-) */
62543 if (fs) {
62544 - fs->users = 1;
62545 + atomic_set(&fs->users, 1);
62546 fs->in_exec = 0;
62547 spin_lock_init(&fs->lock);
62548 seqcount_init(&fs->seq);
62549 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62550 spin_lock(&old->lock);
62551 fs->root = old->root;
62552 path_get(&fs->root);
62553 + /* instead of calling gr_set_chroot_entries here,
62554 + we call it from every caller of this function
62555 + */
62556 fs->pwd = old->pwd;
62557 path_get(&fs->pwd);
62558 spin_unlock(&old->lock);
62559 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62560
62561 task_lock(current);
62562 spin_lock(&fs->lock);
62563 - kill = !--fs->users;
62564 + kill = !atomic_dec_return(&fs->users);
62565 current->fs = new_fs;
62566 + gr_set_chroot_entries(current, &new_fs->root);
62567 spin_unlock(&fs->lock);
62568 task_unlock(current);
62569
62570 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62571
62572 int current_umask(void)
62573 {
62574 - return current->fs->umask;
62575 + return current->fs->umask | gr_acl_umask();
62576 }
62577 EXPORT_SYMBOL(current_umask);
62578
62579 /* to be mentioned only in INIT_TASK */
62580 struct fs_struct init_fs = {
62581 - .users = 1,
62582 + .users = ATOMIC_INIT(1),
62583 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62584 .seq = SEQCNT_ZERO(init_fs.seq),
62585 .umask = 0022,
62586 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62587 index 89acec7..a575262 100644
62588 --- a/fs/fscache/cookie.c
62589 +++ b/fs/fscache/cookie.c
62590 @@ -19,7 +19,7 @@
62591
62592 struct kmem_cache *fscache_cookie_jar;
62593
62594 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62595 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62596
62597 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62598 static int fscache_alloc_object(struct fscache_cache *cache,
62599 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62600 parent ? (char *) parent->def->name : "<no-parent>",
62601 def->name, netfs_data, enable);
62602
62603 - fscache_stat(&fscache_n_acquires);
62604 + fscache_stat_unchecked(&fscache_n_acquires);
62605
62606 /* if there's no parent cookie, then we don't create one here either */
62607 if (!parent) {
62608 - fscache_stat(&fscache_n_acquires_null);
62609 + fscache_stat_unchecked(&fscache_n_acquires_null);
62610 _leave(" [no parent]");
62611 return NULL;
62612 }
62613 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62614 /* allocate and initialise a cookie */
62615 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62616 if (!cookie) {
62617 - fscache_stat(&fscache_n_acquires_oom);
62618 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62619 _leave(" [ENOMEM]");
62620 return NULL;
62621 }
62622 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62623
62624 switch (cookie->def->type) {
62625 case FSCACHE_COOKIE_TYPE_INDEX:
62626 - fscache_stat(&fscache_n_cookie_index);
62627 + fscache_stat_unchecked(&fscache_n_cookie_index);
62628 break;
62629 case FSCACHE_COOKIE_TYPE_DATAFILE:
62630 - fscache_stat(&fscache_n_cookie_data);
62631 + fscache_stat_unchecked(&fscache_n_cookie_data);
62632 break;
62633 default:
62634 - fscache_stat(&fscache_n_cookie_special);
62635 + fscache_stat_unchecked(&fscache_n_cookie_special);
62636 break;
62637 }
62638
62639 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62640 } else {
62641 atomic_dec(&parent->n_children);
62642 __fscache_cookie_put(cookie);
62643 - fscache_stat(&fscache_n_acquires_nobufs);
62644 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62645 _leave(" = NULL");
62646 return NULL;
62647 }
62648 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62649 }
62650 }
62651
62652 - fscache_stat(&fscache_n_acquires_ok);
62653 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62654 _leave(" = %p", cookie);
62655 return cookie;
62656 }
62657 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62658 cache = fscache_select_cache_for_object(cookie->parent);
62659 if (!cache) {
62660 up_read(&fscache_addremove_sem);
62661 - fscache_stat(&fscache_n_acquires_no_cache);
62662 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62663 _leave(" = -ENOMEDIUM [no cache]");
62664 return -ENOMEDIUM;
62665 }
62666 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62667 object = cache->ops->alloc_object(cache, cookie);
62668 fscache_stat_d(&fscache_n_cop_alloc_object);
62669 if (IS_ERR(object)) {
62670 - fscache_stat(&fscache_n_object_no_alloc);
62671 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62672 ret = PTR_ERR(object);
62673 goto error;
62674 }
62675
62676 - fscache_stat(&fscache_n_object_alloc);
62677 + fscache_stat_unchecked(&fscache_n_object_alloc);
62678
62679 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62680 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62681
62682 _debug("ALLOC OBJ%x: %s {%lx}",
62683 object->debug_id, cookie->def->name, object->events);
62684 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62685
62686 _enter("{%s}", cookie->def->name);
62687
62688 - fscache_stat(&fscache_n_invalidates);
62689 + fscache_stat_unchecked(&fscache_n_invalidates);
62690
62691 /* Only permit invalidation of data files. Invalidating an index will
62692 * require the caller to release all its attachments to the tree rooted
62693 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62694 {
62695 struct fscache_object *object;
62696
62697 - fscache_stat(&fscache_n_updates);
62698 + fscache_stat_unchecked(&fscache_n_updates);
62699
62700 if (!cookie) {
62701 - fscache_stat(&fscache_n_updates_null);
62702 + fscache_stat_unchecked(&fscache_n_updates_null);
62703 _leave(" [no cookie]");
62704 return;
62705 }
62706 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62707 */
62708 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62709 {
62710 - fscache_stat(&fscache_n_relinquishes);
62711 + fscache_stat_unchecked(&fscache_n_relinquishes);
62712 if (retire)
62713 - fscache_stat(&fscache_n_relinquishes_retire);
62714 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62715
62716 if (!cookie) {
62717 - fscache_stat(&fscache_n_relinquishes_null);
62718 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62719 _leave(" [no cookie]");
62720 return;
62721 }
62722 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62723 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62724 goto inconsistent;
62725
62726 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62727 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62728
62729 __fscache_use_cookie(cookie);
62730 if (fscache_submit_op(object, op) < 0)
62731 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62732 index 7872a62..d91b19f 100644
62733 --- a/fs/fscache/internal.h
62734 +++ b/fs/fscache/internal.h
62735 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62736 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62737 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62738 struct fscache_operation *,
62739 - atomic_t *,
62740 - atomic_t *,
62741 + atomic_unchecked_t *,
62742 + atomic_unchecked_t *,
62743 void (*)(struct fscache_operation *));
62744 extern void fscache_invalidate_writes(struct fscache_cookie *);
62745
62746 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62747 * stats.c
62748 */
62749 #ifdef CONFIG_FSCACHE_STATS
62750 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62751 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62752 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62753 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62754
62755 -extern atomic_t fscache_n_op_pend;
62756 -extern atomic_t fscache_n_op_run;
62757 -extern atomic_t fscache_n_op_enqueue;
62758 -extern atomic_t fscache_n_op_deferred_release;
62759 -extern atomic_t fscache_n_op_release;
62760 -extern atomic_t fscache_n_op_gc;
62761 -extern atomic_t fscache_n_op_cancelled;
62762 -extern atomic_t fscache_n_op_rejected;
62763 +extern atomic_unchecked_t fscache_n_op_pend;
62764 +extern atomic_unchecked_t fscache_n_op_run;
62765 +extern atomic_unchecked_t fscache_n_op_enqueue;
62766 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62767 +extern atomic_unchecked_t fscache_n_op_release;
62768 +extern atomic_unchecked_t fscache_n_op_gc;
62769 +extern atomic_unchecked_t fscache_n_op_cancelled;
62770 +extern atomic_unchecked_t fscache_n_op_rejected;
62771
62772 -extern atomic_t fscache_n_attr_changed;
62773 -extern atomic_t fscache_n_attr_changed_ok;
62774 -extern atomic_t fscache_n_attr_changed_nobufs;
62775 -extern atomic_t fscache_n_attr_changed_nomem;
62776 -extern atomic_t fscache_n_attr_changed_calls;
62777 +extern atomic_unchecked_t fscache_n_attr_changed;
62778 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62779 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62780 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62781 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62782
62783 -extern atomic_t fscache_n_allocs;
62784 -extern atomic_t fscache_n_allocs_ok;
62785 -extern atomic_t fscache_n_allocs_wait;
62786 -extern atomic_t fscache_n_allocs_nobufs;
62787 -extern atomic_t fscache_n_allocs_intr;
62788 -extern atomic_t fscache_n_allocs_object_dead;
62789 -extern atomic_t fscache_n_alloc_ops;
62790 -extern atomic_t fscache_n_alloc_op_waits;
62791 +extern atomic_unchecked_t fscache_n_allocs;
62792 +extern atomic_unchecked_t fscache_n_allocs_ok;
62793 +extern atomic_unchecked_t fscache_n_allocs_wait;
62794 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62795 +extern atomic_unchecked_t fscache_n_allocs_intr;
62796 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62797 +extern atomic_unchecked_t fscache_n_alloc_ops;
62798 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62799
62800 -extern atomic_t fscache_n_retrievals;
62801 -extern atomic_t fscache_n_retrievals_ok;
62802 -extern atomic_t fscache_n_retrievals_wait;
62803 -extern atomic_t fscache_n_retrievals_nodata;
62804 -extern atomic_t fscache_n_retrievals_nobufs;
62805 -extern atomic_t fscache_n_retrievals_intr;
62806 -extern atomic_t fscache_n_retrievals_nomem;
62807 -extern atomic_t fscache_n_retrievals_object_dead;
62808 -extern atomic_t fscache_n_retrieval_ops;
62809 -extern atomic_t fscache_n_retrieval_op_waits;
62810 +extern atomic_unchecked_t fscache_n_retrievals;
62811 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62812 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62813 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62814 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62815 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62816 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62817 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62818 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62819 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62820
62821 -extern atomic_t fscache_n_stores;
62822 -extern atomic_t fscache_n_stores_ok;
62823 -extern atomic_t fscache_n_stores_again;
62824 -extern atomic_t fscache_n_stores_nobufs;
62825 -extern atomic_t fscache_n_stores_oom;
62826 -extern atomic_t fscache_n_store_ops;
62827 -extern atomic_t fscache_n_store_calls;
62828 -extern atomic_t fscache_n_store_pages;
62829 -extern atomic_t fscache_n_store_radix_deletes;
62830 -extern atomic_t fscache_n_store_pages_over_limit;
62831 +extern atomic_unchecked_t fscache_n_stores;
62832 +extern atomic_unchecked_t fscache_n_stores_ok;
62833 +extern atomic_unchecked_t fscache_n_stores_again;
62834 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62835 +extern atomic_unchecked_t fscache_n_stores_oom;
62836 +extern atomic_unchecked_t fscache_n_store_ops;
62837 +extern atomic_unchecked_t fscache_n_store_calls;
62838 +extern atomic_unchecked_t fscache_n_store_pages;
62839 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62840 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62841
62842 -extern atomic_t fscache_n_store_vmscan_not_storing;
62843 -extern atomic_t fscache_n_store_vmscan_gone;
62844 -extern atomic_t fscache_n_store_vmscan_busy;
62845 -extern atomic_t fscache_n_store_vmscan_cancelled;
62846 -extern atomic_t fscache_n_store_vmscan_wait;
62847 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62848 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62849 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62850 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62851 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62852
62853 -extern atomic_t fscache_n_marks;
62854 -extern atomic_t fscache_n_uncaches;
62855 +extern atomic_unchecked_t fscache_n_marks;
62856 +extern atomic_unchecked_t fscache_n_uncaches;
62857
62858 -extern atomic_t fscache_n_acquires;
62859 -extern atomic_t fscache_n_acquires_null;
62860 -extern atomic_t fscache_n_acquires_no_cache;
62861 -extern atomic_t fscache_n_acquires_ok;
62862 -extern atomic_t fscache_n_acquires_nobufs;
62863 -extern atomic_t fscache_n_acquires_oom;
62864 +extern atomic_unchecked_t fscache_n_acquires;
62865 +extern atomic_unchecked_t fscache_n_acquires_null;
62866 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62867 +extern atomic_unchecked_t fscache_n_acquires_ok;
62868 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62869 +extern atomic_unchecked_t fscache_n_acquires_oom;
62870
62871 -extern atomic_t fscache_n_invalidates;
62872 -extern atomic_t fscache_n_invalidates_run;
62873 +extern atomic_unchecked_t fscache_n_invalidates;
62874 +extern atomic_unchecked_t fscache_n_invalidates_run;
62875
62876 -extern atomic_t fscache_n_updates;
62877 -extern atomic_t fscache_n_updates_null;
62878 -extern atomic_t fscache_n_updates_run;
62879 +extern atomic_unchecked_t fscache_n_updates;
62880 +extern atomic_unchecked_t fscache_n_updates_null;
62881 +extern atomic_unchecked_t fscache_n_updates_run;
62882
62883 -extern atomic_t fscache_n_relinquishes;
62884 -extern atomic_t fscache_n_relinquishes_null;
62885 -extern atomic_t fscache_n_relinquishes_waitcrt;
62886 -extern atomic_t fscache_n_relinquishes_retire;
62887 +extern atomic_unchecked_t fscache_n_relinquishes;
62888 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62889 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62890 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62891
62892 -extern atomic_t fscache_n_cookie_index;
62893 -extern atomic_t fscache_n_cookie_data;
62894 -extern atomic_t fscache_n_cookie_special;
62895 +extern atomic_unchecked_t fscache_n_cookie_index;
62896 +extern atomic_unchecked_t fscache_n_cookie_data;
62897 +extern atomic_unchecked_t fscache_n_cookie_special;
62898
62899 -extern atomic_t fscache_n_object_alloc;
62900 -extern atomic_t fscache_n_object_no_alloc;
62901 -extern atomic_t fscache_n_object_lookups;
62902 -extern atomic_t fscache_n_object_lookups_negative;
62903 -extern atomic_t fscache_n_object_lookups_positive;
62904 -extern atomic_t fscache_n_object_lookups_timed_out;
62905 -extern atomic_t fscache_n_object_created;
62906 -extern atomic_t fscache_n_object_avail;
62907 -extern atomic_t fscache_n_object_dead;
62908 +extern atomic_unchecked_t fscache_n_object_alloc;
62909 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62910 +extern atomic_unchecked_t fscache_n_object_lookups;
62911 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62912 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62913 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62914 +extern atomic_unchecked_t fscache_n_object_created;
62915 +extern atomic_unchecked_t fscache_n_object_avail;
62916 +extern atomic_unchecked_t fscache_n_object_dead;
62917
62918 -extern atomic_t fscache_n_checkaux_none;
62919 -extern atomic_t fscache_n_checkaux_okay;
62920 -extern atomic_t fscache_n_checkaux_update;
62921 -extern atomic_t fscache_n_checkaux_obsolete;
62922 +extern atomic_unchecked_t fscache_n_checkaux_none;
62923 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62924 +extern atomic_unchecked_t fscache_n_checkaux_update;
62925 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62926
62927 extern atomic_t fscache_n_cop_alloc_object;
62928 extern atomic_t fscache_n_cop_lookup_object;
62929 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62930 atomic_inc(stat);
62931 }
62932
62933 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62934 +{
62935 + atomic_inc_unchecked(stat);
62936 +}
62937 +
62938 static inline void fscache_stat_d(atomic_t *stat)
62939 {
62940 atomic_dec(stat);
62941 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62942
62943 #define __fscache_stat(stat) (NULL)
62944 #define fscache_stat(stat) do {} while (0)
62945 +#define fscache_stat_unchecked(stat) do {} while (0)
62946 #define fscache_stat_d(stat) do {} while (0)
62947 #endif
62948
62949 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62950 index da032da..0076ce7 100644
62951 --- a/fs/fscache/object.c
62952 +++ b/fs/fscache/object.c
62953 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62954 _debug("LOOKUP \"%s\" in \"%s\"",
62955 cookie->def->name, object->cache->tag->name);
62956
62957 - fscache_stat(&fscache_n_object_lookups);
62958 + fscache_stat_unchecked(&fscache_n_object_lookups);
62959 fscache_stat(&fscache_n_cop_lookup_object);
62960 ret = object->cache->ops->lookup_object(object);
62961 fscache_stat_d(&fscache_n_cop_lookup_object);
62962 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62963 if (ret == -ETIMEDOUT) {
62964 /* probably stuck behind another object, so move this one to
62965 * the back of the queue */
62966 - fscache_stat(&fscache_n_object_lookups_timed_out);
62967 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62968 _leave(" [timeout]");
62969 return NO_TRANSIT;
62970 }
62971 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62972 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62973
62974 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62975 - fscache_stat(&fscache_n_object_lookups_negative);
62976 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62977
62978 /* Allow write requests to begin stacking up and read requests to begin
62979 * returning ENODATA.
62980 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62981 /* if we were still looking up, then we must have a positive lookup
62982 * result, in which case there may be data available */
62983 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62984 - fscache_stat(&fscache_n_object_lookups_positive);
62985 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62986
62987 /* We do (presumably) have data */
62988 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62989 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62990 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62991 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62992 } else {
62993 - fscache_stat(&fscache_n_object_created);
62994 + fscache_stat_unchecked(&fscache_n_object_created);
62995 }
62996
62997 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62998 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62999 fscache_stat_d(&fscache_n_cop_lookup_complete);
63000
63001 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63002 - fscache_stat(&fscache_n_object_avail);
63003 + fscache_stat_unchecked(&fscache_n_object_avail);
63004
63005 _leave("");
63006 return transit_to(JUMPSTART_DEPS);
63007 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63008
63009 /* this just shifts the object release to the work processor */
63010 fscache_put_object(object);
63011 - fscache_stat(&fscache_n_object_dead);
63012 + fscache_stat_unchecked(&fscache_n_object_dead);
63013
63014 _leave("");
63015 return transit_to(OBJECT_DEAD);
63016 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63017 enum fscache_checkaux result;
63018
63019 if (!object->cookie->def->check_aux) {
63020 - fscache_stat(&fscache_n_checkaux_none);
63021 + fscache_stat_unchecked(&fscache_n_checkaux_none);
63022 return FSCACHE_CHECKAUX_OKAY;
63023 }
63024
63025 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63026 switch (result) {
63027 /* entry okay as is */
63028 case FSCACHE_CHECKAUX_OKAY:
63029 - fscache_stat(&fscache_n_checkaux_okay);
63030 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
63031 break;
63032
63033 /* entry requires update */
63034 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63035 - fscache_stat(&fscache_n_checkaux_update);
63036 + fscache_stat_unchecked(&fscache_n_checkaux_update);
63037 break;
63038
63039 /* entry requires deletion */
63040 case FSCACHE_CHECKAUX_OBSOLETE:
63041 - fscache_stat(&fscache_n_checkaux_obsolete);
63042 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63043 break;
63044
63045 default:
63046 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63047 {
63048 const struct fscache_state *s;
63049
63050 - fscache_stat(&fscache_n_invalidates_run);
63051 + fscache_stat_unchecked(&fscache_n_invalidates_run);
63052 fscache_stat(&fscache_n_cop_invalidate_object);
63053 s = _fscache_invalidate_object(object, event);
63054 fscache_stat_d(&fscache_n_cop_invalidate_object);
63055 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63056 {
63057 _enter("{OBJ%x},%d", object->debug_id, event);
63058
63059 - fscache_stat(&fscache_n_updates_run);
63060 + fscache_stat_unchecked(&fscache_n_updates_run);
63061 fscache_stat(&fscache_n_cop_update_object);
63062 object->cache->ops->update_object(object);
63063 fscache_stat_d(&fscache_n_cop_update_object);
63064 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63065 index e7b87a0..a85d47a 100644
63066 --- a/fs/fscache/operation.c
63067 +++ b/fs/fscache/operation.c
63068 @@ -17,7 +17,7 @@
63069 #include <linux/slab.h>
63070 #include "internal.h"
63071
63072 -atomic_t fscache_op_debug_id;
63073 +atomic_unchecked_t fscache_op_debug_id;
63074 EXPORT_SYMBOL(fscache_op_debug_id);
63075
63076 /**
63077 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63078 ASSERTCMP(atomic_read(&op->usage), >, 0);
63079 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63080
63081 - fscache_stat(&fscache_n_op_enqueue);
63082 + fscache_stat_unchecked(&fscache_n_op_enqueue);
63083 switch (op->flags & FSCACHE_OP_TYPE) {
63084 case FSCACHE_OP_ASYNC:
63085 _debug("queue async");
63086 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63087 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63088 if (op->processor)
63089 fscache_enqueue_operation(op);
63090 - fscache_stat(&fscache_n_op_run);
63091 + fscache_stat_unchecked(&fscache_n_op_run);
63092 }
63093
63094 /*
63095 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63096 if (object->n_in_progress > 0) {
63097 atomic_inc(&op->usage);
63098 list_add_tail(&op->pend_link, &object->pending_ops);
63099 - fscache_stat(&fscache_n_op_pend);
63100 + fscache_stat_unchecked(&fscache_n_op_pend);
63101 } else if (!list_empty(&object->pending_ops)) {
63102 atomic_inc(&op->usage);
63103 list_add_tail(&op->pend_link, &object->pending_ops);
63104 - fscache_stat(&fscache_n_op_pend);
63105 + fscache_stat_unchecked(&fscache_n_op_pend);
63106 fscache_start_operations(object);
63107 } else {
63108 ASSERTCMP(object->n_in_progress, ==, 0);
63109 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63110 object->n_exclusive++; /* reads and writes must wait */
63111 atomic_inc(&op->usage);
63112 list_add_tail(&op->pend_link, &object->pending_ops);
63113 - fscache_stat(&fscache_n_op_pend);
63114 + fscache_stat_unchecked(&fscache_n_op_pend);
63115 ret = 0;
63116 } else {
63117 /* If we're in any other state, there must have been an I/O
63118 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63119 if (object->n_exclusive > 0) {
63120 atomic_inc(&op->usage);
63121 list_add_tail(&op->pend_link, &object->pending_ops);
63122 - fscache_stat(&fscache_n_op_pend);
63123 + fscache_stat_unchecked(&fscache_n_op_pend);
63124 } else if (!list_empty(&object->pending_ops)) {
63125 atomic_inc(&op->usage);
63126 list_add_tail(&op->pend_link, &object->pending_ops);
63127 - fscache_stat(&fscache_n_op_pend);
63128 + fscache_stat_unchecked(&fscache_n_op_pend);
63129 fscache_start_operations(object);
63130 } else {
63131 ASSERTCMP(object->n_exclusive, ==, 0);
63132 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63133 object->n_ops++;
63134 atomic_inc(&op->usage);
63135 list_add_tail(&op->pend_link, &object->pending_ops);
63136 - fscache_stat(&fscache_n_op_pend);
63137 + fscache_stat_unchecked(&fscache_n_op_pend);
63138 ret = 0;
63139 } else if (fscache_object_is_dying(object)) {
63140 - fscache_stat(&fscache_n_op_rejected);
63141 + fscache_stat_unchecked(&fscache_n_op_rejected);
63142 op->state = FSCACHE_OP_ST_CANCELLED;
63143 ret = -ENOBUFS;
63144 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63145 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63146 ret = -EBUSY;
63147 if (op->state == FSCACHE_OP_ST_PENDING) {
63148 ASSERT(!list_empty(&op->pend_link));
63149 - fscache_stat(&fscache_n_op_cancelled);
63150 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63151 list_del_init(&op->pend_link);
63152 if (do_cancel)
63153 do_cancel(op);
63154 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63155 while (!list_empty(&object->pending_ops)) {
63156 op = list_entry(object->pending_ops.next,
63157 struct fscache_operation, pend_link);
63158 - fscache_stat(&fscache_n_op_cancelled);
63159 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63160 list_del_init(&op->pend_link);
63161
63162 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63163 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63164 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63165 op->state = FSCACHE_OP_ST_DEAD;
63166
63167 - fscache_stat(&fscache_n_op_release);
63168 + fscache_stat_unchecked(&fscache_n_op_release);
63169
63170 if (op->release) {
63171 op->release(op);
63172 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63173 * lock, and defer it otherwise */
63174 if (!spin_trylock(&object->lock)) {
63175 _debug("defer put");
63176 - fscache_stat(&fscache_n_op_deferred_release);
63177 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63178
63179 cache = object->cache;
63180 spin_lock(&cache->op_gc_list_lock);
63181 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63182
63183 _debug("GC DEFERRED REL OBJ%x OP%x",
63184 object->debug_id, op->debug_id);
63185 - fscache_stat(&fscache_n_op_gc);
63186 + fscache_stat_unchecked(&fscache_n_op_gc);
63187
63188 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63189 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63190 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63191 index de33b3f..8be4d29 100644
63192 --- a/fs/fscache/page.c
63193 +++ b/fs/fscache/page.c
63194 @@ -74,7 +74,7 @@ try_again:
63195 val = radix_tree_lookup(&cookie->stores, page->index);
63196 if (!val) {
63197 rcu_read_unlock();
63198 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63199 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63200 __fscache_uncache_page(cookie, page);
63201 return true;
63202 }
63203 @@ -104,11 +104,11 @@ try_again:
63204 spin_unlock(&cookie->stores_lock);
63205
63206 if (xpage) {
63207 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63208 - fscache_stat(&fscache_n_store_radix_deletes);
63209 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63210 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63211 ASSERTCMP(xpage, ==, page);
63212 } else {
63213 - fscache_stat(&fscache_n_store_vmscan_gone);
63214 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63215 }
63216
63217 wake_up_bit(&cookie->flags, 0);
63218 @@ -123,11 +123,11 @@ page_busy:
63219 * sleeping on memory allocation, so we may need to impose a timeout
63220 * too. */
63221 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63222 - fscache_stat(&fscache_n_store_vmscan_busy);
63223 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63224 return false;
63225 }
63226
63227 - fscache_stat(&fscache_n_store_vmscan_wait);
63228 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63229 if (!release_page_wait_timeout(cookie, page))
63230 _debug("fscache writeout timeout page: %p{%lx}",
63231 page, page->index);
63232 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63233 FSCACHE_COOKIE_STORING_TAG);
63234 if (!radix_tree_tag_get(&cookie->stores, page->index,
63235 FSCACHE_COOKIE_PENDING_TAG)) {
63236 - fscache_stat(&fscache_n_store_radix_deletes);
63237 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63238 xpage = radix_tree_delete(&cookie->stores, page->index);
63239 }
63240 spin_unlock(&cookie->stores_lock);
63241 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63242
63243 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63244
63245 - fscache_stat(&fscache_n_attr_changed_calls);
63246 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63247
63248 if (fscache_object_is_active(object)) {
63249 fscache_stat(&fscache_n_cop_attr_changed);
63250 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63251
63252 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63253
63254 - fscache_stat(&fscache_n_attr_changed);
63255 + fscache_stat_unchecked(&fscache_n_attr_changed);
63256
63257 op = kzalloc(sizeof(*op), GFP_KERNEL);
63258 if (!op) {
63259 - fscache_stat(&fscache_n_attr_changed_nomem);
63260 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63261 _leave(" = -ENOMEM");
63262 return -ENOMEM;
63263 }
63264 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63265 if (fscache_submit_exclusive_op(object, op) < 0)
63266 goto nobufs_dec;
63267 spin_unlock(&cookie->lock);
63268 - fscache_stat(&fscache_n_attr_changed_ok);
63269 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63270 fscache_put_operation(op);
63271 _leave(" = 0");
63272 return 0;
63273 @@ -242,7 +242,7 @@ nobufs:
63274 kfree(op);
63275 if (wake_cookie)
63276 __fscache_wake_unused_cookie(cookie);
63277 - fscache_stat(&fscache_n_attr_changed_nobufs);
63278 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63279 _leave(" = %d", -ENOBUFS);
63280 return -ENOBUFS;
63281 }
63282 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63283 /* allocate a retrieval operation and attempt to submit it */
63284 op = kzalloc(sizeof(*op), GFP_NOIO);
63285 if (!op) {
63286 - fscache_stat(&fscache_n_retrievals_nomem);
63287 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63288 return NULL;
63289 }
63290
63291 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63292 return 0;
63293 }
63294
63295 - fscache_stat(&fscache_n_retrievals_wait);
63296 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63297
63298 jif = jiffies;
63299 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63300 TASK_INTERRUPTIBLE) != 0) {
63301 - fscache_stat(&fscache_n_retrievals_intr);
63302 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63303 _leave(" = -ERESTARTSYS");
63304 return -ERESTARTSYS;
63305 }
63306 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63307 */
63308 int fscache_wait_for_operation_activation(struct fscache_object *object,
63309 struct fscache_operation *op,
63310 - atomic_t *stat_op_waits,
63311 - atomic_t *stat_object_dead,
63312 + atomic_unchecked_t *stat_op_waits,
63313 + atomic_unchecked_t *stat_object_dead,
63314 void (*do_cancel)(struct fscache_operation *))
63315 {
63316 int ret;
63317 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63318
63319 _debug(">>> WT");
63320 if (stat_op_waits)
63321 - fscache_stat(stat_op_waits);
63322 + fscache_stat_unchecked(stat_op_waits);
63323 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63324 TASK_INTERRUPTIBLE) != 0) {
63325 ret = fscache_cancel_op(op, do_cancel);
63326 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63327 check_if_dead:
63328 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63329 if (stat_object_dead)
63330 - fscache_stat(stat_object_dead);
63331 + fscache_stat_unchecked(stat_object_dead);
63332 _leave(" = -ENOBUFS [cancelled]");
63333 return -ENOBUFS;
63334 }
63335 @@ -381,7 +381,7 @@ check_if_dead:
63336 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63337 fscache_cancel_op(op, do_cancel);
63338 if (stat_object_dead)
63339 - fscache_stat(stat_object_dead);
63340 + fscache_stat_unchecked(stat_object_dead);
63341 return -ENOBUFS;
63342 }
63343 return 0;
63344 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63345
63346 _enter("%p,%p,,,", cookie, page);
63347
63348 - fscache_stat(&fscache_n_retrievals);
63349 + fscache_stat_unchecked(&fscache_n_retrievals);
63350
63351 if (hlist_empty(&cookie->backing_objects))
63352 goto nobufs;
63353 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63354 goto nobufs_unlock_dec;
63355 spin_unlock(&cookie->lock);
63356
63357 - fscache_stat(&fscache_n_retrieval_ops);
63358 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63359
63360 /* pin the netfs read context in case we need to do the actual netfs
63361 * read because we've encountered a cache read failure */
63362 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63363
63364 error:
63365 if (ret == -ENOMEM)
63366 - fscache_stat(&fscache_n_retrievals_nomem);
63367 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63368 else if (ret == -ERESTARTSYS)
63369 - fscache_stat(&fscache_n_retrievals_intr);
63370 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63371 else if (ret == -ENODATA)
63372 - fscache_stat(&fscache_n_retrievals_nodata);
63373 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63374 else if (ret < 0)
63375 - fscache_stat(&fscache_n_retrievals_nobufs);
63376 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63377 else
63378 - fscache_stat(&fscache_n_retrievals_ok);
63379 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63380
63381 fscache_put_retrieval(op);
63382 _leave(" = %d", ret);
63383 @@ -505,7 +505,7 @@ nobufs_unlock:
63384 __fscache_wake_unused_cookie(cookie);
63385 kfree(op);
63386 nobufs:
63387 - fscache_stat(&fscache_n_retrievals_nobufs);
63388 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63389 _leave(" = -ENOBUFS");
63390 return -ENOBUFS;
63391 }
63392 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63393
63394 _enter("%p,,%d,,,", cookie, *nr_pages);
63395
63396 - fscache_stat(&fscache_n_retrievals);
63397 + fscache_stat_unchecked(&fscache_n_retrievals);
63398
63399 if (hlist_empty(&cookie->backing_objects))
63400 goto nobufs;
63401 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63402 goto nobufs_unlock_dec;
63403 spin_unlock(&cookie->lock);
63404
63405 - fscache_stat(&fscache_n_retrieval_ops);
63406 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63407
63408 /* pin the netfs read context in case we need to do the actual netfs
63409 * read because we've encountered a cache read failure */
63410 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63411
63412 error:
63413 if (ret == -ENOMEM)
63414 - fscache_stat(&fscache_n_retrievals_nomem);
63415 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63416 else if (ret == -ERESTARTSYS)
63417 - fscache_stat(&fscache_n_retrievals_intr);
63418 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63419 else if (ret == -ENODATA)
63420 - fscache_stat(&fscache_n_retrievals_nodata);
63421 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63422 else if (ret < 0)
63423 - fscache_stat(&fscache_n_retrievals_nobufs);
63424 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63425 else
63426 - fscache_stat(&fscache_n_retrievals_ok);
63427 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63428
63429 fscache_put_retrieval(op);
63430 _leave(" = %d", ret);
63431 @@ -636,7 +636,7 @@ nobufs_unlock:
63432 if (wake_cookie)
63433 __fscache_wake_unused_cookie(cookie);
63434 nobufs:
63435 - fscache_stat(&fscache_n_retrievals_nobufs);
63436 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63437 _leave(" = -ENOBUFS");
63438 return -ENOBUFS;
63439 }
63440 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63441
63442 _enter("%p,%p,,,", cookie, page);
63443
63444 - fscache_stat(&fscache_n_allocs);
63445 + fscache_stat_unchecked(&fscache_n_allocs);
63446
63447 if (hlist_empty(&cookie->backing_objects))
63448 goto nobufs;
63449 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63450 goto nobufs_unlock_dec;
63451 spin_unlock(&cookie->lock);
63452
63453 - fscache_stat(&fscache_n_alloc_ops);
63454 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63455
63456 ret = fscache_wait_for_operation_activation(
63457 object, &op->op,
63458 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63459
63460 error:
63461 if (ret == -ERESTARTSYS)
63462 - fscache_stat(&fscache_n_allocs_intr);
63463 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63464 else if (ret < 0)
63465 - fscache_stat(&fscache_n_allocs_nobufs);
63466 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63467 else
63468 - fscache_stat(&fscache_n_allocs_ok);
63469 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63470
63471 fscache_put_retrieval(op);
63472 _leave(" = %d", ret);
63473 @@ -730,7 +730,7 @@ nobufs_unlock:
63474 if (wake_cookie)
63475 __fscache_wake_unused_cookie(cookie);
63476 nobufs:
63477 - fscache_stat(&fscache_n_allocs_nobufs);
63478 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63479 _leave(" = -ENOBUFS");
63480 return -ENOBUFS;
63481 }
63482 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63483
63484 spin_lock(&cookie->stores_lock);
63485
63486 - fscache_stat(&fscache_n_store_calls);
63487 + fscache_stat_unchecked(&fscache_n_store_calls);
63488
63489 /* find a page to store */
63490 page = NULL;
63491 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63492 page = results[0];
63493 _debug("gang %d [%lx]", n, page->index);
63494 if (page->index > op->store_limit) {
63495 - fscache_stat(&fscache_n_store_pages_over_limit);
63496 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63497 goto superseded;
63498 }
63499
63500 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63501 spin_unlock(&cookie->stores_lock);
63502 spin_unlock(&object->lock);
63503
63504 - fscache_stat(&fscache_n_store_pages);
63505 + fscache_stat_unchecked(&fscache_n_store_pages);
63506 fscache_stat(&fscache_n_cop_write_page);
63507 ret = object->cache->ops->write_page(op, page);
63508 fscache_stat_d(&fscache_n_cop_write_page);
63509 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63510 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63511 ASSERT(PageFsCache(page));
63512
63513 - fscache_stat(&fscache_n_stores);
63514 + fscache_stat_unchecked(&fscache_n_stores);
63515
63516 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63517 _leave(" = -ENOBUFS [invalidating]");
63518 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63519 spin_unlock(&cookie->stores_lock);
63520 spin_unlock(&object->lock);
63521
63522 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63523 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63524 op->store_limit = object->store_limit;
63525
63526 __fscache_use_cookie(cookie);
63527 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63528
63529 spin_unlock(&cookie->lock);
63530 radix_tree_preload_end();
63531 - fscache_stat(&fscache_n_store_ops);
63532 - fscache_stat(&fscache_n_stores_ok);
63533 + fscache_stat_unchecked(&fscache_n_store_ops);
63534 + fscache_stat_unchecked(&fscache_n_stores_ok);
63535
63536 /* the work queue now carries its own ref on the object */
63537 fscache_put_operation(&op->op);
63538 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63539 return 0;
63540
63541 already_queued:
63542 - fscache_stat(&fscache_n_stores_again);
63543 + fscache_stat_unchecked(&fscache_n_stores_again);
63544 already_pending:
63545 spin_unlock(&cookie->stores_lock);
63546 spin_unlock(&object->lock);
63547 spin_unlock(&cookie->lock);
63548 radix_tree_preload_end();
63549 kfree(op);
63550 - fscache_stat(&fscache_n_stores_ok);
63551 + fscache_stat_unchecked(&fscache_n_stores_ok);
63552 _leave(" = 0");
63553 return 0;
63554
63555 @@ -1039,14 +1039,14 @@ nobufs:
63556 kfree(op);
63557 if (wake_cookie)
63558 __fscache_wake_unused_cookie(cookie);
63559 - fscache_stat(&fscache_n_stores_nobufs);
63560 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63561 _leave(" = -ENOBUFS");
63562 return -ENOBUFS;
63563
63564 nomem_free:
63565 kfree(op);
63566 nomem:
63567 - fscache_stat(&fscache_n_stores_oom);
63568 + fscache_stat_unchecked(&fscache_n_stores_oom);
63569 _leave(" = -ENOMEM");
63570 return -ENOMEM;
63571 }
63572 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63573 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63574 ASSERTCMP(page, !=, NULL);
63575
63576 - fscache_stat(&fscache_n_uncaches);
63577 + fscache_stat_unchecked(&fscache_n_uncaches);
63578
63579 /* cache withdrawal may beat us to it */
63580 if (!PageFsCache(page))
63581 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63582 struct fscache_cookie *cookie = op->op.object->cookie;
63583
63584 #ifdef CONFIG_FSCACHE_STATS
63585 - atomic_inc(&fscache_n_marks);
63586 + atomic_inc_unchecked(&fscache_n_marks);
63587 #endif
63588
63589 _debug("- mark %p{%lx}", page, page->index);
63590 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63591 index 40d13c7..ddf52b9 100644
63592 --- a/fs/fscache/stats.c
63593 +++ b/fs/fscache/stats.c
63594 @@ -18,99 +18,99 @@
63595 /*
63596 * operation counters
63597 */
63598 -atomic_t fscache_n_op_pend;
63599 -atomic_t fscache_n_op_run;
63600 -atomic_t fscache_n_op_enqueue;
63601 -atomic_t fscache_n_op_requeue;
63602 -atomic_t fscache_n_op_deferred_release;
63603 -atomic_t fscache_n_op_release;
63604 -atomic_t fscache_n_op_gc;
63605 -atomic_t fscache_n_op_cancelled;
63606 -atomic_t fscache_n_op_rejected;
63607 +atomic_unchecked_t fscache_n_op_pend;
63608 +atomic_unchecked_t fscache_n_op_run;
63609 +atomic_unchecked_t fscache_n_op_enqueue;
63610 +atomic_unchecked_t fscache_n_op_requeue;
63611 +atomic_unchecked_t fscache_n_op_deferred_release;
63612 +atomic_unchecked_t fscache_n_op_release;
63613 +atomic_unchecked_t fscache_n_op_gc;
63614 +atomic_unchecked_t fscache_n_op_cancelled;
63615 +atomic_unchecked_t fscache_n_op_rejected;
63616
63617 -atomic_t fscache_n_attr_changed;
63618 -atomic_t fscache_n_attr_changed_ok;
63619 -atomic_t fscache_n_attr_changed_nobufs;
63620 -atomic_t fscache_n_attr_changed_nomem;
63621 -atomic_t fscache_n_attr_changed_calls;
63622 +atomic_unchecked_t fscache_n_attr_changed;
63623 +atomic_unchecked_t fscache_n_attr_changed_ok;
63624 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63625 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63626 +atomic_unchecked_t fscache_n_attr_changed_calls;
63627
63628 -atomic_t fscache_n_allocs;
63629 -atomic_t fscache_n_allocs_ok;
63630 -atomic_t fscache_n_allocs_wait;
63631 -atomic_t fscache_n_allocs_nobufs;
63632 -atomic_t fscache_n_allocs_intr;
63633 -atomic_t fscache_n_allocs_object_dead;
63634 -atomic_t fscache_n_alloc_ops;
63635 -atomic_t fscache_n_alloc_op_waits;
63636 +atomic_unchecked_t fscache_n_allocs;
63637 +atomic_unchecked_t fscache_n_allocs_ok;
63638 +atomic_unchecked_t fscache_n_allocs_wait;
63639 +atomic_unchecked_t fscache_n_allocs_nobufs;
63640 +atomic_unchecked_t fscache_n_allocs_intr;
63641 +atomic_unchecked_t fscache_n_allocs_object_dead;
63642 +atomic_unchecked_t fscache_n_alloc_ops;
63643 +atomic_unchecked_t fscache_n_alloc_op_waits;
63644
63645 -atomic_t fscache_n_retrievals;
63646 -atomic_t fscache_n_retrievals_ok;
63647 -atomic_t fscache_n_retrievals_wait;
63648 -atomic_t fscache_n_retrievals_nodata;
63649 -atomic_t fscache_n_retrievals_nobufs;
63650 -atomic_t fscache_n_retrievals_intr;
63651 -atomic_t fscache_n_retrievals_nomem;
63652 -atomic_t fscache_n_retrievals_object_dead;
63653 -atomic_t fscache_n_retrieval_ops;
63654 -atomic_t fscache_n_retrieval_op_waits;
63655 +atomic_unchecked_t fscache_n_retrievals;
63656 +atomic_unchecked_t fscache_n_retrievals_ok;
63657 +atomic_unchecked_t fscache_n_retrievals_wait;
63658 +atomic_unchecked_t fscache_n_retrievals_nodata;
63659 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63660 +atomic_unchecked_t fscache_n_retrievals_intr;
63661 +atomic_unchecked_t fscache_n_retrievals_nomem;
63662 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63663 +atomic_unchecked_t fscache_n_retrieval_ops;
63664 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63665
63666 -atomic_t fscache_n_stores;
63667 -atomic_t fscache_n_stores_ok;
63668 -atomic_t fscache_n_stores_again;
63669 -atomic_t fscache_n_stores_nobufs;
63670 -atomic_t fscache_n_stores_oom;
63671 -atomic_t fscache_n_store_ops;
63672 -atomic_t fscache_n_store_calls;
63673 -atomic_t fscache_n_store_pages;
63674 -atomic_t fscache_n_store_radix_deletes;
63675 -atomic_t fscache_n_store_pages_over_limit;
63676 +atomic_unchecked_t fscache_n_stores;
63677 +atomic_unchecked_t fscache_n_stores_ok;
63678 +atomic_unchecked_t fscache_n_stores_again;
63679 +atomic_unchecked_t fscache_n_stores_nobufs;
63680 +atomic_unchecked_t fscache_n_stores_oom;
63681 +atomic_unchecked_t fscache_n_store_ops;
63682 +atomic_unchecked_t fscache_n_store_calls;
63683 +atomic_unchecked_t fscache_n_store_pages;
63684 +atomic_unchecked_t fscache_n_store_radix_deletes;
63685 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63686
63687 -atomic_t fscache_n_store_vmscan_not_storing;
63688 -atomic_t fscache_n_store_vmscan_gone;
63689 -atomic_t fscache_n_store_vmscan_busy;
63690 -atomic_t fscache_n_store_vmscan_cancelled;
63691 -atomic_t fscache_n_store_vmscan_wait;
63692 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63693 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63694 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63695 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63696 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63697
63698 -atomic_t fscache_n_marks;
63699 -atomic_t fscache_n_uncaches;
63700 +atomic_unchecked_t fscache_n_marks;
63701 +atomic_unchecked_t fscache_n_uncaches;
63702
63703 -atomic_t fscache_n_acquires;
63704 -atomic_t fscache_n_acquires_null;
63705 -atomic_t fscache_n_acquires_no_cache;
63706 -atomic_t fscache_n_acquires_ok;
63707 -atomic_t fscache_n_acquires_nobufs;
63708 -atomic_t fscache_n_acquires_oom;
63709 +atomic_unchecked_t fscache_n_acquires;
63710 +atomic_unchecked_t fscache_n_acquires_null;
63711 +atomic_unchecked_t fscache_n_acquires_no_cache;
63712 +atomic_unchecked_t fscache_n_acquires_ok;
63713 +atomic_unchecked_t fscache_n_acquires_nobufs;
63714 +atomic_unchecked_t fscache_n_acquires_oom;
63715
63716 -atomic_t fscache_n_invalidates;
63717 -atomic_t fscache_n_invalidates_run;
63718 +atomic_unchecked_t fscache_n_invalidates;
63719 +atomic_unchecked_t fscache_n_invalidates_run;
63720
63721 -atomic_t fscache_n_updates;
63722 -atomic_t fscache_n_updates_null;
63723 -atomic_t fscache_n_updates_run;
63724 +atomic_unchecked_t fscache_n_updates;
63725 +atomic_unchecked_t fscache_n_updates_null;
63726 +atomic_unchecked_t fscache_n_updates_run;
63727
63728 -atomic_t fscache_n_relinquishes;
63729 -atomic_t fscache_n_relinquishes_null;
63730 -atomic_t fscache_n_relinquishes_waitcrt;
63731 -atomic_t fscache_n_relinquishes_retire;
63732 +atomic_unchecked_t fscache_n_relinquishes;
63733 +atomic_unchecked_t fscache_n_relinquishes_null;
63734 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63735 +atomic_unchecked_t fscache_n_relinquishes_retire;
63736
63737 -atomic_t fscache_n_cookie_index;
63738 -atomic_t fscache_n_cookie_data;
63739 -atomic_t fscache_n_cookie_special;
63740 +atomic_unchecked_t fscache_n_cookie_index;
63741 +atomic_unchecked_t fscache_n_cookie_data;
63742 +atomic_unchecked_t fscache_n_cookie_special;
63743
63744 -atomic_t fscache_n_object_alloc;
63745 -atomic_t fscache_n_object_no_alloc;
63746 -atomic_t fscache_n_object_lookups;
63747 -atomic_t fscache_n_object_lookups_negative;
63748 -atomic_t fscache_n_object_lookups_positive;
63749 -atomic_t fscache_n_object_lookups_timed_out;
63750 -atomic_t fscache_n_object_created;
63751 -atomic_t fscache_n_object_avail;
63752 -atomic_t fscache_n_object_dead;
63753 +atomic_unchecked_t fscache_n_object_alloc;
63754 +atomic_unchecked_t fscache_n_object_no_alloc;
63755 +atomic_unchecked_t fscache_n_object_lookups;
63756 +atomic_unchecked_t fscache_n_object_lookups_negative;
63757 +atomic_unchecked_t fscache_n_object_lookups_positive;
63758 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63759 +atomic_unchecked_t fscache_n_object_created;
63760 +atomic_unchecked_t fscache_n_object_avail;
63761 +atomic_unchecked_t fscache_n_object_dead;
63762
63763 -atomic_t fscache_n_checkaux_none;
63764 -atomic_t fscache_n_checkaux_okay;
63765 -atomic_t fscache_n_checkaux_update;
63766 -atomic_t fscache_n_checkaux_obsolete;
63767 +atomic_unchecked_t fscache_n_checkaux_none;
63768 +atomic_unchecked_t fscache_n_checkaux_okay;
63769 +atomic_unchecked_t fscache_n_checkaux_update;
63770 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63771
63772 atomic_t fscache_n_cop_alloc_object;
63773 atomic_t fscache_n_cop_lookup_object;
63774 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63775 seq_puts(m, "FS-Cache statistics\n");
63776
63777 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63778 - atomic_read(&fscache_n_cookie_index),
63779 - atomic_read(&fscache_n_cookie_data),
63780 - atomic_read(&fscache_n_cookie_special));
63781 + atomic_read_unchecked(&fscache_n_cookie_index),
63782 + atomic_read_unchecked(&fscache_n_cookie_data),
63783 + atomic_read_unchecked(&fscache_n_cookie_special));
63784
63785 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63786 - atomic_read(&fscache_n_object_alloc),
63787 - atomic_read(&fscache_n_object_no_alloc),
63788 - atomic_read(&fscache_n_object_avail),
63789 - atomic_read(&fscache_n_object_dead));
63790 + atomic_read_unchecked(&fscache_n_object_alloc),
63791 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63792 + atomic_read_unchecked(&fscache_n_object_avail),
63793 + atomic_read_unchecked(&fscache_n_object_dead));
63794 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63795 - atomic_read(&fscache_n_checkaux_none),
63796 - atomic_read(&fscache_n_checkaux_okay),
63797 - atomic_read(&fscache_n_checkaux_update),
63798 - atomic_read(&fscache_n_checkaux_obsolete));
63799 + atomic_read_unchecked(&fscache_n_checkaux_none),
63800 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63801 + atomic_read_unchecked(&fscache_n_checkaux_update),
63802 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63803
63804 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63805 - atomic_read(&fscache_n_marks),
63806 - atomic_read(&fscache_n_uncaches));
63807 + atomic_read_unchecked(&fscache_n_marks),
63808 + atomic_read_unchecked(&fscache_n_uncaches));
63809
63810 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63811 " oom=%u\n",
63812 - atomic_read(&fscache_n_acquires),
63813 - atomic_read(&fscache_n_acquires_null),
63814 - atomic_read(&fscache_n_acquires_no_cache),
63815 - atomic_read(&fscache_n_acquires_ok),
63816 - atomic_read(&fscache_n_acquires_nobufs),
63817 - atomic_read(&fscache_n_acquires_oom));
63818 + atomic_read_unchecked(&fscache_n_acquires),
63819 + atomic_read_unchecked(&fscache_n_acquires_null),
63820 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63821 + atomic_read_unchecked(&fscache_n_acquires_ok),
63822 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63823 + atomic_read_unchecked(&fscache_n_acquires_oom));
63824
63825 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63826 - atomic_read(&fscache_n_object_lookups),
63827 - atomic_read(&fscache_n_object_lookups_negative),
63828 - atomic_read(&fscache_n_object_lookups_positive),
63829 - atomic_read(&fscache_n_object_created),
63830 - atomic_read(&fscache_n_object_lookups_timed_out));
63831 + atomic_read_unchecked(&fscache_n_object_lookups),
63832 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63833 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63834 + atomic_read_unchecked(&fscache_n_object_created),
63835 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63836
63837 seq_printf(m, "Invals : n=%u run=%u\n",
63838 - atomic_read(&fscache_n_invalidates),
63839 - atomic_read(&fscache_n_invalidates_run));
63840 + atomic_read_unchecked(&fscache_n_invalidates),
63841 + atomic_read_unchecked(&fscache_n_invalidates_run));
63842
63843 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63844 - atomic_read(&fscache_n_updates),
63845 - atomic_read(&fscache_n_updates_null),
63846 - atomic_read(&fscache_n_updates_run));
63847 + atomic_read_unchecked(&fscache_n_updates),
63848 + atomic_read_unchecked(&fscache_n_updates_null),
63849 + atomic_read_unchecked(&fscache_n_updates_run));
63850
63851 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63852 - atomic_read(&fscache_n_relinquishes),
63853 - atomic_read(&fscache_n_relinquishes_null),
63854 - atomic_read(&fscache_n_relinquishes_waitcrt),
63855 - atomic_read(&fscache_n_relinquishes_retire));
63856 + atomic_read_unchecked(&fscache_n_relinquishes),
63857 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63858 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63859 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63860
63861 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63862 - atomic_read(&fscache_n_attr_changed),
63863 - atomic_read(&fscache_n_attr_changed_ok),
63864 - atomic_read(&fscache_n_attr_changed_nobufs),
63865 - atomic_read(&fscache_n_attr_changed_nomem),
63866 - atomic_read(&fscache_n_attr_changed_calls));
63867 + atomic_read_unchecked(&fscache_n_attr_changed),
63868 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63869 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63870 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63871 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63872
63873 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63874 - atomic_read(&fscache_n_allocs),
63875 - atomic_read(&fscache_n_allocs_ok),
63876 - atomic_read(&fscache_n_allocs_wait),
63877 - atomic_read(&fscache_n_allocs_nobufs),
63878 - atomic_read(&fscache_n_allocs_intr));
63879 + atomic_read_unchecked(&fscache_n_allocs),
63880 + atomic_read_unchecked(&fscache_n_allocs_ok),
63881 + atomic_read_unchecked(&fscache_n_allocs_wait),
63882 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63883 + atomic_read_unchecked(&fscache_n_allocs_intr));
63884 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63885 - atomic_read(&fscache_n_alloc_ops),
63886 - atomic_read(&fscache_n_alloc_op_waits),
63887 - atomic_read(&fscache_n_allocs_object_dead));
63888 + atomic_read_unchecked(&fscache_n_alloc_ops),
63889 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63890 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63891
63892 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63893 " int=%u oom=%u\n",
63894 - atomic_read(&fscache_n_retrievals),
63895 - atomic_read(&fscache_n_retrievals_ok),
63896 - atomic_read(&fscache_n_retrievals_wait),
63897 - atomic_read(&fscache_n_retrievals_nodata),
63898 - atomic_read(&fscache_n_retrievals_nobufs),
63899 - atomic_read(&fscache_n_retrievals_intr),
63900 - atomic_read(&fscache_n_retrievals_nomem));
63901 + atomic_read_unchecked(&fscache_n_retrievals),
63902 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63903 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63904 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63905 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63906 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63907 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63908 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63909 - atomic_read(&fscache_n_retrieval_ops),
63910 - atomic_read(&fscache_n_retrieval_op_waits),
63911 - atomic_read(&fscache_n_retrievals_object_dead));
63912 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63913 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63914 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63915
63916 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63917 - atomic_read(&fscache_n_stores),
63918 - atomic_read(&fscache_n_stores_ok),
63919 - atomic_read(&fscache_n_stores_again),
63920 - atomic_read(&fscache_n_stores_nobufs),
63921 - atomic_read(&fscache_n_stores_oom));
63922 + atomic_read_unchecked(&fscache_n_stores),
63923 + atomic_read_unchecked(&fscache_n_stores_ok),
63924 + atomic_read_unchecked(&fscache_n_stores_again),
63925 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63926 + atomic_read_unchecked(&fscache_n_stores_oom));
63927 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63928 - atomic_read(&fscache_n_store_ops),
63929 - atomic_read(&fscache_n_store_calls),
63930 - atomic_read(&fscache_n_store_pages),
63931 - atomic_read(&fscache_n_store_radix_deletes),
63932 - atomic_read(&fscache_n_store_pages_over_limit));
63933 + atomic_read_unchecked(&fscache_n_store_ops),
63934 + atomic_read_unchecked(&fscache_n_store_calls),
63935 + atomic_read_unchecked(&fscache_n_store_pages),
63936 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63937 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63938
63939 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63940 - atomic_read(&fscache_n_store_vmscan_not_storing),
63941 - atomic_read(&fscache_n_store_vmscan_gone),
63942 - atomic_read(&fscache_n_store_vmscan_busy),
63943 - atomic_read(&fscache_n_store_vmscan_cancelled),
63944 - atomic_read(&fscache_n_store_vmscan_wait));
63945 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63946 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63947 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63948 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63949 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63950
63951 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63952 - atomic_read(&fscache_n_op_pend),
63953 - atomic_read(&fscache_n_op_run),
63954 - atomic_read(&fscache_n_op_enqueue),
63955 - atomic_read(&fscache_n_op_cancelled),
63956 - atomic_read(&fscache_n_op_rejected));
63957 + atomic_read_unchecked(&fscache_n_op_pend),
63958 + atomic_read_unchecked(&fscache_n_op_run),
63959 + atomic_read_unchecked(&fscache_n_op_enqueue),
63960 + atomic_read_unchecked(&fscache_n_op_cancelled),
63961 + atomic_read_unchecked(&fscache_n_op_rejected));
63962 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63963 - atomic_read(&fscache_n_op_deferred_release),
63964 - atomic_read(&fscache_n_op_release),
63965 - atomic_read(&fscache_n_op_gc));
63966 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63967 + atomic_read_unchecked(&fscache_n_op_release),
63968 + atomic_read_unchecked(&fscache_n_op_gc));
63969
63970 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63971 atomic_read(&fscache_n_cop_alloc_object),
63972 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63973 index 966ace8..030a03a 100644
63974 --- a/fs/fuse/cuse.c
63975 +++ b/fs/fuse/cuse.c
63976 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63977 INIT_LIST_HEAD(&cuse_conntbl[i]);
63978
63979 /* inherit and extend fuse_dev_operations */
63980 - cuse_channel_fops = fuse_dev_operations;
63981 - cuse_channel_fops.owner = THIS_MODULE;
63982 - cuse_channel_fops.open = cuse_channel_open;
63983 - cuse_channel_fops.release = cuse_channel_release;
63984 + pax_open_kernel();
63985 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63986 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63987 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63988 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63989 + pax_close_kernel();
63990
63991 cuse_class = class_create(THIS_MODULE, "cuse");
63992 if (IS_ERR(cuse_class))
63993 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63994 index ca88731..8e9c55d 100644
63995 --- a/fs/fuse/dev.c
63996 +++ b/fs/fuse/dev.c
63997 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63998 ret = 0;
63999 pipe_lock(pipe);
64000
64001 - if (!pipe->readers) {
64002 + if (!atomic_read(&pipe->readers)) {
64003 send_sig(SIGPIPE, current, 0);
64004 if (!ret)
64005 ret = -EPIPE;
64006 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64007 page_nr++;
64008 ret += buf->len;
64009
64010 - if (pipe->files)
64011 + if (atomic_read(&pipe->files))
64012 do_wakeup = 1;
64013 }
64014
64015 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64016 index de1d84a..fd69c0c 100644
64017 --- a/fs/fuse/dir.c
64018 +++ b/fs/fuse/dir.c
64019 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
64020 return link;
64021 }
64022
64023 -static void free_link(char *link)
64024 +static void free_link(const char *link)
64025 {
64026 if (!IS_ERR(link))
64027 free_page((unsigned long) link);
64028 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64029 index fd62cae..3494dfa 100644
64030 --- a/fs/hostfs/hostfs_kern.c
64031 +++ b/fs/hostfs/hostfs_kern.c
64032 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64033
64034 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64035 {
64036 - char *s = nd_get_link(nd);
64037 + const char *s = nd_get_link(nd);
64038 if (!IS_ERR(s))
64039 __putname(s);
64040 }
64041 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64042 index 1e2872b..7aea000 100644
64043 --- a/fs/hugetlbfs/inode.c
64044 +++ b/fs/hugetlbfs/inode.c
64045 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64046 struct mm_struct *mm = current->mm;
64047 struct vm_area_struct *vma;
64048 struct hstate *h = hstate_file(file);
64049 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64050 struct vm_unmapped_area_info info;
64051
64052 if (len & ~huge_page_mask(h))
64053 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64054 return addr;
64055 }
64056
64057 +#ifdef CONFIG_PAX_RANDMMAP
64058 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64059 +#endif
64060 +
64061 if (addr) {
64062 addr = ALIGN(addr, huge_page_size(h));
64063 vma = find_vma(mm, addr);
64064 - if (TASK_SIZE - len >= addr &&
64065 - (!vma || addr + len <= vma->vm_start))
64066 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64067 return addr;
64068 }
64069
64070 info.flags = 0;
64071 info.length = len;
64072 info.low_limit = TASK_UNMAPPED_BASE;
64073 +
64074 +#ifdef CONFIG_PAX_RANDMMAP
64075 + if (mm->pax_flags & MF_PAX_RANDMMAP)
64076 + info.low_limit += mm->delta_mmap;
64077 +#endif
64078 +
64079 info.high_limit = TASK_SIZE;
64080 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64081 info.align_offset = 0;
64082 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64083 };
64084 MODULE_ALIAS_FS("hugetlbfs");
64085
64086 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64087 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64088
64089 static int can_do_hugetlb_shm(void)
64090 {
64091 diff --git a/fs/inode.c b/fs/inode.c
64092 index 26753ba..d19eb34 100644
64093 --- a/fs/inode.c
64094 +++ b/fs/inode.c
64095 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
64096 unsigned int *p = &get_cpu_var(last_ino);
64097 unsigned int res = *p;
64098
64099 +start:
64100 +
64101 #ifdef CONFIG_SMP
64102 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64103 - static atomic_t shared_last_ino;
64104 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64105 + static atomic_unchecked_t shared_last_ino;
64106 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64107
64108 res = next - LAST_INO_BATCH;
64109 }
64110 #endif
64111
64112 - *p = ++res;
64113 + if (unlikely(!++res))
64114 + goto start; /* never zero */
64115 + *p = res;
64116 put_cpu_var(last_ino);
64117 return res;
64118 }
64119 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64120 index 4a6cf28..d3a29d3 100644
64121 --- a/fs/jffs2/erase.c
64122 +++ b/fs/jffs2/erase.c
64123 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64124 struct jffs2_unknown_node marker = {
64125 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64126 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64127 - .totlen = cpu_to_je32(c->cleanmarker_size)
64128 + .totlen = cpu_to_je32(c->cleanmarker_size),
64129 + .hdr_crc = cpu_to_je32(0)
64130 };
64131
64132 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64133 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64134 index a6597d6..41b30ec 100644
64135 --- a/fs/jffs2/wbuf.c
64136 +++ b/fs/jffs2/wbuf.c
64137 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64138 {
64139 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64140 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64141 - .totlen = constant_cpu_to_je32(8)
64142 + .totlen = constant_cpu_to_je32(8),
64143 + .hdr_crc = constant_cpu_to_je32(0)
64144 };
64145
64146 /*
64147 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64148 index adf8cb0..bb935fa 100644
64149 --- a/fs/jfs/super.c
64150 +++ b/fs/jfs/super.c
64151 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64152
64153 jfs_inode_cachep =
64154 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64155 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64156 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64157 init_once);
64158 if (jfs_inode_cachep == NULL)
64159 return -ENOMEM;
64160 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64161 index a693f5b..82276a1 100644
64162 --- a/fs/kernfs/dir.c
64163 +++ b/fs/kernfs/dir.c
64164 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64165 *
64166 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64167 */
64168 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64169 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64170 {
64171 unsigned long hash = init_name_hash();
64172 unsigned int len = strlen(name);
64173 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64174 index 4429d6d..9831f52 100644
64175 --- a/fs/kernfs/file.c
64176 +++ b/fs/kernfs/file.c
64177 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64178
64179 struct kernfs_open_node {
64180 atomic_t refcnt;
64181 - atomic_t event;
64182 + atomic_unchecked_t event;
64183 wait_queue_head_t poll;
64184 struct list_head files; /* goes through kernfs_open_file.list */
64185 };
64186 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64187 {
64188 struct kernfs_open_file *of = sf->private;
64189
64190 - of->event = atomic_read(&of->kn->attr.open->event);
64191 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64192
64193 return of->kn->attr.ops->seq_show(sf, v);
64194 }
64195 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64196 return ret;
64197 }
64198
64199 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64200 - void *buf, int len, int write)
64201 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64202 + void *buf, size_t len, int write)
64203 {
64204 struct file *file = vma->vm_file;
64205 struct kernfs_open_file *of = kernfs_of(file);
64206 - int ret;
64207 + ssize_t ret;
64208
64209 if (!of->vm_ops)
64210 return -EINVAL;
64211 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64212 return -ENOMEM;
64213
64214 atomic_set(&new_on->refcnt, 0);
64215 - atomic_set(&new_on->event, 1);
64216 + atomic_set_unchecked(&new_on->event, 1);
64217 init_waitqueue_head(&new_on->poll);
64218 INIT_LIST_HEAD(&new_on->files);
64219 goto retry;
64220 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64221
64222 kernfs_put_active(kn);
64223
64224 - if (of->event != atomic_read(&on->event))
64225 + if (of->event != atomic_read_unchecked(&on->event))
64226 goto trigger;
64227
64228 return DEFAULT_POLLMASK;
64229 @@ -818,7 +818,7 @@ repeat:
64230
64231 on = kn->attr.open;
64232 if (on) {
64233 - atomic_inc(&on->event);
64234 + atomic_inc_unchecked(&on->event);
64235 wake_up_interruptible(&on->poll);
64236 }
64237
64238 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64239 index 8a19889..4c3069a 100644
64240 --- a/fs/kernfs/symlink.c
64241 +++ b/fs/kernfs/symlink.c
64242 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64243 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64244 void *cookie)
64245 {
64246 - char *page = nd_get_link(nd);
64247 + const char *page = nd_get_link(nd);
64248 if (!IS_ERR(page))
64249 free_page((unsigned long)page);
64250 }
64251 diff --git a/fs/libfs.c b/fs/libfs.c
64252 index 88e3e00..979c262 100644
64253 --- a/fs/libfs.c
64254 +++ b/fs/libfs.c
64255 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64256
64257 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64258 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64259 + char d_name[sizeof(next->d_iname)];
64260 + const unsigned char *name;
64261 +
64262 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64263 if (!simple_positive(next)) {
64264 spin_unlock(&next->d_lock);
64265 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64266
64267 spin_unlock(&next->d_lock);
64268 spin_unlock(&dentry->d_lock);
64269 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64270 + name = next->d_name.name;
64271 + if (name == next->d_iname) {
64272 + memcpy(d_name, name, next->d_name.len);
64273 + name = d_name;
64274 + }
64275 + if (!dir_emit(ctx, name, next->d_name.len,
64276 next->d_inode->i_ino, dt_type(next->d_inode)))
64277 return 0;
64278 spin_lock(&dentry->d_lock);
64279 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64280 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64281 void *cookie)
64282 {
64283 - char *s = nd_get_link(nd);
64284 + const char *s = nd_get_link(nd);
64285 if (!IS_ERR(s))
64286 kfree(s);
64287 }
64288 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64289 index acd3947..1f896e2 100644
64290 --- a/fs/lockd/clntproc.c
64291 +++ b/fs/lockd/clntproc.c
64292 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64293 /*
64294 * Cookie counter for NLM requests
64295 */
64296 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64297 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64298
64299 void nlmclnt_next_cookie(struct nlm_cookie *c)
64300 {
64301 - u32 cookie = atomic_inc_return(&nlm_cookie);
64302 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64303
64304 memcpy(c->data, &cookie, 4);
64305 c->len=4;
64306 diff --git a/fs/locks.c b/fs/locks.c
64307 index bb08857..f65e8bf 100644
64308 --- a/fs/locks.c
64309 +++ b/fs/locks.c
64310 @@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64311 locks_remove_posix(filp, filp);
64312
64313 if (filp->f_op->flock) {
64314 - struct file_lock fl = {
64315 + struct file_lock flock = {
64316 .fl_owner = filp,
64317 .fl_pid = current->tgid,
64318 .fl_file = filp,
64319 @@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64320 .fl_type = F_UNLCK,
64321 .fl_end = OFFSET_MAX,
64322 };
64323 - filp->f_op->flock(filp, F_SETLKW, &fl);
64324 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64325 - fl.fl_ops->fl_release_private(&fl);
64326 + filp->f_op->flock(filp, F_SETLKW, &flock);
64327 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64328 + flock.fl_ops->fl_release_private(&flock);
64329 }
64330
64331 spin_lock(&inode->i_lock);
64332 diff --git a/fs/mount.h b/fs/mount.h
64333 index 6740a62..ccb472f 100644
64334 --- a/fs/mount.h
64335 +++ b/fs/mount.h
64336 @@ -11,7 +11,7 @@ struct mnt_namespace {
64337 u64 seq; /* Sequence number to prevent loops */
64338 wait_queue_head_t poll;
64339 u64 event;
64340 -};
64341 +} __randomize_layout;
64342
64343 struct mnt_pcp {
64344 int mnt_count;
64345 @@ -57,7 +57,7 @@ struct mount {
64346 int mnt_expiry_mark; /* true if marked for expiry */
64347 struct hlist_head mnt_pins;
64348 struct path mnt_ex_mountpoint;
64349 -};
64350 +} __randomize_layout;
64351
64352 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64353
64354 diff --git a/fs/namei.c b/fs/namei.c
64355 index a7b05bf..9b251d4 100644
64356 --- a/fs/namei.c
64357 +++ b/fs/namei.c
64358 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64359 if (ret != -EACCES)
64360 return ret;
64361
64362 +#ifdef CONFIG_GRKERNSEC
64363 + /* we'll block if we have to log due to a denied capability use */
64364 + if (mask & MAY_NOT_BLOCK)
64365 + return -ECHILD;
64366 +#endif
64367 +
64368 if (S_ISDIR(inode->i_mode)) {
64369 /* DACs are overridable for directories */
64370 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64371 - return 0;
64372 if (!(mask & MAY_WRITE))
64373 - if (capable_wrt_inode_uidgid(inode,
64374 - CAP_DAC_READ_SEARCH))
64375 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64376 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64377 return 0;
64378 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64379 + return 0;
64380 return -EACCES;
64381 }
64382 /*
64383 + * Searching includes executable on directories, else just read.
64384 + */
64385 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64386 + if (mask == MAY_READ)
64387 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64388 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64389 + return 0;
64390 +
64391 + /*
64392 * Read/write DACs are always overridable.
64393 * Executable DACs are overridable when there is
64394 * at least one exec bit set.
64395 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64396 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64397 return 0;
64398
64399 - /*
64400 - * Searching includes executable on directories, else just read.
64401 - */
64402 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64403 - if (mask == MAY_READ)
64404 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64405 - return 0;
64406 -
64407 return -EACCES;
64408 }
64409 EXPORT_SYMBOL(generic_permission);
64410 @@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64411 {
64412 struct dentry *dentry = link->dentry;
64413 int error;
64414 - char *s;
64415 + const char *s;
64416
64417 BUG_ON(nd->flags & LOOKUP_RCU);
64418
64419 @@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64420 if (error)
64421 goto out_put_nd_path;
64422
64423 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64424 + dentry->d_inode, dentry, nd->path.mnt)) {
64425 + error = -EACCES;
64426 + goto out_put_nd_path;
64427 + }
64428 +
64429 nd->last_type = LAST_BIND;
64430 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64431 error = PTR_ERR(*p);
64432 @@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64433 if (res)
64434 break;
64435 res = walk_component(nd, path, LOOKUP_FOLLOW);
64436 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64437 + res = -EACCES;
64438 put_link(nd, &link, cookie);
64439 } while (res > 0);
64440
64441 @@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64442 static inline u64 hash_name(const char *name)
64443 {
64444 unsigned long a, b, adata, bdata, mask, hash, len;
64445 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64446 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64447
64448 hash = a = 0;
64449 len = -sizeof(unsigned long);
64450 @@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64451 if (err)
64452 break;
64453 err = lookup_last(nd, &path);
64454 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64455 + err = -EACCES;
64456 put_link(nd, &link, cookie);
64457 }
64458 }
64459 @@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64460 if (!err)
64461 err = complete_walk(nd);
64462
64463 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64464 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64465 + path_put(&nd->path);
64466 + err = -ENOENT;
64467 + }
64468 + }
64469 +
64470 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64471 if (!d_can_lookup(nd->path.dentry)) {
64472 path_put(&nd->path);
64473 @@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64474 retval = path_lookupat(dfd, name->name,
64475 flags | LOOKUP_REVAL, nd);
64476
64477 - if (likely(!retval))
64478 + if (likely(!retval)) {
64479 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64480 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64481 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64482 + path_put(&nd->path);
64483 + return -ENOENT;
64484 + }
64485 + }
64486 + }
64487 return retval;
64488 }
64489
64490 @@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64491 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64492 return -EPERM;
64493
64494 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64495 + return -EPERM;
64496 + if (gr_handle_rawio(inode))
64497 + return -EPERM;
64498 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64499 + return -EACCES;
64500 +
64501 return 0;
64502 }
64503
64504 @@ -2816,7 +2854,7 @@ looked_up:
64505 * cleared otherwise prior to returning.
64506 */
64507 static int lookup_open(struct nameidata *nd, struct path *path,
64508 - struct file *file,
64509 + struct path *link, struct file *file,
64510 const struct open_flags *op,
64511 bool got_write, int *opened)
64512 {
64513 @@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64514 /* Negative dentry, just create the file */
64515 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64516 umode_t mode = op->mode;
64517 +
64518 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64519 + error = -EACCES;
64520 + goto out_dput;
64521 + }
64522 +
64523 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64524 + error = -EACCES;
64525 + goto out_dput;
64526 + }
64527 +
64528 if (!IS_POSIXACL(dir->d_inode))
64529 mode &= ~current_umask();
64530 /*
64531 @@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64532 nd->flags & LOOKUP_EXCL);
64533 if (error)
64534 goto out_dput;
64535 + else
64536 + gr_handle_create(dentry, nd->path.mnt);
64537 }
64538 out_no_open:
64539 path->dentry = dentry;
64540 @@ -2886,7 +2937,7 @@ out_dput:
64541 /*
64542 * Handle the last step of open()
64543 */
64544 -static int do_last(struct nameidata *nd, struct path *path,
64545 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64546 struct file *file, const struct open_flags *op,
64547 int *opened, struct filename *name)
64548 {
64549 @@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64550 if (error)
64551 return error;
64552
64553 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64554 + error = -ENOENT;
64555 + goto out;
64556 + }
64557 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64558 + error = -EACCES;
64559 + goto out;
64560 + }
64561 +
64562 audit_inode(name, dir, LOOKUP_PARENT);
64563 error = -EISDIR;
64564 /* trailing slashes? */
64565 @@ -2955,7 +3015,7 @@ retry_lookup:
64566 */
64567 }
64568 mutex_lock(&dir->d_inode->i_mutex);
64569 - error = lookup_open(nd, path, file, op, got_write, opened);
64570 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64571 mutex_unlock(&dir->d_inode->i_mutex);
64572
64573 if (error <= 0) {
64574 @@ -2979,11 +3039,28 @@ retry_lookup:
64575 goto finish_open_created;
64576 }
64577
64578 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64579 + error = -ENOENT;
64580 + goto exit_dput;
64581 + }
64582 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64583 + error = -EACCES;
64584 + goto exit_dput;
64585 + }
64586 +
64587 /*
64588 * create/update audit record if it already exists.
64589 */
64590 - if (d_is_positive(path->dentry))
64591 + if (d_is_positive(path->dentry)) {
64592 + /* only check if O_CREAT is specified, all other checks need to go
64593 + into may_open */
64594 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64595 + error = -EACCES;
64596 + goto exit_dput;
64597 + }
64598 +
64599 audit_inode(name, path->dentry, 0);
64600 + }
64601
64602 /*
64603 * If atomic_open() acquired write access it is dropped now due to
64604 @@ -3024,6 +3101,11 @@ finish_lookup:
64605 }
64606 }
64607 BUG_ON(inode != path->dentry->d_inode);
64608 + /* if we're resolving a symlink to another symlink */
64609 + if (link && gr_handle_symlink_owner(link, inode)) {
64610 + error = -EACCES;
64611 + goto out;
64612 + }
64613 return 1;
64614 }
64615
64616 @@ -3033,7 +3115,6 @@ finish_lookup:
64617 save_parent.dentry = nd->path.dentry;
64618 save_parent.mnt = mntget(path->mnt);
64619 nd->path.dentry = path->dentry;
64620 -
64621 }
64622 nd->inode = inode;
64623 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64624 @@ -3043,7 +3124,18 @@ finish_open:
64625 path_put(&save_parent);
64626 return error;
64627 }
64628 +
64629 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64630 + error = -ENOENT;
64631 + goto out;
64632 + }
64633 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64634 + error = -EACCES;
64635 + goto out;
64636 + }
64637 +
64638 audit_inode(name, nd->path.dentry, 0);
64639 +
64640 error = -EISDIR;
64641 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64642 goto out;
64643 @@ -3206,7 +3298,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64644 if (unlikely(error))
64645 goto out;
64646
64647 - error = do_last(nd, &path, file, op, &opened, pathname);
64648 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64649 while (unlikely(error > 0)) { /* trailing symlink */
64650 struct path link = path;
64651 void *cookie;
64652 @@ -3224,7 +3316,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64653 error = follow_link(&link, nd, &cookie);
64654 if (unlikely(error))
64655 break;
64656 - error = do_last(nd, &path, file, op, &opened, pathname);
64657 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64658 put_link(nd, &link, cookie);
64659 }
64660 out:
64661 @@ -3324,9 +3416,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64662 goto unlock;
64663
64664 error = -EEXIST;
64665 - if (d_is_positive(dentry))
64666 + if (d_is_positive(dentry)) {
64667 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64668 + error = -ENOENT;
64669 goto fail;
64670 -
64671 + }
64672 /*
64673 * Special case - lookup gave negative, but... we had foo/bar/
64674 * From the vfs_mknod() POV we just have a negative dentry -
64675 @@ -3378,6 +3472,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64676 }
64677 EXPORT_SYMBOL(user_path_create);
64678
64679 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64680 +{
64681 + struct filename *tmp = getname(pathname);
64682 + struct dentry *res;
64683 + if (IS_ERR(tmp))
64684 + return ERR_CAST(tmp);
64685 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64686 + if (IS_ERR(res))
64687 + putname(tmp);
64688 + else
64689 + *to = tmp;
64690 + return res;
64691 +}
64692 +
64693 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64694 {
64695 int error = may_create(dir, dentry);
64696 @@ -3441,6 +3549,17 @@ retry:
64697
64698 if (!IS_POSIXACL(path.dentry->d_inode))
64699 mode &= ~current_umask();
64700 +
64701 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64702 + error = -EPERM;
64703 + goto out;
64704 + }
64705 +
64706 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64707 + error = -EACCES;
64708 + goto out;
64709 + }
64710 +
64711 error = security_path_mknod(&path, dentry, mode, dev);
64712 if (error)
64713 goto out;
64714 @@ -3456,6 +3575,8 @@ retry:
64715 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64716 break;
64717 }
64718 + if (!error)
64719 + gr_handle_create(dentry, path.mnt);
64720 out:
64721 done_path_create(&path, dentry);
64722 if (retry_estale(error, lookup_flags)) {
64723 @@ -3510,9 +3631,16 @@ retry:
64724
64725 if (!IS_POSIXACL(path.dentry->d_inode))
64726 mode &= ~current_umask();
64727 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64728 + error = -EACCES;
64729 + goto out;
64730 + }
64731 error = security_path_mkdir(&path, dentry, mode);
64732 if (!error)
64733 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64734 + if (!error)
64735 + gr_handle_create(dentry, path.mnt);
64736 +out:
64737 done_path_create(&path, dentry);
64738 if (retry_estale(error, lookup_flags)) {
64739 lookup_flags |= LOOKUP_REVAL;
64740 @@ -3595,6 +3723,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64741 struct filename *name;
64742 struct dentry *dentry;
64743 struct nameidata nd;
64744 + ino_t saved_ino = 0;
64745 + dev_t saved_dev = 0;
64746 unsigned int lookup_flags = 0;
64747 retry:
64748 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64749 @@ -3627,10 +3757,21 @@ retry:
64750 error = -ENOENT;
64751 goto exit3;
64752 }
64753 +
64754 + saved_ino = dentry->d_inode->i_ino;
64755 + saved_dev = gr_get_dev_from_dentry(dentry);
64756 +
64757 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64758 + error = -EACCES;
64759 + goto exit3;
64760 + }
64761 +
64762 error = security_path_rmdir(&nd.path, dentry);
64763 if (error)
64764 goto exit3;
64765 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64766 + if (!error && (saved_dev || saved_ino))
64767 + gr_handle_delete(saved_ino, saved_dev);
64768 exit3:
64769 dput(dentry);
64770 exit2:
64771 @@ -3721,6 +3862,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64772 struct nameidata nd;
64773 struct inode *inode = NULL;
64774 struct inode *delegated_inode = NULL;
64775 + ino_t saved_ino = 0;
64776 + dev_t saved_dev = 0;
64777 unsigned int lookup_flags = 0;
64778 retry:
64779 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64780 @@ -3747,10 +3890,22 @@ retry_deleg:
64781 if (d_is_negative(dentry))
64782 goto slashes;
64783 ihold(inode);
64784 +
64785 + if (inode->i_nlink <= 1) {
64786 + saved_ino = inode->i_ino;
64787 + saved_dev = gr_get_dev_from_dentry(dentry);
64788 + }
64789 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64790 + error = -EACCES;
64791 + goto exit2;
64792 + }
64793 +
64794 error = security_path_unlink(&nd.path, dentry);
64795 if (error)
64796 goto exit2;
64797 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64798 + if (!error && (saved_ino || saved_dev))
64799 + gr_handle_delete(saved_ino, saved_dev);
64800 exit2:
64801 dput(dentry);
64802 }
64803 @@ -3839,9 +3994,17 @@ retry:
64804 if (IS_ERR(dentry))
64805 goto out_putname;
64806
64807 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64808 + error = -EACCES;
64809 + goto out;
64810 + }
64811 +
64812 error = security_path_symlink(&path, dentry, from->name);
64813 if (!error)
64814 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64815 + if (!error)
64816 + gr_handle_create(dentry, path.mnt);
64817 +out:
64818 done_path_create(&path, dentry);
64819 if (retry_estale(error, lookup_flags)) {
64820 lookup_flags |= LOOKUP_REVAL;
64821 @@ -3945,6 +4108,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64822 struct dentry *new_dentry;
64823 struct path old_path, new_path;
64824 struct inode *delegated_inode = NULL;
64825 + struct filename *to = NULL;
64826 int how = 0;
64827 int error;
64828
64829 @@ -3968,7 +4132,7 @@ retry:
64830 if (error)
64831 return error;
64832
64833 - new_dentry = user_path_create(newdfd, newname, &new_path,
64834 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64835 (how & LOOKUP_REVAL));
64836 error = PTR_ERR(new_dentry);
64837 if (IS_ERR(new_dentry))
64838 @@ -3980,11 +4144,28 @@ retry:
64839 error = may_linkat(&old_path);
64840 if (unlikely(error))
64841 goto out_dput;
64842 +
64843 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64844 + old_path.dentry->d_inode,
64845 + old_path.dentry->d_inode->i_mode, to)) {
64846 + error = -EACCES;
64847 + goto out_dput;
64848 + }
64849 +
64850 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64851 + old_path.dentry, old_path.mnt, to)) {
64852 + error = -EACCES;
64853 + goto out_dput;
64854 + }
64855 +
64856 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64857 if (error)
64858 goto out_dput;
64859 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64860 + if (!error)
64861 + gr_handle_create(new_dentry, new_path.mnt);
64862 out_dput:
64863 + putname(to);
64864 done_path_create(&new_path, new_dentry);
64865 if (delegated_inode) {
64866 error = break_deleg_wait(&delegated_inode);
64867 @@ -4295,6 +4476,12 @@ retry_deleg:
64868 if (new_dentry == trap)
64869 goto exit5;
64870
64871 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64872 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64873 + to, flags);
64874 + if (error)
64875 + goto exit5;
64876 +
64877 error = security_path_rename(&oldnd.path, old_dentry,
64878 &newnd.path, new_dentry, flags);
64879 if (error)
64880 @@ -4302,6 +4489,9 @@ retry_deleg:
64881 error = vfs_rename(old_dir->d_inode, old_dentry,
64882 new_dir->d_inode, new_dentry,
64883 &delegated_inode, flags);
64884 + if (!error)
64885 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64886 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64887 exit5:
64888 dput(new_dentry);
64889 exit4:
64890 @@ -4344,14 +4534,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
64891
64892 int readlink_copy(char __user *buffer, int buflen, const char *link)
64893 {
64894 + char tmpbuf[64];
64895 + const char *newlink;
64896 int len = PTR_ERR(link);
64897 +
64898 if (IS_ERR(link))
64899 goto out;
64900
64901 len = strlen(link);
64902 if (len > (unsigned) buflen)
64903 len = buflen;
64904 - if (copy_to_user(buffer, link, len))
64905 +
64906 + if (len < sizeof(tmpbuf)) {
64907 + memcpy(tmpbuf, link, len);
64908 + newlink = tmpbuf;
64909 + } else
64910 + newlink = link;
64911 +
64912 + if (copy_to_user(buffer, newlink, len))
64913 len = -EFAULT;
64914 out:
64915 return len;
64916 diff --git a/fs/namespace.c b/fs/namespace.c
64917 index ef42d9b..b8dfe4f 100644
64918 --- a/fs/namespace.c
64919 +++ b/fs/namespace.c
64920 @@ -1360,6 +1360,9 @@ static int do_umount(struct mount *mnt, int flags)
64921 if (!(sb->s_flags & MS_RDONLY))
64922 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64923 up_write(&sb->s_umount);
64924 +
64925 + gr_log_remount(mnt->mnt_devname, retval);
64926 +
64927 return retval;
64928 }
64929
64930 @@ -1382,6 +1385,9 @@ static int do_umount(struct mount *mnt, int flags)
64931 }
64932 unlock_mount_hash();
64933 namespace_unlock();
64934 +
64935 + gr_log_unmount(mnt->mnt_devname, retval);
64936 +
64937 return retval;
64938 }
64939
64940 @@ -1401,7 +1407,7 @@ static inline bool may_mount(void)
64941 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64942 */
64943
64944 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64945 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64946 {
64947 struct path path;
64948 struct mount *mnt;
64949 @@ -1443,7 +1449,7 @@ out:
64950 /*
64951 * The 2.0 compatible umount. No flags.
64952 */
64953 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64954 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64955 {
64956 return sys_umount(name, 0);
64957 }
64958 @@ -2492,6 +2498,16 @@ long do_mount(const char *dev_name, const char *dir_name,
64959 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64960 MS_STRICTATIME);
64961
64962 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64963 + retval = -EPERM;
64964 + goto dput_out;
64965 + }
64966 +
64967 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64968 + retval = -EPERM;
64969 + goto dput_out;
64970 + }
64971 +
64972 if (flags & MS_REMOUNT)
64973 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64974 data_page);
64975 @@ -2506,6 +2522,9 @@ long do_mount(const char *dev_name, const char *dir_name,
64976 dev_name, data_page);
64977 dput_out:
64978 path_put(&path);
64979 +
64980 + gr_log_mount(dev_name, dir_name, retval);
64981 +
64982 return retval;
64983 }
64984
64985 @@ -2523,7 +2542,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64986 * number incrementing at 10Ghz will take 12,427 years to wrap which
64987 * is effectively never, so we can ignore the possibility.
64988 */
64989 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64990 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64991
64992 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64993 {
64994 @@ -2538,7 +2557,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64995 kfree(new_ns);
64996 return ERR_PTR(ret);
64997 }
64998 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64999 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65000 atomic_set(&new_ns->count, 1);
65001 new_ns->root = NULL;
65002 INIT_LIST_HEAD(&new_ns->list);
65003 @@ -2548,7 +2567,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65004 return new_ns;
65005 }
65006
65007 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65008 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65009 struct user_namespace *user_ns, struct fs_struct *new_fs)
65010 {
65011 struct mnt_namespace *new_ns;
65012 @@ -2669,8 +2688,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65013 }
65014 EXPORT_SYMBOL(mount_subtree);
65015
65016 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65017 - char __user *, type, unsigned long, flags, void __user *, data)
65018 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65019 + const char __user *, type, unsigned long, flags, void __user *, data)
65020 {
65021 int ret;
65022 char *kernel_type;
65023 @@ -2783,6 +2802,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65024 if (error)
65025 goto out2;
65026
65027 + if (gr_handle_chroot_pivot()) {
65028 + error = -EPERM;
65029 + goto out2;
65030 + }
65031 +
65032 get_fs_root(current->fs, &root);
65033 old_mp = lock_mount(&old);
65034 error = PTR_ERR(old_mp);
65035 @@ -2820,6 +2844,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65036 /* make sure we can reach put_old from new_root */
65037 if (!is_path_reachable(old_mnt, old.dentry, &new))
65038 goto out4;
65039 + /* make certain new is below the root */
65040 + if (!is_path_reachable(new_mnt, new.dentry, &root))
65041 + goto out4;
65042 root_mp->m_count++; /* pin it so it won't go away */
65043 lock_mount_hash();
65044 detach_mnt(new_mnt, &parent_path);
65045 @@ -3051,7 +3078,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65046 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65047 return -EPERM;
65048
65049 - if (fs->users != 1)
65050 + if (atomic_read(&fs->users) != 1)
65051 return -EINVAL;
65052
65053 get_mnt_ns(mnt_ns);
65054 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65055 index f4ccfe6..a5cf064 100644
65056 --- a/fs/nfs/callback_xdr.c
65057 +++ b/fs/nfs/callback_xdr.c
65058 @@ -51,7 +51,7 @@ struct callback_op {
65059 callback_decode_arg_t decode_args;
65060 callback_encode_res_t encode_res;
65061 long res_maxsize;
65062 -};
65063 +} __do_const;
65064
65065 static struct callback_op callback_ops[];
65066
65067 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65068 index 577a36f..1cde799 100644
65069 --- a/fs/nfs/inode.c
65070 +++ b/fs/nfs/inode.c
65071 @@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65072 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65073 }
65074
65075 -static atomic_long_t nfs_attr_generation_counter;
65076 +static atomic_long_unchecked_t nfs_attr_generation_counter;
65077
65078 static unsigned long nfs_read_attr_generation_counter(void)
65079 {
65080 - return atomic_long_read(&nfs_attr_generation_counter);
65081 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65082 }
65083
65084 unsigned long nfs_inc_attr_generation_counter(void)
65085 {
65086 - return atomic_long_inc_return(&nfs_attr_generation_counter);
65087 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65088 }
65089
65090 void nfs_fattr_init(struct nfs_fattr *fattr)
65091 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65092 index 5e0dc52..64681bc 100644
65093 --- a/fs/nfsd/nfs4proc.c
65094 +++ b/fs/nfsd/nfs4proc.c
65095 @@ -1155,7 +1155,7 @@ struct nfsd4_operation {
65096 nfsd4op_rsize op_rsize_bop;
65097 stateid_getter op_get_currentstateid;
65098 stateid_setter op_set_currentstateid;
65099 -};
65100 +} __do_const;
65101
65102 static struct nfsd4_operation nfsd4_ops[];
65103
65104 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65105 index b01f6e1..4aab09a 100644
65106 --- a/fs/nfsd/nfs4xdr.c
65107 +++ b/fs/nfsd/nfs4xdr.c
65108 @@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65109
65110 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65111
65112 -static nfsd4_dec nfsd4_dec_ops[] = {
65113 +static const nfsd4_dec nfsd4_dec_ops[] = {
65114 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65115 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65116 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65117 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65118 index ff95676..96cf3f62 100644
65119 --- a/fs/nfsd/nfscache.c
65120 +++ b/fs/nfsd/nfscache.c
65121 @@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65122 {
65123 struct svc_cacherep *rp = rqstp->rq_cacherep;
65124 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65125 - int len;
65126 + long len;
65127 size_t bufsize = 0;
65128
65129 if (!rp)
65130 return;
65131
65132 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65133 - len >>= 2;
65134 + if (statp) {
65135 + len = (char*)statp - (char*)resv->iov_base;
65136 + len = resv->iov_len - len;
65137 + len >>= 2;
65138 + }
65139
65140 /* Don't cache excessive amounts of data and XDR failures */
65141 - if (!statp || len > (256 >> 2)) {
65142 + if (!statp || len > (256 >> 2) || len < 0) {
65143 nfsd_reply_cache_free(rp);
65144 return;
65145 }
65146 @@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65147 switch (cachetype) {
65148 case RC_REPLSTAT:
65149 if (len != 1)
65150 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65151 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65152 rp->c_replstat = *statp;
65153 break;
65154 case RC_REPLBUFF:
65155 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65156 index f501a9b..8155556 100644
65157 --- a/fs/nfsd/vfs.c
65158 +++ b/fs/nfsd/vfs.c
65159 @@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65160
65161 oldfs = get_fs();
65162 set_fs(KERNEL_DS);
65163 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65164 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65165 set_fs(oldfs);
65166 return nfsd_finish_read(file, count, host_err);
65167 }
65168 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65169
65170 /* Write the data. */
65171 oldfs = get_fs(); set_fs(KERNEL_DS);
65172 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65173 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65174 set_fs(oldfs);
65175 if (host_err < 0)
65176 goto out_nfserr;
65177 @@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65178 */
65179
65180 oldfs = get_fs(); set_fs(KERNEL_DS);
65181 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65182 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65183 set_fs(oldfs);
65184
65185 if (host_err < 0)
65186 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65187 index 52ccd34..7a6b202 100644
65188 --- a/fs/nls/nls_base.c
65189 +++ b/fs/nls/nls_base.c
65190 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65191
65192 int __register_nls(struct nls_table *nls, struct module *owner)
65193 {
65194 - struct nls_table ** tmp = &tables;
65195 + struct nls_table *tmp = tables;
65196
65197 if (nls->next)
65198 return -EBUSY;
65199
65200 - nls->owner = owner;
65201 + pax_open_kernel();
65202 + *(void **)&nls->owner = owner;
65203 + pax_close_kernel();
65204 spin_lock(&nls_lock);
65205 - while (*tmp) {
65206 - if (nls == *tmp) {
65207 + while (tmp) {
65208 + if (nls == tmp) {
65209 spin_unlock(&nls_lock);
65210 return -EBUSY;
65211 }
65212 - tmp = &(*tmp)->next;
65213 + tmp = tmp->next;
65214 }
65215 - nls->next = tables;
65216 + pax_open_kernel();
65217 + *(struct nls_table **)&nls->next = tables;
65218 + pax_close_kernel();
65219 tables = nls;
65220 spin_unlock(&nls_lock);
65221 return 0;
65222 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65223
65224 int unregister_nls(struct nls_table * nls)
65225 {
65226 - struct nls_table ** tmp = &tables;
65227 + struct nls_table * const * tmp = &tables;
65228
65229 spin_lock(&nls_lock);
65230 while (*tmp) {
65231 if (nls == *tmp) {
65232 - *tmp = nls->next;
65233 + pax_open_kernel();
65234 + *(struct nls_table **)tmp = nls->next;
65235 + pax_close_kernel();
65236 spin_unlock(&nls_lock);
65237 return 0;
65238 }
65239 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65240 return -EINVAL;
65241 }
65242
65243 -static struct nls_table *find_nls(char *charset)
65244 +static struct nls_table *find_nls(const char *charset)
65245 {
65246 struct nls_table *nls;
65247 spin_lock(&nls_lock);
65248 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65249 return nls;
65250 }
65251
65252 -struct nls_table *load_nls(char *charset)
65253 +struct nls_table *load_nls(const char *charset)
65254 {
65255 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65256 }
65257 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65258 index 162b3f1..6076a7c 100644
65259 --- a/fs/nls/nls_euc-jp.c
65260 +++ b/fs/nls/nls_euc-jp.c
65261 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65262 p_nls = load_nls("cp932");
65263
65264 if (p_nls) {
65265 - table.charset2upper = p_nls->charset2upper;
65266 - table.charset2lower = p_nls->charset2lower;
65267 + pax_open_kernel();
65268 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65269 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65270 + pax_close_kernel();
65271 return register_nls(&table);
65272 }
65273
65274 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65275 index a80a741..7b96e1b 100644
65276 --- a/fs/nls/nls_koi8-ru.c
65277 +++ b/fs/nls/nls_koi8-ru.c
65278 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65279 p_nls = load_nls("koi8-u");
65280
65281 if (p_nls) {
65282 - table.charset2upper = p_nls->charset2upper;
65283 - table.charset2lower = p_nls->charset2lower;
65284 + pax_open_kernel();
65285 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65286 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65287 + pax_close_kernel();
65288 return register_nls(&table);
65289 }
65290
65291 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65292 index b13992a..536c8d8 100644
65293 --- a/fs/notify/fanotify/fanotify_user.c
65294 +++ b/fs/notify/fanotify/fanotify_user.c
65295 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65296
65297 fd = fanotify_event_metadata.fd;
65298 ret = -EFAULT;
65299 - if (copy_to_user(buf, &fanotify_event_metadata,
65300 - fanotify_event_metadata.event_len))
65301 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65302 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65303 goto out_close_fd;
65304
65305 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65306 diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65307 index 0f88bc0..7d888d7 100644
65308 --- a/fs/notify/inotify/inotify_fsnotify.c
65309 +++ b/fs/notify/inotify/inotify_fsnotify.c
65310 @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65311 /* ideally the idr is empty and we won't hit the BUG in the callback */
65312 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65313 idr_destroy(&group->inotify_data.idr);
65314 - atomic_dec(&group->inotify_data.user->inotify_devs);
65315 - free_uid(group->inotify_data.user);
65316 + if (group->inotify_data.user) {
65317 + atomic_dec(&group->inotify_data.user->inotify_devs);
65318 + free_uid(group->inotify_data.user);
65319 + }
65320 }
65321
65322 static void inotify_free_event(struct fsnotify_event *fsn_event)
65323 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65324 index a95d8e0..a91a5fd 100644
65325 --- a/fs/notify/notification.c
65326 +++ b/fs/notify/notification.c
65327 @@ -48,7 +48,7 @@
65328 #include <linux/fsnotify_backend.h>
65329 #include "fsnotify.h"
65330
65331 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65332 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65333
65334 /**
65335 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65336 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65337 */
65338 u32 fsnotify_get_cookie(void)
65339 {
65340 - return atomic_inc_return(&fsnotify_sync_cookie);
65341 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65342 }
65343 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65344
65345 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65346 index 9e38daf..5727cae 100644
65347 --- a/fs/ntfs/dir.c
65348 +++ b/fs/ntfs/dir.c
65349 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65350 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65351 ~(s64)(ndir->itype.index.block_size - 1)));
65352 /* Bounds checks. */
65353 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65354 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65355 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65356 "inode 0x%lx or driver bug.", vdir->i_ino);
65357 goto err_out;
65358 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65359 index f5ec1ce..807fd78 100644
65360 --- a/fs/ntfs/file.c
65361 +++ b/fs/ntfs/file.c
65362 @@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65363 char *addr;
65364 size_t total = 0;
65365 unsigned len;
65366 - int left;
65367 + unsigned left;
65368
65369 do {
65370 len = PAGE_CACHE_SIZE - ofs;
65371 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65372 index 6c3296e..c0b99f0 100644
65373 --- a/fs/ntfs/super.c
65374 +++ b/fs/ntfs/super.c
65375 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65376 if (!silent)
65377 ntfs_error(sb, "Primary boot sector is invalid.");
65378 } else if (!silent)
65379 - ntfs_error(sb, read_err_str, "primary");
65380 + ntfs_error(sb, read_err_str, "%s", "primary");
65381 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65382 if (bh_primary)
65383 brelse(bh_primary);
65384 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65385 goto hotfix_primary_boot_sector;
65386 brelse(bh_backup);
65387 } else if (!silent)
65388 - ntfs_error(sb, read_err_str, "backup");
65389 + ntfs_error(sb, read_err_str, "%s", "backup");
65390 /* Try to read NT3.51- backup boot sector. */
65391 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65392 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65393 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65394 "sector.");
65395 brelse(bh_backup);
65396 } else if (!silent)
65397 - ntfs_error(sb, read_err_str, "backup");
65398 + ntfs_error(sb, read_err_str, "%s", "backup");
65399 /* We failed. Cleanup and return. */
65400 if (bh_primary)
65401 brelse(bh_primary);
65402 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65403 index 0440134..d52c93a 100644
65404 --- a/fs/ocfs2/localalloc.c
65405 +++ b/fs/ocfs2/localalloc.c
65406 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65407 goto bail;
65408 }
65409
65410 - atomic_inc(&osb->alloc_stats.moves);
65411 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65412
65413 bail:
65414 if (handle)
65415 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65416 index bbec539..7b266d5 100644
65417 --- a/fs/ocfs2/ocfs2.h
65418 +++ b/fs/ocfs2/ocfs2.h
65419 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65420
65421 struct ocfs2_alloc_stats
65422 {
65423 - atomic_t moves;
65424 - atomic_t local_data;
65425 - atomic_t bitmap_data;
65426 - atomic_t bg_allocs;
65427 - atomic_t bg_extends;
65428 + atomic_unchecked_t moves;
65429 + atomic_unchecked_t local_data;
65430 + atomic_unchecked_t bitmap_data;
65431 + atomic_unchecked_t bg_allocs;
65432 + atomic_unchecked_t bg_extends;
65433 };
65434
65435 enum ocfs2_local_alloc_state
65436 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65437 index 0cb889a..6a26b24 100644
65438 --- a/fs/ocfs2/suballoc.c
65439 +++ b/fs/ocfs2/suballoc.c
65440 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65441 mlog_errno(status);
65442 goto bail;
65443 }
65444 - atomic_inc(&osb->alloc_stats.bg_extends);
65445 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65446
65447 /* You should never ask for this much metadata */
65448 BUG_ON(bits_wanted >
65449 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65450 mlog_errno(status);
65451 goto bail;
65452 }
65453 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65454 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65455
65456 *suballoc_loc = res.sr_bg_blkno;
65457 *suballoc_bit_start = res.sr_bit_offset;
65458 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65459 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65460 res->sr_bits);
65461
65462 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65463 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65464
65465 BUG_ON(res->sr_bits != 1);
65466
65467 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65468 mlog_errno(status);
65469 goto bail;
65470 }
65471 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65472 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65473
65474 BUG_ON(res.sr_bits != 1);
65475
65476 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65477 cluster_start,
65478 num_clusters);
65479 if (!status)
65480 - atomic_inc(&osb->alloc_stats.local_data);
65481 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65482 } else {
65483 if (min_clusters > (osb->bitmap_cpg - 1)) {
65484 /* The only paths asking for contiguousness
65485 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65486 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65487 res.sr_bg_blkno,
65488 res.sr_bit_offset);
65489 - atomic_inc(&osb->alloc_stats.bitmap_data);
65490 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65491 *num_clusters = res.sr_bits;
65492 }
65493 }
65494 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65495 index 4142546..69375a9 100644
65496 --- a/fs/ocfs2/super.c
65497 +++ b/fs/ocfs2/super.c
65498 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65499 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65500 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65501 "Stats",
65502 - atomic_read(&osb->alloc_stats.bitmap_data),
65503 - atomic_read(&osb->alloc_stats.local_data),
65504 - atomic_read(&osb->alloc_stats.bg_allocs),
65505 - atomic_read(&osb->alloc_stats.moves),
65506 - atomic_read(&osb->alloc_stats.bg_extends));
65507 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65508 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65509 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65510 + atomic_read_unchecked(&osb->alloc_stats.moves),
65511 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65512
65513 out += snprintf(buf + out, len - out,
65514 "%10s => State: %u Descriptor: %llu Size: %u bits "
65515 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65516
65517 mutex_init(&osb->system_file_mutex);
65518
65519 - atomic_set(&osb->alloc_stats.moves, 0);
65520 - atomic_set(&osb->alloc_stats.local_data, 0);
65521 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65522 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65523 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65524 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65525 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65526 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65527 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65528 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65529
65530 /* Copy the blockcheck stats from the superblock probe */
65531 osb->osb_ecc_stats = *stats;
65532 diff --git a/fs/open.c b/fs/open.c
65533 index d6fd3ac..6ccf474 100644
65534 --- a/fs/open.c
65535 +++ b/fs/open.c
65536 @@ -32,6 +32,8 @@
65537 #include <linux/dnotify.h>
65538 #include <linux/compat.h>
65539
65540 +#define CREATE_TRACE_POINTS
65541 +#include <trace/events/fs.h>
65542 #include "internal.h"
65543
65544 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65545 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65546 error = locks_verify_truncate(inode, NULL, length);
65547 if (!error)
65548 error = security_path_truncate(path);
65549 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65550 + error = -EACCES;
65551 if (!error)
65552 error = do_truncate(path->dentry, length, 0, NULL);
65553
65554 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65555 error = locks_verify_truncate(inode, f.file, length);
65556 if (!error)
65557 error = security_path_truncate(&f.file->f_path);
65558 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65559 + error = -EACCES;
65560 if (!error)
65561 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65562 sb_end_write(inode->i_sb);
65563 @@ -380,6 +386,9 @@ retry:
65564 if (__mnt_is_readonly(path.mnt))
65565 res = -EROFS;
65566
65567 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65568 + res = -EACCES;
65569 +
65570 out_path_release:
65571 path_put(&path);
65572 if (retry_estale(res, lookup_flags)) {
65573 @@ -411,6 +420,8 @@ retry:
65574 if (error)
65575 goto dput_and_out;
65576
65577 + gr_log_chdir(path.dentry, path.mnt);
65578 +
65579 set_fs_pwd(current->fs, &path);
65580
65581 dput_and_out:
65582 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65583 goto out_putf;
65584
65585 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65586 +
65587 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65588 + error = -EPERM;
65589 +
65590 + if (!error)
65591 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65592 +
65593 if (!error)
65594 set_fs_pwd(current->fs, &f.file->f_path);
65595 out_putf:
65596 @@ -469,7 +487,13 @@ retry:
65597 if (error)
65598 goto dput_and_out;
65599
65600 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65601 + goto dput_and_out;
65602 +
65603 set_fs_root(current->fs, &path);
65604 +
65605 + gr_handle_chroot_chdir(&path);
65606 +
65607 error = 0;
65608 dput_and_out:
65609 path_put(&path);
65610 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65611 return error;
65612 retry_deleg:
65613 mutex_lock(&inode->i_mutex);
65614 +
65615 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65616 + error = -EACCES;
65617 + goto out_unlock;
65618 + }
65619 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65620 + error = -EACCES;
65621 + goto out_unlock;
65622 + }
65623 +
65624 error = security_path_chmod(path, mode);
65625 if (error)
65626 goto out_unlock;
65627 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65628 uid = make_kuid(current_user_ns(), user);
65629 gid = make_kgid(current_user_ns(), group);
65630
65631 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65632 + return -EACCES;
65633 +
65634 newattrs.ia_valid = ATTR_CTIME;
65635 if (user != (uid_t) -1) {
65636 if (!uid_valid(uid))
65637 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65638 } else {
65639 fsnotify_open(f);
65640 fd_install(fd, f);
65641 + trace_do_sys_open(tmp->name, flags, mode);
65642 }
65643 }
65644 putname(tmp);
65645 diff --git a/fs/pipe.c b/fs/pipe.c
65646 index 21981e5..3d5f55c 100644
65647 --- a/fs/pipe.c
65648 +++ b/fs/pipe.c
65649 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65650
65651 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65652 {
65653 - if (pipe->files)
65654 + if (atomic_read(&pipe->files))
65655 mutex_lock_nested(&pipe->mutex, subclass);
65656 }
65657
65658 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65659
65660 void pipe_unlock(struct pipe_inode_info *pipe)
65661 {
65662 - if (pipe->files)
65663 + if (atomic_read(&pipe->files))
65664 mutex_unlock(&pipe->mutex);
65665 }
65666 EXPORT_SYMBOL(pipe_unlock);
65667 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65668 }
65669 if (bufs) /* More to do? */
65670 continue;
65671 - if (!pipe->writers)
65672 + if (!atomic_read(&pipe->writers))
65673 break;
65674 - if (!pipe->waiting_writers) {
65675 + if (!atomic_read(&pipe->waiting_writers)) {
65676 /* syscall merging: Usually we must not sleep
65677 * if O_NONBLOCK is set, or if we got some data.
65678 * But if a writer sleeps in kernel space, then
65679 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65680
65681 __pipe_lock(pipe);
65682
65683 - if (!pipe->readers) {
65684 + if (!atomic_read(&pipe->readers)) {
65685 send_sig(SIGPIPE, current, 0);
65686 ret = -EPIPE;
65687 goto out;
65688 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65689 for (;;) {
65690 int bufs;
65691
65692 - if (!pipe->readers) {
65693 + if (!atomic_read(&pipe->readers)) {
65694 send_sig(SIGPIPE, current, 0);
65695 if (!ret)
65696 ret = -EPIPE;
65697 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65698 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65699 do_wakeup = 0;
65700 }
65701 - pipe->waiting_writers++;
65702 + atomic_inc(&pipe->waiting_writers);
65703 pipe_wait(pipe);
65704 - pipe->waiting_writers--;
65705 + atomic_dec(&pipe->waiting_writers);
65706 }
65707 out:
65708 __pipe_unlock(pipe);
65709 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65710 mask = 0;
65711 if (filp->f_mode & FMODE_READ) {
65712 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65713 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65714 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65715 mask |= POLLHUP;
65716 }
65717
65718 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65719 * Most Unices do not set POLLERR for FIFOs but on Linux they
65720 * behave exactly like pipes for poll().
65721 */
65722 - if (!pipe->readers)
65723 + if (!atomic_read(&pipe->readers))
65724 mask |= POLLERR;
65725 }
65726
65727 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65728 int kill = 0;
65729
65730 spin_lock(&inode->i_lock);
65731 - if (!--pipe->files) {
65732 + if (atomic_dec_and_test(&pipe->files)) {
65733 inode->i_pipe = NULL;
65734 kill = 1;
65735 }
65736 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65737
65738 __pipe_lock(pipe);
65739 if (file->f_mode & FMODE_READ)
65740 - pipe->readers--;
65741 + atomic_dec(&pipe->readers);
65742 if (file->f_mode & FMODE_WRITE)
65743 - pipe->writers--;
65744 + atomic_dec(&pipe->writers);
65745
65746 - if (pipe->readers || pipe->writers) {
65747 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65748 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65749 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65750 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65751 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65752 kfree(pipe);
65753 }
65754
65755 -static struct vfsmount *pipe_mnt __read_mostly;
65756 +struct vfsmount *pipe_mnt __read_mostly;
65757
65758 /*
65759 * pipefs_dname() is called from d_path().
65760 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65761 goto fail_iput;
65762
65763 inode->i_pipe = pipe;
65764 - pipe->files = 2;
65765 - pipe->readers = pipe->writers = 1;
65766 + atomic_set(&pipe->files, 2);
65767 + atomic_set(&pipe->readers, 1);
65768 + atomic_set(&pipe->writers, 1);
65769 inode->i_fop = &pipefifo_fops;
65770
65771 /*
65772 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65773 spin_lock(&inode->i_lock);
65774 if (inode->i_pipe) {
65775 pipe = inode->i_pipe;
65776 - pipe->files++;
65777 + atomic_inc(&pipe->files);
65778 spin_unlock(&inode->i_lock);
65779 } else {
65780 spin_unlock(&inode->i_lock);
65781 pipe = alloc_pipe_info();
65782 if (!pipe)
65783 return -ENOMEM;
65784 - pipe->files = 1;
65785 + atomic_set(&pipe->files, 1);
65786 spin_lock(&inode->i_lock);
65787 if (unlikely(inode->i_pipe)) {
65788 - inode->i_pipe->files++;
65789 + atomic_inc(&inode->i_pipe->files);
65790 spin_unlock(&inode->i_lock);
65791 free_pipe_info(pipe);
65792 pipe = inode->i_pipe;
65793 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65794 * opened, even when there is no process writing the FIFO.
65795 */
65796 pipe->r_counter++;
65797 - if (pipe->readers++ == 0)
65798 + if (atomic_inc_return(&pipe->readers) == 1)
65799 wake_up_partner(pipe);
65800
65801 - if (!is_pipe && !pipe->writers) {
65802 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65803 if ((filp->f_flags & O_NONBLOCK)) {
65804 /* suppress POLLHUP until we have
65805 * seen a writer */
65806 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65807 * errno=ENXIO when there is no process reading the FIFO.
65808 */
65809 ret = -ENXIO;
65810 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65811 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65812 goto err;
65813
65814 pipe->w_counter++;
65815 - if (!pipe->writers++)
65816 + if (atomic_inc_return(&pipe->writers) == 1)
65817 wake_up_partner(pipe);
65818
65819 - if (!is_pipe && !pipe->readers) {
65820 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65821 if (wait_for_partner(pipe, &pipe->r_counter))
65822 goto err_wr;
65823 }
65824 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65825 * the process can at least talk to itself.
65826 */
65827
65828 - pipe->readers++;
65829 - pipe->writers++;
65830 + atomic_inc(&pipe->readers);
65831 + atomic_inc(&pipe->writers);
65832 pipe->r_counter++;
65833 pipe->w_counter++;
65834 - if (pipe->readers == 1 || pipe->writers == 1)
65835 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65836 wake_up_partner(pipe);
65837 break;
65838
65839 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65840 return 0;
65841
65842 err_rd:
65843 - if (!--pipe->readers)
65844 + if (atomic_dec_and_test(&pipe->readers))
65845 wake_up_interruptible(&pipe->wait);
65846 ret = -ERESTARTSYS;
65847 goto err;
65848
65849 err_wr:
65850 - if (!--pipe->writers)
65851 + if (atomic_dec_and_test(&pipe->writers))
65852 wake_up_interruptible(&pipe->wait);
65853 ret = -ERESTARTSYS;
65854 goto err;
65855 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65856 index 0855f77..6787d50 100644
65857 --- a/fs/posix_acl.c
65858 +++ b/fs/posix_acl.c
65859 @@ -20,6 +20,7 @@
65860 #include <linux/xattr.h>
65861 #include <linux/export.h>
65862 #include <linux/user_namespace.h>
65863 +#include <linux/grsecurity.h>
65864
65865 struct posix_acl **acl_by_type(struct inode *inode, int type)
65866 {
65867 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65868 }
65869 }
65870 if (mode_p)
65871 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65872 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65873 return not_equiv;
65874 }
65875 EXPORT_SYMBOL(posix_acl_equiv_mode);
65876 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65877 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65878 }
65879
65880 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65881 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65882 return not_equiv;
65883 }
65884
65885 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65886 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65887 int err = -ENOMEM;
65888 if (clone) {
65889 + *mode_p &= ~gr_acl_umask();
65890 +
65891 err = posix_acl_create_masq(clone, mode_p);
65892 if (err < 0) {
65893 posix_acl_release(clone);
65894 @@ -659,11 +662,12 @@ struct posix_acl *
65895 posix_acl_from_xattr(struct user_namespace *user_ns,
65896 const void *value, size_t size)
65897 {
65898 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65899 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65900 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65901 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65902 int count;
65903 struct posix_acl *acl;
65904 struct posix_acl_entry *acl_e;
65905 + umode_t umask = gr_acl_umask();
65906
65907 if (!value)
65908 return NULL;
65909 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65910
65911 switch(acl_e->e_tag) {
65912 case ACL_USER_OBJ:
65913 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65914 + break;
65915 case ACL_GROUP_OBJ:
65916 case ACL_MASK:
65917 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65918 + break;
65919 case ACL_OTHER:
65920 + acl_e->e_perm &= ~(umask & S_IRWXO);
65921 break;
65922
65923 case ACL_USER:
65924 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65925 acl_e->e_uid =
65926 make_kuid(user_ns,
65927 le32_to_cpu(entry->e_id));
65928 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65929 goto fail;
65930 break;
65931 case ACL_GROUP:
65932 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65933 acl_e->e_gid =
65934 make_kgid(user_ns,
65935 le32_to_cpu(entry->e_id));
65936 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65937 index 2183fcf..3c32a98 100644
65938 --- a/fs/proc/Kconfig
65939 +++ b/fs/proc/Kconfig
65940 @@ -30,7 +30,7 @@ config PROC_FS
65941
65942 config PROC_KCORE
65943 bool "/proc/kcore support" if !ARM
65944 - depends on PROC_FS && MMU
65945 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65946 help
65947 Provides a virtual ELF core file of the live kernel. This can
65948 be read with gdb and other ELF tools. No modifications can be
65949 @@ -38,8 +38,8 @@ config PROC_KCORE
65950
65951 config PROC_VMCORE
65952 bool "/proc/vmcore support"
65953 - depends on PROC_FS && CRASH_DUMP
65954 - default y
65955 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65956 + default n
65957 help
65958 Exports the dump image of crashed kernel in ELF format.
65959
65960 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65961 limited in memory.
65962
65963 config PROC_PAGE_MONITOR
65964 - default y
65965 - depends on PROC_FS && MMU
65966 + default n
65967 + depends on PROC_FS && MMU && !GRKERNSEC
65968 bool "Enable /proc page monitoring" if EXPERT
65969 help
65970 Various /proc files exist to monitor process memory utilization:
65971 diff --git a/fs/proc/array.c b/fs/proc/array.c
65972 index cd3653e..9b9b79a 100644
65973 --- a/fs/proc/array.c
65974 +++ b/fs/proc/array.c
65975 @@ -60,6 +60,7 @@
65976 #include <linux/tty.h>
65977 #include <linux/string.h>
65978 #include <linux/mman.h>
65979 +#include <linux/grsecurity.h>
65980 #include <linux/proc_fs.h>
65981 #include <linux/ioport.h>
65982 #include <linux/uaccess.h>
65983 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65984 seq_putc(m, '\n');
65985 }
65986
65987 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65988 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65989 +{
65990 + if (p->mm)
65991 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65992 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65993 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65994 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65995 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65996 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65997 + else
65998 + seq_printf(m, "PaX:\t-----\n");
65999 +}
66000 +#endif
66001 +
66002 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66003 struct pid *pid, struct task_struct *task)
66004 {
66005 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66006 task_cpus_allowed(m, task);
66007 cpuset_task_status_allowed(m, task);
66008 task_context_switch_counts(m, task);
66009 +
66010 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66011 + task_pax(m, task);
66012 +#endif
66013 +
66014 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66015 + task_grsec_rbac(m, task);
66016 +#endif
66017 +
66018 return 0;
66019 }
66020
66021 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66022 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66023 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66024 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66025 +#endif
66026 +
66027 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66028 struct pid *pid, struct task_struct *task, int whole)
66029 {
66030 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66031 char tcomm[sizeof(task->comm)];
66032 unsigned long flags;
66033
66034 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66035 + if (current->exec_id != m->exec_id) {
66036 + gr_log_badprocpid("stat");
66037 + return 0;
66038 + }
66039 +#endif
66040 +
66041 state = *get_task_state(task);
66042 vsize = eip = esp = 0;
66043 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66044 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66045 gtime = task_gtime(task);
66046 }
66047
66048 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66049 + if (PAX_RAND_FLAGS(mm)) {
66050 + eip = 0;
66051 + esp = 0;
66052 + wchan = 0;
66053 + }
66054 +#endif
66055 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66056 + wchan = 0;
66057 + eip =0;
66058 + esp =0;
66059 +#endif
66060 +
66061 /* scale priority and nice values from timeslices to -20..20 */
66062 /* to make it look like a "normal" Unix priority/nice value */
66063 priority = task_prio(task);
66064 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66065 seq_put_decimal_ull(m, ' ', vsize);
66066 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66067 seq_put_decimal_ull(m, ' ', rsslim);
66068 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66069 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66070 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66071 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66072 +#else
66073 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66074 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66075 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66076 +#endif
66077 seq_put_decimal_ull(m, ' ', esp);
66078 seq_put_decimal_ull(m, ' ', eip);
66079 /* The signal information here is obsolete.
66080 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66081 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66082 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66083
66084 - if (mm && permitted) {
66085 + if (mm && permitted
66086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66087 + && !PAX_RAND_FLAGS(mm)
66088 +#endif
66089 + ) {
66090 seq_put_decimal_ull(m, ' ', mm->start_data);
66091 seq_put_decimal_ull(m, ' ', mm->end_data);
66092 seq_put_decimal_ull(m, ' ', mm->start_brk);
66093 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66094 struct pid *pid, struct task_struct *task)
66095 {
66096 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66097 - struct mm_struct *mm = get_task_mm(task);
66098 + struct mm_struct *mm;
66099
66100 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66101 + if (current->exec_id != m->exec_id) {
66102 + gr_log_badprocpid("statm");
66103 + return 0;
66104 + }
66105 +#endif
66106 + mm = get_task_mm(task);
66107 if (mm) {
66108 size = task_statm(mm, &shared, &text, &data, &resident);
66109 mmput(mm);
66110 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66111 return 0;
66112 }
66113
66114 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66115 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
66116 +{
66117 + unsigned long flags;
66118 + u32 curr_ip = 0;
66119 +
66120 + if (lock_task_sighand(task, &flags)) {
66121 + curr_ip = task->signal->curr_ip;
66122 + unlock_task_sighand(task, &flags);
66123 + }
66124 + return seq_printf(m, "%pI4\n", &curr_ip);
66125 +}
66126 +#endif
66127 +
66128 #ifdef CONFIG_CHECKPOINT_RESTORE
66129 static struct pid *
66130 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66131 diff --git a/fs/proc/base.c b/fs/proc/base.c
66132 index baf852b..03fe930 100644
66133 --- a/fs/proc/base.c
66134 +++ b/fs/proc/base.c
66135 @@ -113,6 +113,14 @@ struct pid_entry {
66136 union proc_op op;
66137 };
66138
66139 +struct getdents_callback {
66140 + struct linux_dirent __user * current_dir;
66141 + struct linux_dirent __user * previous;
66142 + struct file * file;
66143 + int count;
66144 + int error;
66145 +};
66146 +
66147 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66148 .name = (NAME), \
66149 .len = sizeof(NAME) - 1, \
66150 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
66151 return 0;
66152 }
66153
66154 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66155 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66156 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66157 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66158 +#endif
66159 +
66160 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66161 struct pid *pid, struct task_struct *task)
66162 {
66163 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66164 if (mm && !IS_ERR(mm)) {
66165 unsigned int nwords = 0;
66166 +
66167 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66168 + /* allow if we're currently ptracing this task */
66169 + if (PAX_RAND_FLAGS(mm) &&
66170 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66171 + mmput(mm);
66172 + return 0;
66173 + }
66174 +#endif
66175 +
66176 do {
66177 nwords += 2;
66178 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66179 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66180 }
66181
66182
66183 -#ifdef CONFIG_KALLSYMS
66184 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66185 /*
66186 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66187 * Returns the resolved symbol. If that fails, simply return the address.
66188 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66189 mutex_unlock(&task->signal->cred_guard_mutex);
66190 }
66191
66192 -#ifdef CONFIG_STACKTRACE
66193 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66194
66195 #define MAX_STACK_TRACE_DEPTH 64
66196
66197 @@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66198 return 0;
66199 }
66200
66201 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66202 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66203 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66204 struct pid *pid, struct task_struct *task)
66205 {
66206 @@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66207 /************************************************************************/
66208
66209 /* permission checks */
66210 -static int proc_fd_access_allowed(struct inode *inode)
66211 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66212 {
66213 struct task_struct *task;
66214 int allowed = 0;
66215 @@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66216 */
66217 task = get_proc_task(inode);
66218 if (task) {
66219 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66220 + if (log)
66221 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66222 + else
66223 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66224 put_task_struct(task);
66225 }
66226 return allowed;
66227 @@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66228 struct task_struct *task,
66229 int hide_pid_min)
66230 {
66231 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66232 + return false;
66233 +
66234 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66235 + rcu_read_lock();
66236 + {
66237 + const struct cred *tmpcred = current_cred();
66238 + const struct cred *cred = __task_cred(task);
66239 +
66240 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66241 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66242 + || in_group_p(grsec_proc_gid)
66243 +#endif
66244 + ) {
66245 + rcu_read_unlock();
66246 + return true;
66247 + }
66248 + }
66249 + rcu_read_unlock();
66250 +
66251 + if (!pid->hide_pid)
66252 + return false;
66253 +#endif
66254 +
66255 if (pid->hide_pid < hide_pid_min)
66256 return true;
66257 if (in_group_p(pid->pid_gid))
66258 return true;
66259 +
66260 return ptrace_may_access(task, PTRACE_MODE_READ);
66261 }
66262
66263 @@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66264 put_task_struct(task);
66265
66266 if (!has_perms) {
66267 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66268 + {
66269 +#else
66270 if (pid->hide_pid == 2) {
66271 +#endif
66272 /*
66273 * Let's make getdents(), stat(), and open()
66274 * consistent with each other. If a process
66275 @@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66276 if (!task)
66277 return -ESRCH;
66278
66279 + if (gr_acl_handle_procpidmem(task)) {
66280 + put_task_struct(task);
66281 + return -EPERM;
66282 + }
66283 +
66284 mm = mm_access(task, mode);
66285 put_task_struct(task);
66286
66287 @@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66288
66289 file->private_data = mm;
66290
66291 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66292 + file->f_version = current->exec_id;
66293 +#endif
66294 +
66295 return 0;
66296 }
66297
66298 @@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66299 ssize_t copied;
66300 char *page;
66301
66302 +#ifdef CONFIG_GRKERNSEC
66303 + if (write)
66304 + return -EPERM;
66305 +#endif
66306 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66307 + if (file->f_version != current->exec_id) {
66308 + gr_log_badprocpid("mem");
66309 + return 0;
66310 + }
66311 +#endif
66312 +
66313 if (!mm)
66314 return 0;
66315
66316 @@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66317 goto free;
66318
66319 while (count > 0) {
66320 - int this_len = min_t(int, count, PAGE_SIZE);
66321 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66322
66323 if (write && copy_from_user(page, buf, this_len)) {
66324 copied = -EFAULT;
66325 @@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66326 if (!mm)
66327 return 0;
66328
66329 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66330 + if (file->f_version != current->exec_id) {
66331 + gr_log_badprocpid("environ");
66332 + return 0;
66333 + }
66334 +#endif
66335 +
66336 page = (char *)__get_free_page(GFP_TEMPORARY);
66337 if (!page)
66338 return -ENOMEM;
66339 @@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66340 goto free;
66341 while (count > 0) {
66342 size_t this_len, max_len;
66343 - int retval;
66344 + ssize_t retval;
66345
66346 if (src >= (mm->env_end - mm->env_start))
66347 break;
66348 @@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66349 int error = -EACCES;
66350
66351 /* Are we allowed to snoop on the tasks file descriptors? */
66352 - if (!proc_fd_access_allowed(inode))
66353 + if (!proc_fd_access_allowed(inode, 0))
66354 goto out;
66355
66356 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66357 @@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66358 struct path path;
66359
66360 /* Are we allowed to snoop on the tasks file descriptors? */
66361 - if (!proc_fd_access_allowed(inode))
66362 - goto out;
66363 + /* logging this is needed for learning on chromium to work properly,
66364 + but we don't want to flood the logs from 'ps' which does a readlink
66365 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66366 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66367 + */
66368 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66369 + if (!proc_fd_access_allowed(inode,0))
66370 + goto out;
66371 + } else {
66372 + if (!proc_fd_access_allowed(inode,1))
66373 + goto out;
66374 + }
66375
66376 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66377 if (error)
66378 @@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66379 rcu_read_lock();
66380 cred = __task_cred(task);
66381 inode->i_uid = cred->euid;
66382 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66383 + inode->i_gid = grsec_proc_gid;
66384 +#else
66385 inode->i_gid = cred->egid;
66386 +#endif
66387 rcu_read_unlock();
66388 }
66389 security_task_to_inode(task, inode);
66390 @@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66391 return -ENOENT;
66392 }
66393 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66394 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66395 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66396 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66397 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66398 +#endif
66399 task_dumpable(task)) {
66400 cred = __task_cred(task);
66401 stat->uid = cred->euid;
66402 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66403 + stat->gid = grsec_proc_gid;
66404 +#else
66405 stat->gid = cred->egid;
66406 +#endif
66407 }
66408 }
66409 rcu_read_unlock();
66410 @@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66411
66412 if (task) {
66413 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66414 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66415 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66416 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66417 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66418 +#endif
66419 task_dumpable(task)) {
66420 rcu_read_lock();
66421 cred = __task_cred(task);
66422 inode->i_uid = cred->euid;
66423 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66424 + inode->i_gid = grsec_proc_gid;
66425 +#else
66426 inode->i_gid = cred->egid;
66427 +#endif
66428 rcu_read_unlock();
66429 } else {
66430 inode->i_uid = GLOBAL_ROOT_UID;
66431 @@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66432 if (!task)
66433 goto out_no_task;
66434
66435 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66436 + goto out;
66437 +
66438 /*
66439 * Yes, it does not scale. And it should not. Don't add
66440 * new entries into /proc/<tgid>/ without very good reasons.
66441 @@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66442 if (!task)
66443 return -ENOENT;
66444
66445 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66446 + goto out;
66447 +
66448 if (!dir_emit_dots(file, ctx))
66449 goto out;
66450
66451 @@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66452 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66453 #endif
66454 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66455 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66456 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66457 ONE("syscall", S_IRUSR, proc_pid_syscall),
66458 #endif
66459 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66460 @@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66461 #ifdef CONFIG_SECURITY
66462 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66463 #endif
66464 -#ifdef CONFIG_KALLSYMS
66465 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66466 ONE("wchan", S_IRUGO, proc_pid_wchan),
66467 #endif
66468 -#ifdef CONFIG_STACKTRACE
66469 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66470 ONE("stack", S_IRUSR, proc_pid_stack),
66471 #endif
66472 #ifdef CONFIG_SCHEDSTATS
66473 @@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66474 #ifdef CONFIG_HARDWALL
66475 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66476 #endif
66477 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66478 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66479 +#endif
66480 #ifdef CONFIG_USER_NS
66481 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66482 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66483 @@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66484 if (!inode)
66485 goto out;
66486
66487 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66488 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66489 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66490 + inode->i_gid = grsec_proc_gid;
66491 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66492 +#else
66493 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66494 +#endif
66495 inode->i_op = &proc_tgid_base_inode_operations;
66496 inode->i_fop = &proc_tgid_base_operations;
66497 inode->i_flags|=S_IMMUTABLE;
66498 @@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66499 if (!task)
66500 goto out;
66501
66502 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66503 + goto out_put_task;
66504 +
66505 result = proc_pid_instantiate(dir, dentry, task, NULL);
66506 +out_put_task:
66507 put_task_struct(task);
66508 out:
66509 return ERR_PTR(result);
66510 @@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66511 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66512 #endif
66513 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66514 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66515 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66516 ONE("syscall", S_IRUSR, proc_pid_syscall),
66517 #endif
66518 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66519 @@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66520 #ifdef CONFIG_SECURITY
66521 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66522 #endif
66523 -#ifdef CONFIG_KALLSYMS
66524 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66525 ONE("wchan", S_IRUGO, proc_pid_wchan),
66526 #endif
66527 -#ifdef CONFIG_STACKTRACE
66528 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66529 ONE("stack", S_IRUSR, proc_pid_stack),
66530 #endif
66531 #ifdef CONFIG_SCHEDSTATS
66532 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66533 index cbd82df..c0407d2 100644
66534 --- a/fs/proc/cmdline.c
66535 +++ b/fs/proc/cmdline.c
66536 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66537
66538 static int __init proc_cmdline_init(void)
66539 {
66540 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66541 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66542 +#else
66543 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66544 +#endif
66545 return 0;
66546 }
66547 fs_initcall(proc_cmdline_init);
66548 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66549 index 50493ed..248166b 100644
66550 --- a/fs/proc/devices.c
66551 +++ b/fs/proc/devices.c
66552 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66553
66554 static int __init proc_devices_init(void)
66555 {
66556 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66557 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66558 +#else
66559 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66560 +#endif
66561 return 0;
66562 }
66563 fs_initcall(proc_devices_init);
66564 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66565 index 955bb55..71948bd 100644
66566 --- a/fs/proc/fd.c
66567 +++ b/fs/proc/fd.c
66568 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66569 if (!task)
66570 return -ENOENT;
66571
66572 - files = get_files_struct(task);
66573 + if (!gr_acl_handle_procpidmem(task))
66574 + files = get_files_struct(task);
66575 put_task_struct(task);
66576
66577 if (files) {
66578 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66579 */
66580 int proc_fd_permission(struct inode *inode, int mask)
66581 {
66582 + struct task_struct *task;
66583 int rv = generic_permission(inode, mask);
66584 - if (rv == 0)
66585 - return 0;
66586 +
66587 if (task_tgid(current) == proc_pid(inode))
66588 rv = 0;
66589 +
66590 + task = get_proc_task(inode);
66591 + if (task == NULL)
66592 + return rv;
66593 +
66594 + if (gr_acl_handle_procpidmem(task))
66595 + rv = -EACCES;
66596 +
66597 + put_task_struct(task);
66598 +
66599 return rv;
66600 }
66601
66602 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66603 index 317b726..e329aed 100644
66604 --- a/fs/proc/generic.c
66605 +++ b/fs/proc/generic.c
66606 @@ -23,6 +23,7 @@
66607 #include <linux/bitops.h>
66608 #include <linux/spinlock.h>
66609 #include <linux/completion.h>
66610 +#include <linux/grsecurity.h>
66611 #include <asm/uaccess.h>
66612
66613 #include "internal.h"
66614 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66615 return proc_lookup_de(PDE(dir), dir, dentry);
66616 }
66617
66618 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66619 + unsigned int flags)
66620 +{
66621 + if (gr_proc_is_restricted())
66622 + return ERR_PTR(-EACCES);
66623 +
66624 + return proc_lookup_de(PDE(dir), dir, dentry);
66625 +}
66626 +
66627 /*
66628 * This returns non-zero if at EOF, so that the /proc
66629 * root directory can use this and check if it should
66630 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66631 return proc_readdir_de(PDE(inode), file, ctx);
66632 }
66633
66634 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66635 +{
66636 + struct inode *inode = file_inode(file);
66637 +
66638 + if (gr_proc_is_restricted())
66639 + return -EACCES;
66640 +
66641 + return proc_readdir_de(PDE(inode), file, ctx);
66642 +}
66643 +
66644 /*
66645 * These are the generic /proc directory operations. They
66646 * use the in-memory "struct proc_dir_entry" tree to parse
66647 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66648 .iterate = proc_readdir,
66649 };
66650
66651 +static const struct file_operations proc_dir_restricted_operations = {
66652 + .llseek = generic_file_llseek,
66653 + .read = generic_read_dir,
66654 + .iterate = proc_readdir_restrict,
66655 +};
66656 +
66657 /*
66658 * proc directories can do almost nothing..
66659 */
66660 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66661 .setattr = proc_notify_change,
66662 };
66663
66664 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66665 + .lookup = proc_lookup_restrict,
66666 + .getattr = proc_getattr,
66667 + .setattr = proc_notify_change,
66668 +};
66669 +
66670 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66671 {
66672 struct proc_dir_entry *tmp;
66673 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66674 return ret;
66675
66676 if (S_ISDIR(dp->mode)) {
66677 - dp->proc_fops = &proc_dir_operations;
66678 - dp->proc_iops = &proc_dir_inode_operations;
66679 + if (dp->restricted) {
66680 + dp->proc_fops = &proc_dir_restricted_operations;
66681 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66682 + } else {
66683 + dp->proc_fops = &proc_dir_operations;
66684 + dp->proc_iops = &proc_dir_inode_operations;
66685 + }
66686 dir->nlink++;
66687 } else if (S_ISLNK(dp->mode)) {
66688 dp->proc_iops = &proc_link_inode_operations;
66689 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66690 }
66691 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66692
66693 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66694 + struct proc_dir_entry *parent, void *data)
66695 +{
66696 + struct proc_dir_entry *ent;
66697 +
66698 + if (mode == 0)
66699 + mode = S_IRUGO | S_IXUGO;
66700 +
66701 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66702 + if (ent) {
66703 + ent->data = data;
66704 + ent->restricted = 1;
66705 + if (proc_register(parent, ent) < 0) {
66706 + kfree(ent);
66707 + ent = NULL;
66708 + }
66709 + }
66710 + return ent;
66711 +}
66712 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66713 +
66714 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66715 struct proc_dir_entry *parent)
66716 {
66717 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66718 }
66719 EXPORT_SYMBOL(proc_mkdir);
66720
66721 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66722 + struct proc_dir_entry *parent)
66723 +{
66724 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66725 +}
66726 +EXPORT_SYMBOL(proc_mkdir_restrict);
66727 +
66728 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66729 struct proc_dir_entry *parent,
66730 const struct file_operations *proc_fops,
66731 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66732 index 333080d..0a35ec4 100644
66733 --- a/fs/proc/inode.c
66734 +++ b/fs/proc/inode.c
66735 @@ -23,11 +23,17 @@
66736 #include <linux/slab.h>
66737 #include <linux/mount.h>
66738 #include <linux/magic.h>
66739 +#include <linux/grsecurity.h>
66740
66741 #include <asm/uaccess.h>
66742
66743 #include "internal.h"
66744
66745 +#ifdef CONFIG_PROC_SYSCTL
66746 +extern const struct inode_operations proc_sys_inode_operations;
66747 +extern const struct inode_operations proc_sys_dir_operations;
66748 +#endif
66749 +
66750 static void proc_evict_inode(struct inode *inode)
66751 {
66752 struct proc_dir_entry *de;
66753 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66754 ns = PROC_I(inode)->ns.ns;
66755 if (ns_ops && ns)
66756 ns_ops->put(ns);
66757 +
66758 +#ifdef CONFIG_PROC_SYSCTL
66759 + if (inode->i_op == &proc_sys_inode_operations ||
66760 + inode->i_op == &proc_sys_dir_operations)
66761 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66762 +#endif
66763 +
66764 }
66765
66766 static struct kmem_cache * proc_inode_cachep;
66767 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66768 if (de->mode) {
66769 inode->i_mode = de->mode;
66770 inode->i_uid = de->uid;
66771 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66772 + inode->i_gid = grsec_proc_gid;
66773 +#else
66774 inode->i_gid = de->gid;
66775 +#endif
66776 }
66777 if (de->size)
66778 inode->i_size = de->size;
66779 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66780 index 7da13e4..68d0981 100644
66781 --- a/fs/proc/internal.h
66782 +++ b/fs/proc/internal.h
66783 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66784 struct completion *pde_unload_completion;
66785 struct list_head pde_openers; /* who did ->open, but not ->release */
66786 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66787 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66788 u8 namelen;
66789 char name[];
66790 -};
66791 +} __randomize_layout;
66792
66793 union proc_op {
66794 int (*proc_get_link)(struct dentry *, struct path *);
66795 @@ -66,7 +67,7 @@ struct proc_inode {
66796 struct ctl_table *sysctl_entry;
66797 struct proc_ns ns;
66798 struct inode vfs_inode;
66799 -};
66800 +} __randomize_layout;
66801
66802 /*
66803 * General functions
66804 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66805 struct pid *, struct task_struct *);
66806 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66807 struct pid *, struct task_struct *);
66808 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66809 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66810 + struct pid *, struct task_struct *);
66811 +#endif
66812
66813 /*
66814 * base.c
66815 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66816 * generic.c
66817 */
66818 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66819 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66820 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66821 struct dentry *);
66822 extern int proc_readdir(struct file *, struct dir_context *);
66823 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66824 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66825
66826 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66827 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66828 index a352d57..cb94a5c 100644
66829 --- a/fs/proc/interrupts.c
66830 +++ b/fs/proc/interrupts.c
66831 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66832
66833 static int __init proc_interrupts_init(void)
66834 {
66835 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66836 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66837 +#else
66838 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66839 +#endif
66840 return 0;
66841 }
66842 fs_initcall(proc_interrupts_init);
66843 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66844 index 6df8d07..3321060 100644
66845 --- a/fs/proc/kcore.c
66846 +++ b/fs/proc/kcore.c
66847 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66848 * the addresses in the elf_phdr on our list.
66849 */
66850 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66851 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66852 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66853 + if (tsz > buflen)
66854 tsz = buflen;
66855 -
66856 +
66857 while (buflen) {
66858 struct kcore_list *m;
66859
66860 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66861 kfree(elf_buf);
66862 } else {
66863 if (kern_addr_valid(start)) {
66864 - unsigned long n;
66865 + char *elf_buf;
66866 + mm_segment_t oldfs;
66867
66868 - n = copy_to_user(buffer, (char *)start, tsz);
66869 - /*
66870 - * We cannot distinguish between fault on source
66871 - * and fault on destination. When this happens
66872 - * we clear too and hope it will trigger the
66873 - * EFAULT again.
66874 - */
66875 - if (n) {
66876 - if (clear_user(buffer + tsz - n,
66877 - n))
66878 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66879 + if (!elf_buf)
66880 + return -ENOMEM;
66881 + oldfs = get_fs();
66882 + set_fs(KERNEL_DS);
66883 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66884 + set_fs(oldfs);
66885 + if (copy_to_user(buffer, elf_buf, tsz)) {
66886 + kfree(elf_buf);
66887 return -EFAULT;
66888 + }
66889 }
66890 + set_fs(oldfs);
66891 + kfree(elf_buf);
66892 } else {
66893 if (clear_user(buffer, tsz))
66894 return -EFAULT;
66895 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66896
66897 static int open_kcore(struct inode *inode, struct file *filp)
66898 {
66899 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66900 + return -EPERM;
66901 +#endif
66902 if (!capable(CAP_SYS_RAWIO))
66903 return -EPERM;
66904 if (kcore_need_update)
66905 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66906 index aa1eee0..03dda72 100644
66907 --- a/fs/proc/meminfo.c
66908 +++ b/fs/proc/meminfo.c
66909 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66910 vmi.used >> 10,
66911 vmi.largest_chunk >> 10
66912 #ifdef CONFIG_MEMORY_FAILURE
66913 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66914 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66915 #endif
66916 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66917 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66918 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66919 index d4a3574..b421ce9 100644
66920 --- a/fs/proc/nommu.c
66921 +++ b/fs/proc/nommu.c
66922 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66923
66924 if (file) {
66925 seq_pad(m, ' ');
66926 - seq_path(m, &file->f_path, "");
66927 + seq_path(m, &file->f_path, "\n\\");
66928 }
66929
66930 seq_putc(m, '\n');
66931 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66932 index a63af3e..b4f262a 100644
66933 --- a/fs/proc/proc_net.c
66934 +++ b/fs/proc/proc_net.c
66935 @@ -23,9 +23,27 @@
66936 #include <linux/nsproxy.h>
66937 #include <net/net_namespace.h>
66938 #include <linux/seq_file.h>
66939 +#include <linux/grsecurity.h>
66940
66941 #include "internal.h"
66942
66943 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66944 +static struct seq_operations *ipv6_seq_ops_addr;
66945 +
66946 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66947 +{
66948 + ipv6_seq_ops_addr = addr;
66949 +}
66950 +
66951 +void unregister_ipv6_seq_ops_addr(void)
66952 +{
66953 + ipv6_seq_ops_addr = NULL;
66954 +}
66955 +
66956 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66957 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66958 +#endif
66959 +
66960 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66961 {
66962 return pde->parent->data;
66963 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66964 return maybe_get_net(PDE_NET(PDE(inode)));
66965 }
66966
66967 +extern const struct seq_operations dev_seq_ops;
66968 +
66969 int seq_open_net(struct inode *ino, struct file *f,
66970 const struct seq_operations *ops, int size)
66971 {
66972 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66973
66974 BUG_ON(size < sizeof(*p));
66975
66976 + /* only permit access to /proc/net/dev */
66977 + if (
66978 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66979 + ops != ipv6_seq_ops_addr &&
66980 +#endif
66981 + ops != &dev_seq_ops && gr_proc_is_restricted())
66982 + return -EACCES;
66983 +
66984 net = get_proc_net(ino);
66985 if (net == NULL)
66986 return -ENXIO;
66987 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66988 int err;
66989 struct net *net;
66990
66991 + if (gr_proc_is_restricted())
66992 + return -EACCES;
66993 +
66994 err = -ENXIO;
66995 net = get_proc_net(inode);
66996 if (net == NULL)
66997 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66998 index f92d5dd..26398ac 100644
66999 --- a/fs/proc/proc_sysctl.c
67000 +++ b/fs/proc/proc_sysctl.c
67001 @@ -11,13 +11,21 @@
67002 #include <linux/namei.h>
67003 #include <linux/mm.h>
67004 #include <linux/module.h>
67005 +#include <linux/nsproxy.h>
67006 +#ifdef CONFIG_GRKERNSEC
67007 +#include <net/net_namespace.h>
67008 +#endif
67009 #include "internal.h"
67010
67011 +extern int gr_handle_chroot_sysctl(const int op);
67012 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67013 + const int op);
67014 +
67015 static const struct dentry_operations proc_sys_dentry_operations;
67016 static const struct file_operations proc_sys_file_operations;
67017 -static const struct inode_operations proc_sys_inode_operations;
67018 +const struct inode_operations proc_sys_inode_operations;
67019 static const struct file_operations proc_sys_dir_file_operations;
67020 -static const struct inode_operations proc_sys_dir_operations;
67021 +const struct inode_operations proc_sys_dir_operations;
67022
67023 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67024 {
67025 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67026
67027 err = NULL;
67028 d_set_d_op(dentry, &proc_sys_dentry_operations);
67029 +
67030 + gr_handle_proc_create(dentry, inode);
67031 +
67032 d_add(dentry, inode);
67033
67034 out:
67035 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67036 struct inode *inode = file_inode(filp);
67037 struct ctl_table_header *head = grab_header(inode);
67038 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67039 + int op = write ? MAY_WRITE : MAY_READ;
67040 ssize_t error;
67041 size_t res;
67042
67043 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67044 * and won't be until we finish.
67045 */
67046 error = -EPERM;
67047 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67048 + if (sysctl_perm(head, table, op))
67049 goto out;
67050
67051 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67052 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67053 if (!table->proc_handler)
67054 goto out;
67055
67056 +#ifdef CONFIG_GRKERNSEC
67057 + error = -EPERM;
67058 + if (gr_handle_chroot_sysctl(op))
67059 + goto out;
67060 + dget(filp->f_path.dentry);
67061 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67062 + dput(filp->f_path.dentry);
67063 + goto out;
67064 + }
67065 + dput(filp->f_path.dentry);
67066 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67067 + goto out;
67068 + if (write) {
67069 + if (current->nsproxy->net_ns != table->extra2) {
67070 + if (!capable(CAP_SYS_ADMIN))
67071 + goto out;
67072 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67073 + goto out;
67074 + }
67075 +#endif
67076 +
67077 /* careful: calling conventions are nasty here */
67078 res = count;
67079 error = table->proc_handler(table, write, buf, &res, ppos);
67080 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67081 return false;
67082 } else {
67083 d_set_d_op(child, &proc_sys_dentry_operations);
67084 +
67085 + gr_handle_proc_create(child, inode);
67086 +
67087 d_add(child, inode);
67088 }
67089 } else {
67090 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
67091 if ((*pos)++ < ctx->pos)
67092 return true;
67093
67094 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67095 + return 0;
67096 +
67097 if (unlikely(S_ISLNK(table->mode)))
67098 res = proc_sys_link_fill_cache(file, ctx, head, table);
67099 else
67100 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67101 if (IS_ERR(head))
67102 return PTR_ERR(head);
67103
67104 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67105 + return -ENOENT;
67106 +
67107 generic_fillattr(inode, stat);
67108 if (table)
67109 stat->mode = (stat->mode & S_IFMT) | table->mode;
67110 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67111 .llseek = generic_file_llseek,
67112 };
67113
67114 -static const struct inode_operations proc_sys_inode_operations = {
67115 +const struct inode_operations proc_sys_inode_operations = {
67116 .permission = proc_sys_permission,
67117 .setattr = proc_sys_setattr,
67118 .getattr = proc_sys_getattr,
67119 };
67120
67121 -static const struct inode_operations proc_sys_dir_operations = {
67122 +const struct inode_operations proc_sys_dir_operations = {
67123 .lookup = proc_sys_lookup,
67124 .permission = proc_sys_permission,
67125 .setattr = proc_sys_setattr,
67126 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67127 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67128 const char *name, int namelen)
67129 {
67130 - struct ctl_table *table;
67131 + ctl_table_no_const *table;
67132 struct ctl_dir *new;
67133 struct ctl_node *node;
67134 char *new_name;
67135 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67136 return NULL;
67137
67138 node = (struct ctl_node *)(new + 1);
67139 - table = (struct ctl_table *)(node + 1);
67140 + table = (ctl_table_no_const *)(node + 1);
67141 new_name = (char *)(table + 2);
67142 memcpy(new_name, name, namelen);
67143 new_name[namelen] = '\0';
67144 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67145 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67146 struct ctl_table_root *link_root)
67147 {
67148 - struct ctl_table *link_table, *entry, *link;
67149 + ctl_table_no_const *link_table, *link;
67150 + struct ctl_table *entry;
67151 struct ctl_table_header *links;
67152 struct ctl_node *node;
67153 char *link_name;
67154 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67155 return NULL;
67156
67157 node = (struct ctl_node *)(links + 1);
67158 - link_table = (struct ctl_table *)(node + nr_entries);
67159 + link_table = (ctl_table_no_const *)(node + nr_entries);
67160 link_name = (char *)&link_table[nr_entries + 1];
67161
67162 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67163 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67164 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67165 struct ctl_table *table)
67166 {
67167 - struct ctl_table *ctl_table_arg = NULL;
67168 - struct ctl_table *entry, *files;
67169 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67170 + struct ctl_table *entry;
67171 int nr_files = 0;
67172 int nr_dirs = 0;
67173 int err = -ENOMEM;
67174 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67175 nr_files++;
67176 }
67177
67178 - files = table;
67179 /* If there are mixed files and directories we need a new table */
67180 if (nr_dirs && nr_files) {
67181 - struct ctl_table *new;
67182 + ctl_table_no_const *new;
67183 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67184 GFP_KERNEL);
67185 if (!files)
67186 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67187 /* Register everything except a directory full of subdirectories */
67188 if (nr_files || !nr_dirs) {
67189 struct ctl_table_header *header;
67190 - header = __register_sysctl_table(set, path, files);
67191 + header = __register_sysctl_table(set, path, files ? files : table);
67192 if (!header) {
67193 kfree(ctl_table_arg);
67194 goto out;
67195 diff --git a/fs/proc/root.c b/fs/proc/root.c
67196 index 094e44d..085a877 100644
67197 --- a/fs/proc/root.c
67198 +++ b/fs/proc/root.c
67199 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
67200 proc_mkdir("openprom", NULL);
67201 #endif
67202 proc_tty_init();
67203 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67204 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67205 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67206 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67207 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67208 +#endif
67209 +#else
67210 proc_mkdir("bus", NULL);
67211 +#endif
67212 proc_sys_init();
67213 }
67214
67215 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67216 index bf2d03f..f058f9c 100644
67217 --- a/fs/proc/stat.c
67218 +++ b/fs/proc/stat.c
67219 @@ -11,6 +11,7 @@
67220 #include <linux/irqnr.h>
67221 #include <linux/cputime.h>
67222 #include <linux/tick.h>
67223 +#include <linux/grsecurity.h>
67224
67225 #ifndef arch_irq_stat_cpu
67226 #define arch_irq_stat_cpu(cpu) 0
67227 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67228 u64 sum_softirq = 0;
67229 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67230 struct timespec boottime;
67231 + int unrestricted = 1;
67232 +
67233 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67234 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67235 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67236 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67237 + && !in_group_p(grsec_proc_gid)
67238 +#endif
67239 + )
67240 + unrestricted = 0;
67241 +#endif
67242 +#endif
67243
67244 user = nice = system = idle = iowait =
67245 irq = softirq = steal = 0;
67246 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67247 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67248 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67249 idle += get_idle_time(i);
67250 - iowait += get_iowait_time(i);
67251 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67252 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67253 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67254 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67255 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67256 - sum += kstat_cpu_irqs_sum(i);
67257 - sum += arch_irq_stat_cpu(i);
67258 + if (unrestricted) {
67259 + iowait += get_iowait_time(i);
67260 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67261 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67262 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67263 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67264 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67265 + sum += kstat_cpu_irqs_sum(i);
67266 + sum += arch_irq_stat_cpu(i);
67267 + for (j = 0; j < NR_SOFTIRQS; j++) {
67268 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67269
67270 - for (j = 0; j < NR_SOFTIRQS; j++) {
67271 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67272 -
67273 - per_softirq_sums[j] += softirq_stat;
67274 - sum_softirq += softirq_stat;
67275 + per_softirq_sums[j] += softirq_stat;
67276 + sum_softirq += softirq_stat;
67277 + }
67278 }
67279 }
67280 - sum += arch_irq_stat();
67281 + if (unrestricted)
67282 + sum += arch_irq_stat();
67283
67284 seq_puts(p, "cpu ");
67285 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67286 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67287 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67288 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67289 idle = get_idle_time(i);
67290 - iowait = get_iowait_time(i);
67291 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67292 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67293 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67294 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67295 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67296 + if (unrestricted) {
67297 + iowait = get_iowait_time(i);
67298 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67299 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67300 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67301 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67302 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67303 + }
67304 seq_printf(p, "cpu%d", i);
67305 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67306 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67307 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67308
67309 /* sum again ? it could be updated? */
67310 for_each_irq_nr(j)
67311 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67312 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67313
67314 seq_printf(p,
67315 "\nctxt %llu\n"
67316 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67317 "processes %lu\n"
67318 "procs_running %lu\n"
67319 "procs_blocked %lu\n",
67320 - nr_context_switches(),
67321 + unrestricted ? nr_context_switches() : 0ULL,
67322 (unsigned long)jif,
67323 - total_forks,
67324 - nr_running(),
67325 - nr_iowait());
67326 + unrestricted ? total_forks : 0UL,
67327 + unrestricted ? nr_running() : 0UL,
67328 + unrestricted ? nr_iowait() : 0UL);
67329
67330 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67331
67332 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67333 index c341568..75852a2 100644
67334 --- a/fs/proc/task_mmu.c
67335 +++ b/fs/proc/task_mmu.c
67336 @@ -13,12 +13,19 @@
67337 #include <linux/swap.h>
67338 #include <linux/swapops.h>
67339 #include <linux/mmu_notifier.h>
67340 +#include <linux/grsecurity.h>
67341
67342 #include <asm/elf.h>
67343 #include <asm/uaccess.h>
67344 #include <asm/tlbflush.h>
67345 #include "internal.h"
67346
67347 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67348 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67349 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67350 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67351 +#endif
67352 +
67353 void task_mem(struct seq_file *m, struct mm_struct *mm)
67354 {
67355 unsigned long data, text, lib, swap;
67356 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67357 "VmExe:\t%8lu kB\n"
67358 "VmLib:\t%8lu kB\n"
67359 "VmPTE:\t%8lu kB\n"
67360 - "VmSwap:\t%8lu kB\n",
67361 - hiwater_vm << (PAGE_SHIFT-10),
67362 + "VmSwap:\t%8lu kB\n"
67363 +
67364 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67365 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67366 +#endif
67367 +
67368 + ,hiwater_vm << (PAGE_SHIFT-10),
67369 total_vm << (PAGE_SHIFT-10),
67370 mm->locked_vm << (PAGE_SHIFT-10),
67371 mm->pinned_vm << (PAGE_SHIFT-10),
67372 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67373 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67374 (PTRS_PER_PTE * sizeof(pte_t) *
67375 atomic_long_read(&mm->nr_ptes)) >> 10,
67376 - swap << (PAGE_SHIFT-10));
67377 + swap << (PAGE_SHIFT-10)
67378 +
67379 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67380 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67381 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67382 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67383 +#else
67384 + , mm->context.user_cs_base
67385 + , mm->context.user_cs_limit
67386 +#endif
67387 +#endif
67388 +
67389 + );
67390 }
67391
67392 unsigned long task_vsize(struct mm_struct *mm)
67393 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67394 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67395 }
67396
67397 - /* We don't show the stack guard page in /proc/maps */
67398 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67399 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67400 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67401 +#else
67402 start = vma->vm_start;
67403 - if (stack_guard_page_start(vma, start))
67404 - start += PAGE_SIZE;
67405 end = vma->vm_end;
67406 - if (stack_guard_page_end(vma, end))
67407 - end -= PAGE_SIZE;
67408 +#endif
67409
67410 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67411 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67412 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67413 flags & VM_WRITE ? 'w' : '-',
67414 flags & VM_EXEC ? 'x' : '-',
67415 flags & VM_MAYSHARE ? 's' : 'p',
67416 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67417 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67418 +#else
67419 pgoff,
67420 +#endif
67421 MAJOR(dev), MINOR(dev), ino);
67422
67423 /*
67424 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67425 */
67426 if (file) {
67427 seq_pad(m, ' ');
67428 - seq_path(m, &file->f_path, "\n");
67429 + seq_path(m, &file->f_path, "\n\\");
67430 goto done;
67431 }
67432
67433 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67434 * Thread stack in /proc/PID/task/TID/maps or
67435 * the main process stack.
67436 */
67437 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67438 - vma->vm_end >= mm->start_stack)) {
67439 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67440 + (vma->vm_start <= mm->start_stack &&
67441 + vma->vm_end >= mm->start_stack)) {
67442 name = "[stack]";
67443 } else {
67444 /* Thread stack in /proc/PID/maps */
67445 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67446 struct proc_maps_private *priv = m->private;
67447 struct task_struct *task = priv->task;
67448
67449 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67450 + if (current->exec_id != m->exec_id) {
67451 + gr_log_badprocpid("maps");
67452 + return 0;
67453 + }
67454 +#endif
67455 +
67456 show_map_vma(m, vma, is_pid);
67457
67458 if (m->count < m->size) /* vma is copied successfully */
67459 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67460 .private = &mss,
67461 };
67462
67463 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67464 + if (current->exec_id != m->exec_id) {
67465 + gr_log_badprocpid("smaps");
67466 + return 0;
67467 + }
67468 +#endif
67469 memset(&mss, 0, sizeof mss);
67470 - mss.vma = vma;
67471 - /* mmap_sem is held in m_start */
67472 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67473 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67474 -
67475 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67476 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67477 +#endif
67478 + mss.vma = vma;
67479 + /* mmap_sem is held in m_start */
67480 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67481 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67482 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67483 + }
67484 +#endif
67485 show_map_vma(m, vma, is_pid);
67486
67487 seq_printf(m,
67488 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67489 "KernelPageSize: %8lu kB\n"
67490 "MMUPageSize: %8lu kB\n"
67491 "Locked: %8lu kB\n",
67492 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67493 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67494 +#else
67495 (vma->vm_end - vma->vm_start) >> 10,
67496 +#endif
67497 mss.resident >> 10,
67498 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67499 mss.shared_clean >> 10,
67500 @@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67501 char buffer[64];
67502 int nid;
67503
67504 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67505 + if (current->exec_id != m->exec_id) {
67506 + gr_log_badprocpid("numa_maps");
67507 + return 0;
67508 + }
67509 +#endif
67510 +
67511 if (!mm)
67512 return 0;
67513
67514 @@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67515 mpol_to_str(buffer, sizeof(buffer), pol);
67516 mpol_cond_put(pol);
67517
67518 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67519 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67520 +#else
67521 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67522 +#endif
67523
67524 if (file) {
67525 seq_puts(m, " file=");
67526 - seq_path(m, &file->f_path, "\n\t= ");
67527 + seq_path(m, &file->f_path, "\n\t\\= ");
67528 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67529 seq_puts(m, " heap");
67530 } else {
67531 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67532 index 678455d..ebd3245 100644
67533 --- a/fs/proc/task_nommu.c
67534 +++ b/fs/proc/task_nommu.c
67535 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67536 else
67537 bytes += kobjsize(mm);
67538
67539 - if (current->fs && current->fs->users > 1)
67540 + if (current->fs && atomic_read(&current->fs->users) > 1)
67541 sbytes += kobjsize(current->fs);
67542 else
67543 bytes += kobjsize(current->fs);
67544 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67545
67546 if (file) {
67547 seq_pad(m, ' ');
67548 - seq_path(m, &file->f_path, "");
67549 + seq_path(m, &file->f_path, "\n\\");
67550 } else if (mm) {
67551 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67552
67553 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67554 index a90d6d35..d08047c 100644
67555 --- a/fs/proc/vmcore.c
67556 +++ b/fs/proc/vmcore.c
67557 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67558 nr_bytes = count;
67559
67560 /* If pfn is not ram, return zeros for sparse dump files */
67561 - if (pfn_is_ram(pfn) == 0)
67562 - memset(buf, 0, nr_bytes);
67563 - else {
67564 + if (pfn_is_ram(pfn) == 0) {
67565 + if (userbuf) {
67566 + if (clear_user((char __force_user *)buf, nr_bytes))
67567 + return -EFAULT;
67568 + } else
67569 + memset(buf, 0, nr_bytes);
67570 + } else {
67571 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67572 offset, userbuf);
67573 if (tmp < 0)
67574 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67575 static int copy_to(void *target, void *src, size_t size, int userbuf)
67576 {
67577 if (userbuf) {
67578 - if (copy_to_user((char __user *) target, src, size))
67579 + if (copy_to_user((char __force_user *) target, src, size))
67580 return -EFAULT;
67581 } else {
67582 memcpy(target, src, size);
67583 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67584 if (*fpos < m->offset + m->size) {
67585 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67586 start = m->paddr + *fpos - m->offset;
67587 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67588 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67589 if (tmp < 0)
67590 return tmp;
67591 buflen -= tsz;
67592 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67593 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67594 size_t buflen, loff_t *fpos)
67595 {
67596 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67597 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67598 }
67599
67600 /*
67601 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67602 index d3fb2b6..43a8140 100644
67603 --- a/fs/qnx6/qnx6.h
67604 +++ b/fs/qnx6/qnx6.h
67605 @@ -74,7 +74,7 @@ enum {
67606 BYTESEX_BE,
67607 };
67608
67609 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67610 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67611 {
67612 if (sbi->s_bytesex == BYTESEX_LE)
67613 return le64_to_cpu((__force __le64)n);
67614 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67615 return (__force __fs64)cpu_to_be64(n);
67616 }
67617
67618 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67619 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67620 {
67621 if (sbi->s_bytesex == BYTESEX_LE)
67622 return le32_to_cpu((__force __le32)n);
67623 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67624 index bb2869f..d34ada8 100644
67625 --- a/fs/quota/netlink.c
67626 +++ b/fs/quota/netlink.c
67627 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67628 void quota_send_warning(struct kqid qid, dev_t dev,
67629 const char warntype)
67630 {
67631 - static atomic_t seq;
67632 + static atomic_unchecked_t seq;
67633 struct sk_buff *skb;
67634 void *msg_head;
67635 int ret;
67636 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67637 "VFS: Not enough memory to send quota warning.\n");
67638 return;
67639 }
67640 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67641 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67642 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67643 if (!msg_head) {
67644 printk(KERN_ERR
67645 diff --git a/fs/read_write.c b/fs/read_write.c
67646 index 009d854..16ce214 100644
67647 --- a/fs/read_write.c
67648 +++ b/fs/read_write.c
67649 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67650
67651 old_fs = get_fs();
67652 set_fs(get_ds());
67653 - p = (__force const char __user *)buf;
67654 + p = (const char __force_user *)buf;
67655 if (count > MAX_RW_COUNT)
67656 count = MAX_RW_COUNT;
67657 if (file->f_op->write)
67658 diff --git a/fs/readdir.c b/fs/readdir.c
67659 index 33fd922..e0d6094 100644
67660 --- a/fs/readdir.c
67661 +++ b/fs/readdir.c
67662 @@ -18,6 +18,7 @@
67663 #include <linux/security.h>
67664 #include <linux/syscalls.h>
67665 #include <linux/unistd.h>
67666 +#include <linux/namei.h>
67667
67668 #include <asm/uaccess.h>
67669
67670 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67671 struct readdir_callback {
67672 struct dir_context ctx;
67673 struct old_linux_dirent __user * dirent;
67674 + struct file * file;
67675 int result;
67676 };
67677
67678 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67679 buf->result = -EOVERFLOW;
67680 return -EOVERFLOW;
67681 }
67682 +
67683 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67684 + return 0;
67685 +
67686 buf->result++;
67687 dirent = buf->dirent;
67688 if (!access_ok(VERIFY_WRITE, dirent,
67689 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67690 if (!f.file)
67691 return -EBADF;
67692
67693 + buf.file = f.file;
67694 error = iterate_dir(f.file, &buf.ctx);
67695 if (buf.result)
67696 error = buf.result;
67697 @@ -144,6 +151,7 @@ struct getdents_callback {
67698 struct dir_context ctx;
67699 struct linux_dirent __user * current_dir;
67700 struct linux_dirent __user * previous;
67701 + struct file * file;
67702 int count;
67703 int error;
67704 };
67705 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67706 buf->error = -EOVERFLOW;
67707 return -EOVERFLOW;
67708 }
67709 +
67710 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67711 + return 0;
67712 +
67713 dirent = buf->previous;
67714 if (dirent) {
67715 if (__put_user(offset, &dirent->d_off))
67716 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67717 if (!f.file)
67718 return -EBADF;
67719
67720 + buf.file = f.file;
67721 error = iterate_dir(f.file, &buf.ctx);
67722 if (error >= 0)
67723 error = buf.error;
67724 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67725 struct dir_context ctx;
67726 struct linux_dirent64 __user * current_dir;
67727 struct linux_dirent64 __user * previous;
67728 + struct file *file;
67729 int count;
67730 int error;
67731 };
67732 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67733 buf->error = -EINVAL; /* only used if we fail.. */
67734 if (reclen > buf->count)
67735 return -EINVAL;
67736 +
67737 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67738 + return 0;
67739 +
67740 dirent = buf->previous;
67741 if (dirent) {
67742 if (__put_user(offset, &dirent->d_off))
67743 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67744 if (!f.file)
67745 return -EBADF;
67746
67747 + buf.file = f.file;
67748 error = iterate_dir(f.file, &buf.ctx);
67749 if (error >= 0)
67750 error = buf.error;
67751 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67752 index 9c02d96..6562c10 100644
67753 --- a/fs/reiserfs/do_balan.c
67754 +++ b/fs/reiserfs/do_balan.c
67755 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67756 return;
67757 }
67758
67759 - atomic_inc(&fs_generation(tb->tb_sb));
67760 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67761 do_balance_starts(tb);
67762
67763 /*
67764 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67765 index aca73dd..e3c558d 100644
67766 --- a/fs/reiserfs/item_ops.c
67767 +++ b/fs/reiserfs/item_ops.c
67768 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67769 }
67770
67771 static struct item_operations errcatch_ops = {
67772 - errcatch_bytes_number,
67773 - errcatch_decrement_key,
67774 - errcatch_is_left_mergeable,
67775 - errcatch_print_item,
67776 - errcatch_check_item,
67777 + .bytes_number = errcatch_bytes_number,
67778 + .decrement_key = errcatch_decrement_key,
67779 + .is_left_mergeable = errcatch_is_left_mergeable,
67780 + .print_item = errcatch_print_item,
67781 + .check_item = errcatch_check_item,
67782
67783 - errcatch_create_vi,
67784 - errcatch_check_left,
67785 - errcatch_check_right,
67786 - errcatch_part_size,
67787 - errcatch_unit_num,
67788 - errcatch_print_vi
67789 + .create_vi = errcatch_create_vi,
67790 + .check_left = errcatch_check_left,
67791 + .check_right = errcatch_check_right,
67792 + .part_size = errcatch_part_size,
67793 + .unit_num = errcatch_unit_num,
67794 + .print_vi = errcatch_print_vi
67795 };
67796
67797 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67798 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67799 index 621b9f3..af527fd 100644
67800 --- a/fs/reiserfs/procfs.c
67801 +++ b/fs/reiserfs/procfs.c
67802 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67803 "SMALL_TAILS " : "NO_TAILS ",
67804 replay_only(sb) ? "REPLAY_ONLY " : "",
67805 convert_reiserfs(sb) ? "CONV " : "",
67806 - atomic_read(&r->s_generation_counter),
67807 + atomic_read_unchecked(&r->s_generation_counter),
67808 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67809 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67810 SF(s_good_search_by_key_reada), SF(s_bmaps),
67811 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67812 index 735c2c2..81b91af 100644
67813 --- a/fs/reiserfs/reiserfs.h
67814 +++ b/fs/reiserfs/reiserfs.h
67815 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67816 /* Comment? -Hans */
67817 wait_queue_head_t s_wait;
67818 /* increased by one every time the tree gets re-balanced */
67819 - atomic_t s_generation_counter;
67820 + atomic_unchecked_t s_generation_counter;
67821
67822 /* File system properties. Currently holds on-disk FS format */
67823 unsigned long s_properties;
67824 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67825 #define REISERFS_USER_MEM 1 /* user memory mode */
67826
67827 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67828 -#define get_generation(s) atomic_read (&fs_generation(s))
67829 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67830 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67831 #define __fs_changed(gen,s) (gen != get_generation (s))
67832 #define fs_changed(gen,s) \
67833 diff --git a/fs/select.c b/fs/select.c
67834 index 467bb1c..cf9d65a 100644
67835 --- a/fs/select.c
67836 +++ b/fs/select.c
67837 @@ -20,6 +20,7 @@
67838 #include <linux/export.h>
67839 #include <linux/slab.h>
67840 #include <linux/poll.h>
67841 +#include <linux/security.h>
67842 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67843 #include <linux/file.h>
67844 #include <linux/fdtable.h>
67845 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67846 struct poll_list *walk = head;
67847 unsigned long todo = nfds;
67848
67849 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67850 if (nfds > rlimit(RLIMIT_NOFILE))
67851 return -EINVAL;
67852
67853 diff --git a/fs/seq_file.c b/fs/seq_file.c
67854 index 3857b72..0b7281e 100644
67855 --- a/fs/seq_file.c
67856 +++ b/fs/seq_file.c
67857 @@ -12,6 +12,8 @@
67858 #include <linux/slab.h>
67859 #include <linux/cred.h>
67860 #include <linux/mm.h>
67861 +#include <linux/sched.h>
67862 +#include <linux/grsecurity.h>
67863
67864 #include <asm/uaccess.h>
67865 #include <asm/page.h>
67866 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67867
67868 static void *seq_buf_alloc(unsigned long size)
67869 {
67870 - void *buf;
67871 -
67872 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67873 - if (!buf && size > PAGE_SIZE)
67874 - buf = vmalloc(size);
67875 - return buf;
67876 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67877 }
67878
67879 /**
67880 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67881 #ifdef CONFIG_USER_NS
67882 p->user_ns = file->f_cred->user_ns;
67883 #endif
67884 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67885 + p->exec_id = current->exec_id;
67886 +#endif
67887
67888 /*
67889 * Wrappers around seq_open(e.g. swaps_open) need to be
67890 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67891 }
67892 EXPORT_SYMBOL(seq_open);
67893
67894 +
67895 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67896 +{
67897 + if (gr_proc_is_restricted())
67898 + return -EACCES;
67899 +
67900 + return seq_open(file, op);
67901 +}
67902 +EXPORT_SYMBOL(seq_open_restrict);
67903 +
67904 static int traverse(struct seq_file *m, loff_t offset)
67905 {
67906 loff_t pos = 0, index;
67907 @@ -165,7 +175,7 @@ Eoverflow:
67908 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67909 {
67910 struct seq_file *m = file->private_data;
67911 - size_t copied = 0;
67912 + ssize_t copied = 0;
67913 loff_t pos;
67914 size_t n;
67915 void *p;
67916 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67917 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67918 void *data)
67919 {
67920 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67921 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67922 int res = -ENOMEM;
67923
67924 if (op) {
67925 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67926 }
67927 EXPORT_SYMBOL(single_open_size);
67928
67929 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67930 + void *data)
67931 +{
67932 + if (gr_proc_is_restricted())
67933 + return -EACCES;
67934 +
67935 + return single_open(file, show, data);
67936 +}
67937 +EXPORT_SYMBOL(single_open_restrict);
67938 +
67939 +
67940 int single_release(struct inode *inode, struct file *file)
67941 {
67942 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67943 diff --git a/fs/splice.c b/fs/splice.c
67944 index f5cb9ba..8ddb1e9 100644
67945 --- a/fs/splice.c
67946 +++ b/fs/splice.c
67947 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67948 pipe_lock(pipe);
67949
67950 for (;;) {
67951 - if (!pipe->readers) {
67952 + if (!atomic_read(&pipe->readers)) {
67953 send_sig(SIGPIPE, current, 0);
67954 if (!ret)
67955 ret = -EPIPE;
67956 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67957 page_nr++;
67958 ret += buf->len;
67959
67960 - if (pipe->files)
67961 + if (atomic_read(&pipe->files))
67962 do_wakeup = 1;
67963
67964 if (!--spd->nr_pages)
67965 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67966 do_wakeup = 0;
67967 }
67968
67969 - pipe->waiting_writers++;
67970 + atomic_inc(&pipe->waiting_writers);
67971 pipe_wait(pipe);
67972 - pipe->waiting_writers--;
67973 + atomic_dec(&pipe->waiting_writers);
67974 }
67975
67976 pipe_unlock(pipe);
67977 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67978 old_fs = get_fs();
67979 set_fs(get_ds());
67980 /* The cast to a user pointer is valid due to the set_fs() */
67981 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67982 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67983 set_fs(old_fs);
67984
67985 return res;
67986 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67987 old_fs = get_fs();
67988 set_fs(get_ds());
67989 /* The cast to a user pointer is valid due to the set_fs() */
67990 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67991 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67992 set_fs(old_fs);
67993
67994 return res;
67995 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67996 goto err;
67997
67998 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67999 - vec[i].iov_base = (void __user *) page_address(page);
68000 + vec[i].iov_base = (void __force_user *) page_address(page);
68001 vec[i].iov_len = this_len;
68002 spd.pages[i] = page;
68003 spd.nr_pages++;
68004 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68005 ops->release(pipe, buf);
68006 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68007 pipe->nrbufs--;
68008 - if (pipe->files)
68009 + if (atomic_read(&pipe->files))
68010 sd->need_wakeup = true;
68011 }
68012
68013 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68014 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68015 {
68016 while (!pipe->nrbufs) {
68017 - if (!pipe->writers)
68018 + if (!atomic_read(&pipe->writers))
68019 return 0;
68020
68021 - if (!pipe->waiting_writers && sd->num_spliced)
68022 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68023 return 0;
68024
68025 if (sd->flags & SPLICE_F_NONBLOCK)
68026 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68027 ops->release(pipe, buf);
68028 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68029 pipe->nrbufs--;
68030 - if (pipe->files)
68031 + if (atomic_read(&pipe->files))
68032 sd.need_wakeup = true;
68033 } else {
68034 buf->offset += ret;
68035 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68036 * out of the pipe right after the splice_to_pipe(). So set
68037 * PIPE_READERS appropriately.
68038 */
68039 - pipe->readers = 1;
68040 + atomic_set(&pipe->readers, 1);
68041
68042 current->splice_pipe = pipe;
68043 }
68044 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68045
68046 partial[buffers].offset = off;
68047 partial[buffers].len = plen;
68048 + partial[buffers].private = 0;
68049
68050 off = 0;
68051 len -= plen;
68052 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68053 ret = -ERESTARTSYS;
68054 break;
68055 }
68056 - if (!pipe->writers)
68057 + if (!atomic_read(&pipe->writers))
68058 break;
68059 - if (!pipe->waiting_writers) {
68060 + if (!atomic_read(&pipe->waiting_writers)) {
68061 if (flags & SPLICE_F_NONBLOCK) {
68062 ret = -EAGAIN;
68063 break;
68064 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68065 pipe_lock(pipe);
68066
68067 while (pipe->nrbufs >= pipe->buffers) {
68068 - if (!pipe->readers) {
68069 + if (!atomic_read(&pipe->readers)) {
68070 send_sig(SIGPIPE, current, 0);
68071 ret = -EPIPE;
68072 break;
68073 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68074 ret = -ERESTARTSYS;
68075 break;
68076 }
68077 - pipe->waiting_writers++;
68078 + atomic_inc(&pipe->waiting_writers);
68079 pipe_wait(pipe);
68080 - pipe->waiting_writers--;
68081 + atomic_dec(&pipe->waiting_writers);
68082 }
68083
68084 pipe_unlock(pipe);
68085 @@ -1817,14 +1818,14 @@ retry:
68086 pipe_double_lock(ipipe, opipe);
68087
68088 do {
68089 - if (!opipe->readers) {
68090 + if (!atomic_read(&opipe->readers)) {
68091 send_sig(SIGPIPE, current, 0);
68092 if (!ret)
68093 ret = -EPIPE;
68094 break;
68095 }
68096
68097 - if (!ipipe->nrbufs && !ipipe->writers)
68098 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68099 break;
68100
68101 /*
68102 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68103 pipe_double_lock(ipipe, opipe);
68104
68105 do {
68106 - if (!opipe->readers) {
68107 + if (!atomic_read(&opipe->readers)) {
68108 send_sig(SIGPIPE, current, 0);
68109 if (!ret)
68110 ret = -EPIPE;
68111 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68112 * return EAGAIN if we have the potential of some data in the
68113 * future, otherwise just return 0
68114 */
68115 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68116 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68117 ret = -EAGAIN;
68118
68119 pipe_unlock(ipipe);
68120 diff --git a/fs/stat.c b/fs/stat.c
68121 index ae0c3ce..9ee641c 100644
68122 --- a/fs/stat.c
68123 +++ b/fs/stat.c
68124 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68125 stat->gid = inode->i_gid;
68126 stat->rdev = inode->i_rdev;
68127 stat->size = i_size_read(inode);
68128 - stat->atime = inode->i_atime;
68129 - stat->mtime = inode->i_mtime;
68130 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68131 + stat->atime = inode->i_ctime;
68132 + stat->mtime = inode->i_ctime;
68133 + } else {
68134 + stat->atime = inode->i_atime;
68135 + stat->mtime = inode->i_mtime;
68136 + }
68137 stat->ctime = inode->i_ctime;
68138 stat->blksize = (1 << inode->i_blkbits);
68139 stat->blocks = inode->i_blocks;
68140 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68141 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68142 {
68143 struct inode *inode = path->dentry->d_inode;
68144 + int retval;
68145
68146 - if (inode->i_op->getattr)
68147 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68148 + if (inode->i_op->getattr) {
68149 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68150 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68151 + stat->atime = stat->ctime;
68152 + stat->mtime = stat->ctime;
68153 + }
68154 + return retval;
68155 + }
68156
68157 generic_fillattr(inode, stat);
68158 return 0;
68159 diff --git a/fs/super.c b/fs/super.c
68160 index b9a214d..6f8c954 100644
68161 --- a/fs/super.c
68162 +++ b/fs/super.c
68163 @@ -80,6 +80,8 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
68164 inodes = list_lru_count_node(&sb->s_inode_lru, sc->nid);
68165 dentries = list_lru_count_node(&sb->s_dentry_lru, sc->nid);
68166 total_objects = dentries + inodes + fs_objects + 1;
68167 + if (!total_objects)
68168 + total_objects = 1;
68169
68170 /* proportion the scan between the caches */
68171 dentries = mult_frac(sc->nr_to_scan, dentries, total_objects);
68172 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68173 index 0b45ff4..847de5b 100644
68174 --- a/fs/sysfs/dir.c
68175 +++ b/fs/sysfs/dir.c
68176 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68177 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68178 {
68179 struct kernfs_node *parent, *kn;
68180 + const char *name;
68181 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68182 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68183 + const char *parent_name;
68184 +#endif
68185
68186 BUG_ON(!kobj);
68187
68188 + name = kobject_name(kobj);
68189 +
68190 if (kobj->parent)
68191 parent = kobj->parent->sd;
68192 else
68193 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68194 if (!parent)
68195 return -ENOENT;
68196
68197 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68198 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68199 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68200 + parent_name = parent->name;
68201 + mode = S_IRWXU;
68202 +
68203 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68204 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68205 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68206 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68207 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68208 +#endif
68209 +
68210 + kn = kernfs_create_dir_ns(parent, name,
68211 + mode, kobj, ns);
68212 if (IS_ERR(kn)) {
68213 if (PTR_ERR(kn) == -EEXIST)
68214 - sysfs_warn_dup(parent, kobject_name(kobj));
68215 + sysfs_warn_dup(parent, name);
68216 return PTR_ERR(kn);
68217 }
68218
68219 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68220 index 69d4889..a810bd4 100644
68221 --- a/fs/sysv/sysv.h
68222 +++ b/fs/sysv/sysv.h
68223 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68224 #endif
68225 }
68226
68227 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68228 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68229 {
68230 if (sbi->s_bytesex == BYTESEX_PDP)
68231 return PDP_swab((__force __u32)n);
68232 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68233 index fb08b0c..65fcc7e 100644
68234 --- a/fs/ubifs/io.c
68235 +++ b/fs/ubifs/io.c
68236 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68237 return err;
68238 }
68239
68240 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68241 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68242 {
68243 int err;
68244
68245 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68246 index c175b4d..8f36a16 100644
68247 --- a/fs/udf/misc.c
68248 +++ b/fs/udf/misc.c
68249 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68250
68251 u8 udf_tag_checksum(const struct tag *t)
68252 {
68253 - u8 *data = (u8 *)t;
68254 + const u8 *data = (const u8 *)t;
68255 u8 checksum = 0;
68256 int i;
68257 for (i = 0; i < sizeof(struct tag); ++i)
68258 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68259 index 8d974c4..b82f6ec 100644
68260 --- a/fs/ufs/swab.h
68261 +++ b/fs/ufs/swab.h
68262 @@ -22,7 +22,7 @@ enum {
68263 BYTESEX_BE
68264 };
68265
68266 -static inline u64
68267 +static inline u64 __intentional_overflow(-1)
68268 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68269 {
68270 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68271 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68272 return (__force __fs64)cpu_to_be64(n);
68273 }
68274
68275 -static inline u32
68276 +static inline u32 __intentional_overflow(-1)
68277 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68278 {
68279 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68280 diff --git a/fs/utimes.c b/fs/utimes.c
68281 index aa138d6..5f3a811 100644
68282 --- a/fs/utimes.c
68283 +++ b/fs/utimes.c
68284 @@ -1,6 +1,7 @@
68285 #include <linux/compiler.h>
68286 #include <linux/file.h>
68287 #include <linux/fs.h>
68288 +#include <linux/security.h>
68289 #include <linux/linkage.h>
68290 #include <linux/mount.h>
68291 #include <linux/namei.h>
68292 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68293 }
68294 }
68295 retry_deleg:
68296 +
68297 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68298 + error = -EACCES;
68299 + goto mnt_drop_write_and_out;
68300 + }
68301 +
68302 mutex_lock(&inode->i_mutex);
68303 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68304 mutex_unlock(&inode->i_mutex);
68305 diff --git a/fs/xattr.c b/fs/xattr.c
68306 index c69e6d4..cc56af5 100644
68307 --- a/fs/xattr.c
68308 +++ b/fs/xattr.c
68309 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68310 return rc;
68311 }
68312
68313 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68314 +ssize_t
68315 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68316 +{
68317 + struct inode *inode = dentry->d_inode;
68318 + ssize_t error;
68319 +
68320 + error = inode_permission(inode, MAY_EXEC);
68321 + if (error)
68322 + return error;
68323 +
68324 + if (inode->i_op->getxattr)
68325 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68326 + else
68327 + error = -EOPNOTSUPP;
68328 +
68329 + return error;
68330 +}
68331 +EXPORT_SYMBOL(pax_getxattr);
68332 +#endif
68333 +
68334 ssize_t
68335 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68336 {
68337 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68338 * Extended attribute SET operations
68339 */
68340 static long
68341 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68342 +setxattr(struct path *path, const char __user *name, const void __user *value,
68343 size_t size, int flags)
68344 {
68345 int error;
68346 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68347 posix_acl_fix_xattr_from_user(kvalue, size);
68348 }
68349
68350 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68351 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68352 + error = -EACCES;
68353 + goto out;
68354 + }
68355 +
68356 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68357 out:
68358 if (vvalue)
68359 vfree(vvalue);
68360 @@ -377,7 +403,7 @@ retry:
68361 return error;
68362 error = mnt_want_write(path.mnt);
68363 if (!error) {
68364 - error = setxattr(path.dentry, name, value, size, flags);
68365 + error = setxattr(&path, name, value, size, flags);
68366 mnt_drop_write(path.mnt);
68367 }
68368 path_put(&path);
68369 @@ -401,7 +427,7 @@ retry:
68370 return error;
68371 error = mnt_want_write(path.mnt);
68372 if (!error) {
68373 - error = setxattr(path.dentry, name, value, size, flags);
68374 + error = setxattr(&path, name, value, size, flags);
68375 mnt_drop_write(path.mnt);
68376 }
68377 path_put(&path);
68378 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68379 const void __user *,value, size_t, size, int, flags)
68380 {
68381 struct fd f = fdget(fd);
68382 - struct dentry *dentry;
68383 int error = -EBADF;
68384
68385 if (!f.file)
68386 return error;
68387 - dentry = f.file->f_path.dentry;
68388 - audit_inode(NULL, dentry, 0);
68389 + audit_inode(NULL, f.file->f_path.dentry, 0);
68390 error = mnt_want_write_file(f.file);
68391 if (!error) {
68392 - error = setxattr(dentry, name, value, size, flags);
68393 + error = setxattr(&f.file->f_path, name, value, size, flags);
68394 mnt_drop_write_file(f.file);
68395 }
68396 fdput(f);
68397 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68398 * Extended attribute REMOVE operations
68399 */
68400 static long
68401 -removexattr(struct dentry *d, const char __user *name)
68402 +removexattr(struct path *path, const char __user *name)
68403 {
68404 int error;
68405 char kname[XATTR_NAME_MAX + 1];
68406 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68407 if (error < 0)
68408 return error;
68409
68410 - return vfs_removexattr(d, kname);
68411 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68412 + return -EACCES;
68413 +
68414 + return vfs_removexattr(path->dentry, kname);
68415 }
68416
68417 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68418 @@ -652,7 +679,7 @@ retry:
68419 return error;
68420 error = mnt_want_write(path.mnt);
68421 if (!error) {
68422 - error = removexattr(path.dentry, name);
68423 + error = removexattr(&path, name);
68424 mnt_drop_write(path.mnt);
68425 }
68426 path_put(&path);
68427 @@ -675,7 +702,7 @@ retry:
68428 return error;
68429 error = mnt_want_write(path.mnt);
68430 if (!error) {
68431 - error = removexattr(path.dentry, name);
68432 + error = removexattr(&path, name);
68433 mnt_drop_write(path.mnt);
68434 }
68435 path_put(&path);
68436 @@ -689,16 +716,16 @@ retry:
68437 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68438 {
68439 struct fd f = fdget(fd);
68440 - struct dentry *dentry;
68441 + struct path *path;
68442 int error = -EBADF;
68443
68444 if (!f.file)
68445 return error;
68446 - dentry = f.file->f_path.dentry;
68447 - audit_inode(NULL, dentry, 0);
68448 + path = &f.file->f_path;
68449 + audit_inode(NULL, path->dentry, 0);
68450 error = mnt_want_write_file(f.file);
68451 if (!error) {
68452 - error = removexattr(dentry, name);
68453 + error = removexattr(path, name);
68454 mnt_drop_write_file(f.file);
68455 }
68456 fdput(f);
68457 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68458 index 86df952..ac430d6 100644
68459 --- a/fs/xfs/libxfs/xfs_bmap.c
68460 +++ b/fs/xfs/libxfs/xfs_bmap.c
68461 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68462
68463 #else
68464 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68465 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68466 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68467 #endif /* DEBUG */
68468
68469 /*
68470 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68471 index f1b69ed..3d0222f 100644
68472 --- a/fs/xfs/xfs_dir2_readdir.c
68473 +++ b/fs/xfs/xfs_dir2_readdir.c
68474 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68475 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68476 filetype = dp->d_ops->sf_get_ftype(sfep);
68477 ctx->pos = off & 0x7fffffff;
68478 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68479 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68480 + char name[sfep->namelen];
68481 + memcpy(name, sfep->name, sfep->namelen);
68482 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68483 + return 0;
68484 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68485 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68486 return 0;
68487 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68488 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68489 index 3799695..0ddc953 100644
68490 --- a/fs/xfs/xfs_ioctl.c
68491 +++ b/fs/xfs/xfs_ioctl.c
68492 @@ -122,7 +122,7 @@ xfs_find_handle(
68493 }
68494
68495 error = -EFAULT;
68496 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68497 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68498 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68499 goto out_put;
68500
68501 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68502 new file mode 100644
68503 index 0000000..f27264e
68504 --- /dev/null
68505 +++ b/grsecurity/Kconfig
68506 @@ -0,0 +1,1166 @@
68507 +#
68508 +# grecurity configuration
68509 +#
68510 +menu "Memory Protections"
68511 +depends on GRKERNSEC
68512 +
68513 +config GRKERNSEC_KMEM
68514 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68515 + default y if GRKERNSEC_CONFIG_AUTO
68516 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68517 + help
68518 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68519 + be written to or read from to modify or leak the contents of the running
68520 + kernel. /dev/port will also not be allowed to be opened, writing to
68521 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68522 + If you have module support disabled, enabling this will close up several
68523 + ways that are currently used to insert malicious code into the running
68524 + kernel.
68525 +
68526 + Even with this feature enabled, we still highly recommend that
68527 + you use the RBAC system, as it is still possible for an attacker to
68528 + modify the running kernel through other more obscure methods.
68529 +
68530 + It is highly recommended that you say Y here if you meet all the
68531 + conditions above.
68532 +
68533 +config GRKERNSEC_VM86
68534 + bool "Restrict VM86 mode"
68535 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68536 + depends on X86_32
68537 +
68538 + help
68539 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68540 + make use of a special execution mode on 32bit x86 processors called
68541 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68542 + video cards and will still work with this option enabled. The purpose
68543 + of the option is to prevent exploitation of emulation errors in
68544 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68545 + Nearly all users should be able to enable this option.
68546 +
68547 +config GRKERNSEC_IO
68548 + bool "Disable privileged I/O"
68549 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68550 + depends on X86
68551 + select RTC_CLASS
68552 + select RTC_INTF_DEV
68553 + select RTC_DRV_CMOS
68554 +
68555 + help
68556 + If you say Y here, all ioperm and iopl calls will return an error.
68557 + Ioperm and iopl can be used to modify the running kernel.
68558 + Unfortunately, some programs need this access to operate properly,
68559 + the most notable of which are XFree86 and hwclock. hwclock can be
68560 + remedied by having RTC support in the kernel, so real-time
68561 + clock support is enabled if this option is enabled, to ensure
68562 + that hwclock operates correctly. If hwclock still does not work,
68563 + either update udev or symlink /dev/rtc to /dev/rtc0.
68564 +
68565 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68566 + you may not be able to boot into a graphical environment with this
68567 + option enabled. In this case, you should use the RBAC system instead.
68568 +
68569 +config GRKERNSEC_BPF_HARDEN
68570 + bool "Harden BPF interpreter"
68571 + default y if GRKERNSEC_CONFIG_AUTO
68572 + help
68573 + Unlike previous versions of grsecurity that hardened both the BPF
68574 + interpreted code against corruption at rest as well as the JIT code
68575 + against JIT-spray attacks and attacker-controlled immediate values
68576 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68577 + and will ensure the interpreted code is read-only at rest. This feature
68578 + may be removed at a later time when eBPF stabilizes to entirely revert
68579 + back to the more secure pre-3.16 BPF interpreter/JIT.
68580 +
68581 + If you're using KERNEXEC, it's recommended that you enable this option
68582 + to supplement the hardening of the kernel.
68583 +
68584 +config GRKERNSEC_PERF_HARDEN
68585 + bool "Disable unprivileged PERF_EVENTS usage by default"
68586 + default y if GRKERNSEC_CONFIG_AUTO
68587 + depends on PERF_EVENTS
68588 + help
68589 + If you say Y here, the range of acceptable values for the
68590 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68591 + default to a new value: 3. When the sysctl is set to this value, no
68592 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68593 +
68594 + Though PERF_EVENTS can be used legitimately for performance monitoring
68595 + and low-level application profiling, it is forced on regardless of
68596 + configuration, has been at fault for several vulnerabilities, and
68597 + creates new opportunities for side channels and other information leaks.
68598 +
68599 + This feature puts PERF_EVENTS into a secure default state and permits
68600 + the administrator to change out of it temporarily if unprivileged
68601 + application profiling is needed.
68602 +
68603 +config GRKERNSEC_RAND_THREADSTACK
68604 + bool "Insert random gaps between thread stacks"
68605 + default y if GRKERNSEC_CONFIG_AUTO
68606 + depends on PAX_RANDMMAP && !PPC
68607 + help
68608 + If you say Y here, a random-sized gap will be enforced between allocated
68609 + thread stacks. Glibc's NPTL and other threading libraries that
68610 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68611 + The implementation currently provides 8 bits of entropy for the gap.
68612 +
68613 + Many distributions do not compile threaded remote services with the
68614 + -fstack-check argument to GCC, causing the variable-sized stack-based
68615 + allocator, alloca(), to not probe the stack on allocation. This
68616 + permits an unbounded alloca() to skip over any guard page and potentially
68617 + modify another thread's stack reliably. An enforced random gap
68618 + reduces the reliability of such an attack and increases the chance
68619 + that such a read/write to another thread's stack instead lands in
68620 + an unmapped area, causing a crash and triggering grsecurity's
68621 + anti-bruteforcing logic.
68622 +
68623 +config GRKERNSEC_PROC_MEMMAP
68624 + bool "Harden ASLR against information leaks and entropy reduction"
68625 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68626 + depends on PAX_NOEXEC || PAX_ASLR
68627 + help
68628 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68629 + give no information about the addresses of its mappings if
68630 + PaX features that rely on random addresses are enabled on the task.
68631 + In addition to sanitizing this information and disabling other
68632 + dangerous sources of information, this option causes reads of sensitive
68633 + /proc/<pid> entries where the file descriptor was opened in a different
68634 + task than the one performing the read. Such attempts are logged.
68635 + This option also limits argv/env strings for suid/sgid binaries
68636 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68637 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68638 + binaries to prevent alternative mmap layouts from being abused.
68639 +
68640 + If you use PaX it is essential that you say Y here as it closes up
68641 + several holes that make full ASLR useless locally.
68642 +
68643 +
68644 +config GRKERNSEC_KSTACKOVERFLOW
68645 + bool "Prevent kernel stack overflows"
68646 + default y if GRKERNSEC_CONFIG_AUTO
68647 + depends on !IA64 && 64BIT
68648 + help
68649 + If you say Y here, the kernel's process stacks will be allocated
68650 + with vmalloc instead of the kernel's default allocator. This
68651 + introduces guard pages that in combination with the alloca checking
68652 + of the STACKLEAK feature prevents all forms of kernel process stack
68653 + overflow abuse. Note that this is different from kernel stack
68654 + buffer overflows.
68655 +
68656 +config GRKERNSEC_BRUTE
68657 + bool "Deter exploit bruteforcing"
68658 + default y if GRKERNSEC_CONFIG_AUTO
68659 + help
68660 + If you say Y here, attempts to bruteforce exploits against forking
68661 + daemons such as apache or sshd, as well as against suid/sgid binaries
68662 + will be deterred. When a child of a forking daemon is killed by PaX
68663 + or crashes due to an illegal instruction or other suspicious signal,
68664 + the parent process will be delayed 30 seconds upon every subsequent
68665 + fork until the administrator is able to assess the situation and
68666 + restart the daemon.
68667 + In the suid/sgid case, the attempt is logged, the user has all their
68668 + existing instances of the suid/sgid binary terminated and will
68669 + be unable to execute any suid/sgid binaries for 15 minutes.
68670 +
68671 + It is recommended that you also enable signal logging in the auditing
68672 + section so that logs are generated when a process triggers a suspicious
68673 + signal.
68674 + If the sysctl option is enabled, a sysctl option with name
68675 + "deter_bruteforce" is created.
68676 +
68677 +config GRKERNSEC_MODHARDEN
68678 + bool "Harden module auto-loading"
68679 + default y if GRKERNSEC_CONFIG_AUTO
68680 + depends on MODULES
68681 + help
68682 + If you say Y here, module auto-loading in response to use of some
68683 + feature implemented by an unloaded module will be restricted to
68684 + root users. Enabling this option helps defend against attacks
68685 + by unprivileged users who abuse the auto-loading behavior to
68686 + cause a vulnerable module to load that is then exploited.
68687 +
68688 + If this option prevents a legitimate use of auto-loading for a
68689 + non-root user, the administrator can execute modprobe manually
68690 + with the exact name of the module mentioned in the alert log.
68691 + Alternatively, the administrator can add the module to the list
68692 + of modules loaded at boot by modifying init scripts.
68693 +
68694 + Modification of init scripts will most likely be needed on
68695 + Ubuntu servers with encrypted home directory support enabled,
68696 + as the first non-root user logging in will cause the ecb(aes),
68697 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68698 +
68699 +config GRKERNSEC_HIDESYM
68700 + bool "Hide kernel symbols"
68701 + default y if GRKERNSEC_CONFIG_AUTO
68702 + select PAX_USERCOPY_SLABS
68703 + help
68704 + If you say Y here, getting information on loaded modules, and
68705 + displaying all kernel symbols through a syscall will be restricted
68706 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68707 + /proc/kallsyms will be restricted to the root user. The RBAC
68708 + system can hide that entry even from root.
68709 +
68710 + This option also prevents leaking of kernel addresses through
68711 + several /proc entries.
68712 +
68713 + Note that this option is only effective provided the following
68714 + conditions are met:
68715 + 1) The kernel using grsecurity is not precompiled by some distribution
68716 + 2) You have also enabled GRKERNSEC_DMESG
68717 + 3) You are using the RBAC system and hiding other files such as your
68718 + kernel image and System.map. Alternatively, enabling this option
68719 + causes the permissions on /boot, /lib/modules, and the kernel
68720 + source directory to change at compile time to prevent
68721 + reading by non-root users.
68722 + If the above conditions are met, this option will aid in providing a
68723 + useful protection against local kernel exploitation of overflows
68724 + and arbitrary read/write vulnerabilities.
68725 +
68726 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68727 + in addition to this feature.
68728 +
68729 +config GRKERNSEC_RANDSTRUCT
68730 + bool "Randomize layout of sensitive kernel structures"
68731 + default y if GRKERNSEC_CONFIG_AUTO
68732 + select GRKERNSEC_HIDESYM
68733 + select MODVERSIONS if MODULES
68734 + help
68735 + If you say Y here, the layouts of a number of sensitive kernel
68736 + structures (task, fs, cred, etc) and all structures composed entirely
68737 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68738 + This can introduce the requirement of an additional infoleak
68739 + vulnerability for exploits targeting these structure types.
68740 +
68741 + Enabling this feature will introduce some performance impact, slightly
68742 + increase memory usage, and prevent the use of forensic tools like
68743 + Volatility against the system (unless the kernel source tree isn't
68744 + cleaned after kernel installation).
68745 +
68746 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68747 + It remains after a make clean to allow for external modules to be compiled
68748 + with the existing seed and will be removed by a make mrproper or
68749 + make distclean.
68750 +
68751 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68752 + to install the supporting headers explicitly in addition to the normal
68753 + gcc package.
68754 +
68755 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68756 + bool "Use cacheline-aware structure randomization"
68757 + depends on GRKERNSEC_RANDSTRUCT
68758 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68759 + help
68760 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68761 + at restricting randomization to cacheline-sized groups of elements. It
68762 + will further not randomize bitfields in structures. This reduces the
68763 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68764 +
68765 +config GRKERNSEC_KERN_LOCKOUT
68766 + bool "Active kernel exploit response"
68767 + default y if GRKERNSEC_CONFIG_AUTO
68768 + depends on X86 || ARM || PPC || SPARC
68769 + help
68770 + If you say Y here, when a PaX alert is triggered due to suspicious
68771 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68772 + or an OOPS occurs due to bad memory accesses, instead of just
68773 + terminating the offending process (and potentially allowing
68774 + a subsequent exploit from the same user), we will take one of two
68775 + actions:
68776 + If the user was root, we will panic the system
68777 + If the user was non-root, we will log the attempt, terminate
68778 + all processes owned by the user, then prevent them from creating
68779 + any new processes until the system is restarted
68780 + This deters repeated kernel exploitation/bruteforcing attempts
68781 + and is useful for later forensics.
68782 +
68783 +config GRKERNSEC_OLD_ARM_USERLAND
68784 + bool "Old ARM userland compatibility"
68785 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68786 + help
68787 + If you say Y here, stubs of executable code to perform such operations
68788 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68789 + table. This is unfortunately needed for old ARM userland meant to run
68790 + across a wide range of processors. Without this option enabled,
68791 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68792 + which is enough for Linaro userlands or other userlands designed for v6
68793 + and newer ARM CPUs. It's recommended that you try without this option enabled
68794 + first, and only enable it if your userland does not boot (it will likely fail
68795 + at init time).
68796 +
68797 +endmenu
68798 +menu "Role Based Access Control Options"
68799 +depends on GRKERNSEC
68800 +
68801 +config GRKERNSEC_RBAC_DEBUG
68802 + bool
68803 +
68804 +config GRKERNSEC_NO_RBAC
68805 + bool "Disable RBAC system"
68806 + help
68807 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68808 + preventing the RBAC system from being enabled. You should only say Y
68809 + here if you have no intention of using the RBAC system, so as to prevent
68810 + an attacker with root access from misusing the RBAC system to hide files
68811 + and processes when loadable module support and /dev/[k]mem have been
68812 + locked down.
68813 +
68814 +config GRKERNSEC_ACL_HIDEKERN
68815 + bool "Hide kernel processes"
68816 + help
68817 + If you say Y here, all kernel threads will be hidden to all
68818 + processes but those whose subject has the "view hidden processes"
68819 + flag.
68820 +
68821 +config GRKERNSEC_ACL_MAXTRIES
68822 + int "Maximum tries before password lockout"
68823 + default 3
68824 + help
68825 + This option enforces the maximum number of times a user can attempt
68826 + to authorize themselves with the grsecurity RBAC system before being
68827 + denied the ability to attempt authorization again for a specified time.
68828 + The lower the number, the harder it will be to brute-force a password.
68829 +
68830 +config GRKERNSEC_ACL_TIMEOUT
68831 + int "Time to wait after max password tries, in seconds"
68832 + default 30
68833 + help
68834 + This option specifies the time the user must wait after attempting to
68835 + authorize to the RBAC system with the maximum number of invalid
68836 + passwords. The higher the number, the harder it will be to brute-force
68837 + a password.
68838 +
68839 +endmenu
68840 +menu "Filesystem Protections"
68841 +depends on GRKERNSEC
68842 +
68843 +config GRKERNSEC_PROC
68844 + bool "Proc restrictions"
68845 + default y if GRKERNSEC_CONFIG_AUTO
68846 + help
68847 + If you say Y here, the permissions of the /proc filesystem
68848 + will be altered to enhance system security and privacy. You MUST
68849 + choose either a user only restriction or a user and group restriction.
68850 + Depending upon the option you choose, you can either restrict users to
68851 + see only the processes they themselves run, or choose a group that can
68852 + view all processes and files normally restricted to root if you choose
68853 + the "restrict to user only" option. NOTE: If you're running identd or
68854 + ntpd as a non-root user, you will have to run it as the group you
68855 + specify here.
68856 +
68857 +config GRKERNSEC_PROC_USER
68858 + bool "Restrict /proc to user only"
68859 + depends on GRKERNSEC_PROC
68860 + help
68861 + If you say Y here, non-root users will only be able to view their own
68862 + processes, and restricts them from viewing network-related information,
68863 + and viewing kernel symbol and module information.
68864 +
68865 +config GRKERNSEC_PROC_USERGROUP
68866 + bool "Allow special group"
68867 + default y if GRKERNSEC_CONFIG_AUTO
68868 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68869 + help
68870 + If you say Y here, you will be able to select a group that will be
68871 + able to view all processes and network-related information. If you've
68872 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68873 + remain hidden. This option is useful if you want to run identd as
68874 + a non-root user. The group you select may also be chosen at boot time
68875 + via "grsec_proc_gid=" on the kernel commandline.
68876 +
68877 +config GRKERNSEC_PROC_GID
68878 + int "GID for special group"
68879 + depends on GRKERNSEC_PROC_USERGROUP
68880 + default 1001
68881 +
68882 +config GRKERNSEC_PROC_ADD
68883 + bool "Additional restrictions"
68884 + default y if GRKERNSEC_CONFIG_AUTO
68885 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68886 + help
68887 + If you say Y here, additional restrictions will be placed on
68888 + /proc that keep normal users from viewing device information and
68889 + slabinfo information that could be useful for exploits.
68890 +
68891 +config GRKERNSEC_LINK
68892 + bool "Linking restrictions"
68893 + default y if GRKERNSEC_CONFIG_AUTO
68894 + help
68895 + If you say Y here, /tmp race exploits will be prevented, since users
68896 + will no longer be able to follow symlinks owned by other users in
68897 + world-writable +t directories (e.g. /tmp), unless the owner of the
68898 + symlink is the owner of the directory. users will also not be
68899 + able to hardlink to files they do not own. If the sysctl option is
68900 + enabled, a sysctl option with name "linking_restrictions" is created.
68901 +
68902 +config GRKERNSEC_SYMLINKOWN
68903 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68904 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68905 + help
68906 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68907 + that prevents it from being used as a security feature. As Apache
68908 + verifies the symlink by performing a stat() against the target of
68909 + the symlink before it is followed, an attacker can setup a symlink
68910 + to point to a same-owned file, then replace the symlink with one
68911 + that targets another user's file just after Apache "validates" the
68912 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68913 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68914 + will be in place for the group you specify. If the sysctl option
68915 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68916 + created.
68917 +
68918 +config GRKERNSEC_SYMLINKOWN_GID
68919 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68920 + depends on GRKERNSEC_SYMLINKOWN
68921 + default 1006
68922 + help
68923 + Setting this GID determines what group kernel-enforced
68924 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68925 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68926 +
68927 +config GRKERNSEC_FIFO
68928 + bool "FIFO restrictions"
68929 + default y if GRKERNSEC_CONFIG_AUTO
68930 + help
68931 + If you say Y here, users will not be able to write to FIFOs they don't
68932 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68933 + the FIFO is the same owner of the directory it's held in. If the sysctl
68934 + option is enabled, a sysctl option with name "fifo_restrictions" is
68935 + created.
68936 +
68937 +config GRKERNSEC_SYSFS_RESTRICT
68938 + bool "Sysfs/debugfs restriction"
68939 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68940 + depends on SYSFS
68941 + help
68942 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68943 + any filesystem normally mounted under it (e.g. debugfs) will be
68944 + mostly accessible only by root. These filesystems generally provide access
68945 + to hardware and debug information that isn't appropriate for unprivileged
68946 + users of the system. Sysfs and debugfs have also become a large source
68947 + of new vulnerabilities, ranging from infoleaks to local compromise.
68948 + There has been very little oversight with an eye toward security involved
68949 + in adding new exporters of information to these filesystems, so their
68950 + use is discouraged.
68951 + For reasons of compatibility, a few directories have been whitelisted
68952 + for access by non-root users:
68953 + /sys/fs/selinux
68954 + /sys/fs/fuse
68955 + /sys/devices/system/cpu
68956 +
68957 +config GRKERNSEC_ROFS
68958 + bool "Runtime read-only mount protection"
68959 + depends on SYSCTL
68960 + help
68961 + If you say Y here, a sysctl option with name "romount_protect" will
68962 + be created. By setting this option to 1 at runtime, filesystems
68963 + will be protected in the following ways:
68964 + * No new writable mounts will be allowed
68965 + * Existing read-only mounts won't be able to be remounted read/write
68966 + * Write operations will be denied on all block devices
68967 + This option acts independently of grsec_lock: once it is set to 1,
68968 + it cannot be turned off. Therefore, please be mindful of the resulting
68969 + behavior if this option is enabled in an init script on a read-only
68970 + filesystem.
68971 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68972 + and GRKERNSEC_IO should be enabled and module loading disabled via
68973 + config or at runtime.
68974 + This feature is mainly intended for secure embedded systems.
68975 +
68976 +
68977 +config GRKERNSEC_DEVICE_SIDECHANNEL
68978 + bool "Eliminate stat/notify-based device sidechannels"
68979 + default y if GRKERNSEC_CONFIG_AUTO
68980 + help
68981 + If you say Y here, timing analyses on block or character
68982 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68983 + will be thwarted for unprivileged users. If a process without
68984 + CAP_MKNOD stats such a device, the last access and last modify times
68985 + will match the device's create time. No access or modify events
68986 + will be triggered through inotify/dnotify/fanotify for such devices.
68987 + This feature will prevent attacks that may at a minimum
68988 + allow an attacker to determine the administrator's password length.
68989 +
68990 +config GRKERNSEC_CHROOT
68991 + bool "Chroot jail restrictions"
68992 + default y if GRKERNSEC_CONFIG_AUTO
68993 + help
68994 + If you say Y here, you will be able to choose several options that will
68995 + make breaking out of a chrooted jail much more difficult. If you
68996 + encounter no software incompatibilities with the following options, it
68997 + is recommended that you enable each one.
68998 +
68999 + Note that the chroot restrictions are not intended to apply to "chroots"
69000 + to directories that are simple bind mounts of the global root filesystem.
69001 + For several other reasons, a user shouldn't expect any significant
69002 + security by performing such a chroot.
69003 +
69004 +config GRKERNSEC_CHROOT_MOUNT
69005 + bool "Deny mounts"
69006 + default y if GRKERNSEC_CONFIG_AUTO
69007 + depends on GRKERNSEC_CHROOT
69008 + help
69009 + If you say Y here, processes inside a chroot will not be able to
69010 + mount or remount filesystems. If the sysctl option is enabled, a
69011 + sysctl option with name "chroot_deny_mount" is created.
69012 +
69013 +config GRKERNSEC_CHROOT_DOUBLE
69014 + bool "Deny double-chroots"
69015 + default y if GRKERNSEC_CONFIG_AUTO
69016 + depends on GRKERNSEC_CHROOT
69017 + help
69018 + If you say Y here, processes inside a chroot will not be able to chroot
69019 + again outside the chroot. This is a widely used method of breaking
69020 + out of a chroot jail and should not be allowed. If the sysctl
69021 + option is enabled, a sysctl option with name
69022 + "chroot_deny_chroot" is created.
69023 +
69024 +config GRKERNSEC_CHROOT_PIVOT
69025 + bool "Deny pivot_root in chroot"
69026 + default y if GRKERNSEC_CONFIG_AUTO
69027 + depends on GRKERNSEC_CHROOT
69028 + help
69029 + If you say Y here, processes inside a chroot will not be able to use
69030 + a function called pivot_root() that was introduced in Linux 2.3.41. It
69031 + works similar to chroot in that it changes the root filesystem. This
69032 + function could be misused in a chrooted process to attempt to break out
69033 + of the chroot, and therefore should not be allowed. If the sysctl
69034 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
69035 + created.
69036 +
69037 +config GRKERNSEC_CHROOT_CHDIR
69038 + bool "Enforce chdir(\"/\") on all chroots"
69039 + default y if GRKERNSEC_CONFIG_AUTO
69040 + depends on GRKERNSEC_CHROOT
69041 + help
69042 + If you say Y here, the current working directory of all newly-chrooted
69043 + applications will be set to the the root directory of the chroot.
69044 + The man page on chroot(2) states:
69045 + Note that this call does not change the current working
69046 + directory, so that `.' can be outside the tree rooted at
69047 + `/'. In particular, the super-user can escape from a
69048 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69049 +
69050 + It is recommended that you say Y here, since it's not known to break
69051 + any software. If the sysctl option is enabled, a sysctl option with
69052 + name "chroot_enforce_chdir" is created.
69053 +
69054 +config GRKERNSEC_CHROOT_CHMOD
69055 + bool "Deny (f)chmod +s"
69056 + default y if GRKERNSEC_CONFIG_AUTO
69057 + depends on GRKERNSEC_CHROOT
69058 + help
69059 + If you say Y here, processes inside a chroot will not be able to chmod
69060 + or fchmod files to make them have suid or sgid bits. This protects
69061 + against another published method of breaking a chroot. If the sysctl
69062 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
69063 + created.
69064 +
69065 +config GRKERNSEC_CHROOT_FCHDIR
69066 + bool "Deny fchdir and fhandle out of chroot"
69067 + default y if GRKERNSEC_CONFIG_AUTO
69068 + depends on GRKERNSEC_CHROOT
69069 + help
69070 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
69071 + to a file descriptor of the chrooting process that points to a directory
69072 + outside the filesystem will be stopped. Additionally, this option prevents
69073 + use of the recently-created syscall for opening files by a guessable "file
69074 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69075 + with name "chroot_deny_fchdir" is created.
69076 +
69077 +config GRKERNSEC_CHROOT_MKNOD
69078 + bool "Deny mknod"
69079 + default y if GRKERNSEC_CONFIG_AUTO
69080 + depends on GRKERNSEC_CHROOT
69081 + help
69082 + If you say Y here, processes inside a chroot will not be allowed to
69083 + mknod. The problem with using mknod inside a chroot is that it
69084 + would allow an attacker to create a device entry that is the same
69085 + as one on the physical root of your system, which could range from
69086 + anything from the console device to a device for your harddrive (which
69087 + they could then use to wipe the drive or steal data). It is recommended
69088 + that you say Y here, unless you run into software incompatibilities.
69089 + If the sysctl option is enabled, a sysctl option with name
69090 + "chroot_deny_mknod" is created.
69091 +
69092 +config GRKERNSEC_CHROOT_SHMAT
69093 + bool "Deny shmat() out of chroot"
69094 + default y if GRKERNSEC_CONFIG_AUTO
69095 + depends on GRKERNSEC_CHROOT
69096 + help
69097 + If you say Y here, processes inside a chroot will not be able to attach
69098 + to shared memory segments that were created outside of the chroot jail.
69099 + It is recommended that you say Y here. If the sysctl option is enabled,
69100 + a sysctl option with name "chroot_deny_shmat" is created.
69101 +
69102 +config GRKERNSEC_CHROOT_UNIX
69103 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
69104 + default y if GRKERNSEC_CONFIG_AUTO
69105 + depends on GRKERNSEC_CHROOT
69106 + help
69107 + If you say Y here, processes inside a chroot will not be able to
69108 + connect to abstract (meaning not belonging to a filesystem) Unix
69109 + domain sockets that were bound outside of a chroot. It is recommended
69110 + that you say Y here. If the sysctl option is enabled, a sysctl option
69111 + with name "chroot_deny_unix" is created.
69112 +
69113 +config GRKERNSEC_CHROOT_FINDTASK
69114 + bool "Protect outside processes"
69115 + default y if GRKERNSEC_CONFIG_AUTO
69116 + depends on GRKERNSEC_CHROOT
69117 + help
69118 + If you say Y here, processes inside a chroot will not be able to
69119 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69120 + getsid, or view any process outside of the chroot. If the sysctl
69121 + option is enabled, a sysctl option with name "chroot_findtask" is
69122 + created.
69123 +
69124 +config GRKERNSEC_CHROOT_NICE
69125 + bool "Restrict priority changes"
69126 + default y if GRKERNSEC_CONFIG_AUTO
69127 + depends on GRKERNSEC_CHROOT
69128 + help
69129 + If you say Y here, processes inside a chroot will not be able to raise
69130 + the priority of processes in the chroot, or alter the priority of
69131 + processes outside the chroot. This provides more security than simply
69132 + removing CAP_SYS_NICE from the process' capability set. If the
69133 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69134 + is created.
69135 +
69136 +config GRKERNSEC_CHROOT_SYSCTL
69137 + bool "Deny sysctl writes"
69138 + default y if GRKERNSEC_CONFIG_AUTO
69139 + depends on GRKERNSEC_CHROOT
69140 + help
69141 + If you say Y here, an attacker in a chroot will not be able to
69142 + write to sysctl entries, either by sysctl(2) or through a /proc
69143 + interface. It is strongly recommended that you say Y here. If the
69144 + sysctl option is enabled, a sysctl option with name
69145 + "chroot_deny_sysctl" is created.
69146 +
69147 +config GRKERNSEC_CHROOT_CAPS
69148 + bool "Capability restrictions"
69149 + default y if GRKERNSEC_CONFIG_AUTO
69150 + depends on GRKERNSEC_CHROOT
69151 + help
69152 + If you say Y here, the capabilities on all processes within a
69153 + chroot jail will be lowered to stop module insertion, raw i/o,
69154 + system and net admin tasks, rebooting the system, modifying immutable
69155 + files, modifying IPC owned by another, and changing the system time.
69156 + This is left an option because it can break some apps. Disable this
69157 + if your chrooted apps are having problems performing those kinds of
69158 + tasks. If the sysctl option is enabled, a sysctl option with
69159 + name "chroot_caps" is created.
69160 +
69161 +config GRKERNSEC_CHROOT_INITRD
69162 + bool "Exempt initrd tasks from restrictions"
69163 + default y if GRKERNSEC_CONFIG_AUTO
69164 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69165 + help
69166 + If you say Y here, tasks started prior to init will be exempted from
69167 + grsecurity's chroot restrictions. This option is mainly meant to
69168 + resolve Plymouth's performing privileged operations unnecessarily
69169 + in a chroot.
69170 +
69171 +endmenu
69172 +menu "Kernel Auditing"
69173 +depends on GRKERNSEC
69174 +
69175 +config GRKERNSEC_AUDIT_GROUP
69176 + bool "Single group for auditing"
69177 + help
69178 + If you say Y here, the exec and chdir logging features will only operate
69179 + on a group you specify. This option is recommended if you only want to
69180 + watch certain users instead of having a large amount of logs from the
69181 + entire system. If the sysctl option is enabled, a sysctl option with
69182 + name "audit_group" is created.
69183 +
69184 +config GRKERNSEC_AUDIT_GID
69185 + int "GID for auditing"
69186 + depends on GRKERNSEC_AUDIT_GROUP
69187 + default 1007
69188 +
69189 +config GRKERNSEC_EXECLOG
69190 + bool "Exec logging"
69191 + help
69192 + If you say Y here, all execve() calls will be logged (since the
69193 + other exec*() calls are frontends to execve(), all execution
69194 + will be logged). Useful for shell-servers that like to keep track
69195 + of their users. If the sysctl option is enabled, a sysctl option with
69196 + name "exec_logging" is created.
69197 + WARNING: This option when enabled will produce a LOT of logs, especially
69198 + on an active system.
69199 +
69200 +config GRKERNSEC_RESLOG
69201 + bool "Resource logging"
69202 + default y if GRKERNSEC_CONFIG_AUTO
69203 + help
69204 + If you say Y here, all attempts to overstep resource limits will
69205 + be logged with the resource name, the requested size, and the current
69206 + limit. It is highly recommended that you say Y here. If the sysctl
69207 + option is enabled, a sysctl option with name "resource_logging" is
69208 + created. If the RBAC system is enabled, the sysctl value is ignored.
69209 +
69210 +config GRKERNSEC_CHROOT_EXECLOG
69211 + bool "Log execs within chroot"
69212 + help
69213 + If you say Y here, all executions inside a chroot jail will be logged
69214 + to syslog. This can cause a large amount of logs if certain
69215 + applications (eg. djb's daemontools) are installed on the system, and
69216 + is therefore left as an option. If the sysctl option is enabled, a
69217 + sysctl option with name "chroot_execlog" is created.
69218 +
69219 +config GRKERNSEC_AUDIT_PTRACE
69220 + bool "Ptrace logging"
69221 + help
69222 + If you say Y here, all attempts to attach to a process via ptrace
69223 + will be logged. If the sysctl option is enabled, a sysctl option
69224 + with name "audit_ptrace" is created.
69225 +
69226 +config GRKERNSEC_AUDIT_CHDIR
69227 + bool "Chdir logging"
69228 + help
69229 + If you say Y here, all chdir() calls will be logged. If the sysctl
69230 + option is enabled, a sysctl option with name "audit_chdir" is created.
69231 +
69232 +config GRKERNSEC_AUDIT_MOUNT
69233 + bool "(Un)Mount logging"
69234 + help
69235 + If you say Y here, all mounts and unmounts will be logged. If the
69236 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69237 + created.
69238 +
69239 +config GRKERNSEC_SIGNAL
69240 + bool "Signal logging"
69241 + default y if GRKERNSEC_CONFIG_AUTO
69242 + help
69243 + If you say Y here, certain important signals will be logged, such as
69244 + SIGSEGV, which will as a result inform you of when a error in a program
69245 + occurred, which in some cases could mean a possible exploit attempt.
69246 + If the sysctl option is enabled, a sysctl option with name
69247 + "signal_logging" is created.
69248 +
69249 +config GRKERNSEC_FORKFAIL
69250 + bool "Fork failure logging"
69251 + help
69252 + If you say Y here, all failed fork() attempts will be logged.
69253 + This could suggest a fork bomb, or someone attempting to overstep
69254 + their process limit. If the sysctl option is enabled, a sysctl option
69255 + with name "forkfail_logging" is created.
69256 +
69257 +config GRKERNSEC_TIME
69258 + bool "Time change logging"
69259 + default y if GRKERNSEC_CONFIG_AUTO
69260 + help
69261 + If you say Y here, any changes of the system clock will be logged.
69262 + If the sysctl option is enabled, a sysctl option with name
69263 + "timechange_logging" is created.
69264 +
69265 +config GRKERNSEC_PROC_IPADDR
69266 + bool "/proc/<pid>/ipaddr support"
69267 + default y if GRKERNSEC_CONFIG_AUTO
69268 + help
69269 + If you say Y here, a new entry will be added to each /proc/<pid>
69270 + directory that contains the IP address of the person using the task.
69271 + The IP is carried across local TCP and AF_UNIX stream sockets.
69272 + This information can be useful for IDS/IPSes to perform remote response
69273 + to a local attack. The entry is readable by only the owner of the
69274 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69275 + the RBAC system), and thus does not create privacy concerns.
69276 +
69277 +config GRKERNSEC_RWXMAP_LOG
69278 + bool 'Denied RWX mmap/mprotect logging'
69279 + default y if GRKERNSEC_CONFIG_AUTO
69280 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69281 + help
69282 + If you say Y here, calls to mmap() and mprotect() with explicit
69283 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69284 + denied by the PAX_MPROTECT feature. This feature will also
69285 + log other problematic scenarios that can occur when PAX_MPROTECT
69286 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69287 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69288 + is created.
69289 +
69290 +endmenu
69291 +
69292 +menu "Executable Protections"
69293 +depends on GRKERNSEC
69294 +
69295 +config GRKERNSEC_DMESG
69296 + bool "Dmesg(8) restriction"
69297 + default y if GRKERNSEC_CONFIG_AUTO
69298 + help
69299 + If you say Y here, non-root users will not be able to use dmesg(8)
69300 + to view the contents of the kernel's circular log buffer.
69301 + The kernel's log buffer often contains kernel addresses and other
69302 + identifying information useful to an attacker in fingerprinting a
69303 + system for a targeted exploit.
69304 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69305 + created.
69306 +
69307 +config GRKERNSEC_HARDEN_PTRACE
69308 + bool "Deter ptrace-based process snooping"
69309 + default y if GRKERNSEC_CONFIG_AUTO
69310 + help
69311 + If you say Y here, TTY sniffers and other malicious monitoring
69312 + programs implemented through ptrace will be defeated. If you
69313 + have been using the RBAC system, this option has already been
69314 + enabled for several years for all users, with the ability to make
69315 + fine-grained exceptions.
69316 +
69317 + This option only affects the ability of non-root users to ptrace
69318 + processes that are not a descendent of the ptracing process.
69319 + This means that strace ./binary and gdb ./binary will still work,
69320 + but attaching to arbitrary processes will not. If the sysctl
69321 + option is enabled, a sysctl option with name "harden_ptrace" is
69322 + created.
69323 +
69324 +config GRKERNSEC_PTRACE_READEXEC
69325 + bool "Require read access to ptrace sensitive binaries"
69326 + default y if GRKERNSEC_CONFIG_AUTO
69327 + help
69328 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69329 + binaries. This option is useful in environments that
69330 + remove the read bits (e.g. file mode 4711) from suid binaries to
69331 + prevent infoleaking of their contents. This option adds
69332 + consistency to the use of that file mode, as the binary could normally
69333 + be read out when run without privileges while ptracing.
69334 +
69335 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69336 + is created.
69337 +
69338 +config GRKERNSEC_SETXID
69339 + bool "Enforce consistent multithreaded privileges"
69340 + default y if GRKERNSEC_CONFIG_AUTO
69341 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69342 + help
69343 + If you say Y here, a change from a root uid to a non-root uid
69344 + in a multithreaded application will cause the resulting uids,
69345 + gids, supplementary groups, and capabilities in that thread
69346 + to be propagated to the other threads of the process. In most
69347 + cases this is unnecessary, as glibc will emulate this behavior
69348 + on behalf of the application. Other libcs do not act in the
69349 + same way, allowing the other threads of the process to continue
69350 + running with root privileges. If the sysctl option is enabled,
69351 + a sysctl option with name "consistent_setxid" is created.
69352 +
69353 +config GRKERNSEC_HARDEN_IPC
69354 + bool "Disallow access to overly-permissive IPC objects"
69355 + default y if GRKERNSEC_CONFIG_AUTO
69356 + depends on SYSVIPC
69357 + help
69358 + If you say Y here, access to overly-permissive IPC objects (shared
69359 + memory, message queues, and semaphores) will be denied for processes
69360 + given the following criteria beyond normal permission checks:
69361 + 1) If the IPC object is world-accessible and the euid doesn't match
69362 + that of the creator or current uid for the IPC object
69363 + 2) If the IPC object is group-accessible and the egid doesn't
69364 + match that of the creator or current gid for the IPC object
69365 + It's a common error to grant too much permission to these objects,
69366 + with impact ranging from denial of service and information leaking to
69367 + privilege escalation. This feature was developed in response to
69368 + research by Tim Brown:
69369 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69370 + who found hundreds of such insecure usages. Processes with
69371 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69372 + If the sysctl option is enabled, a sysctl option with name
69373 + "harden_ipc" is created.
69374 +
69375 +config GRKERNSEC_TPE
69376 + bool "Trusted Path Execution (TPE)"
69377 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69378 + help
69379 + If you say Y here, you will be able to choose a gid to add to the
69380 + supplementary groups of users you want to mark as "untrusted."
69381 + These users will not be able to execute any files that are not in
69382 + root-owned directories writable only by root. If the sysctl option
69383 + is enabled, a sysctl option with name "tpe" is created.
69384 +
69385 +config GRKERNSEC_TPE_ALL
69386 + bool "Partially restrict all non-root users"
69387 + depends on GRKERNSEC_TPE
69388 + help
69389 + If you say Y here, all non-root users will be covered under
69390 + a weaker TPE restriction. This is separate from, and in addition to,
69391 + the main TPE options that you have selected elsewhere. Thus, if a
69392 + "trusted" GID is chosen, this restriction applies to even that GID.
69393 + Under this restriction, all non-root users will only be allowed to
69394 + execute files in directories they own that are not group or
69395 + world-writable, or in directories owned by root and writable only by
69396 + root. If the sysctl option is enabled, a sysctl option with name
69397 + "tpe_restrict_all" is created.
69398 +
69399 +config GRKERNSEC_TPE_INVERT
69400 + bool "Invert GID option"
69401 + depends on GRKERNSEC_TPE
69402 + help
69403 + If you say Y here, the group you specify in the TPE configuration will
69404 + decide what group TPE restrictions will be *disabled* for. This
69405 + option is useful if you want TPE restrictions to be applied to most
69406 + users on the system. If the sysctl option is enabled, a sysctl option
69407 + with name "tpe_invert" is created. Unlike other sysctl options, this
69408 + entry will default to on for backward-compatibility.
69409 +
69410 +config GRKERNSEC_TPE_GID
69411 + int
69412 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69413 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69414 +
69415 +config GRKERNSEC_TPE_UNTRUSTED_GID
69416 + int "GID for TPE-untrusted users"
69417 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69418 + default 1005
69419 + help
69420 + Setting this GID determines what group TPE restrictions will be
69421 + *enabled* for. If the sysctl option is enabled, a sysctl option
69422 + with name "tpe_gid" is created.
69423 +
69424 +config GRKERNSEC_TPE_TRUSTED_GID
69425 + int "GID for TPE-trusted users"
69426 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69427 + default 1005
69428 + help
69429 + Setting this GID determines what group TPE restrictions will be
69430 + *disabled* for. If the sysctl option is enabled, a sysctl option
69431 + with name "tpe_gid" is created.
69432 +
69433 +endmenu
69434 +menu "Network Protections"
69435 +depends on GRKERNSEC
69436 +
69437 +config GRKERNSEC_BLACKHOLE
69438 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69439 + default y if GRKERNSEC_CONFIG_AUTO
69440 + depends on NET
69441 + help
69442 + If you say Y here, neither TCP resets nor ICMP
69443 + destination-unreachable packets will be sent in response to packets
69444 + sent to ports for which no associated listening process exists.
69445 + It will also prevent the sending of ICMP protocol unreachable packets
69446 + in response to packets with unknown protocols.
69447 + This feature supports both IPV4 and IPV6 and exempts the
69448 + loopback interface from blackholing. Enabling this feature
69449 + makes a host more resilient to DoS attacks and reduces network
69450 + visibility against scanners.
69451 +
69452 + The blackhole feature as-implemented is equivalent to the FreeBSD
69453 + blackhole feature, as it prevents RST responses to all packets, not
69454 + just SYNs. Under most application behavior this causes no
69455 + problems, but applications (like haproxy) may not close certain
69456 + connections in a way that cleanly terminates them on the remote
69457 + end, leaving the remote host in LAST_ACK state. Because of this
69458 + side-effect and to prevent intentional LAST_ACK DoSes, this
69459 + feature also adds automatic mitigation against such attacks.
69460 + The mitigation drastically reduces the amount of time a socket
69461 + can spend in LAST_ACK state. If you're using haproxy and not
69462 + all servers it connects to have this option enabled, consider
69463 + disabling this feature on the haproxy host.
69464 +
69465 + If the sysctl option is enabled, two sysctl options with names
69466 + "ip_blackhole" and "lastack_retries" will be created.
69467 + While "ip_blackhole" takes the standard zero/non-zero on/off
69468 + toggle, "lastack_retries" uses the same kinds of values as
69469 + "tcp_retries1" and "tcp_retries2". The default value of 4
69470 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69471 + state.
69472 +
69473 +config GRKERNSEC_NO_SIMULT_CONNECT
69474 + bool "Disable TCP Simultaneous Connect"
69475 + default y if GRKERNSEC_CONFIG_AUTO
69476 + depends on NET
69477 + help
69478 + If you say Y here, a feature by Willy Tarreau will be enabled that
69479 + removes a weakness in Linux's strict implementation of TCP that
69480 + allows two clients to connect to each other without either entering
69481 + a listening state. The weakness allows an attacker to easily prevent
69482 + a client from connecting to a known server provided the source port
69483 + for the connection is guessed correctly.
69484 +
69485 + As the weakness could be used to prevent an antivirus or IPS from
69486 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69487 + it should be eliminated by enabling this option. Though Linux is
69488 + one of few operating systems supporting simultaneous connect, it
69489 + has no legitimate use in practice and is rarely supported by firewalls.
69490 +
69491 +config GRKERNSEC_SOCKET
69492 + bool "Socket restrictions"
69493 + depends on NET
69494 + help
69495 + If you say Y here, you will be able to choose from several options.
69496 + If you assign a GID on your system and add it to the supplementary
69497 + groups of users you want to restrict socket access to, this patch
69498 + will perform up to three things, based on the option(s) you choose.
69499 +
69500 +config GRKERNSEC_SOCKET_ALL
69501 + bool "Deny any sockets to group"
69502 + depends on GRKERNSEC_SOCKET
69503 + help
69504 + If you say Y here, you will be able to choose a GID of whose users will
69505 + be unable to connect to other hosts from your machine or run server
69506 + applications from your machine. If the sysctl option is enabled, a
69507 + sysctl option with name "socket_all" is created.
69508 +
69509 +config GRKERNSEC_SOCKET_ALL_GID
69510 + int "GID to deny all sockets for"
69511 + depends on GRKERNSEC_SOCKET_ALL
69512 + default 1004
69513 + help
69514 + Here you can choose the GID to disable socket access for. Remember to
69515 + add the users you want socket access disabled for to the GID
69516 + specified here. If the sysctl option is enabled, a sysctl option
69517 + with name "socket_all_gid" is created.
69518 +
69519 +config GRKERNSEC_SOCKET_CLIENT
69520 + bool "Deny client sockets to group"
69521 + depends on GRKERNSEC_SOCKET
69522 + help
69523 + If you say Y here, you will be able to choose a GID of whose users will
69524 + be unable to connect to other hosts from your machine, but will be
69525 + able to run servers. If this option is enabled, all users in the group
69526 + you specify will have to use passive mode when initiating ftp transfers
69527 + from the shell on your machine. If the sysctl option is enabled, a
69528 + sysctl option with name "socket_client" is created.
69529 +
69530 +config GRKERNSEC_SOCKET_CLIENT_GID
69531 + int "GID to deny client sockets for"
69532 + depends on GRKERNSEC_SOCKET_CLIENT
69533 + default 1003
69534 + help
69535 + Here you can choose the GID to disable client socket access for.
69536 + Remember to add the users you want client socket access disabled for to
69537 + the GID specified here. If the sysctl option is enabled, a sysctl
69538 + option with name "socket_client_gid" is created.
69539 +
69540 +config GRKERNSEC_SOCKET_SERVER
69541 + bool "Deny server sockets to group"
69542 + depends on GRKERNSEC_SOCKET
69543 + help
69544 + If you say Y here, you will be able to choose a GID of whose users will
69545 + be unable to run server applications from your machine. If the sysctl
69546 + option is enabled, a sysctl option with name "socket_server" is created.
69547 +
69548 +config GRKERNSEC_SOCKET_SERVER_GID
69549 + int "GID to deny server sockets for"
69550 + depends on GRKERNSEC_SOCKET_SERVER
69551 + default 1002
69552 + help
69553 + Here you can choose the GID to disable server socket access for.
69554 + Remember to add the users you want server socket access disabled for to
69555 + the GID specified here. If the sysctl option is enabled, a sysctl
69556 + option with name "socket_server_gid" is created.
69557 +
69558 +endmenu
69559 +
69560 +menu "Physical Protections"
69561 +depends on GRKERNSEC
69562 +
69563 +config GRKERNSEC_DENYUSB
69564 + bool "Deny new USB connections after toggle"
69565 + default y if GRKERNSEC_CONFIG_AUTO
69566 + depends on SYSCTL && USB_SUPPORT
69567 + help
69568 + If you say Y here, a new sysctl option with name "deny_new_usb"
69569 + will be created. Setting its value to 1 will prevent any new
69570 + USB devices from being recognized by the OS. Any attempted USB
69571 + device insertion will be logged. This option is intended to be
69572 + used against custom USB devices designed to exploit vulnerabilities
69573 + in various USB device drivers.
69574 +
69575 + For greatest effectiveness, this sysctl should be set after any
69576 + relevant init scripts. This option is safe to enable in distros
69577 + as each user can choose whether or not to toggle the sysctl.
69578 +
69579 +config GRKERNSEC_DENYUSB_FORCE
69580 + bool "Reject all USB devices not connected at boot"
69581 + select USB
69582 + depends on GRKERNSEC_DENYUSB
69583 + help
69584 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69585 + that doesn't involve a sysctl entry. This option should only be
69586 + enabled if you're sure you want to deny all new USB connections
69587 + at runtime and don't want to modify init scripts. This should not
69588 + be enabled by distros. It forces the core USB code to be built
69589 + into the kernel image so that all devices connected at boot time
69590 + can be recognized and new USB device connections can be prevented
69591 + prior to init running.
69592 +
69593 +endmenu
69594 +
69595 +menu "Sysctl Support"
69596 +depends on GRKERNSEC && SYSCTL
69597 +
69598 +config GRKERNSEC_SYSCTL
69599 + bool "Sysctl support"
69600 + default y if GRKERNSEC_CONFIG_AUTO
69601 + help
69602 + If you say Y here, you will be able to change the options that
69603 + grsecurity runs with at bootup, without having to recompile your
69604 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69605 + to enable (1) or disable (0) various features. All the sysctl entries
69606 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69607 + All features enabled in the kernel configuration are disabled at boot
69608 + if you do not say Y to the "Turn on features by default" option.
69609 + All options should be set at startup, and the grsec_lock entry should
69610 + be set to a non-zero value after all the options are set.
69611 + *THIS IS EXTREMELY IMPORTANT*
69612 +
69613 +config GRKERNSEC_SYSCTL_DISTRO
69614 + bool "Extra sysctl support for distro makers (READ HELP)"
69615 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69616 + help
69617 + If you say Y here, additional sysctl options will be created
69618 + for features that affect processes running as root. Therefore,
69619 + it is critical when using this option that the grsec_lock entry be
69620 + enabled after boot. Only distros with prebuilt kernel packages
69621 + with this option enabled that can ensure grsec_lock is enabled
69622 + after boot should use this option.
69623 + *Failure to set grsec_lock after boot makes all grsec features
69624 + this option covers useless*
69625 +
69626 + Currently this option creates the following sysctl entries:
69627 + "Disable Privileged I/O": "disable_priv_io"
69628 +
69629 +config GRKERNSEC_SYSCTL_ON
69630 + bool "Turn on features by default"
69631 + default y if GRKERNSEC_CONFIG_AUTO
69632 + depends on GRKERNSEC_SYSCTL
69633 + help
69634 + If you say Y here, instead of having all features enabled in the
69635 + kernel configuration disabled at boot time, the features will be
69636 + enabled at boot time. It is recommended you say Y here unless
69637 + there is some reason you would want all sysctl-tunable features to
69638 + be disabled by default. As mentioned elsewhere, it is important
69639 + to enable the grsec_lock entry once you have finished modifying
69640 + the sysctl entries.
69641 +
69642 +endmenu
69643 +menu "Logging Options"
69644 +depends on GRKERNSEC
69645 +
69646 +config GRKERNSEC_FLOODTIME
69647 + int "Seconds in between log messages (minimum)"
69648 + default 10
69649 + help
69650 + This option allows you to enforce the number of seconds between
69651 + grsecurity log messages. The default should be suitable for most
69652 + people, however, if you choose to change it, choose a value small enough
69653 + to allow informative logs to be produced, but large enough to
69654 + prevent flooding.
69655 +
69656 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69657 + any rate limiting on grsecurity log messages.
69658 +
69659 +config GRKERNSEC_FLOODBURST
69660 + int "Number of messages in a burst (maximum)"
69661 + default 6
69662 + help
69663 + This option allows you to choose the maximum number of messages allowed
69664 + within the flood time interval you chose in a separate option. The
69665 + default should be suitable for most people, however if you find that
69666 + many of your logs are being interpreted as flooding, you may want to
69667 + raise this value.
69668 +
69669 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69670 + any rate limiting on grsecurity log messages.
69671 +
69672 +endmenu
69673 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69674 new file mode 100644
69675 index 0000000..30ababb
69676 --- /dev/null
69677 +++ b/grsecurity/Makefile
69678 @@ -0,0 +1,54 @@
69679 +# grsecurity – access control and security hardening for Linux
69680 +# All code in this directory and various hooks located throughout the Linux kernel are
69681 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69682 +# http://www.grsecurity.net spender@grsecurity.net
69683 +#
69684 +# This program is free software; you can redistribute it and/or
69685 +# modify it under the terms of the GNU General Public License version 2
69686 +# as published by the Free Software Foundation.
69687 +#
69688 +# This program is distributed in the hope that it will be useful,
69689 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69690 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69691 +# GNU General Public License for more details.
69692 +#
69693 +# You should have received a copy of the GNU General Public License
69694 +# along with this program; if not, write to the Free Software
69695 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69696 +
69697 +KBUILD_CFLAGS += -Werror
69698 +
69699 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69700 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69701 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69702 + grsec_usb.o grsec_ipc.o grsec_proc.o
69703 +
69704 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69705 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69706 + gracl_learn.o grsec_log.o gracl_policy.o
69707 +ifdef CONFIG_COMPAT
69708 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69709 +endif
69710 +
69711 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69712 +
69713 +ifdef CONFIG_NET
69714 +obj-y += grsec_sock.o
69715 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69716 +endif
69717 +
69718 +ifndef CONFIG_GRKERNSEC
69719 +obj-y += grsec_disabled.o
69720 +endif
69721 +
69722 +ifdef CONFIG_GRKERNSEC_HIDESYM
69723 +extra-y := grsec_hidesym.o
69724 +$(obj)/grsec_hidesym.o:
69725 + @-chmod -f 500 /boot
69726 + @-chmod -f 500 /lib/modules
69727 + @-chmod -f 500 /lib64/modules
69728 + @-chmod -f 500 /lib32/modules
69729 + @-chmod -f 700 .
69730 + @-chmod -f 700 $(objtree)
69731 + @echo ' grsec: protected kernel image paths'
69732 +endif
69733 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69734 new file mode 100644
69735 index 0000000..6ae3aa0
69736 --- /dev/null
69737 +++ b/grsecurity/gracl.c
69738 @@ -0,0 +1,2703 @@
69739 +#include <linux/kernel.h>
69740 +#include <linux/module.h>
69741 +#include <linux/sched.h>
69742 +#include <linux/mm.h>
69743 +#include <linux/file.h>
69744 +#include <linux/fs.h>
69745 +#include <linux/namei.h>
69746 +#include <linux/mount.h>
69747 +#include <linux/tty.h>
69748 +#include <linux/proc_fs.h>
69749 +#include <linux/lglock.h>
69750 +#include <linux/slab.h>
69751 +#include <linux/vmalloc.h>
69752 +#include <linux/types.h>
69753 +#include <linux/sysctl.h>
69754 +#include <linux/netdevice.h>
69755 +#include <linux/ptrace.h>
69756 +#include <linux/gracl.h>
69757 +#include <linux/gralloc.h>
69758 +#include <linux/security.h>
69759 +#include <linux/grinternal.h>
69760 +#include <linux/pid_namespace.h>
69761 +#include <linux/stop_machine.h>
69762 +#include <linux/fdtable.h>
69763 +#include <linux/percpu.h>
69764 +#include <linux/lglock.h>
69765 +#include <linux/hugetlb.h>
69766 +#include <linux/posix-timers.h>
69767 +#include <linux/prefetch.h>
69768 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69769 +#include <linux/magic.h>
69770 +#include <linux/pagemap.h>
69771 +#include "../fs/btrfs/async-thread.h"
69772 +#include "../fs/btrfs/ctree.h"
69773 +#include "../fs/btrfs/btrfs_inode.h"
69774 +#endif
69775 +#include "../fs/mount.h"
69776 +
69777 +#include <asm/uaccess.h>
69778 +#include <asm/errno.h>
69779 +#include <asm/mman.h>
69780 +
69781 +#define FOR_EACH_ROLE_START(role) \
69782 + role = running_polstate.role_list; \
69783 + while (role) {
69784 +
69785 +#define FOR_EACH_ROLE_END(role) \
69786 + role = role->prev; \
69787 + }
69788 +
69789 +extern struct path gr_real_root;
69790 +
69791 +static struct gr_policy_state running_polstate;
69792 +struct gr_policy_state *polstate = &running_polstate;
69793 +extern struct gr_alloc_state *current_alloc_state;
69794 +
69795 +extern char *gr_shared_page[4];
69796 +DEFINE_RWLOCK(gr_inode_lock);
69797 +
69798 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69799 +
69800 +#ifdef CONFIG_NET
69801 +extern struct vfsmount *sock_mnt;
69802 +#endif
69803 +
69804 +extern struct vfsmount *pipe_mnt;
69805 +extern struct vfsmount *shm_mnt;
69806 +
69807 +#ifdef CONFIG_HUGETLBFS
69808 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69809 +#endif
69810 +
69811 +extern u16 acl_sp_role_value;
69812 +extern struct acl_object_label *fakefs_obj_rw;
69813 +extern struct acl_object_label *fakefs_obj_rwx;
69814 +
69815 +int gr_acl_is_enabled(void)
69816 +{
69817 + return (gr_status & GR_READY);
69818 +}
69819 +
69820 +void gr_enable_rbac_system(void)
69821 +{
69822 + pax_open_kernel();
69823 + gr_status |= GR_READY;
69824 + pax_close_kernel();
69825 +}
69826 +
69827 +int gr_rbac_disable(void *unused)
69828 +{
69829 + pax_open_kernel();
69830 + gr_status &= ~GR_READY;
69831 + pax_close_kernel();
69832 +
69833 + return 0;
69834 +}
69835 +
69836 +static inline dev_t __get_dev(const struct dentry *dentry)
69837 +{
69838 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69839 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69840 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69841 + else
69842 +#endif
69843 + return dentry->d_sb->s_dev;
69844 +}
69845 +
69846 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69847 +{
69848 + return __get_dev(dentry);
69849 +}
69850 +
69851 +static char gr_task_roletype_to_char(struct task_struct *task)
69852 +{
69853 + switch (task->role->roletype &
69854 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69855 + GR_ROLE_SPECIAL)) {
69856 + case GR_ROLE_DEFAULT:
69857 + return 'D';
69858 + case GR_ROLE_USER:
69859 + return 'U';
69860 + case GR_ROLE_GROUP:
69861 + return 'G';
69862 + case GR_ROLE_SPECIAL:
69863 + return 'S';
69864 + }
69865 +
69866 + return 'X';
69867 +}
69868 +
69869 +char gr_roletype_to_char(void)
69870 +{
69871 + return gr_task_roletype_to_char(current);
69872 +}
69873 +
69874 +__inline__ int
69875 +gr_acl_tpe_check(void)
69876 +{
69877 + if (unlikely(!(gr_status & GR_READY)))
69878 + return 0;
69879 + if (current->role->roletype & GR_ROLE_TPE)
69880 + return 1;
69881 + else
69882 + return 0;
69883 +}
69884 +
69885 +int
69886 +gr_handle_rawio(const struct inode *inode)
69887 +{
69888 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69889 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69890 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69891 + !capable(CAP_SYS_RAWIO))
69892 + return 1;
69893 +#endif
69894 + return 0;
69895 +}
69896 +
69897 +int
69898 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69899 +{
69900 + if (likely(lena != lenb))
69901 + return 0;
69902 +
69903 + return !memcmp(a, b, lena);
69904 +}
69905 +
69906 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69907 +{
69908 + *buflen -= namelen;
69909 + if (*buflen < 0)
69910 + return -ENAMETOOLONG;
69911 + *buffer -= namelen;
69912 + memcpy(*buffer, str, namelen);
69913 + return 0;
69914 +}
69915 +
69916 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69917 +{
69918 + return prepend(buffer, buflen, name->name, name->len);
69919 +}
69920 +
69921 +static int prepend_path(const struct path *path, struct path *root,
69922 + char **buffer, int *buflen)
69923 +{
69924 + struct dentry *dentry = path->dentry;
69925 + struct vfsmount *vfsmnt = path->mnt;
69926 + struct mount *mnt = real_mount(vfsmnt);
69927 + bool slash = false;
69928 + int error = 0;
69929 +
69930 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69931 + struct dentry * parent;
69932 +
69933 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69934 + /* Global root? */
69935 + if (!mnt_has_parent(mnt)) {
69936 + goto out;
69937 + }
69938 + dentry = mnt->mnt_mountpoint;
69939 + mnt = mnt->mnt_parent;
69940 + vfsmnt = &mnt->mnt;
69941 + continue;
69942 + }
69943 + parent = dentry->d_parent;
69944 + prefetch(parent);
69945 + spin_lock(&dentry->d_lock);
69946 + error = prepend_name(buffer, buflen, &dentry->d_name);
69947 + spin_unlock(&dentry->d_lock);
69948 + if (!error)
69949 + error = prepend(buffer, buflen, "/", 1);
69950 + if (error)
69951 + break;
69952 +
69953 + slash = true;
69954 + dentry = parent;
69955 + }
69956 +
69957 +out:
69958 + if (!error && !slash)
69959 + error = prepend(buffer, buflen, "/", 1);
69960 +
69961 + return error;
69962 +}
69963 +
69964 +/* this must be called with mount_lock and rename_lock held */
69965 +
69966 +static char *__our_d_path(const struct path *path, struct path *root,
69967 + char *buf, int buflen)
69968 +{
69969 + char *res = buf + buflen;
69970 + int error;
69971 +
69972 + prepend(&res, &buflen, "\0", 1);
69973 + error = prepend_path(path, root, &res, &buflen);
69974 + if (error)
69975 + return ERR_PTR(error);
69976 +
69977 + return res;
69978 +}
69979 +
69980 +static char *
69981 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69982 +{
69983 + char *retval;
69984 +
69985 + retval = __our_d_path(path, root, buf, buflen);
69986 + if (unlikely(IS_ERR(retval)))
69987 + retval = strcpy(buf, "<path too long>");
69988 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69989 + retval[1] = '\0';
69990 +
69991 + return retval;
69992 +}
69993 +
69994 +static char *
69995 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69996 + char *buf, int buflen)
69997 +{
69998 + struct path path;
69999 + char *res;
70000 +
70001 + path.dentry = (struct dentry *)dentry;
70002 + path.mnt = (struct vfsmount *)vfsmnt;
70003 +
70004 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70005 + by the RBAC system */
70006 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
70007 +
70008 + return res;
70009 +}
70010 +
70011 +static char *
70012 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70013 + char *buf, int buflen)
70014 +{
70015 + char *res;
70016 + struct path path;
70017 + struct path root;
70018 + struct task_struct *reaper = init_pid_ns.child_reaper;
70019 +
70020 + path.dentry = (struct dentry *)dentry;
70021 + path.mnt = (struct vfsmount *)vfsmnt;
70022 +
70023 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70024 + get_fs_root(reaper->fs, &root);
70025 +
70026 + read_seqlock_excl(&mount_lock);
70027 + write_seqlock(&rename_lock);
70028 + res = gen_full_path(&path, &root, buf, buflen);
70029 + write_sequnlock(&rename_lock);
70030 + read_sequnlock_excl(&mount_lock);
70031 +
70032 + path_put(&root);
70033 + return res;
70034 +}
70035 +
70036 +char *
70037 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70038 +{
70039 + char *ret;
70040 + read_seqlock_excl(&mount_lock);
70041 + write_seqlock(&rename_lock);
70042 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70043 + PAGE_SIZE);
70044 + write_sequnlock(&rename_lock);
70045 + read_sequnlock_excl(&mount_lock);
70046 + return ret;
70047 +}
70048 +
70049 +static char *
70050 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70051 +{
70052 + char *ret;
70053 + char *buf;
70054 + int buflen;
70055 +
70056 + read_seqlock_excl(&mount_lock);
70057 + write_seqlock(&rename_lock);
70058 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70059 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70060 + buflen = (int)(ret - buf);
70061 + if (buflen >= 5)
70062 + prepend(&ret, &buflen, "/proc", 5);
70063 + else
70064 + ret = strcpy(buf, "<path too long>");
70065 + write_sequnlock(&rename_lock);
70066 + read_sequnlock_excl(&mount_lock);
70067 + return ret;
70068 +}
70069 +
70070 +char *
70071 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70072 +{
70073 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70074 + PAGE_SIZE);
70075 +}
70076 +
70077 +char *
70078 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70079 +{
70080 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70081 + PAGE_SIZE);
70082 +}
70083 +
70084 +char *
70085 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70086 +{
70087 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70088 + PAGE_SIZE);
70089 +}
70090 +
70091 +char *
70092 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70093 +{
70094 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70095 + PAGE_SIZE);
70096 +}
70097 +
70098 +char *
70099 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70100 +{
70101 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70102 + PAGE_SIZE);
70103 +}
70104 +
70105 +__inline__ __u32
70106 +to_gr_audit(const __u32 reqmode)
70107 +{
70108 + /* masks off auditable permission flags, then shifts them to create
70109 + auditing flags, and adds the special case of append auditing if
70110 + we're requesting write */
70111 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70112 +}
70113 +
70114 +struct acl_role_label *
70115 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70116 + const gid_t gid)
70117 +{
70118 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70119 + struct acl_role_label *match;
70120 + struct role_allowed_ip *ipp;
70121 + unsigned int x;
70122 + u32 curr_ip = task->signal->saved_ip;
70123 +
70124 + match = state->acl_role_set.r_hash[index];
70125 +
70126 + while (match) {
70127 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70128 + for (x = 0; x < match->domain_child_num; x++) {
70129 + if (match->domain_children[x] == uid)
70130 + goto found;
70131 + }
70132 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70133 + break;
70134 + match = match->next;
70135 + }
70136 +found:
70137 + if (match == NULL) {
70138 + try_group:
70139 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70140 + match = state->acl_role_set.r_hash[index];
70141 +
70142 + while (match) {
70143 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70144 + for (x = 0; x < match->domain_child_num; x++) {
70145 + if (match->domain_children[x] == gid)
70146 + goto found2;
70147 + }
70148 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70149 + break;
70150 + match = match->next;
70151 + }
70152 +found2:
70153 + if (match == NULL)
70154 + match = state->default_role;
70155 + if (match->allowed_ips == NULL)
70156 + return match;
70157 + else {
70158 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70159 + if (likely
70160 + ((ntohl(curr_ip) & ipp->netmask) ==
70161 + (ntohl(ipp->addr) & ipp->netmask)))
70162 + return match;
70163 + }
70164 + match = state->default_role;
70165 + }
70166 + } else if (match->allowed_ips == NULL) {
70167 + return match;
70168 + } else {
70169 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70170 + if (likely
70171 + ((ntohl(curr_ip) & ipp->netmask) ==
70172 + (ntohl(ipp->addr) & ipp->netmask)))
70173 + return match;
70174 + }
70175 + goto try_group;
70176 + }
70177 +
70178 + return match;
70179 +}
70180 +
70181 +static struct acl_role_label *
70182 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70183 + const gid_t gid)
70184 +{
70185 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70186 +}
70187 +
70188 +struct acl_subject_label *
70189 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70190 + const struct acl_role_label *role)
70191 +{
70192 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70193 + struct acl_subject_label *match;
70194 +
70195 + match = role->subj_hash[index];
70196 +
70197 + while (match && (match->inode != ino || match->device != dev ||
70198 + (match->mode & GR_DELETED))) {
70199 + match = match->next;
70200 + }
70201 +
70202 + if (match && !(match->mode & GR_DELETED))
70203 + return match;
70204 + else
70205 + return NULL;
70206 +}
70207 +
70208 +struct acl_subject_label *
70209 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70210 + const struct acl_role_label *role)
70211 +{
70212 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70213 + struct acl_subject_label *match;
70214 +
70215 + match = role->subj_hash[index];
70216 +
70217 + while (match && (match->inode != ino || match->device != dev ||
70218 + !(match->mode & GR_DELETED))) {
70219 + match = match->next;
70220 + }
70221 +
70222 + if (match && (match->mode & GR_DELETED))
70223 + return match;
70224 + else
70225 + return NULL;
70226 +}
70227 +
70228 +static struct acl_object_label *
70229 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70230 + const struct acl_subject_label *subj)
70231 +{
70232 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70233 + struct acl_object_label *match;
70234 +
70235 + match = subj->obj_hash[index];
70236 +
70237 + while (match && (match->inode != ino || match->device != dev ||
70238 + (match->mode & GR_DELETED))) {
70239 + match = match->next;
70240 + }
70241 +
70242 + if (match && !(match->mode & GR_DELETED))
70243 + return match;
70244 + else
70245 + return NULL;
70246 +}
70247 +
70248 +static struct acl_object_label *
70249 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70250 + const struct acl_subject_label *subj)
70251 +{
70252 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70253 + struct acl_object_label *match;
70254 +
70255 + match = subj->obj_hash[index];
70256 +
70257 + while (match && (match->inode != ino || match->device != dev ||
70258 + !(match->mode & GR_DELETED))) {
70259 + match = match->next;
70260 + }
70261 +
70262 + if (match && (match->mode & GR_DELETED))
70263 + return match;
70264 +
70265 + match = subj->obj_hash[index];
70266 +
70267 + while (match && (match->inode != ino || match->device != dev ||
70268 + (match->mode & GR_DELETED))) {
70269 + match = match->next;
70270 + }
70271 +
70272 + if (match && !(match->mode & GR_DELETED))
70273 + return match;
70274 + else
70275 + return NULL;
70276 +}
70277 +
70278 +struct name_entry *
70279 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70280 +{
70281 + unsigned int len = strlen(name);
70282 + unsigned int key = full_name_hash(name, len);
70283 + unsigned int index = key % state->name_set.n_size;
70284 + struct name_entry *match;
70285 +
70286 + match = state->name_set.n_hash[index];
70287 +
70288 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70289 + match = match->next;
70290 +
70291 + return match;
70292 +}
70293 +
70294 +static struct name_entry *
70295 +lookup_name_entry(const char *name)
70296 +{
70297 + return __lookup_name_entry(&running_polstate, name);
70298 +}
70299 +
70300 +static struct name_entry *
70301 +lookup_name_entry_create(const char *name)
70302 +{
70303 + unsigned int len = strlen(name);
70304 + unsigned int key = full_name_hash(name, len);
70305 + unsigned int index = key % running_polstate.name_set.n_size;
70306 + struct name_entry *match;
70307 +
70308 + match = running_polstate.name_set.n_hash[index];
70309 +
70310 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70311 + !match->deleted))
70312 + match = match->next;
70313 +
70314 + if (match && match->deleted)
70315 + return match;
70316 +
70317 + match = running_polstate.name_set.n_hash[index];
70318 +
70319 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70320 + match->deleted))
70321 + match = match->next;
70322 +
70323 + if (match && !match->deleted)
70324 + return match;
70325 + else
70326 + return NULL;
70327 +}
70328 +
70329 +static struct inodev_entry *
70330 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70331 +{
70332 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70333 + struct inodev_entry *match;
70334 +
70335 + match = running_polstate.inodev_set.i_hash[index];
70336 +
70337 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70338 + match = match->next;
70339 +
70340 + return match;
70341 +}
70342 +
70343 +void
70344 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70345 +{
70346 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70347 + state->inodev_set.i_size);
70348 + struct inodev_entry **curr;
70349 +
70350 + entry->prev = NULL;
70351 +
70352 + curr = &state->inodev_set.i_hash[index];
70353 + if (*curr != NULL)
70354 + (*curr)->prev = entry;
70355 +
70356 + entry->next = *curr;
70357 + *curr = entry;
70358 +
70359 + return;
70360 +}
70361 +
70362 +static void
70363 +insert_inodev_entry(struct inodev_entry *entry)
70364 +{
70365 + __insert_inodev_entry(&running_polstate, entry);
70366 +}
70367 +
70368 +void
70369 +insert_acl_obj_label(struct acl_object_label *obj,
70370 + struct acl_subject_label *subj)
70371 +{
70372 + unsigned int index =
70373 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70374 + struct acl_object_label **curr;
70375 +
70376 + obj->prev = NULL;
70377 +
70378 + curr = &subj->obj_hash[index];
70379 + if (*curr != NULL)
70380 + (*curr)->prev = obj;
70381 +
70382 + obj->next = *curr;
70383 + *curr = obj;
70384 +
70385 + return;
70386 +}
70387 +
70388 +void
70389 +insert_acl_subj_label(struct acl_subject_label *obj,
70390 + struct acl_role_label *role)
70391 +{
70392 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70393 + struct acl_subject_label **curr;
70394 +
70395 + obj->prev = NULL;
70396 +
70397 + curr = &role->subj_hash[index];
70398 + if (*curr != NULL)
70399 + (*curr)->prev = obj;
70400 +
70401 + obj->next = *curr;
70402 + *curr = obj;
70403 +
70404 + return;
70405 +}
70406 +
70407 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70408 +
70409 +static int
70410 +glob_match(const char *p, const char *n)
70411 +{
70412 + char c;
70413 +
70414 + while ((c = *p++) != '\0') {
70415 + switch (c) {
70416 + case '?':
70417 + if (*n == '\0')
70418 + return 1;
70419 + else if (*n == '/')
70420 + return 1;
70421 + break;
70422 + case '\\':
70423 + if (*n != c)
70424 + return 1;
70425 + break;
70426 + case '*':
70427 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70428 + if (*n == '/')
70429 + return 1;
70430 + else if (c == '?') {
70431 + if (*n == '\0')
70432 + return 1;
70433 + else
70434 + ++n;
70435 + }
70436 + }
70437 + if (c == '\0') {
70438 + return 0;
70439 + } else {
70440 + const char *endp;
70441 +
70442 + if ((endp = strchr(n, '/')) == NULL)
70443 + endp = n + strlen(n);
70444 +
70445 + if (c == '[') {
70446 + for (--p; n < endp; ++n)
70447 + if (!glob_match(p, n))
70448 + return 0;
70449 + } else if (c == '/') {
70450 + while (*n != '\0' && *n != '/')
70451 + ++n;
70452 + if (*n == '/' && !glob_match(p, n + 1))
70453 + return 0;
70454 + } else {
70455 + for (--p; n < endp; ++n)
70456 + if (*n == c && !glob_match(p, n))
70457 + return 0;
70458 + }
70459 +
70460 + return 1;
70461 + }
70462 + case '[':
70463 + {
70464 + int not;
70465 + char cold;
70466 +
70467 + if (*n == '\0' || *n == '/')
70468 + return 1;
70469 +
70470 + not = (*p == '!' || *p == '^');
70471 + if (not)
70472 + ++p;
70473 +
70474 + c = *p++;
70475 + for (;;) {
70476 + unsigned char fn = (unsigned char)*n;
70477 +
70478 + if (c == '\0')
70479 + return 1;
70480 + else {
70481 + if (c == fn)
70482 + goto matched;
70483 + cold = c;
70484 + c = *p++;
70485 +
70486 + if (c == '-' && *p != ']') {
70487 + unsigned char cend = *p++;
70488 +
70489 + if (cend == '\0')
70490 + return 1;
70491 +
70492 + if (cold <= fn && fn <= cend)
70493 + goto matched;
70494 +
70495 + c = *p++;
70496 + }
70497 + }
70498 +
70499 + if (c == ']')
70500 + break;
70501 + }
70502 + if (!not)
70503 + return 1;
70504 + break;
70505 + matched:
70506 + while (c != ']') {
70507 + if (c == '\0')
70508 + return 1;
70509 +
70510 + c = *p++;
70511 + }
70512 + if (not)
70513 + return 1;
70514 + }
70515 + break;
70516 + default:
70517 + if (c != *n)
70518 + return 1;
70519 + }
70520 +
70521 + ++n;
70522 + }
70523 +
70524 + if (*n == '\0')
70525 + return 0;
70526 +
70527 + if (*n == '/')
70528 + return 0;
70529 +
70530 + return 1;
70531 +}
70532 +
70533 +static struct acl_object_label *
70534 +chk_glob_label(struct acl_object_label *globbed,
70535 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70536 +{
70537 + struct acl_object_label *tmp;
70538 +
70539 + if (*path == NULL)
70540 + *path = gr_to_filename_nolock(dentry, mnt);
70541 +
70542 + tmp = globbed;
70543 +
70544 + while (tmp) {
70545 + if (!glob_match(tmp->filename, *path))
70546 + return tmp;
70547 + tmp = tmp->next;
70548 + }
70549 +
70550 + return NULL;
70551 +}
70552 +
70553 +static struct acl_object_label *
70554 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70555 + const ino_t curr_ino, const dev_t curr_dev,
70556 + const struct acl_subject_label *subj, char **path, const int checkglob)
70557 +{
70558 + struct acl_subject_label *tmpsubj;
70559 + struct acl_object_label *retval;
70560 + struct acl_object_label *retval2;
70561 +
70562 + tmpsubj = (struct acl_subject_label *) subj;
70563 + read_lock(&gr_inode_lock);
70564 + do {
70565 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70566 + if (retval) {
70567 + if (checkglob && retval->globbed) {
70568 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70569 + if (retval2)
70570 + retval = retval2;
70571 + }
70572 + break;
70573 + }
70574 + } while ((tmpsubj = tmpsubj->parent_subject));
70575 + read_unlock(&gr_inode_lock);
70576 +
70577 + return retval;
70578 +}
70579 +
70580 +static __inline__ struct acl_object_label *
70581 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70582 + struct dentry *curr_dentry,
70583 + const struct acl_subject_label *subj, char **path, const int checkglob)
70584 +{
70585 + int newglob = checkglob;
70586 + ino_t inode;
70587 + dev_t device;
70588 +
70589 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70590 + as we don't want a / * rule to match instead of the / object
70591 + don't do this for create lookups that call this function though, since they're looking up
70592 + on the parent and thus need globbing checks on all paths
70593 + */
70594 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70595 + newglob = GR_NO_GLOB;
70596 +
70597 + spin_lock(&curr_dentry->d_lock);
70598 + inode = curr_dentry->d_inode->i_ino;
70599 + device = __get_dev(curr_dentry);
70600 + spin_unlock(&curr_dentry->d_lock);
70601 +
70602 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70603 +}
70604 +
70605 +#ifdef CONFIG_HUGETLBFS
70606 +static inline bool
70607 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70608 +{
70609 + int i;
70610 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70611 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70612 + return true;
70613 + }
70614 +
70615 + return false;
70616 +}
70617 +#endif
70618 +
70619 +static struct acl_object_label *
70620 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70621 + const struct acl_subject_label *subj, char *path, const int checkglob)
70622 +{
70623 + struct dentry *dentry = (struct dentry *) l_dentry;
70624 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70625 + struct mount *real_mnt = real_mount(mnt);
70626 + struct acl_object_label *retval;
70627 + struct dentry *parent;
70628 +
70629 + read_seqlock_excl(&mount_lock);
70630 + write_seqlock(&rename_lock);
70631 +
70632 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70633 +#ifdef CONFIG_NET
70634 + mnt == sock_mnt ||
70635 +#endif
70636 +#ifdef CONFIG_HUGETLBFS
70637 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70638 +#endif
70639 + /* ignore Eric Biederman */
70640 + IS_PRIVATE(l_dentry->d_inode))) {
70641 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70642 + goto out;
70643 + }
70644 +
70645 + for (;;) {
70646 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70647 + break;
70648 +
70649 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70650 + if (!mnt_has_parent(real_mnt))
70651 + break;
70652 +
70653 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70654 + if (retval != NULL)
70655 + goto out;
70656 +
70657 + dentry = real_mnt->mnt_mountpoint;
70658 + real_mnt = real_mnt->mnt_parent;
70659 + mnt = &real_mnt->mnt;
70660 + continue;
70661 + }
70662 +
70663 + parent = dentry->d_parent;
70664 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70665 + if (retval != NULL)
70666 + goto out;
70667 +
70668 + dentry = parent;
70669 + }
70670 +
70671 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70672 +
70673 + /* gr_real_root is pinned so we don't have to hold a reference */
70674 + if (retval == NULL)
70675 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70676 +out:
70677 + write_sequnlock(&rename_lock);
70678 + read_sequnlock_excl(&mount_lock);
70679 +
70680 + BUG_ON(retval == NULL);
70681 +
70682 + return retval;
70683 +}
70684 +
70685 +static __inline__ struct acl_object_label *
70686 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70687 + const struct acl_subject_label *subj)
70688 +{
70689 + char *path = NULL;
70690 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70691 +}
70692 +
70693 +static __inline__ struct acl_object_label *
70694 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70695 + const struct acl_subject_label *subj)
70696 +{
70697 + char *path = NULL;
70698 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70699 +}
70700 +
70701 +static __inline__ struct acl_object_label *
70702 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70703 + const struct acl_subject_label *subj, char *path)
70704 +{
70705 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70706 +}
70707 +
70708 +struct acl_subject_label *
70709 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70710 + const struct acl_role_label *role)
70711 +{
70712 + struct dentry *dentry = (struct dentry *) l_dentry;
70713 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70714 + struct mount *real_mnt = real_mount(mnt);
70715 + struct acl_subject_label *retval;
70716 + struct dentry *parent;
70717 +
70718 + read_seqlock_excl(&mount_lock);
70719 + write_seqlock(&rename_lock);
70720 +
70721 + for (;;) {
70722 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70723 + break;
70724 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70725 + if (!mnt_has_parent(real_mnt))
70726 + break;
70727 +
70728 + spin_lock(&dentry->d_lock);
70729 + read_lock(&gr_inode_lock);
70730 + retval =
70731 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70732 + __get_dev(dentry), role);
70733 + read_unlock(&gr_inode_lock);
70734 + spin_unlock(&dentry->d_lock);
70735 + if (retval != NULL)
70736 + goto out;
70737 +
70738 + dentry = real_mnt->mnt_mountpoint;
70739 + real_mnt = real_mnt->mnt_parent;
70740 + mnt = &real_mnt->mnt;
70741 + continue;
70742 + }
70743 +
70744 + spin_lock(&dentry->d_lock);
70745 + read_lock(&gr_inode_lock);
70746 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70747 + __get_dev(dentry), role);
70748 + read_unlock(&gr_inode_lock);
70749 + parent = dentry->d_parent;
70750 + spin_unlock(&dentry->d_lock);
70751 +
70752 + if (retval != NULL)
70753 + goto out;
70754 +
70755 + dentry = parent;
70756 + }
70757 +
70758 + spin_lock(&dentry->d_lock);
70759 + read_lock(&gr_inode_lock);
70760 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70761 + __get_dev(dentry), role);
70762 + read_unlock(&gr_inode_lock);
70763 + spin_unlock(&dentry->d_lock);
70764 +
70765 + if (unlikely(retval == NULL)) {
70766 + /* gr_real_root is pinned, we don't need to hold a reference */
70767 + read_lock(&gr_inode_lock);
70768 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70769 + __get_dev(gr_real_root.dentry), role);
70770 + read_unlock(&gr_inode_lock);
70771 + }
70772 +out:
70773 + write_sequnlock(&rename_lock);
70774 + read_sequnlock_excl(&mount_lock);
70775 +
70776 + BUG_ON(retval == NULL);
70777 +
70778 + return retval;
70779 +}
70780 +
70781 +void
70782 +assign_special_role(const char *rolename)
70783 +{
70784 + struct acl_object_label *obj;
70785 + struct acl_role_label *r;
70786 + struct acl_role_label *assigned = NULL;
70787 + struct task_struct *tsk;
70788 + struct file *filp;
70789 +
70790 + FOR_EACH_ROLE_START(r)
70791 + if (!strcmp(rolename, r->rolename) &&
70792 + (r->roletype & GR_ROLE_SPECIAL)) {
70793 + assigned = r;
70794 + break;
70795 + }
70796 + FOR_EACH_ROLE_END(r)
70797 +
70798 + if (!assigned)
70799 + return;
70800 +
70801 + read_lock(&tasklist_lock);
70802 + read_lock(&grsec_exec_file_lock);
70803 +
70804 + tsk = current->real_parent;
70805 + if (tsk == NULL)
70806 + goto out_unlock;
70807 +
70808 + filp = tsk->exec_file;
70809 + if (filp == NULL)
70810 + goto out_unlock;
70811 +
70812 + tsk->is_writable = 0;
70813 + tsk->inherited = 0;
70814 +
70815 + tsk->acl_sp_role = 1;
70816 + tsk->acl_role_id = ++acl_sp_role_value;
70817 + tsk->role = assigned;
70818 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70819 +
70820 + /* ignore additional mmap checks for processes that are writable
70821 + by the default ACL */
70822 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70823 + if (unlikely(obj->mode & GR_WRITE))
70824 + tsk->is_writable = 1;
70825 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70826 + if (unlikely(obj->mode & GR_WRITE))
70827 + tsk->is_writable = 1;
70828 +
70829 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70830 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70831 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70832 +#endif
70833 +
70834 +out_unlock:
70835 + read_unlock(&grsec_exec_file_lock);
70836 + read_unlock(&tasklist_lock);
70837 + return;
70838 +}
70839 +
70840 +
70841 +static void
70842 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70843 +{
70844 + struct task_struct *task = current;
70845 + const struct cred *cred = current_cred();
70846 +
70847 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70848 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70849 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70850 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70851 +
70852 + return;
70853 +}
70854 +
70855 +static void
70856 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70857 +{
70858 + struct task_struct *task = current;
70859 + const struct cred *cred = current_cred();
70860 +
70861 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70862 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70863 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70864 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70865 +
70866 + return;
70867 +}
70868 +
70869 +static void
70870 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70871 +{
70872 + struct task_struct *task = current;
70873 + const struct cred *cred = current_cred();
70874 +
70875 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70876 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70877 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70878 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70879 +
70880 + return;
70881 +}
70882 +
70883 +static void
70884 +gr_set_proc_res(struct task_struct *task)
70885 +{
70886 + struct acl_subject_label *proc;
70887 + unsigned short i;
70888 +
70889 + proc = task->acl;
70890 +
70891 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70892 + return;
70893 +
70894 + for (i = 0; i < RLIM_NLIMITS; i++) {
70895 + if (!(proc->resmask & (1U << i)))
70896 + continue;
70897 +
70898 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70899 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70900 +
70901 + if (i == RLIMIT_CPU)
70902 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70903 + }
70904 +
70905 + return;
70906 +}
70907 +
70908 +/* both of the below must be called with
70909 + rcu_read_lock();
70910 + read_lock(&tasklist_lock);
70911 + read_lock(&grsec_exec_file_lock);
70912 +*/
70913 +
70914 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70915 +{
70916 + char *tmpname;
70917 + struct acl_subject_label *tmpsubj;
70918 + struct file *filp;
70919 + struct name_entry *nmatch;
70920 +
70921 + filp = task->exec_file;
70922 + if (filp == NULL)
70923 + return NULL;
70924 +
70925 + /* the following is to apply the correct subject
70926 + on binaries running when the RBAC system
70927 + is enabled, when the binaries have been
70928 + replaced or deleted since their execution
70929 + -----
70930 + when the RBAC system starts, the inode/dev
70931 + from exec_file will be one the RBAC system
70932 + is unaware of. It only knows the inode/dev
70933 + of the present file on disk, or the absence
70934 + of it.
70935 + */
70936 +
70937 + if (filename)
70938 + nmatch = __lookup_name_entry(state, filename);
70939 + else {
70940 + preempt_disable();
70941 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70942 +
70943 + nmatch = __lookup_name_entry(state, tmpname);
70944 + preempt_enable();
70945 + }
70946 + tmpsubj = NULL;
70947 + if (nmatch) {
70948 + if (nmatch->deleted)
70949 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70950 + else
70951 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70952 + }
70953 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70954 + then we fall back to a normal lookup based on the binary's ino/dev
70955 + */
70956 + if (tmpsubj == NULL)
70957 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70958 +
70959 + return tmpsubj;
70960 +}
70961 +
70962 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70963 +{
70964 + return __gr_get_subject_for_task(&running_polstate, task, filename);
70965 +}
70966 +
70967 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70968 +{
70969 + struct acl_object_label *obj;
70970 + struct file *filp;
70971 +
70972 + filp = task->exec_file;
70973 +
70974 + task->acl = subj;
70975 + task->is_writable = 0;
70976 + /* ignore additional mmap checks for processes that are writable
70977 + by the default ACL */
70978 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70979 + if (unlikely(obj->mode & GR_WRITE))
70980 + task->is_writable = 1;
70981 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70982 + if (unlikely(obj->mode & GR_WRITE))
70983 + task->is_writable = 1;
70984 +
70985 + gr_set_proc_res(task);
70986 +
70987 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70988 + 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);
70989 +#endif
70990 +}
70991 +
70992 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70993 +{
70994 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70995 +}
70996 +
70997 +__u32
70998 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70999 + const struct vfsmount * mnt)
71000 +{
71001 + __u32 retval = mode;
71002 + struct acl_subject_label *curracl;
71003 + struct acl_object_label *currobj;
71004 +
71005 + if (unlikely(!(gr_status & GR_READY)))
71006 + return (mode & ~GR_AUDITS);
71007 +
71008 + curracl = current->acl;
71009 +
71010 + currobj = chk_obj_label(dentry, mnt, curracl);
71011 + retval = currobj->mode & mode;
71012 +
71013 + /* if we're opening a specified transfer file for writing
71014 + (e.g. /dev/initctl), then transfer our role to init
71015 + */
71016 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71017 + current->role->roletype & GR_ROLE_PERSIST)) {
71018 + struct task_struct *task = init_pid_ns.child_reaper;
71019 +
71020 + if (task->role != current->role) {
71021 + struct acl_subject_label *subj;
71022 +
71023 + task->acl_sp_role = 0;
71024 + task->acl_role_id = current->acl_role_id;
71025 + task->role = current->role;
71026 + rcu_read_lock();
71027 + read_lock(&grsec_exec_file_lock);
71028 + subj = gr_get_subject_for_task(task, NULL);
71029 + gr_apply_subject_to_task(task, subj);
71030 + read_unlock(&grsec_exec_file_lock);
71031 + rcu_read_unlock();
71032 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71033 + }
71034 + }
71035 +
71036 + if (unlikely
71037 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71038 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71039 + __u32 new_mode = mode;
71040 +
71041 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71042 +
71043 + retval = new_mode;
71044 +
71045 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71046 + new_mode |= GR_INHERIT;
71047 +
71048 + if (!(mode & GR_NOLEARN))
71049 + gr_log_learn(dentry, mnt, new_mode);
71050 + }
71051 +
71052 + return retval;
71053 +}
71054 +
71055 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71056 + const struct dentry *parent,
71057 + const struct vfsmount *mnt)
71058 +{
71059 + struct name_entry *match;
71060 + struct acl_object_label *matchpo;
71061 + struct acl_subject_label *curracl;
71062 + char *path;
71063 +
71064 + if (unlikely(!(gr_status & GR_READY)))
71065 + return NULL;
71066 +
71067 + preempt_disable();
71068 + path = gr_to_filename_rbac(new_dentry, mnt);
71069 + match = lookup_name_entry_create(path);
71070 +
71071 + curracl = current->acl;
71072 +
71073 + if (match) {
71074 + read_lock(&gr_inode_lock);
71075 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71076 + read_unlock(&gr_inode_lock);
71077 +
71078 + if (matchpo) {
71079 + preempt_enable();
71080 + return matchpo;
71081 + }
71082 + }
71083 +
71084 + // lookup parent
71085 +
71086 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71087 +
71088 + preempt_enable();
71089 + return matchpo;
71090 +}
71091 +
71092 +__u32
71093 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71094 + const struct vfsmount * mnt, const __u32 mode)
71095 +{
71096 + struct acl_object_label *matchpo;
71097 + __u32 retval;
71098 +
71099 + if (unlikely(!(gr_status & GR_READY)))
71100 + return (mode & ~GR_AUDITS);
71101 +
71102 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
71103 +
71104 + retval = matchpo->mode & mode;
71105 +
71106 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71107 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71108 + __u32 new_mode = mode;
71109 +
71110 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71111 +
71112 + gr_log_learn(new_dentry, mnt, new_mode);
71113 + return new_mode;
71114 + }
71115 +
71116 + return retval;
71117 +}
71118 +
71119 +__u32
71120 +gr_check_link(const struct dentry * new_dentry,
71121 + const struct dentry * parent_dentry,
71122 + const struct vfsmount * parent_mnt,
71123 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71124 +{
71125 + struct acl_object_label *obj;
71126 + __u32 oldmode, newmode;
71127 + __u32 needmode;
71128 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71129 + GR_DELETE | GR_INHERIT;
71130 +
71131 + if (unlikely(!(gr_status & GR_READY)))
71132 + return (GR_CREATE | GR_LINK);
71133 +
71134 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71135 + oldmode = obj->mode;
71136 +
71137 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71138 + newmode = obj->mode;
71139 +
71140 + needmode = newmode & checkmodes;
71141 +
71142 + // old name for hardlink must have at least the permissions of the new name
71143 + if ((oldmode & needmode) != needmode)
71144 + goto bad;
71145 +
71146 + // if old name had restrictions/auditing, make sure the new name does as well
71147 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71148 +
71149 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71150 + if (is_privileged_binary(old_dentry))
71151 + needmode |= GR_SETID;
71152 +
71153 + if ((newmode & needmode) != needmode)
71154 + goto bad;
71155 +
71156 + // enforce minimum permissions
71157 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71158 + return newmode;
71159 +bad:
71160 + needmode = oldmode;
71161 + if (is_privileged_binary(old_dentry))
71162 + needmode |= GR_SETID;
71163 +
71164 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71165 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71166 + return (GR_CREATE | GR_LINK);
71167 + } else if (newmode & GR_SUPPRESS)
71168 + return GR_SUPPRESS;
71169 + else
71170 + return 0;
71171 +}
71172 +
71173 +int
71174 +gr_check_hidden_task(const struct task_struct *task)
71175 +{
71176 + if (unlikely(!(gr_status & GR_READY)))
71177 + return 0;
71178 +
71179 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71180 + return 1;
71181 +
71182 + return 0;
71183 +}
71184 +
71185 +int
71186 +gr_check_protected_task(const struct task_struct *task)
71187 +{
71188 + if (unlikely(!(gr_status & GR_READY) || !task))
71189 + return 0;
71190 +
71191 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71192 + task->acl != current->acl)
71193 + return 1;
71194 +
71195 + return 0;
71196 +}
71197 +
71198 +int
71199 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71200 +{
71201 + struct task_struct *p;
71202 + int ret = 0;
71203 +
71204 + if (unlikely(!(gr_status & GR_READY) || !pid))
71205 + return ret;
71206 +
71207 + read_lock(&tasklist_lock);
71208 + do_each_pid_task(pid, type, p) {
71209 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71210 + p->acl != current->acl) {
71211 + ret = 1;
71212 + goto out;
71213 + }
71214 + } while_each_pid_task(pid, type, p);
71215 +out:
71216 + read_unlock(&tasklist_lock);
71217 +
71218 + return ret;
71219 +}
71220 +
71221 +void
71222 +gr_copy_label(struct task_struct *tsk)
71223 +{
71224 + struct task_struct *p = current;
71225 +
71226 + tsk->inherited = p->inherited;
71227 + tsk->acl_sp_role = 0;
71228 + tsk->acl_role_id = p->acl_role_id;
71229 + tsk->acl = p->acl;
71230 + tsk->role = p->role;
71231 + tsk->signal->used_accept = 0;
71232 + tsk->signal->curr_ip = p->signal->curr_ip;
71233 + tsk->signal->saved_ip = p->signal->saved_ip;
71234 + if (p->exec_file)
71235 + get_file(p->exec_file);
71236 + tsk->exec_file = p->exec_file;
71237 + tsk->is_writable = p->is_writable;
71238 + if (unlikely(p->signal->used_accept)) {
71239 + p->signal->curr_ip = 0;
71240 + p->signal->saved_ip = 0;
71241 + }
71242 +
71243 + return;
71244 +}
71245 +
71246 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71247 +
71248 +int
71249 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71250 +{
71251 + unsigned int i;
71252 + __u16 num;
71253 + uid_t *uidlist;
71254 + uid_t curuid;
71255 + int realok = 0;
71256 + int effectiveok = 0;
71257 + int fsok = 0;
71258 + uid_t globalreal, globaleffective, globalfs;
71259 +
71260 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71261 + struct user_struct *user;
71262 +
71263 + if (!uid_valid(real))
71264 + goto skipit;
71265 +
71266 + /* find user based on global namespace */
71267 +
71268 + globalreal = GR_GLOBAL_UID(real);
71269 +
71270 + user = find_user(make_kuid(&init_user_ns, globalreal));
71271 + if (user == NULL)
71272 + goto skipit;
71273 +
71274 + if (gr_process_kernel_setuid_ban(user)) {
71275 + /* for find_user */
71276 + free_uid(user);
71277 + return 1;
71278 + }
71279 +
71280 + /* for find_user */
71281 + free_uid(user);
71282 +
71283 +skipit:
71284 +#endif
71285 +
71286 + if (unlikely(!(gr_status & GR_READY)))
71287 + return 0;
71288 +
71289 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71290 + gr_log_learn_uid_change(real, effective, fs);
71291 +
71292 + num = current->acl->user_trans_num;
71293 + uidlist = current->acl->user_transitions;
71294 +
71295 + if (uidlist == NULL)
71296 + return 0;
71297 +
71298 + if (!uid_valid(real)) {
71299 + realok = 1;
71300 + globalreal = (uid_t)-1;
71301 + } else {
71302 + globalreal = GR_GLOBAL_UID(real);
71303 + }
71304 + if (!uid_valid(effective)) {
71305 + effectiveok = 1;
71306 + globaleffective = (uid_t)-1;
71307 + } else {
71308 + globaleffective = GR_GLOBAL_UID(effective);
71309 + }
71310 + if (!uid_valid(fs)) {
71311 + fsok = 1;
71312 + globalfs = (uid_t)-1;
71313 + } else {
71314 + globalfs = GR_GLOBAL_UID(fs);
71315 + }
71316 +
71317 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71318 + for (i = 0; i < num; i++) {
71319 + curuid = uidlist[i];
71320 + if (globalreal == curuid)
71321 + realok = 1;
71322 + if (globaleffective == curuid)
71323 + effectiveok = 1;
71324 + if (globalfs == curuid)
71325 + fsok = 1;
71326 + }
71327 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71328 + for (i = 0; i < num; i++) {
71329 + curuid = uidlist[i];
71330 + if (globalreal == curuid)
71331 + break;
71332 + if (globaleffective == curuid)
71333 + break;
71334 + if (globalfs == curuid)
71335 + break;
71336 + }
71337 + /* not in deny list */
71338 + if (i == num) {
71339 + realok = 1;
71340 + effectiveok = 1;
71341 + fsok = 1;
71342 + }
71343 + }
71344 +
71345 + if (realok && effectiveok && fsok)
71346 + return 0;
71347 + else {
71348 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71349 + return 1;
71350 + }
71351 +}
71352 +
71353 +int
71354 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71355 +{
71356 + unsigned int i;
71357 + __u16 num;
71358 + gid_t *gidlist;
71359 + gid_t curgid;
71360 + int realok = 0;
71361 + int effectiveok = 0;
71362 + int fsok = 0;
71363 + gid_t globalreal, globaleffective, globalfs;
71364 +
71365 + if (unlikely(!(gr_status & GR_READY)))
71366 + return 0;
71367 +
71368 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71369 + gr_log_learn_gid_change(real, effective, fs);
71370 +
71371 + num = current->acl->group_trans_num;
71372 + gidlist = current->acl->group_transitions;
71373 +
71374 + if (gidlist == NULL)
71375 + return 0;
71376 +
71377 + if (!gid_valid(real)) {
71378 + realok = 1;
71379 + globalreal = (gid_t)-1;
71380 + } else {
71381 + globalreal = GR_GLOBAL_GID(real);
71382 + }
71383 + if (!gid_valid(effective)) {
71384 + effectiveok = 1;
71385 + globaleffective = (gid_t)-1;
71386 + } else {
71387 + globaleffective = GR_GLOBAL_GID(effective);
71388 + }
71389 + if (!gid_valid(fs)) {
71390 + fsok = 1;
71391 + globalfs = (gid_t)-1;
71392 + } else {
71393 + globalfs = GR_GLOBAL_GID(fs);
71394 + }
71395 +
71396 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71397 + for (i = 0; i < num; i++) {
71398 + curgid = gidlist[i];
71399 + if (globalreal == curgid)
71400 + realok = 1;
71401 + if (globaleffective == curgid)
71402 + effectiveok = 1;
71403 + if (globalfs == curgid)
71404 + fsok = 1;
71405 + }
71406 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71407 + for (i = 0; i < num; i++) {
71408 + curgid = gidlist[i];
71409 + if (globalreal == curgid)
71410 + break;
71411 + if (globaleffective == curgid)
71412 + break;
71413 + if (globalfs == curgid)
71414 + break;
71415 + }
71416 + /* not in deny list */
71417 + if (i == num) {
71418 + realok = 1;
71419 + effectiveok = 1;
71420 + fsok = 1;
71421 + }
71422 + }
71423 +
71424 + if (realok && effectiveok && fsok)
71425 + return 0;
71426 + else {
71427 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71428 + return 1;
71429 + }
71430 +}
71431 +
71432 +extern int gr_acl_is_capable(const int cap);
71433 +
71434 +void
71435 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71436 +{
71437 + struct acl_role_label *role = task->role;
71438 + struct acl_subject_label *subj = NULL;
71439 + struct acl_object_label *obj;
71440 + struct file *filp;
71441 + uid_t uid;
71442 + gid_t gid;
71443 +
71444 + if (unlikely(!(gr_status & GR_READY)))
71445 + return;
71446 +
71447 + uid = GR_GLOBAL_UID(kuid);
71448 + gid = GR_GLOBAL_GID(kgid);
71449 +
71450 + filp = task->exec_file;
71451 +
71452 + /* kernel process, we'll give them the kernel role */
71453 + if (unlikely(!filp)) {
71454 + task->role = running_polstate.kernel_role;
71455 + task->acl = running_polstate.kernel_role->root_label;
71456 + return;
71457 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71458 + /* save the current ip at time of role lookup so that the proper
71459 + IP will be learned for role_allowed_ip */
71460 + task->signal->saved_ip = task->signal->curr_ip;
71461 + role = lookup_acl_role_label(task, uid, gid);
71462 + }
71463 +
71464 + /* don't change the role if we're not a privileged process */
71465 + if (role && task->role != role &&
71466 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71467 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71468 + return;
71469 +
71470 + /* perform subject lookup in possibly new role
71471 + we can use this result below in the case where role == task->role
71472 + */
71473 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71474 +
71475 + /* if we changed uid/gid, but result in the same role
71476 + and are using inheritance, don't lose the inherited subject
71477 + if current subject is other than what normal lookup
71478 + would result in, we arrived via inheritance, don't
71479 + lose subject
71480 + */
71481 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71482 + (subj == task->acl)))
71483 + task->acl = subj;
71484 +
71485 + /* leave task->inherited unaffected */
71486 +
71487 + task->role = role;
71488 +
71489 + task->is_writable = 0;
71490 +
71491 + /* ignore additional mmap checks for processes that are writable
71492 + by the default ACL */
71493 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71494 + if (unlikely(obj->mode & GR_WRITE))
71495 + task->is_writable = 1;
71496 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71497 + if (unlikely(obj->mode & GR_WRITE))
71498 + task->is_writable = 1;
71499 +
71500 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71501 + 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);
71502 +#endif
71503 +
71504 + gr_set_proc_res(task);
71505 +
71506 + return;
71507 +}
71508 +
71509 +int
71510 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71511 + const int unsafe_flags)
71512 +{
71513 + struct task_struct *task = current;
71514 + struct acl_subject_label *newacl;
71515 + struct acl_object_label *obj;
71516 + __u32 retmode;
71517 +
71518 + if (unlikely(!(gr_status & GR_READY)))
71519 + return 0;
71520 +
71521 + newacl = chk_subj_label(dentry, mnt, task->role);
71522 +
71523 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71524 + did an exec
71525 + */
71526 + rcu_read_lock();
71527 + read_lock(&tasklist_lock);
71528 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71529 + (task->parent->acl->mode & GR_POVERRIDE))) {
71530 + read_unlock(&tasklist_lock);
71531 + rcu_read_unlock();
71532 + goto skip_check;
71533 + }
71534 + read_unlock(&tasklist_lock);
71535 + rcu_read_unlock();
71536 +
71537 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71538 + !(task->role->roletype & GR_ROLE_GOD) &&
71539 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71540 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71541 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71542 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71543 + else
71544 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71545 + return -EACCES;
71546 + }
71547 +
71548 +skip_check:
71549 +
71550 + obj = chk_obj_label(dentry, mnt, task->acl);
71551 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71552 +
71553 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71554 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71555 + if (obj->nested)
71556 + task->acl = obj->nested;
71557 + else
71558 + task->acl = newacl;
71559 + task->inherited = 0;
71560 + } else {
71561 + task->inherited = 1;
71562 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71563 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71564 + }
71565 +
71566 + task->is_writable = 0;
71567 +
71568 + /* ignore additional mmap checks for processes that are writable
71569 + by the default ACL */
71570 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71571 + if (unlikely(obj->mode & GR_WRITE))
71572 + task->is_writable = 1;
71573 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71574 + if (unlikely(obj->mode & GR_WRITE))
71575 + task->is_writable = 1;
71576 +
71577 + gr_set_proc_res(task);
71578 +
71579 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71580 + 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);
71581 +#endif
71582 + return 0;
71583 +}
71584 +
71585 +/* always called with valid inodev ptr */
71586 +static void
71587 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71588 +{
71589 + struct acl_object_label *matchpo;
71590 + struct acl_subject_label *matchps;
71591 + struct acl_subject_label *subj;
71592 + struct acl_role_label *role;
71593 + unsigned int x;
71594 +
71595 + FOR_EACH_ROLE_START(role)
71596 + FOR_EACH_SUBJECT_START(role, subj, x)
71597 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71598 + matchpo->mode |= GR_DELETED;
71599 + FOR_EACH_SUBJECT_END(subj,x)
71600 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71601 + /* nested subjects aren't in the role's subj_hash table */
71602 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71603 + matchpo->mode |= GR_DELETED;
71604 + FOR_EACH_NESTED_SUBJECT_END(subj)
71605 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71606 + matchps->mode |= GR_DELETED;
71607 + FOR_EACH_ROLE_END(role)
71608 +
71609 + inodev->nentry->deleted = 1;
71610 +
71611 + return;
71612 +}
71613 +
71614 +void
71615 +gr_handle_delete(const ino_t ino, const dev_t dev)
71616 +{
71617 + struct inodev_entry *inodev;
71618 +
71619 + if (unlikely(!(gr_status & GR_READY)))
71620 + return;
71621 +
71622 + write_lock(&gr_inode_lock);
71623 + inodev = lookup_inodev_entry(ino, dev);
71624 + if (inodev != NULL)
71625 + do_handle_delete(inodev, ino, dev);
71626 + write_unlock(&gr_inode_lock);
71627 +
71628 + return;
71629 +}
71630 +
71631 +static void
71632 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71633 + const ino_t newinode, const dev_t newdevice,
71634 + struct acl_subject_label *subj)
71635 +{
71636 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71637 + struct acl_object_label *match;
71638 +
71639 + match = subj->obj_hash[index];
71640 +
71641 + while (match && (match->inode != oldinode ||
71642 + match->device != olddevice ||
71643 + !(match->mode & GR_DELETED)))
71644 + match = match->next;
71645 +
71646 + if (match && (match->inode == oldinode)
71647 + && (match->device == olddevice)
71648 + && (match->mode & GR_DELETED)) {
71649 + if (match->prev == NULL) {
71650 + subj->obj_hash[index] = match->next;
71651 + if (match->next != NULL)
71652 + match->next->prev = NULL;
71653 + } else {
71654 + match->prev->next = match->next;
71655 + if (match->next != NULL)
71656 + match->next->prev = match->prev;
71657 + }
71658 + match->prev = NULL;
71659 + match->next = NULL;
71660 + match->inode = newinode;
71661 + match->device = newdevice;
71662 + match->mode &= ~GR_DELETED;
71663 +
71664 + insert_acl_obj_label(match, subj);
71665 + }
71666 +
71667 + return;
71668 +}
71669 +
71670 +static void
71671 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71672 + const ino_t newinode, const dev_t newdevice,
71673 + struct acl_role_label *role)
71674 +{
71675 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71676 + struct acl_subject_label *match;
71677 +
71678 + match = role->subj_hash[index];
71679 +
71680 + while (match && (match->inode != oldinode ||
71681 + match->device != olddevice ||
71682 + !(match->mode & GR_DELETED)))
71683 + match = match->next;
71684 +
71685 + if (match && (match->inode == oldinode)
71686 + && (match->device == olddevice)
71687 + && (match->mode & GR_DELETED)) {
71688 + if (match->prev == NULL) {
71689 + role->subj_hash[index] = match->next;
71690 + if (match->next != NULL)
71691 + match->next->prev = NULL;
71692 + } else {
71693 + match->prev->next = match->next;
71694 + if (match->next != NULL)
71695 + match->next->prev = match->prev;
71696 + }
71697 + match->prev = NULL;
71698 + match->next = NULL;
71699 + match->inode = newinode;
71700 + match->device = newdevice;
71701 + match->mode &= ~GR_DELETED;
71702 +
71703 + insert_acl_subj_label(match, role);
71704 + }
71705 +
71706 + return;
71707 +}
71708 +
71709 +static void
71710 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71711 + const ino_t newinode, const dev_t newdevice)
71712 +{
71713 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71714 + struct inodev_entry *match;
71715 +
71716 + match = running_polstate.inodev_set.i_hash[index];
71717 +
71718 + while (match && (match->nentry->inode != oldinode ||
71719 + match->nentry->device != olddevice || !match->nentry->deleted))
71720 + match = match->next;
71721 +
71722 + if (match && (match->nentry->inode == oldinode)
71723 + && (match->nentry->device == olddevice) &&
71724 + match->nentry->deleted) {
71725 + if (match->prev == NULL) {
71726 + running_polstate.inodev_set.i_hash[index] = match->next;
71727 + if (match->next != NULL)
71728 + match->next->prev = NULL;
71729 + } else {
71730 + match->prev->next = match->next;
71731 + if (match->next != NULL)
71732 + match->next->prev = match->prev;
71733 + }
71734 + match->prev = NULL;
71735 + match->next = NULL;
71736 + match->nentry->inode = newinode;
71737 + match->nentry->device = newdevice;
71738 + match->nentry->deleted = 0;
71739 +
71740 + insert_inodev_entry(match);
71741 + }
71742 +
71743 + return;
71744 +}
71745 +
71746 +static void
71747 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71748 +{
71749 + struct acl_subject_label *subj;
71750 + struct acl_role_label *role;
71751 + unsigned int x;
71752 +
71753 + FOR_EACH_ROLE_START(role)
71754 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71755 +
71756 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71757 + if ((subj->inode == ino) && (subj->device == dev)) {
71758 + subj->inode = ino;
71759 + subj->device = dev;
71760 + }
71761 + /* nested subjects aren't in the role's subj_hash table */
71762 + update_acl_obj_label(matchn->inode, matchn->device,
71763 + ino, dev, subj);
71764 + FOR_EACH_NESTED_SUBJECT_END(subj)
71765 + FOR_EACH_SUBJECT_START(role, subj, x)
71766 + update_acl_obj_label(matchn->inode, matchn->device,
71767 + ino, dev, subj);
71768 + FOR_EACH_SUBJECT_END(subj,x)
71769 + FOR_EACH_ROLE_END(role)
71770 +
71771 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71772 +
71773 + return;
71774 +}
71775 +
71776 +static void
71777 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71778 + const struct vfsmount *mnt)
71779 +{
71780 + ino_t ino = dentry->d_inode->i_ino;
71781 + dev_t dev = __get_dev(dentry);
71782 +
71783 + __do_handle_create(matchn, ino, dev);
71784 +
71785 + return;
71786 +}
71787 +
71788 +void
71789 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71790 +{
71791 + struct name_entry *matchn;
71792 +
71793 + if (unlikely(!(gr_status & GR_READY)))
71794 + return;
71795 +
71796 + preempt_disable();
71797 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71798 +
71799 + if (unlikely((unsigned long)matchn)) {
71800 + write_lock(&gr_inode_lock);
71801 + do_handle_create(matchn, dentry, mnt);
71802 + write_unlock(&gr_inode_lock);
71803 + }
71804 + preempt_enable();
71805 +
71806 + return;
71807 +}
71808 +
71809 +void
71810 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71811 +{
71812 + struct name_entry *matchn;
71813 +
71814 + if (unlikely(!(gr_status & GR_READY)))
71815 + return;
71816 +
71817 + preempt_disable();
71818 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71819 +
71820 + if (unlikely((unsigned long)matchn)) {
71821 + write_lock(&gr_inode_lock);
71822 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71823 + write_unlock(&gr_inode_lock);
71824 + }
71825 + preempt_enable();
71826 +
71827 + return;
71828 +}
71829 +
71830 +void
71831 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71832 + struct dentry *old_dentry,
71833 + struct dentry *new_dentry,
71834 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71835 +{
71836 + struct name_entry *matchn;
71837 + struct name_entry *matchn2 = NULL;
71838 + struct inodev_entry *inodev;
71839 + struct inode *inode = new_dentry->d_inode;
71840 + ino_t old_ino = old_dentry->d_inode->i_ino;
71841 + dev_t old_dev = __get_dev(old_dentry);
71842 + unsigned int exchange = flags & RENAME_EXCHANGE;
71843 +
71844 + /* vfs_rename swaps the name and parent link for old_dentry and
71845 + new_dentry
71846 + at this point, old_dentry has the new name, parent link, and inode
71847 + for the renamed file
71848 + if a file is being replaced by a rename, new_dentry has the inode
71849 + and name for the replaced file
71850 + */
71851 +
71852 + if (unlikely(!(gr_status & GR_READY)))
71853 + return;
71854 +
71855 + preempt_disable();
71856 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71857 +
71858 + /* exchange cases:
71859 + a filename exists for the source, but not dest
71860 + do a recreate on source
71861 + a filename exists for the dest, but not source
71862 + do a recreate on dest
71863 + a filename exists for both source and dest
71864 + delete source and dest, then create source and dest
71865 + a filename exists for neither source nor dest
71866 + no updates needed
71867 +
71868 + the name entry lookups get us the old inode/dev associated with
71869 + each name, so do the deletes first (if possible) so that when
71870 + we do the create, we pick up on the right entries
71871 + */
71872 +
71873 + if (exchange)
71874 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71875 +
71876 + /* we wouldn't have to check d_inode if it weren't for
71877 + NFS silly-renaming
71878 + */
71879 +
71880 + write_lock(&gr_inode_lock);
71881 + if (unlikely((replace || exchange) && inode)) {
71882 + ino_t new_ino = inode->i_ino;
71883 + dev_t new_dev = __get_dev(new_dentry);
71884 +
71885 + inodev = lookup_inodev_entry(new_ino, new_dev);
71886 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71887 + do_handle_delete(inodev, new_ino, new_dev);
71888 + }
71889 +
71890 + inodev = lookup_inodev_entry(old_ino, old_dev);
71891 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71892 + do_handle_delete(inodev, old_ino, old_dev);
71893 +
71894 + if (unlikely(matchn != NULL))
71895 + do_handle_create(matchn, old_dentry, mnt);
71896 +
71897 + if (unlikely(matchn2 != NULL))
71898 + do_handle_create(matchn2, new_dentry, mnt);
71899 +
71900 + write_unlock(&gr_inode_lock);
71901 + preempt_enable();
71902 +
71903 + return;
71904 +}
71905 +
71906 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71907 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71908 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71909 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71910 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71911 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71912 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71913 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71914 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71915 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71916 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71917 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71918 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71919 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71920 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71921 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71922 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71923 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71924 +};
71925 +
71926 +void
71927 +gr_learn_resource(const struct task_struct *task,
71928 + const int res, const unsigned long wanted, const int gt)
71929 +{
71930 + struct acl_subject_label *acl;
71931 + const struct cred *cred;
71932 +
71933 + if (unlikely((gr_status & GR_READY) &&
71934 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71935 + goto skip_reslog;
71936 +
71937 + gr_log_resource(task, res, wanted, gt);
71938 +skip_reslog:
71939 +
71940 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71941 + return;
71942 +
71943 + acl = task->acl;
71944 +
71945 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71946 + !(acl->resmask & (1U << (unsigned short) res))))
71947 + return;
71948 +
71949 + if (wanted >= acl->res[res].rlim_cur) {
71950 + unsigned long res_add;
71951 +
71952 + res_add = wanted + res_learn_bumps[res];
71953 +
71954 + acl->res[res].rlim_cur = res_add;
71955 +
71956 + if (wanted > acl->res[res].rlim_max)
71957 + acl->res[res].rlim_max = res_add;
71958 +
71959 + /* only log the subject filename, since resource logging is supported for
71960 + single-subject learning only */
71961 + rcu_read_lock();
71962 + cred = __task_cred(task);
71963 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71964 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71965 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71966 + "", (unsigned long) res, &task->signal->saved_ip);
71967 + rcu_read_unlock();
71968 + }
71969 +
71970 + return;
71971 +}
71972 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71973 +#endif
71974 +
71975 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71976 +void
71977 +pax_set_initial_flags(struct linux_binprm *bprm)
71978 +{
71979 + struct task_struct *task = current;
71980 + struct acl_subject_label *proc;
71981 + unsigned long flags;
71982 +
71983 + if (unlikely(!(gr_status & GR_READY)))
71984 + return;
71985 +
71986 + flags = pax_get_flags(task);
71987 +
71988 + proc = task->acl;
71989 +
71990 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71991 + flags &= ~MF_PAX_PAGEEXEC;
71992 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71993 + flags &= ~MF_PAX_SEGMEXEC;
71994 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71995 + flags &= ~MF_PAX_RANDMMAP;
71996 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71997 + flags &= ~MF_PAX_EMUTRAMP;
71998 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71999 + flags &= ~MF_PAX_MPROTECT;
72000 +
72001 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72002 + flags |= MF_PAX_PAGEEXEC;
72003 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72004 + flags |= MF_PAX_SEGMEXEC;
72005 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72006 + flags |= MF_PAX_RANDMMAP;
72007 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72008 + flags |= MF_PAX_EMUTRAMP;
72009 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72010 + flags |= MF_PAX_MPROTECT;
72011 +
72012 + pax_set_flags(task, flags);
72013 +
72014 + return;
72015 +}
72016 +#endif
72017 +
72018 +int
72019 +gr_handle_proc_ptrace(struct task_struct *task)
72020 +{
72021 + struct file *filp;
72022 + struct task_struct *tmp = task;
72023 + struct task_struct *curtemp = current;
72024 + __u32 retmode;
72025 +
72026 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72027 + if (unlikely(!(gr_status & GR_READY)))
72028 + return 0;
72029 +#endif
72030 +
72031 + read_lock(&tasklist_lock);
72032 + read_lock(&grsec_exec_file_lock);
72033 + filp = task->exec_file;
72034 +
72035 + while (task_pid_nr(tmp) > 0) {
72036 + if (tmp == curtemp)
72037 + break;
72038 + tmp = tmp->real_parent;
72039 + }
72040 +
72041 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72042 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72043 + read_unlock(&grsec_exec_file_lock);
72044 + read_unlock(&tasklist_lock);
72045 + return 1;
72046 + }
72047 +
72048 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72049 + if (!(gr_status & GR_READY)) {
72050 + read_unlock(&grsec_exec_file_lock);
72051 + read_unlock(&tasklist_lock);
72052 + return 0;
72053 + }
72054 +#endif
72055 +
72056 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72057 + read_unlock(&grsec_exec_file_lock);
72058 + read_unlock(&tasklist_lock);
72059 +
72060 + if (retmode & GR_NOPTRACE)
72061 + return 1;
72062 +
72063 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72064 + && (current->acl != task->acl || (current->acl != current->role->root_label
72065 + && task_pid_nr(current) != task_pid_nr(task))))
72066 + return 1;
72067 +
72068 + return 0;
72069 +}
72070 +
72071 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72072 +{
72073 + if (unlikely(!(gr_status & GR_READY)))
72074 + return;
72075 +
72076 + if (!(current->role->roletype & GR_ROLE_GOD))
72077 + return;
72078 +
72079 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72080 + p->role->rolename, gr_task_roletype_to_char(p),
72081 + p->acl->filename);
72082 +}
72083 +
72084 +int
72085 +gr_handle_ptrace(struct task_struct *task, const long request)
72086 +{
72087 + struct task_struct *tmp = task;
72088 + struct task_struct *curtemp = current;
72089 + __u32 retmode;
72090 +
72091 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72092 + if (unlikely(!(gr_status & GR_READY)))
72093 + return 0;
72094 +#endif
72095 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72096 + read_lock(&tasklist_lock);
72097 + while (task_pid_nr(tmp) > 0) {
72098 + if (tmp == curtemp)
72099 + break;
72100 + tmp = tmp->real_parent;
72101 + }
72102 +
72103 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72104 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72105 + read_unlock(&tasklist_lock);
72106 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72107 + return 1;
72108 + }
72109 + read_unlock(&tasklist_lock);
72110 + }
72111 +
72112 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72113 + if (!(gr_status & GR_READY))
72114 + return 0;
72115 +#endif
72116 +
72117 + read_lock(&grsec_exec_file_lock);
72118 + if (unlikely(!task->exec_file)) {
72119 + read_unlock(&grsec_exec_file_lock);
72120 + return 0;
72121 + }
72122 +
72123 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72124 + read_unlock(&grsec_exec_file_lock);
72125 +
72126 + if (retmode & GR_NOPTRACE) {
72127 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72128 + return 1;
72129 + }
72130 +
72131 + if (retmode & GR_PTRACERD) {
72132 + switch (request) {
72133 + case PTRACE_SEIZE:
72134 + case PTRACE_POKETEXT:
72135 + case PTRACE_POKEDATA:
72136 + case PTRACE_POKEUSR:
72137 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72138 + case PTRACE_SETREGS:
72139 + case PTRACE_SETFPREGS:
72140 +#endif
72141 +#ifdef CONFIG_X86
72142 + case PTRACE_SETFPXREGS:
72143 +#endif
72144 +#ifdef CONFIG_ALTIVEC
72145 + case PTRACE_SETVRREGS:
72146 +#endif
72147 + return 1;
72148 + default:
72149 + return 0;
72150 + }
72151 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72152 + !(current->role->roletype & GR_ROLE_GOD) &&
72153 + (current->acl != task->acl)) {
72154 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72155 + return 1;
72156 + }
72157 +
72158 + return 0;
72159 +}
72160 +
72161 +static int is_writable_mmap(const struct file *filp)
72162 +{
72163 + struct task_struct *task = current;
72164 + struct acl_object_label *obj, *obj2;
72165 +
72166 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72167 + !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))) {
72168 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72169 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72170 + task->role->root_label);
72171 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72172 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72173 + return 1;
72174 + }
72175 + }
72176 + return 0;
72177 +}
72178 +
72179 +int
72180 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72181 +{
72182 + __u32 mode;
72183 +
72184 + if (unlikely(!file || !(prot & PROT_EXEC)))
72185 + return 1;
72186 +
72187 + if (is_writable_mmap(file))
72188 + return 0;
72189 +
72190 + mode =
72191 + gr_search_file(file->f_path.dentry,
72192 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72193 + file->f_path.mnt);
72194 +
72195 + if (!gr_tpe_allow(file))
72196 + return 0;
72197 +
72198 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72199 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72200 + return 0;
72201 + } else if (unlikely(!(mode & GR_EXEC))) {
72202 + return 0;
72203 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72204 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72205 + return 1;
72206 + }
72207 +
72208 + return 1;
72209 +}
72210 +
72211 +int
72212 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72213 +{
72214 + __u32 mode;
72215 +
72216 + if (unlikely(!file || !(prot & PROT_EXEC)))
72217 + return 1;
72218 +
72219 + if (is_writable_mmap(file))
72220 + return 0;
72221 +
72222 + mode =
72223 + gr_search_file(file->f_path.dentry,
72224 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72225 + file->f_path.mnt);
72226 +
72227 + if (!gr_tpe_allow(file))
72228 + return 0;
72229 +
72230 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72231 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72232 + return 0;
72233 + } else if (unlikely(!(mode & GR_EXEC))) {
72234 + return 0;
72235 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72236 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72237 + return 1;
72238 + }
72239 +
72240 + return 1;
72241 +}
72242 +
72243 +void
72244 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72245 +{
72246 + unsigned long runtime, cputime;
72247 + cputime_t utime, stime;
72248 + unsigned int wday, cday;
72249 + __u8 whr, chr;
72250 + __u8 wmin, cmin;
72251 + __u8 wsec, csec;
72252 + struct timespec curtime, starttime;
72253 +
72254 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72255 + !(task->acl->mode & GR_PROCACCT)))
72256 + return;
72257 +
72258 + curtime = ns_to_timespec(ktime_get_ns());
72259 + starttime = ns_to_timespec(task->start_time);
72260 + runtime = curtime.tv_sec - starttime.tv_sec;
72261 + wday = runtime / (60 * 60 * 24);
72262 + runtime -= wday * (60 * 60 * 24);
72263 + whr = runtime / (60 * 60);
72264 + runtime -= whr * (60 * 60);
72265 + wmin = runtime / 60;
72266 + runtime -= wmin * 60;
72267 + wsec = runtime;
72268 +
72269 + task_cputime(task, &utime, &stime);
72270 + cputime = cputime_to_secs(utime + stime);
72271 + cday = cputime / (60 * 60 * 24);
72272 + cputime -= cday * (60 * 60 * 24);
72273 + chr = cputime / (60 * 60);
72274 + cputime -= chr * (60 * 60);
72275 + cmin = cputime / 60;
72276 + cputime -= cmin * 60;
72277 + csec = cputime;
72278 +
72279 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72280 +
72281 + return;
72282 +}
72283 +
72284 +#ifdef CONFIG_TASKSTATS
72285 +int gr_is_taskstats_denied(int pid)
72286 +{
72287 + struct task_struct *task;
72288 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72289 + const struct cred *cred;
72290 +#endif
72291 + int ret = 0;
72292 +
72293 + /* restrict taskstats viewing to un-chrooted root users
72294 + who have the 'view' subject flag if the RBAC system is enabled
72295 + */
72296 +
72297 + rcu_read_lock();
72298 + read_lock(&tasklist_lock);
72299 + task = find_task_by_vpid(pid);
72300 + if (task) {
72301 +#ifdef CONFIG_GRKERNSEC_CHROOT
72302 + if (proc_is_chrooted(task))
72303 + ret = -EACCES;
72304 +#endif
72305 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72306 + cred = __task_cred(task);
72307 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72308 + if (gr_is_global_nonroot(cred->uid))
72309 + ret = -EACCES;
72310 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72311 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72312 + ret = -EACCES;
72313 +#endif
72314 +#endif
72315 + if (gr_status & GR_READY) {
72316 + if (!(task->acl->mode & GR_VIEW))
72317 + ret = -EACCES;
72318 + }
72319 + } else
72320 + ret = -ENOENT;
72321 +
72322 + read_unlock(&tasklist_lock);
72323 + rcu_read_unlock();
72324 +
72325 + return ret;
72326 +}
72327 +#endif
72328 +
72329 +/* AUXV entries are filled via a descendant of search_binary_handler
72330 + after we've already applied the subject for the target
72331 +*/
72332 +int gr_acl_enable_at_secure(void)
72333 +{
72334 + if (unlikely(!(gr_status & GR_READY)))
72335 + return 0;
72336 +
72337 + if (current->acl->mode & GR_ATSECURE)
72338 + return 1;
72339 +
72340 + return 0;
72341 +}
72342 +
72343 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72344 +{
72345 + struct task_struct *task = current;
72346 + struct dentry *dentry = file->f_path.dentry;
72347 + struct vfsmount *mnt = file->f_path.mnt;
72348 + struct acl_object_label *obj, *tmp;
72349 + struct acl_subject_label *subj;
72350 + unsigned int bufsize;
72351 + int is_not_root;
72352 + char *path;
72353 + dev_t dev = __get_dev(dentry);
72354 +
72355 + if (unlikely(!(gr_status & GR_READY)))
72356 + return 1;
72357 +
72358 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72359 + return 1;
72360 +
72361 + /* ignore Eric Biederman */
72362 + if (IS_PRIVATE(dentry->d_inode))
72363 + return 1;
72364 +
72365 + subj = task->acl;
72366 + read_lock(&gr_inode_lock);
72367 + do {
72368 + obj = lookup_acl_obj_label(ino, dev, subj);
72369 + if (obj != NULL) {
72370 + read_unlock(&gr_inode_lock);
72371 + return (obj->mode & GR_FIND) ? 1 : 0;
72372 + }
72373 + } while ((subj = subj->parent_subject));
72374 + read_unlock(&gr_inode_lock);
72375 +
72376 + /* this is purely an optimization since we're looking for an object
72377 + for the directory we're doing a readdir on
72378 + if it's possible for any globbed object to match the entry we're
72379 + filling into the directory, then the object we find here will be
72380 + an anchor point with attached globbed objects
72381 + */
72382 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72383 + if (obj->globbed == NULL)
72384 + return (obj->mode & GR_FIND) ? 1 : 0;
72385 +
72386 + is_not_root = ((obj->filename[0] == '/') &&
72387 + (obj->filename[1] == '\0')) ? 0 : 1;
72388 + bufsize = PAGE_SIZE - namelen - is_not_root;
72389 +
72390 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72391 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72392 + return 1;
72393 +
72394 + preempt_disable();
72395 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72396 + bufsize);
72397 +
72398 + bufsize = strlen(path);
72399 +
72400 + /* if base is "/", don't append an additional slash */
72401 + if (is_not_root)
72402 + *(path + bufsize) = '/';
72403 + memcpy(path + bufsize + is_not_root, name, namelen);
72404 + *(path + bufsize + namelen + is_not_root) = '\0';
72405 +
72406 + tmp = obj->globbed;
72407 + while (tmp) {
72408 + if (!glob_match(tmp->filename, path)) {
72409 + preempt_enable();
72410 + return (tmp->mode & GR_FIND) ? 1 : 0;
72411 + }
72412 + tmp = tmp->next;
72413 + }
72414 + preempt_enable();
72415 + return (obj->mode & GR_FIND) ? 1 : 0;
72416 +}
72417 +
72418 +void gr_put_exec_file(struct task_struct *task)
72419 +{
72420 + struct file *filp;
72421 +
72422 + write_lock(&grsec_exec_file_lock);
72423 + filp = task->exec_file;
72424 + task->exec_file = NULL;
72425 + write_unlock(&grsec_exec_file_lock);
72426 +
72427 + if (filp)
72428 + fput(filp);
72429 +
72430 + return;
72431 +}
72432 +
72433 +
72434 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72435 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72436 +#endif
72437 +#ifdef CONFIG_SECURITY
72438 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72439 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72440 +#endif
72441 +
72442 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72443 new file mode 100644
72444 index 0000000..18ffbbd
72445 --- /dev/null
72446 +++ b/grsecurity/gracl_alloc.c
72447 @@ -0,0 +1,105 @@
72448 +#include <linux/kernel.h>
72449 +#include <linux/mm.h>
72450 +#include <linux/slab.h>
72451 +#include <linux/vmalloc.h>
72452 +#include <linux/gracl.h>
72453 +#include <linux/grsecurity.h>
72454 +
72455 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72456 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72457 +
72458 +static __inline__ int
72459 +alloc_pop(void)
72460 +{
72461 + if (current_alloc_state->alloc_stack_next == 1)
72462 + return 0;
72463 +
72464 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72465 +
72466 + current_alloc_state->alloc_stack_next--;
72467 +
72468 + return 1;
72469 +}
72470 +
72471 +static __inline__ int
72472 +alloc_push(void *buf)
72473 +{
72474 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72475 + return 1;
72476 +
72477 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72478 +
72479 + current_alloc_state->alloc_stack_next++;
72480 +
72481 + return 0;
72482 +}
72483 +
72484 +void *
72485 +acl_alloc(unsigned long len)
72486 +{
72487 + void *ret = NULL;
72488 +
72489 + if (!len || len > PAGE_SIZE)
72490 + goto out;
72491 +
72492 + ret = kmalloc(len, GFP_KERNEL);
72493 +
72494 + if (ret) {
72495 + if (alloc_push(ret)) {
72496 + kfree(ret);
72497 + ret = NULL;
72498 + }
72499 + }
72500 +
72501 +out:
72502 + return ret;
72503 +}
72504 +
72505 +void *
72506 +acl_alloc_num(unsigned long num, unsigned long len)
72507 +{
72508 + if (!len || (num > (PAGE_SIZE / len)))
72509 + return NULL;
72510 +
72511 + return acl_alloc(num * len);
72512 +}
72513 +
72514 +void
72515 +acl_free_all(void)
72516 +{
72517 + if (!current_alloc_state->alloc_stack)
72518 + return;
72519 +
72520 + while (alloc_pop()) ;
72521 +
72522 + if (current_alloc_state->alloc_stack) {
72523 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72524 + kfree(current_alloc_state->alloc_stack);
72525 + else
72526 + vfree(current_alloc_state->alloc_stack);
72527 + }
72528 +
72529 + current_alloc_state->alloc_stack = NULL;
72530 + current_alloc_state->alloc_stack_size = 1;
72531 + current_alloc_state->alloc_stack_next = 1;
72532 +
72533 + return;
72534 +}
72535 +
72536 +int
72537 +acl_alloc_stack_init(unsigned long size)
72538 +{
72539 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72540 + current_alloc_state->alloc_stack =
72541 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72542 + else
72543 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72544 +
72545 + current_alloc_state->alloc_stack_size = size;
72546 + current_alloc_state->alloc_stack_next = 1;
72547 +
72548 + if (!current_alloc_state->alloc_stack)
72549 + return 0;
72550 + else
72551 + return 1;
72552 +}
72553 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72554 new file mode 100644
72555 index 0000000..1a94c11
72556 --- /dev/null
72557 +++ b/grsecurity/gracl_cap.c
72558 @@ -0,0 +1,127 @@
72559 +#include <linux/kernel.h>
72560 +#include <linux/module.h>
72561 +#include <linux/sched.h>
72562 +#include <linux/gracl.h>
72563 +#include <linux/grsecurity.h>
72564 +#include <linux/grinternal.h>
72565 +
72566 +extern const char *captab_log[];
72567 +extern int captab_log_entries;
72568 +
72569 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72570 +{
72571 + struct acl_subject_label *curracl;
72572 +
72573 + if (!gr_acl_is_enabled())
72574 + return 1;
72575 +
72576 + curracl = task->acl;
72577 +
72578 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72579 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72580 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72581 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72582 + gr_to_filename(task->exec_file->f_path.dentry,
72583 + task->exec_file->f_path.mnt) : curracl->filename,
72584 + curracl->filename, 0UL,
72585 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72586 + return 1;
72587 + }
72588 +
72589 + return 0;
72590 +}
72591 +
72592 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72593 +{
72594 + struct acl_subject_label *curracl;
72595 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72596 + kernel_cap_t cap_audit = __cap_empty_set;
72597 +
72598 + if (!gr_acl_is_enabled())
72599 + return 1;
72600 +
72601 + curracl = task->acl;
72602 +
72603 + cap_drop = curracl->cap_lower;
72604 + cap_mask = curracl->cap_mask;
72605 + cap_audit = curracl->cap_invert_audit;
72606 +
72607 + while ((curracl = curracl->parent_subject)) {
72608 + /* if the cap isn't specified in the current computed mask but is specified in the
72609 + current level subject, and is lowered in the current level subject, then add
72610 + it to the set of dropped capabilities
72611 + otherwise, add the current level subject's mask to the current computed mask
72612 + */
72613 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72614 + cap_raise(cap_mask, cap);
72615 + if (cap_raised(curracl->cap_lower, cap))
72616 + cap_raise(cap_drop, cap);
72617 + if (cap_raised(curracl->cap_invert_audit, cap))
72618 + cap_raise(cap_audit, cap);
72619 + }
72620 + }
72621 +
72622 + if (!cap_raised(cap_drop, cap)) {
72623 + if (cap_raised(cap_audit, cap))
72624 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72625 + return 1;
72626 + }
72627 +
72628 + /* only learn the capability use if the process has the capability in the
72629 + general case, the two uses in sys.c of gr_learn_cap are an exception
72630 + to this rule to ensure any role transition involves what the full-learned
72631 + policy believes in a privileged process
72632 + */
72633 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72634 + return 1;
72635 +
72636 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72637 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72638 +
72639 + return 0;
72640 +}
72641 +
72642 +int
72643 +gr_acl_is_capable(const int cap)
72644 +{
72645 + return gr_task_acl_is_capable(current, current_cred(), cap);
72646 +}
72647 +
72648 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72649 +{
72650 + struct acl_subject_label *curracl;
72651 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72652 +
72653 + if (!gr_acl_is_enabled())
72654 + return 1;
72655 +
72656 + curracl = task->acl;
72657 +
72658 + cap_drop = curracl->cap_lower;
72659 + cap_mask = curracl->cap_mask;
72660 +
72661 + while ((curracl = curracl->parent_subject)) {
72662 + /* if the cap isn't specified in the current computed mask but is specified in the
72663 + current level subject, and is lowered in the current level subject, then add
72664 + it to the set of dropped capabilities
72665 + otherwise, add the current level subject's mask to the current computed mask
72666 + */
72667 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72668 + cap_raise(cap_mask, cap);
72669 + if (cap_raised(curracl->cap_lower, cap))
72670 + cap_raise(cap_drop, cap);
72671 + }
72672 + }
72673 +
72674 + if (!cap_raised(cap_drop, cap))
72675 + return 1;
72676 +
72677 + return 0;
72678 +}
72679 +
72680 +int
72681 +gr_acl_is_capable_nolog(const int cap)
72682 +{
72683 + return gr_task_acl_is_capable_nolog(current, cap);
72684 +}
72685 +
72686 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72687 new file mode 100644
72688 index 0000000..ca25605
72689 --- /dev/null
72690 +++ b/grsecurity/gracl_compat.c
72691 @@ -0,0 +1,270 @@
72692 +#include <linux/kernel.h>
72693 +#include <linux/gracl.h>
72694 +#include <linux/compat.h>
72695 +#include <linux/gracl_compat.h>
72696 +
72697 +#include <asm/uaccess.h>
72698 +
72699 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72700 +{
72701 + struct gr_arg_wrapper_compat uwrapcompat;
72702 +
72703 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72704 + return -EFAULT;
72705 +
72706 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72707 + (uwrapcompat.version != 0x2901)) ||
72708 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72709 + return -EINVAL;
72710 +
72711 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72712 + uwrap->version = uwrapcompat.version;
72713 + uwrap->size = sizeof(struct gr_arg);
72714 +
72715 + return 0;
72716 +}
72717 +
72718 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72719 +{
72720 + struct gr_arg_compat argcompat;
72721 +
72722 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72723 + return -EFAULT;
72724 +
72725 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72726 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72727 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72728 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72729 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72730 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72731 +
72732 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72733 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72734 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72735 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72736 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72737 + arg->segv_device = argcompat.segv_device;
72738 + arg->segv_inode = argcompat.segv_inode;
72739 + arg->segv_uid = argcompat.segv_uid;
72740 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72741 + arg->mode = argcompat.mode;
72742 +
72743 + return 0;
72744 +}
72745 +
72746 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72747 +{
72748 + struct acl_object_label_compat objcompat;
72749 +
72750 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72751 + return -EFAULT;
72752 +
72753 + obj->filename = compat_ptr(objcompat.filename);
72754 + obj->inode = objcompat.inode;
72755 + obj->device = objcompat.device;
72756 + obj->mode = objcompat.mode;
72757 +
72758 + obj->nested = compat_ptr(objcompat.nested);
72759 + obj->globbed = compat_ptr(objcompat.globbed);
72760 +
72761 + obj->prev = compat_ptr(objcompat.prev);
72762 + obj->next = compat_ptr(objcompat.next);
72763 +
72764 + return 0;
72765 +}
72766 +
72767 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72768 +{
72769 + unsigned int i;
72770 + struct acl_subject_label_compat subjcompat;
72771 +
72772 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72773 + return -EFAULT;
72774 +
72775 + subj->filename = compat_ptr(subjcompat.filename);
72776 + subj->inode = subjcompat.inode;
72777 + subj->device = subjcompat.device;
72778 + subj->mode = subjcompat.mode;
72779 + subj->cap_mask = subjcompat.cap_mask;
72780 + subj->cap_lower = subjcompat.cap_lower;
72781 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72782 +
72783 + for (i = 0; i < GR_NLIMITS; i++) {
72784 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72785 + subj->res[i].rlim_cur = RLIM_INFINITY;
72786 + else
72787 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72788 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72789 + subj->res[i].rlim_max = RLIM_INFINITY;
72790 + else
72791 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72792 + }
72793 + subj->resmask = subjcompat.resmask;
72794 +
72795 + subj->user_trans_type = subjcompat.user_trans_type;
72796 + subj->group_trans_type = subjcompat.group_trans_type;
72797 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72798 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72799 + subj->user_trans_num = subjcompat.user_trans_num;
72800 + subj->group_trans_num = subjcompat.group_trans_num;
72801 +
72802 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72803 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72804 + subj->ip_type = subjcompat.ip_type;
72805 + subj->ips = compat_ptr(subjcompat.ips);
72806 + subj->ip_num = subjcompat.ip_num;
72807 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72808 +
72809 + subj->crashes = subjcompat.crashes;
72810 + subj->expires = subjcompat.expires;
72811 +
72812 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72813 + subj->hash = compat_ptr(subjcompat.hash);
72814 + subj->prev = compat_ptr(subjcompat.prev);
72815 + subj->next = compat_ptr(subjcompat.next);
72816 +
72817 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72818 + subj->obj_hash_size = subjcompat.obj_hash_size;
72819 + subj->pax_flags = subjcompat.pax_flags;
72820 +
72821 + return 0;
72822 +}
72823 +
72824 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72825 +{
72826 + struct acl_role_label_compat rolecompat;
72827 +
72828 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72829 + return -EFAULT;
72830 +
72831 + role->rolename = compat_ptr(rolecompat.rolename);
72832 + role->uidgid = rolecompat.uidgid;
72833 + role->roletype = rolecompat.roletype;
72834 +
72835 + role->auth_attempts = rolecompat.auth_attempts;
72836 + role->expires = rolecompat.expires;
72837 +
72838 + role->root_label = compat_ptr(rolecompat.root_label);
72839 + role->hash = compat_ptr(rolecompat.hash);
72840 +
72841 + role->prev = compat_ptr(rolecompat.prev);
72842 + role->next = compat_ptr(rolecompat.next);
72843 +
72844 + role->transitions = compat_ptr(rolecompat.transitions);
72845 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72846 + role->domain_children = compat_ptr(rolecompat.domain_children);
72847 + role->domain_child_num = rolecompat.domain_child_num;
72848 +
72849 + role->umask = rolecompat.umask;
72850 +
72851 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72852 + role->subj_hash_size = rolecompat.subj_hash_size;
72853 +
72854 + return 0;
72855 +}
72856 +
72857 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72858 +{
72859 + struct role_allowed_ip_compat roleip_compat;
72860 +
72861 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72862 + return -EFAULT;
72863 +
72864 + roleip->addr = roleip_compat.addr;
72865 + roleip->netmask = roleip_compat.netmask;
72866 +
72867 + roleip->prev = compat_ptr(roleip_compat.prev);
72868 + roleip->next = compat_ptr(roleip_compat.next);
72869 +
72870 + return 0;
72871 +}
72872 +
72873 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72874 +{
72875 + struct role_transition_compat trans_compat;
72876 +
72877 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72878 + return -EFAULT;
72879 +
72880 + trans->rolename = compat_ptr(trans_compat.rolename);
72881 +
72882 + trans->prev = compat_ptr(trans_compat.prev);
72883 + trans->next = compat_ptr(trans_compat.next);
72884 +
72885 + return 0;
72886 +
72887 +}
72888 +
72889 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72890 +{
72891 + struct gr_hash_struct_compat hash_compat;
72892 +
72893 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72894 + return -EFAULT;
72895 +
72896 + hash->table = compat_ptr(hash_compat.table);
72897 + hash->nametable = compat_ptr(hash_compat.nametable);
72898 + hash->first = compat_ptr(hash_compat.first);
72899 +
72900 + hash->table_size = hash_compat.table_size;
72901 + hash->used_size = hash_compat.used_size;
72902 +
72903 + hash->type = hash_compat.type;
72904 +
72905 + return 0;
72906 +}
72907 +
72908 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72909 +{
72910 + compat_uptr_t ptrcompat;
72911 +
72912 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72913 + return -EFAULT;
72914 +
72915 + *(void **)ptr = compat_ptr(ptrcompat);
72916 +
72917 + return 0;
72918 +}
72919 +
72920 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72921 +{
72922 + struct acl_ip_label_compat ip_compat;
72923 +
72924 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72925 + return -EFAULT;
72926 +
72927 + ip->iface = compat_ptr(ip_compat.iface);
72928 + ip->addr = ip_compat.addr;
72929 + ip->netmask = ip_compat.netmask;
72930 + ip->low = ip_compat.low;
72931 + ip->high = ip_compat.high;
72932 + ip->mode = ip_compat.mode;
72933 + ip->type = ip_compat.type;
72934 +
72935 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72936 +
72937 + ip->prev = compat_ptr(ip_compat.prev);
72938 + ip->next = compat_ptr(ip_compat.next);
72939 +
72940 + return 0;
72941 +}
72942 +
72943 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72944 +{
72945 + struct sprole_pw_compat pw_compat;
72946 +
72947 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72948 + return -EFAULT;
72949 +
72950 + pw->rolename = compat_ptr(pw_compat.rolename);
72951 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72952 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72953 +
72954 + return 0;
72955 +}
72956 +
72957 +size_t get_gr_arg_wrapper_size_compat(void)
72958 +{
72959 + return sizeof(struct gr_arg_wrapper_compat);
72960 +}
72961 +
72962 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72963 new file mode 100644
72964 index 0000000..4008fdc
72965 --- /dev/null
72966 +++ b/grsecurity/gracl_fs.c
72967 @@ -0,0 +1,445 @@
72968 +#include <linux/kernel.h>
72969 +#include <linux/sched.h>
72970 +#include <linux/types.h>
72971 +#include <linux/fs.h>
72972 +#include <linux/file.h>
72973 +#include <linux/stat.h>
72974 +#include <linux/grsecurity.h>
72975 +#include <linux/grinternal.h>
72976 +#include <linux/gracl.h>
72977 +
72978 +umode_t
72979 +gr_acl_umask(void)
72980 +{
72981 + if (unlikely(!gr_acl_is_enabled()))
72982 + return 0;
72983 +
72984 + return current->role->umask;
72985 +}
72986 +
72987 +__u32
72988 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72989 + const struct vfsmount * mnt)
72990 +{
72991 + __u32 mode;
72992 +
72993 + if (unlikely(d_is_negative(dentry)))
72994 + return GR_FIND;
72995 +
72996 + mode =
72997 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72998 +
72999 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73000 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73001 + return mode;
73002 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73003 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73004 + return 0;
73005 + } else if (unlikely(!(mode & GR_FIND)))
73006 + return 0;
73007 +
73008 + return GR_FIND;
73009 +}
73010 +
73011 +__u32
73012 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73013 + int acc_mode)
73014 +{
73015 + __u32 reqmode = GR_FIND;
73016 + __u32 mode;
73017 +
73018 + if (unlikely(d_is_negative(dentry)))
73019 + return reqmode;
73020 +
73021 + if (acc_mode & MAY_APPEND)
73022 + reqmode |= GR_APPEND;
73023 + else if (acc_mode & MAY_WRITE)
73024 + reqmode |= GR_WRITE;
73025 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73026 + reqmode |= GR_READ;
73027 +
73028 + mode =
73029 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73030 + mnt);
73031 +
73032 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73033 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73034 + reqmode & GR_READ ? " reading" : "",
73035 + reqmode & GR_WRITE ? " writing" : reqmode &
73036 + GR_APPEND ? " appending" : "");
73037 + return reqmode;
73038 + } else
73039 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73040 + {
73041 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73042 + reqmode & GR_READ ? " reading" : "",
73043 + reqmode & GR_WRITE ? " writing" : reqmode &
73044 + GR_APPEND ? " appending" : "");
73045 + return 0;
73046 + } else if (unlikely((mode & reqmode) != reqmode))
73047 + return 0;
73048 +
73049 + return reqmode;
73050 +}
73051 +
73052 +__u32
73053 +gr_acl_handle_creat(const struct dentry * dentry,
73054 + const struct dentry * p_dentry,
73055 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73056 + const int imode)
73057 +{
73058 + __u32 reqmode = GR_WRITE | GR_CREATE;
73059 + __u32 mode;
73060 +
73061 + if (acc_mode & MAY_APPEND)
73062 + reqmode |= GR_APPEND;
73063 + // if a directory was required or the directory already exists, then
73064 + // don't count this open as a read
73065 + if ((acc_mode & MAY_READ) &&
73066 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73067 + reqmode |= GR_READ;
73068 + if ((open_flags & O_CREAT) &&
73069 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73070 + reqmode |= GR_SETID;
73071 +
73072 + mode =
73073 + gr_check_create(dentry, p_dentry, p_mnt,
73074 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73075 +
73076 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73077 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73078 + reqmode & GR_READ ? " reading" : "",
73079 + reqmode & GR_WRITE ? " writing" : reqmode &
73080 + GR_APPEND ? " appending" : "");
73081 + return reqmode;
73082 + } else
73083 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73084 + {
73085 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73086 + reqmode & GR_READ ? " reading" : "",
73087 + reqmode & GR_WRITE ? " writing" : reqmode &
73088 + GR_APPEND ? " appending" : "");
73089 + return 0;
73090 + } else if (unlikely((mode & reqmode) != reqmode))
73091 + return 0;
73092 +
73093 + return reqmode;
73094 +}
73095 +
73096 +__u32
73097 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73098 + const int fmode)
73099 +{
73100 + __u32 mode, reqmode = GR_FIND;
73101 +
73102 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73103 + reqmode |= GR_EXEC;
73104 + if (fmode & S_IWOTH)
73105 + reqmode |= GR_WRITE;
73106 + if (fmode & S_IROTH)
73107 + reqmode |= GR_READ;
73108 +
73109 + mode =
73110 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73111 + mnt);
73112 +
73113 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73114 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73115 + reqmode & GR_READ ? " reading" : "",
73116 + reqmode & GR_WRITE ? " writing" : "",
73117 + reqmode & GR_EXEC ? " executing" : "");
73118 + return reqmode;
73119 + } else
73120 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73121 + {
73122 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73123 + reqmode & GR_READ ? " reading" : "",
73124 + reqmode & GR_WRITE ? " writing" : "",
73125 + reqmode & GR_EXEC ? " executing" : "");
73126 + return 0;
73127 + } else if (unlikely((mode & reqmode) != reqmode))
73128 + return 0;
73129 +
73130 + return reqmode;
73131 +}
73132 +
73133 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73134 +{
73135 + __u32 mode;
73136 +
73137 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73138 +
73139 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73140 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73141 + return mode;
73142 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73143 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73144 + return 0;
73145 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73146 + return 0;
73147 +
73148 + return (reqmode);
73149 +}
73150 +
73151 +__u32
73152 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73153 +{
73154 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73155 +}
73156 +
73157 +__u32
73158 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73159 +{
73160 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73161 +}
73162 +
73163 +__u32
73164 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73165 +{
73166 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73167 +}
73168 +
73169 +__u32
73170 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73171 +{
73172 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73173 +}
73174 +
73175 +__u32
73176 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73177 + umode_t *modeptr)
73178 +{
73179 + umode_t mode;
73180 +
73181 + *modeptr &= ~gr_acl_umask();
73182 + mode = *modeptr;
73183 +
73184 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73185 + return 1;
73186 +
73187 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73188 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73189 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73190 + GR_CHMOD_ACL_MSG);
73191 + } else {
73192 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73193 + }
73194 +}
73195 +
73196 +__u32
73197 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73198 +{
73199 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73200 +}
73201 +
73202 +__u32
73203 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73204 +{
73205 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73206 +}
73207 +
73208 +__u32
73209 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73210 +{
73211 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73212 +}
73213 +
73214 +__u32
73215 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73216 +{
73217 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73218 +}
73219 +
73220 +__u32
73221 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73222 +{
73223 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73224 + GR_UNIXCONNECT_ACL_MSG);
73225 +}
73226 +
73227 +/* hardlinks require at minimum create and link permission,
73228 + any additional privilege required is based on the
73229 + privilege of the file being linked to
73230 +*/
73231 +__u32
73232 +gr_acl_handle_link(const struct dentry * new_dentry,
73233 + const struct dentry * parent_dentry,
73234 + const struct vfsmount * parent_mnt,
73235 + const struct dentry * old_dentry,
73236 + const struct vfsmount * old_mnt, const struct filename *to)
73237 +{
73238 + __u32 mode;
73239 + __u32 needmode = GR_CREATE | GR_LINK;
73240 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73241 +
73242 + mode =
73243 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73244 + old_mnt);
73245 +
73246 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73247 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73248 + return mode;
73249 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73250 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73251 + return 0;
73252 + } else if (unlikely((mode & needmode) != needmode))
73253 + return 0;
73254 +
73255 + return 1;
73256 +}
73257 +
73258 +__u32
73259 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73260 + const struct dentry * parent_dentry,
73261 + const struct vfsmount * parent_mnt, const struct filename *from)
73262 +{
73263 + __u32 needmode = GR_WRITE | GR_CREATE;
73264 + __u32 mode;
73265 +
73266 + mode =
73267 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73268 + GR_CREATE | GR_AUDIT_CREATE |
73269 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73270 +
73271 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73272 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73273 + return mode;
73274 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73275 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73276 + return 0;
73277 + } else if (unlikely((mode & needmode) != needmode))
73278 + return 0;
73279 +
73280 + return (GR_WRITE | GR_CREATE);
73281 +}
73282 +
73283 +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)
73284 +{
73285 + __u32 mode;
73286 +
73287 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73288 +
73289 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73290 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73291 + return mode;
73292 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73293 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73294 + return 0;
73295 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73296 + return 0;
73297 +
73298 + return (reqmode);
73299 +}
73300 +
73301 +__u32
73302 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73303 + const struct dentry * parent_dentry,
73304 + const struct vfsmount * parent_mnt,
73305 + const int mode)
73306 +{
73307 + __u32 reqmode = GR_WRITE | GR_CREATE;
73308 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73309 + reqmode |= GR_SETID;
73310 +
73311 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73312 + reqmode, GR_MKNOD_ACL_MSG);
73313 +}
73314 +
73315 +__u32
73316 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73317 + const struct dentry *parent_dentry,
73318 + const struct vfsmount *parent_mnt)
73319 +{
73320 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73321 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73322 +}
73323 +
73324 +#define RENAME_CHECK_SUCCESS(old, new) \
73325 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73326 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73327 +
73328 +int
73329 +gr_acl_handle_rename(struct dentry *new_dentry,
73330 + struct dentry *parent_dentry,
73331 + const struct vfsmount *parent_mnt,
73332 + struct dentry *old_dentry,
73333 + struct inode *old_parent_inode,
73334 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73335 +{
73336 + __u32 comp1, comp2;
73337 + int error = 0;
73338 +
73339 + if (unlikely(!gr_acl_is_enabled()))
73340 + return 0;
73341 +
73342 + if (flags & RENAME_EXCHANGE) {
73343 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73344 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73345 + GR_SUPPRESS, parent_mnt);
73346 + comp2 =
73347 + gr_search_file(old_dentry,
73348 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73349 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73350 + } else if (d_is_negative(new_dentry)) {
73351 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73352 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73353 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73354 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73355 + GR_DELETE | GR_AUDIT_DELETE |
73356 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73357 + GR_SUPPRESS, old_mnt);
73358 + } else {
73359 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73360 + GR_CREATE | GR_DELETE |
73361 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73362 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73363 + GR_SUPPRESS, parent_mnt);
73364 + comp2 =
73365 + gr_search_file(old_dentry,
73366 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73367 + GR_DELETE | GR_AUDIT_DELETE |
73368 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73369 + }
73370 +
73371 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73372 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73373 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73374 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73375 + && !(comp2 & GR_SUPPRESS)) {
73376 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73377 + error = -EACCES;
73378 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73379 + error = -EACCES;
73380 +
73381 + return error;
73382 +}
73383 +
73384 +void
73385 +gr_acl_handle_exit(void)
73386 +{
73387 + u16 id;
73388 + char *rolename;
73389 +
73390 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73391 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73392 + id = current->acl_role_id;
73393 + rolename = current->role->rolename;
73394 + gr_set_acls(1);
73395 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73396 + }
73397 +
73398 + gr_put_exec_file(current);
73399 + return;
73400 +}
73401 +
73402 +int
73403 +gr_acl_handle_procpidmem(const struct task_struct *task)
73404 +{
73405 + if (unlikely(!gr_acl_is_enabled()))
73406 + return 0;
73407 +
73408 + if (task != current && task->acl->mode & GR_PROTPROCFD)
73409 + return -EACCES;
73410 +
73411 + return 0;
73412 +}
73413 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73414 new file mode 100644
73415 index 0000000..f056b81
73416 --- /dev/null
73417 +++ b/grsecurity/gracl_ip.c
73418 @@ -0,0 +1,386 @@
73419 +#include <linux/kernel.h>
73420 +#include <asm/uaccess.h>
73421 +#include <asm/errno.h>
73422 +#include <net/sock.h>
73423 +#include <linux/file.h>
73424 +#include <linux/fs.h>
73425 +#include <linux/net.h>
73426 +#include <linux/in.h>
73427 +#include <linux/skbuff.h>
73428 +#include <linux/ip.h>
73429 +#include <linux/udp.h>
73430 +#include <linux/types.h>
73431 +#include <linux/sched.h>
73432 +#include <linux/netdevice.h>
73433 +#include <linux/inetdevice.h>
73434 +#include <linux/gracl.h>
73435 +#include <linux/grsecurity.h>
73436 +#include <linux/grinternal.h>
73437 +
73438 +#define GR_BIND 0x01
73439 +#define GR_CONNECT 0x02
73440 +#define GR_INVERT 0x04
73441 +#define GR_BINDOVERRIDE 0x08
73442 +#define GR_CONNECTOVERRIDE 0x10
73443 +#define GR_SOCK_FAMILY 0x20
73444 +
73445 +static const char * gr_protocols[IPPROTO_MAX] = {
73446 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73447 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73448 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73449 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73450 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73451 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73452 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73453 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73454 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73455 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73456 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73457 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73458 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73459 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73460 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73461 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73462 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73463 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73464 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73465 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73466 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73467 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73468 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73469 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73470 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73471 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73472 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73473 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73474 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73475 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73476 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73477 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73478 + };
73479 +
73480 +static const char * gr_socktypes[SOCK_MAX] = {
73481 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73482 + "unknown:7", "unknown:8", "unknown:9", "packet"
73483 + };
73484 +
73485 +static const char * gr_sockfamilies[AF_MAX+1] = {
73486 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73487 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73488 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73489 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73490 + };
73491 +
73492 +const char *
73493 +gr_proto_to_name(unsigned char proto)
73494 +{
73495 + return gr_protocols[proto];
73496 +}
73497 +
73498 +const char *
73499 +gr_socktype_to_name(unsigned char type)
73500 +{
73501 + return gr_socktypes[type];
73502 +}
73503 +
73504 +const char *
73505 +gr_sockfamily_to_name(unsigned char family)
73506 +{
73507 + return gr_sockfamilies[family];
73508 +}
73509 +
73510 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73511 +
73512 +int
73513 +gr_search_socket(const int domain, const int type, const int protocol)
73514 +{
73515 + struct acl_subject_label *curr;
73516 + const struct cred *cred = current_cred();
73517 +
73518 + if (unlikely(!gr_acl_is_enabled()))
73519 + goto exit;
73520 +
73521 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73522 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73523 + goto exit; // let the kernel handle it
73524 +
73525 + curr = current->acl;
73526 +
73527 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73528 + /* the family is allowed, if this is PF_INET allow it only if
73529 + the extra sock type/protocol checks pass */
73530 + if (domain == PF_INET)
73531 + goto inet_check;
73532 + goto exit;
73533 + } else {
73534 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73535 + __u32 fakeip = 0;
73536 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73537 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73538 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73539 + gr_to_filename(current->exec_file->f_path.dentry,
73540 + current->exec_file->f_path.mnt) :
73541 + curr->filename, curr->filename,
73542 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73543 + &current->signal->saved_ip);
73544 + goto exit;
73545 + }
73546 + goto exit_fail;
73547 + }
73548 +
73549 +inet_check:
73550 + /* the rest of this checking is for IPv4 only */
73551 + if (!curr->ips)
73552 + goto exit;
73553 +
73554 + if ((curr->ip_type & (1U << type)) &&
73555 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73556 + goto exit;
73557 +
73558 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73559 + /* we don't place acls on raw sockets , and sometimes
73560 + dgram/ip sockets are opened for ioctl and not
73561 + bind/connect, so we'll fake a bind learn log */
73562 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73563 + __u32 fakeip = 0;
73564 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73565 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73566 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73567 + gr_to_filename(current->exec_file->f_path.dentry,
73568 + current->exec_file->f_path.mnt) :
73569 + curr->filename, curr->filename,
73570 + &fakeip, 0, type,
73571 + protocol, GR_CONNECT, &current->signal->saved_ip);
73572 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73573 + __u32 fakeip = 0;
73574 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73575 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73576 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73577 + gr_to_filename(current->exec_file->f_path.dentry,
73578 + current->exec_file->f_path.mnt) :
73579 + curr->filename, curr->filename,
73580 + &fakeip, 0, type,
73581 + protocol, GR_BIND, &current->signal->saved_ip);
73582 + }
73583 + /* we'll log when they use connect or bind */
73584 + goto exit;
73585 + }
73586 +
73587 +exit_fail:
73588 + if (domain == PF_INET)
73589 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73590 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73591 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73592 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73593 + gr_socktype_to_name(type), protocol);
73594 +
73595 + return 0;
73596 +exit:
73597 + return 1;
73598 +}
73599 +
73600 +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)
73601 +{
73602 + if ((ip->mode & mode) &&
73603 + (ip_port >= ip->low) &&
73604 + (ip_port <= ip->high) &&
73605 + ((ntohl(ip_addr) & our_netmask) ==
73606 + (ntohl(our_addr) & our_netmask))
73607 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73608 + && (ip->type & (1U << type))) {
73609 + if (ip->mode & GR_INVERT)
73610 + return 2; // specifically denied
73611 + else
73612 + return 1; // allowed
73613 + }
73614 +
73615 + return 0; // not specifically allowed, may continue parsing
73616 +}
73617 +
73618 +static int
73619 +gr_search_connectbind(const int full_mode, struct sock *sk,
73620 + struct sockaddr_in *addr, const int type)
73621 +{
73622 + char iface[IFNAMSIZ] = {0};
73623 + struct acl_subject_label *curr;
73624 + struct acl_ip_label *ip;
73625 + struct inet_sock *isk;
73626 + struct net_device *dev;
73627 + struct in_device *idev;
73628 + unsigned long i;
73629 + int ret;
73630 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73631 + __u32 ip_addr = 0;
73632 + __u32 our_addr;
73633 + __u32 our_netmask;
73634 + char *p;
73635 + __u16 ip_port = 0;
73636 + const struct cred *cred = current_cred();
73637 +
73638 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73639 + return 0;
73640 +
73641 + curr = current->acl;
73642 + isk = inet_sk(sk);
73643 +
73644 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73645 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73646 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73647 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73648 + struct sockaddr_in saddr;
73649 + int err;
73650 +
73651 + saddr.sin_family = AF_INET;
73652 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73653 + saddr.sin_port = isk->inet_sport;
73654 +
73655 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73656 + if (err)
73657 + return err;
73658 +
73659 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73660 + if (err)
73661 + return err;
73662 + }
73663 +
73664 + if (!curr->ips)
73665 + return 0;
73666 +
73667 + ip_addr = addr->sin_addr.s_addr;
73668 + ip_port = ntohs(addr->sin_port);
73669 +
73670 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73671 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73672 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73673 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73674 + gr_to_filename(current->exec_file->f_path.dentry,
73675 + current->exec_file->f_path.mnt) :
73676 + curr->filename, curr->filename,
73677 + &ip_addr, ip_port, type,
73678 + sk->sk_protocol, mode, &current->signal->saved_ip);
73679 + return 0;
73680 + }
73681 +
73682 + for (i = 0; i < curr->ip_num; i++) {
73683 + ip = *(curr->ips + i);
73684 + if (ip->iface != NULL) {
73685 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73686 + p = strchr(iface, ':');
73687 + if (p != NULL)
73688 + *p = '\0';
73689 + dev = dev_get_by_name(sock_net(sk), iface);
73690 + if (dev == NULL)
73691 + continue;
73692 + idev = in_dev_get(dev);
73693 + if (idev == NULL) {
73694 + dev_put(dev);
73695 + continue;
73696 + }
73697 + rcu_read_lock();
73698 + for_ifa(idev) {
73699 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73700 + our_addr = ifa->ifa_address;
73701 + our_netmask = 0xffffffff;
73702 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73703 + if (ret == 1) {
73704 + rcu_read_unlock();
73705 + in_dev_put(idev);
73706 + dev_put(dev);
73707 + return 0;
73708 + } else if (ret == 2) {
73709 + rcu_read_unlock();
73710 + in_dev_put(idev);
73711 + dev_put(dev);
73712 + goto denied;
73713 + }
73714 + }
73715 + } endfor_ifa(idev);
73716 + rcu_read_unlock();
73717 + in_dev_put(idev);
73718 + dev_put(dev);
73719 + } else {
73720 + our_addr = ip->addr;
73721 + our_netmask = ip->netmask;
73722 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73723 + if (ret == 1)
73724 + return 0;
73725 + else if (ret == 2)
73726 + goto denied;
73727 + }
73728 + }
73729 +
73730 +denied:
73731 + if (mode == GR_BIND)
73732 + 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));
73733 + else if (mode == GR_CONNECT)
73734 + 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));
73735 +
73736 + return -EACCES;
73737 +}
73738 +
73739 +int
73740 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73741 +{
73742 + /* always allow disconnection of dgram sockets with connect */
73743 + if (addr->sin_family == AF_UNSPEC)
73744 + return 0;
73745 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73746 +}
73747 +
73748 +int
73749 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73750 +{
73751 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73752 +}
73753 +
73754 +int gr_search_listen(struct socket *sock)
73755 +{
73756 + struct sock *sk = sock->sk;
73757 + struct sockaddr_in addr;
73758 +
73759 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73760 + addr.sin_port = inet_sk(sk)->inet_sport;
73761 +
73762 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73763 +}
73764 +
73765 +int gr_search_accept(struct socket *sock)
73766 +{
73767 + struct sock *sk = sock->sk;
73768 + struct sockaddr_in addr;
73769 +
73770 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73771 + addr.sin_port = inet_sk(sk)->inet_sport;
73772 +
73773 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73774 +}
73775 +
73776 +int
73777 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73778 +{
73779 + if (addr)
73780 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73781 + else {
73782 + struct sockaddr_in sin;
73783 + const struct inet_sock *inet = inet_sk(sk);
73784 +
73785 + sin.sin_addr.s_addr = inet->inet_daddr;
73786 + sin.sin_port = inet->inet_dport;
73787 +
73788 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73789 + }
73790 +}
73791 +
73792 +int
73793 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73794 +{
73795 + struct sockaddr_in sin;
73796 +
73797 + if (unlikely(skb->len < sizeof (struct udphdr)))
73798 + return 0; // skip this packet
73799 +
73800 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73801 + sin.sin_port = udp_hdr(skb)->source;
73802 +
73803 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73804 +}
73805 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73806 new file mode 100644
73807 index 0000000..25f54ef
73808 --- /dev/null
73809 +++ b/grsecurity/gracl_learn.c
73810 @@ -0,0 +1,207 @@
73811 +#include <linux/kernel.h>
73812 +#include <linux/mm.h>
73813 +#include <linux/sched.h>
73814 +#include <linux/poll.h>
73815 +#include <linux/string.h>
73816 +#include <linux/file.h>
73817 +#include <linux/types.h>
73818 +#include <linux/vmalloc.h>
73819 +#include <linux/grinternal.h>
73820 +
73821 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73822 + size_t count, loff_t *ppos);
73823 +extern int gr_acl_is_enabled(void);
73824 +
73825 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73826 +static int gr_learn_attached;
73827 +
73828 +/* use a 512k buffer */
73829 +#define LEARN_BUFFER_SIZE (512 * 1024)
73830 +
73831 +static DEFINE_SPINLOCK(gr_learn_lock);
73832 +static DEFINE_MUTEX(gr_learn_user_mutex);
73833 +
73834 +/* we need to maintain two buffers, so that the kernel context of grlearn
73835 + uses a semaphore around the userspace copying, and the other kernel contexts
73836 + use a spinlock when copying into the buffer, since they cannot sleep
73837 +*/
73838 +static char *learn_buffer;
73839 +static char *learn_buffer_user;
73840 +static int learn_buffer_len;
73841 +static int learn_buffer_user_len;
73842 +
73843 +static ssize_t
73844 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73845 +{
73846 + DECLARE_WAITQUEUE(wait, current);
73847 + ssize_t retval = 0;
73848 +
73849 + add_wait_queue(&learn_wait, &wait);
73850 + set_current_state(TASK_INTERRUPTIBLE);
73851 + do {
73852 + mutex_lock(&gr_learn_user_mutex);
73853 + spin_lock(&gr_learn_lock);
73854 + if (learn_buffer_len)
73855 + break;
73856 + spin_unlock(&gr_learn_lock);
73857 + mutex_unlock(&gr_learn_user_mutex);
73858 + if (file->f_flags & O_NONBLOCK) {
73859 + retval = -EAGAIN;
73860 + goto out;
73861 + }
73862 + if (signal_pending(current)) {
73863 + retval = -ERESTARTSYS;
73864 + goto out;
73865 + }
73866 +
73867 + schedule();
73868 + } while (1);
73869 +
73870 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73871 + learn_buffer_user_len = learn_buffer_len;
73872 + retval = learn_buffer_len;
73873 + learn_buffer_len = 0;
73874 +
73875 + spin_unlock(&gr_learn_lock);
73876 +
73877 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73878 + retval = -EFAULT;
73879 +
73880 + mutex_unlock(&gr_learn_user_mutex);
73881 +out:
73882 + set_current_state(TASK_RUNNING);
73883 + remove_wait_queue(&learn_wait, &wait);
73884 + return retval;
73885 +}
73886 +
73887 +static unsigned int
73888 +poll_learn(struct file * file, poll_table * wait)
73889 +{
73890 + poll_wait(file, &learn_wait, wait);
73891 +
73892 + if (learn_buffer_len)
73893 + return (POLLIN | POLLRDNORM);
73894 +
73895 + return 0;
73896 +}
73897 +
73898 +void
73899 +gr_clear_learn_entries(void)
73900 +{
73901 + char *tmp;
73902 +
73903 + mutex_lock(&gr_learn_user_mutex);
73904 + spin_lock(&gr_learn_lock);
73905 + tmp = learn_buffer;
73906 + learn_buffer = NULL;
73907 + spin_unlock(&gr_learn_lock);
73908 + if (tmp)
73909 + vfree(tmp);
73910 + if (learn_buffer_user != NULL) {
73911 + vfree(learn_buffer_user);
73912 + learn_buffer_user = NULL;
73913 + }
73914 + learn_buffer_len = 0;
73915 + mutex_unlock(&gr_learn_user_mutex);
73916 +
73917 + return;
73918 +}
73919 +
73920 +void
73921 +gr_add_learn_entry(const char *fmt, ...)
73922 +{
73923 + va_list args;
73924 + unsigned int len;
73925 +
73926 + if (!gr_learn_attached)
73927 + return;
73928 +
73929 + spin_lock(&gr_learn_lock);
73930 +
73931 + /* leave a gap at the end so we know when it's "full" but don't have to
73932 + compute the exact length of the string we're trying to append
73933 + */
73934 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73935 + spin_unlock(&gr_learn_lock);
73936 + wake_up_interruptible(&learn_wait);
73937 + return;
73938 + }
73939 + if (learn_buffer == NULL) {
73940 + spin_unlock(&gr_learn_lock);
73941 + return;
73942 + }
73943 +
73944 + va_start(args, fmt);
73945 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73946 + va_end(args);
73947 +
73948 + learn_buffer_len += len + 1;
73949 +
73950 + spin_unlock(&gr_learn_lock);
73951 + wake_up_interruptible(&learn_wait);
73952 +
73953 + return;
73954 +}
73955 +
73956 +static int
73957 +open_learn(struct inode *inode, struct file *file)
73958 +{
73959 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73960 + return -EBUSY;
73961 + if (file->f_mode & FMODE_READ) {
73962 + int retval = 0;
73963 + mutex_lock(&gr_learn_user_mutex);
73964 + if (learn_buffer == NULL)
73965 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73966 + if (learn_buffer_user == NULL)
73967 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73968 + if (learn_buffer == NULL) {
73969 + retval = -ENOMEM;
73970 + goto out_error;
73971 + }
73972 + if (learn_buffer_user == NULL) {
73973 + retval = -ENOMEM;
73974 + goto out_error;
73975 + }
73976 + learn_buffer_len = 0;
73977 + learn_buffer_user_len = 0;
73978 + gr_learn_attached = 1;
73979 +out_error:
73980 + mutex_unlock(&gr_learn_user_mutex);
73981 + return retval;
73982 + }
73983 + return 0;
73984 +}
73985 +
73986 +static int
73987 +close_learn(struct inode *inode, struct file *file)
73988 +{
73989 + if (file->f_mode & FMODE_READ) {
73990 + char *tmp = NULL;
73991 + mutex_lock(&gr_learn_user_mutex);
73992 + spin_lock(&gr_learn_lock);
73993 + tmp = learn_buffer;
73994 + learn_buffer = NULL;
73995 + spin_unlock(&gr_learn_lock);
73996 + if (tmp)
73997 + vfree(tmp);
73998 + if (learn_buffer_user != NULL) {
73999 + vfree(learn_buffer_user);
74000 + learn_buffer_user = NULL;
74001 + }
74002 + learn_buffer_len = 0;
74003 + learn_buffer_user_len = 0;
74004 + gr_learn_attached = 0;
74005 + mutex_unlock(&gr_learn_user_mutex);
74006 + }
74007 +
74008 + return 0;
74009 +}
74010 +
74011 +const struct file_operations grsec_fops = {
74012 + .read = read_learn,
74013 + .write = write_grsec_handler,
74014 + .open = open_learn,
74015 + .release = close_learn,
74016 + .poll = poll_learn,
74017 +};
74018 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74019 new file mode 100644
74020 index 0000000..3f8ade0
74021 --- /dev/null
74022 +++ b/grsecurity/gracl_policy.c
74023 @@ -0,0 +1,1782 @@
74024 +#include <linux/kernel.h>
74025 +#include <linux/module.h>
74026 +#include <linux/sched.h>
74027 +#include <linux/mm.h>
74028 +#include <linux/file.h>
74029 +#include <linux/fs.h>
74030 +#include <linux/namei.h>
74031 +#include <linux/mount.h>
74032 +#include <linux/tty.h>
74033 +#include <linux/proc_fs.h>
74034 +#include <linux/lglock.h>
74035 +#include <linux/slab.h>
74036 +#include <linux/vmalloc.h>
74037 +#include <linux/types.h>
74038 +#include <linux/sysctl.h>
74039 +#include <linux/netdevice.h>
74040 +#include <linux/ptrace.h>
74041 +#include <linux/gracl.h>
74042 +#include <linux/gralloc.h>
74043 +#include <linux/security.h>
74044 +#include <linux/grinternal.h>
74045 +#include <linux/pid_namespace.h>
74046 +#include <linux/stop_machine.h>
74047 +#include <linux/fdtable.h>
74048 +#include <linux/percpu.h>
74049 +#include <linux/lglock.h>
74050 +#include <linux/hugetlb.h>
74051 +#include <linux/posix-timers.h>
74052 +#include "../fs/mount.h"
74053 +
74054 +#include <asm/uaccess.h>
74055 +#include <asm/errno.h>
74056 +#include <asm/mman.h>
74057 +
74058 +extern struct gr_policy_state *polstate;
74059 +
74060 +#define FOR_EACH_ROLE_START(role) \
74061 + role = polstate->role_list; \
74062 + while (role) {
74063 +
74064 +#define FOR_EACH_ROLE_END(role) \
74065 + role = role->prev; \
74066 + }
74067 +
74068 +struct path gr_real_root;
74069 +
74070 +extern struct gr_alloc_state *current_alloc_state;
74071 +
74072 +u16 acl_sp_role_value;
74073 +
74074 +static DEFINE_MUTEX(gr_dev_mutex);
74075 +
74076 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74077 +extern void gr_clear_learn_entries(void);
74078 +
74079 +struct gr_arg *gr_usermode __read_only;
74080 +unsigned char *gr_system_salt __read_only;
74081 +unsigned char *gr_system_sum __read_only;
74082 +
74083 +static unsigned int gr_auth_attempts = 0;
74084 +static unsigned long gr_auth_expires = 0UL;
74085 +
74086 +struct acl_object_label *fakefs_obj_rw;
74087 +struct acl_object_label *fakefs_obj_rwx;
74088 +
74089 +extern int gr_init_uidset(void);
74090 +extern void gr_free_uidset(void);
74091 +extern void gr_remove_uid(uid_t uid);
74092 +extern int gr_find_uid(uid_t uid);
74093 +
74094 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74095 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74096 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74097 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74098 +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);
74099 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74100 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74101 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74102 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74103 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74104 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74105 +extern void assign_special_role(const char *rolename);
74106 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74107 +extern int gr_rbac_disable(void *unused);
74108 +extern void gr_enable_rbac_system(void);
74109 +
74110 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74111 +{
74112 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74113 + return -EFAULT;
74114 +
74115 + return 0;
74116 +}
74117 +
74118 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74119 +{
74120 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74121 + return -EFAULT;
74122 +
74123 + return 0;
74124 +}
74125 +
74126 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74127 +{
74128 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74129 + return -EFAULT;
74130 +
74131 + return 0;
74132 +}
74133 +
74134 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74135 +{
74136 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74137 + return -EFAULT;
74138 +
74139 + return 0;
74140 +}
74141 +
74142 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74143 +{
74144 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74145 + return -EFAULT;
74146 +
74147 + return 0;
74148 +}
74149 +
74150 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74151 +{
74152 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74153 + return -EFAULT;
74154 +
74155 + return 0;
74156 +}
74157 +
74158 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74159 +{
74160 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74161 + return -EFAULT;
74162 +
74163 + return 0;
74164 +}
74165 +
74166 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74167 +{
74168 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74169 + return -EFAULT;
74170 +
74171 + return 0;
74172 +}
74173 +
74174 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74175 +{
74176 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74177 + return -EFAULT;
74178 +
74179 + return 0;
74180 +}
74181 +
74182 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74183 +{
74184 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74185 + return -EFAULT;
74186 +
74187 + if (((uwrap->version != GRSECURITY_VERSION) &&
74188 + (uwrap->version != 0x2901)) ||
74189 + (uwrap->size != sizeof(struct gr_arg)))
74190 + return -EINVAL;
74191 +
74192 + return 0;
74193 +}
74194 +
74195 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74196 +{
74197 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74198 + return -EFAULT;
74199 +
74200 + return 0;
74201 +}
74202 +
74203 +static size_t get_gr_arg_wrapper_size_normal(void)
74204 +{
74205 + return sizeof(struct gr_arg_wrapper);
74206 +}
74207 +
74208 +#ifdef CONFIG_COMPAT
74209 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74210 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74211 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74212 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74213 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74214 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74215 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74216 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74217 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74218 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74219 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74220 +extern size_t get_gr_arg_wrapper_size_compat(void);
74221 +
74222 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74223 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74224 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74225 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74226 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74227 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74228 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74229 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74230 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74231 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74232 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74233 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74234 +
74235 +#else
74236 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74237 +#define copy_gr_arg copy_gr_arg_normal
74238 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74239 +#define copy_acl_object_label copy_acl_object_label_normal
74240 +#define copy_acl_subject_label copy_acl_subject_label_normal
74241 +#define copy_acl_role_label copy_acl_role_label_normal
74242 +#define copy_acl_ip_label copy_acl_ip_label_normal
74243 +#define copy_pointer_from_array copy_pointer_from_array_normal
74244 +#define copy_sprole_pw copy_sprole_pw_normal
74245 +#define copy_role_transition copy_role_transition_normal
74246 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74247 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74248 +#endif
74249 +
74250 +static struct acl_subject_label *
74251 +lookup_subject_map(const struct acl_subject_label *userp)
74252 +{
74253 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74254 + struct subject_map *match;
74255 +
74256 + match = polstate->subj_map_set.s_hash[index];
74257 +
74258 + while (match && match->user != userp)
74259 + match = match->next;
74260 +
74261 + if (match != NULL)
74262 + return match->kernel;
74263 + else
74264 + return NULL;
74265 +}
74266 +
74267 +static void
74268 +insert_subj_map_entry(struct subject_map *subjmap)
74269 +{
74270 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74271 + struct subject_map **curr;
74272 +
74273 + subjmap->prev = NULL;
74274 +
74275 + curr = &polstate->subj_map_set.s_hash[index];
74276 + if (*curr != NULL)
74277 + (*curr)->prev = subjmap;
74278 +
74279 + subjmap->next = *curr;
74280 + *curr = subjmap;
74281 +
74282 + return;
74283 +}
74284 +
74285 +static void
74286 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74287 +{
74288 + unsigned int index =
74289 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74290 + struct acl_role_label **curr;
74291 + struct acl_role_label *tmp, *tmp2;
74292 +
74293 + curr = &polstate->acl_role_set.r_hash[index];
74294 +
74295 + /* simple case, slot is empty, just set it to our role */
74296 + if (*curr == NULL) {
74297 + *curr = role;
74298 + } else {
74299 + /* example:
74300 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74301 + 2 -> 3
74302 + */
74303 + /* first check to see if we can already be reached via this slot */
74304 + tmp = *curr;
74305 + while (tmp && tmp != role)
74306 + tmp = tmp->next;
74307 + if (tmp == role) {
74308 + /* we don't need to add ourselves to this slot's chain */
74309 + return;
74310 + }
74311 + /* we need to add ourselves to this chain, two cases */
74312 + if (role->next == NULL) {
74313 + /* simple case, append the current chain to our role */
74314 + role->next = *curr;
74315 + *curr = role;
74316 + } else {
74317 + /* 1 -> 2 -> 3 -> 4
74318 + 2 -> 3 -> 4
74319 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74320 + */
74321 + /* trickier case: walk our role's chain until we find
74322 + the role for the start of the current slot's chain */
74323 + tmp = role;
74324 + tmp2 = *curr;
74325 + while (tmp->next && tmp->next != tmp2)
74326 + tmp = tmp->next;
74327 + if (tmp->next == tmp2) {
74328 + /* from example above, we found 3, so just
74329 + replace this slot's chain with ours */
74330 + *curr = role;
74331 + } else {
74332 + /* we didn't find a subset of our role's chain
74333 + in the current slot's chain, so append their
74334 + chain to ours, and set us as the first role in
74335 + the slot's chain
74336 +
74337 + we could fold this case with the case above,
74338 + but making it explicit for clarity
74339 + */
74340 + tmp->next = tmp2;
74341 + *curr = role;
74342 + }
74343 + }
74344 + }
74345 +
74346 + return;
74347 +}
74348 +
74349 +static void
74350 +insert_acl_role_label(struct acl_role_label *role)
74351 +{
74352 + int i;
74353 +
74354 + if (polstate->role_list == NULL) {
74355 + polstate->role_list = role;
74356 + role->prev = NULL;
74357 + } else {
74358 + role->prev = polstate->role_list;
74359 + polstate->role_list = role;
74360 + }
74361 +
74362 + /* used for hash chains */
74363 + role->next = NULL;
74364 +
74365 + if (role->roletype & GR_ROLE_DOMAIN) {
74366 + for (i = 0; i < role->domain_child_num; i++)
74367 + __insert_acl_role_label(role, role->domain_children[i]);
74368 + } else
74369 + __insert_acl_role_label(role, role->uidgid);
74370 +}
74371 +
74372 +static int
74373 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74374 +{
74375 + struct name_entry **curr, *nentry;
74376 + struct inodev_entry *ientry;
74377 + unsigned int len = strlen(name);
74378 + unsigned int key = full_name_hash(name, len);
74379 + unsigned int index = key % polstate->name_set.n_size;
74380 +
74381 + curr = &polstate->name_set.n_hash[index];
74382 +
74383 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74384 + curr = &((*curr)->next);
74385 +
74386 + if (*curr != NULL)
74387 + return 1;
74388 +
74389 + nentry = acl_alloc(sizeof (struct name_entry));
74390 + if (nentry == NULL)
74391 + return 0;
74392 + ientry = acl_alloc(sizeof (struct inodev_entry));
74393 + if (ientry == NULL)
74394 + return 0;
74395 + ientry->nentry = nentry;
74396 +
74397 + nentry->key = key;
74398 + nentry->name = name;
74399 + nentry->inode = inode;
74400 + nentry->device = device;
74401 + nentry->len = len;
74402 + nentry->deleted = deleted;
74403 +
74404 + nentry->prev = NULL;
74405 + curr = &polstate->name_set.n_hash[index];
74406 + if (*curr != NULL)
74407 + (*curr)->prev = nentry;
74408 + nentry->next = *curr;
74409 + *curr = nentry;
74410 +
74411 + /* insert us into the table searchable by inode/dev */
74412 + __insert_inodev_entry(polstate, ientry);
74413 +
74414 + return 1;
74415 +}
74416 +
74417 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74418 +
74419 +static void *
74420 +create_table(__u32 * len, int elementsize)
74421 +{
74422 + unsigned int table_sizes[] = {
74423 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74424 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74425 + 4194301, 8388593, 16777213, 33554393, 67108859
74426 + };
74427 + void *newtable = NULL;
74428 + unsigned int pwr = 0;
74429 +
74430 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74431 + table_sizes[pwr] <= *len)
74432 + pwr++;
74433 +
74434 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74435 + return newtable;
74436 +
74437 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74438 + newtable =
74439 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74440 + else
74441 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74442 +
74443 + *len = table_sizes[pwr];
74444 +
74445 + return newtable;
74446 +}
74447 +
74448 +static int
74449 +init_variables(const struct gr_arg *arg, bool reload)
74450 +{
74451 + struct task_struct *reaper = init_pid_ns.child_reaper;
74452 + unsigned int stacksize;
74453 +
74454 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74455 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74456 + polstate->name_set.n_size = arg->role_db.num_objects;
74457 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74458 +
74459 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74460 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74461 + return 1;
74462 +
74463 + if (!reload) {
74464 + if (!gr_init_uidset())
74465 + return 1;
74466 + }
74467 +
74468 + /* set up the stack that holds allocation info */
74469 +
74470 + stacksize = arg->role_db.num_pointers + 5;
74471 +
74472 + if (!acl_alloc_stack_init(stacksize))
74473 + return 1;
74474 +
74475 + if (!reload) {
74476 + /* grab reference for the real root dentry and vfsmount */
74477 + get_fs_root(reaper->fs, &gr_real_root);
74478 +
74479 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74480 + 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);
74481 +#endif
74482 +
74483 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74484 + if (fakefs_obj_rw == NULL)
74485 + return 1;
74486 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74487 +
74488 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74489 + if (fakefs_obj_rwx == NULL)
74490 + return 1;
74491 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74492 + }
74493 +
74494 + polstate->subj_map_set.s_hash =
74495 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74496 + polstate->acl_role_set.r_hash =
74497 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74498 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74499 + polstate->inodev_set.i_hash =
74500 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74501 +
74502 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74503 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74504 + return 1;
74505 +
74506 + memset(polstate->subj_map_set.s_hash, 0,
74507 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74508 + memset(polstate->acl_role_set.r_hash, 0,
74509 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74510 + memset(polstate->name_set.n_hash, 0,
74511 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74512 + memset(polstate->inodev_set.i_hash, 0,
74513 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74514 +
74515 + return 0;
74516 +}
74517 +
74518 +/* free information not needed after startup
74519 + currently contains user->kernel pointer mappings for subjects
74520 +*/
74521 +
74522 +static void
74523 +free_init_variables(void)
74524 +{
74525 + __u32 i;
74526 +
74527 + if (polstate->subj_map_set.s_hash) {
74528 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74529 + if (polstate->subj_map_set.s_hash[i]) {
74530 + kfree(polstate->subj_map_set.s_hash[i]);
74531 + polstate->subj_map_set.s_hash[i] = NULL;
74532 + }
74533 + }
74534 +
74535 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74536 + PAGE_SIZE)
74537 + kfree(polstate->subj_map_set.s_hash);
74538 + else
74539 + vfree(polstate->subj_map_set.s_hash);
74540 + }
74541 +
74542 + return;
74543 +}
74544 +
74545 +static void
74546 +free_variables(bool reload)
74547 +{
74548 + struct acl_subject_label *s;
74549 + struct acl_role_label *r;
74550 + struct task_struct *task, *task2;
74551 + unsigned int x;
74552 +
74553 + if (!reload) {
74554 + gr_clear_learn_entries();
74555 +
74556 + read_lock(&tasklist_lock);
74557 + do_each_thread(task2, task) {
74558 + task->acl_sp_role = 0;
74559 + task->acl_role_id = 0;
74560 + task->inherited = 0;
74561 + task->acl = NULL;
74562 + task->role = NULL;
74563 + } while_each_thread(task2, task);
74564 + read_unlock(&tasklist_lock);
74565 +
74566 + kfree(fakefs_obj_rw);
74567 + fakefs_obj_rw = NULL;
74568 + kfree(fakefs_obj_rwx);
74569 + fakefs_obj_rwx = NULL;
74570 +
74571 + /* release the reference to the real root dentry and vfsmount */
74572 + path_put(&gr_real_root);
74573 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74574 + }
74575 +
74576 + /* free all object hash tables */
74577 +
74578 + FOR_EACH_ROLE_START(r)
74579 + if (r->subj_hash == NULL)
74580 + goto next_role;
74581 + FOR_EACH_SUBJECT_START(r, s, x)
74582 + if (s->obj_hash == NULL)
74583 + break;
74584 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74585 + kfree(s->obj_hash);
74586 + else
74587 + vfree(s->obj_hash);
74588 + FOR_EACH_SUBJECT_END(s, x)
74589 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74590 + if (s->obj_hash == NULL)
74591 + break;
74592 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74593 + kfree(s->obj_hash);
74594 + else
74595 + vfree(s->obj_hash);
74596 + FOR_EACH_NESTED_SUBJECT_END(s)
74597 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74598 + kfree(r->subj_hash);
74599 + else
74600 + vfree(r->subj_hash);
74601 + r->subj_hash = NULL;
74602 +next_role:
74603 + FOR_EACH_ROLE_END(r)
74604 +
74605 + acl_free_all();
74606 +
74607 + if (polstate->acl_role_set.r_hash) {
74608 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74609 + PAGE_SIZE)
74610 + kfree(polstate->acl_role_set.r_hash);
74611 + else
74612 + vfree(polstate->acl_role_set.r_hash);
74613 + }
74614 + if (polstate->name_set.n_hash) {
74615 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74616 + PAGE_SIZE)
74617 + kfree(polstate->name_set.n_hash);
74618 + else
74619 + vfree(polstate->name_set.n_hash);
74620 + }
74621 +
74622 + if (polstate->inodev_set.i_hash) {
74623 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74624 + PAGE_SIZE)
74625 + kfree(polstate->inodev_set.i_hash);
74626 + else
74627 + vfree(polstate->inodev_set.i_hash);
74628 + }
74629 +
74630 + if (!reload)
74631 + gr_free_uidset();
74632 +
74633 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74634 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74635 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74636 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74637 +
74638 + polstate->default_role = NULL;
74639 + polstate->kernel_role = NULL;
74640 + polstate->role_list = NULL;
74641 +
74642 + return;
74643 +}
74644 +
74645 +static struct acl_subject_label *
74646 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74647 +
74648 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74649 +{
74650 + unsigned int len = strnlen_user(*name, maxlen);
74651 + char *tmp;
74652 +
74653 + if (!len || len >= maxlen)
74654 + return -EINVAL;
74655 +
74656 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74657 + return -ENOMEM;
74658 +
74659 + if (copy_from_user(tmp, *name, len))
74660 + return -EFAULT;
74661 +
74662 + tmp[len-1] = '\0';
74663 + *name = tmp;
74664 +
74665 + return 0;
74666 +}
74667 +
74668 +static int
74669 +copy_user_glob(struct acl_object_label *obj)
74670 +{
74671 + struct acl_object_label *g_tmp, **guser;
74672 + int error;
74673 +
74674 + if (obj->globbed == NULL)
74675 + return 0;
74676 +
74677 + guser = &obj->globbed;
74678 + while (*guser) {
74679 + g_tmp = (struct acl_object_label *)
74680 + acl_alloc(sizeof (struct acl_object_label));
74681 + if (g_tmp == NULL)
74682 + return -ENOMEM;
74683 +
74684 + if (copy_acl_object_label(g_tmp, *guser))
74685 + return -EFAULT;
74686 +
74687 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74688 + if (error)
74689 + return error;
74690 +
74691 + *guser = g_tmp;
74692 + guser = &(g_tmp->next);
74693 + }
74694 +
74695 + return 0;
74696 +}
74697 +
74698 +static int
74699 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74700 + struct acl_role_label *role)
74701 +{
74702 + struct acl_object_label *o_tmp;
74703 + int ret;
74704 +
74705 + while (userp) {
74706 + if ((o_tmp = (struct acl_object_label *)
74707 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74708 + return -ENOMEM;
74709 +
74710 + if (copy_acl_object_label(o_tmp, userp))
74711 + return -EFAULT;
74712 +
74713 + userp = o_tmp->prev;
74714 +
74715 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74716 + if (ret)
74717 + return ret;
74718 +
74719 + insert_acl_obj_label(o_tmp, subj);
74720 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74721 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74722 + return -ENOMEM;
74723 +
74724 + ret = copy_user_glob(o_tmp);
74725 + if (ret)
74726 + return ret;
74727 +
74728 + if (o_tmp->nested) {
74729 + int already_copied;
74730 +
74731 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74732 + if (IS_ERR(o_tmp->nested))
74733 + return PTR_ERR(o_tmp->nested);
74734 +
74735 + /* insert into nested subject list if we haven't copied this one yet
74736 + to prevent duplicate entries */
74737 + if (!already_copied) {
74738 + o_tmp->nested->next = role->hash->first;
74739 + role->hash->first = o_tmp->nested;
74740 + }
74741 + }
74742 + }
74743 +
74744 + return 0;
74745 +}
74746 +
74747 +static __u32
74748 +count_user_subjs(struct acl_subject_label *userp)
74749 +{
74750 + struct acl_subject_label s_tmp;
74751 + __u32 num = 0;
74752 +
74753 + while (userp) {
74754 + if (copy_acl_subject_label(&s_tmp, userp))
74755 + break;
74756 +
74757 + userp = s_tmp.prev;
74758 + }
74759 +
74760 + return num;
74761 +}
74762 +
74763 +static int
74764 +copy_user_allowedips(struct acl_role_label *rolep)
74765 +{
74766 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74767 +
74768 + ruserip = rolep->allowed_ips;
74769 +
74770 + while (ruserip) {
74771 + rlast = rtmp;
74772 +
74773 + if ((rtmp = (struct role_allowed_ip *)
74774 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74775 + return -ENOMEM;
74776 +
74777 + if (copy_role_allowed_ip(rtmp, ruserip))
74778 + return -EFAULT;
74779 +
74780 + ruserip = rtmp->prev;
74781 +
74782 + if (!rlast) {
74783 + rtmp->prev = NULL;
74784 + rolep->allowed_ips = rtmp;
74785 + } else {
74786 + rlast->next = rtmp;
74787 + rtmp->prev = rlast;
74788 + }
74789 +
74790 + if (!ruserip)
74791 + rtmp->next = NULL;
74792 + }
74793 +
74794 + return 0;
74795 +}
74796 +
74797 +static int
74798 +copy_user_transitions(struct acl_role_label *rolep)
74799 +{
74800 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74801 + int error;
74802 +
74803 + rusertp = rolep->transitions;
74804 +
74805 + while (rusertp) {
74806 + rlast = rtmp;
74807 +
74808 + if ((rtmp = (struct role_transition *)
74809 + acl_alloc(sizeof (struct role_transition))) == NULL)
74810 + return -ENOMEM;
74811 +
74812 + if (copy_role_transition(rtmp, rusertp))
74813 + return -EFAULT;
74814 +
74815 + rusertp = rtmp->prev;
74816 +
74817 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74818 + if (error)
74819 + return error;
74820 +
74821 + if (!rlast) {
74822 + rtmp->prev = NULL;
74823 + rolep->transitions = rtmp;
74824 + } else {
74825 + rlast->next = rtmp;
74826 + rtmp->prev = rlast;
74827 + }
74828 +
74829 + if (!rusertp)
74830 + rtmp->next = NULL;
74831 + }
74832 +
74833 + return 0;
74834 +}
74835 +
74836 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74837 +{
74838 + struct acl_object_label o_tmp;
74839 + __u32 num = 0;
74840 +
74841 + while (userp) {
74842 + if (copy_acl_object_label(&o_tmp, userp))
74843 + break;
74844 +
74845 + userp = o_tmp.prev;
74846 + num++;
74847 + }
74848 +
74849 + return num;
74850 +}
74851 +
74852 +static struct acl_subject_label *
74853 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74854 +{
74855 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74856 + __u32 num_objs;
74857 + struct acl_ip_label **i_tmp, *i_utmp2;
74858 + struct gr_hash_struct ghash;
74859 + struct subject_map *subjmap;
74860 + unsigned int i_num;
74861 + int err;
74862 +
74863 + if (already_copied != NULL)
74864 + *already_copied = 0;
74865 +
74866 + s_tmp = lookup_subject_map(userp);
74867 +
74868 + /* we've already copied this subject into the kernel, just return
74869 + the reference to it, and don't copy it over again
74870 + */
74871 + if (s_tmp) {
74872 + if (already_copied != NULL)
74873 + *already_copied = 1;
74874 + return(s_tmp);
74875 + }
74876 +
74877 + if ((s_tmp = (struct acl_subject_label *)
74878 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74879 + return ERR_PTR(-ENOMEM);
74880 +
74881 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74882 + if (subjmap == NULL)
74883 + return ERR_PTR(-ENOMEM);
74884 +
74885 + subjmap->user = userp;
74886 + subjmap->kernel = s_tmp;
74887 + insert_subj_map_entry(subjmap);
74888 +
74889 + if (copy_acl_subject_label(s_tmp, userp))
74890 + return ERR_PTR(-EFAULT);
74891 +
74892 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74893 + if (err)
74894 + return ERR_PTR(err);
74895 +
74896 + if (!strcmp(s_tmp->filename, "/"))
74897 + role->root_label = s_tmp;
74898 +
74899 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74900 + return ERR_PTR(-EFAULT);
74901 +
74902 + /* copy user and group transition tables */
74903 +
74904 + if (s_tmp->user_trans_num) {
74905 + uid_t *uidlist;
74906 +
74907 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74908 + if (uidlist == NULL)
74909 + return ERR_PTR(-ENOMEM);
74910 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74911 + return ERR_PTR(-EFAULT);
74912 +
74913 + s_tmp->user_transitions = uidlist;
74914 + }
74915 +
74916 + if (s_tmp->group_trans_num) {
74917 + gid_t *gidlist;
74918 +
74919 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74920 + if (gidlist == NULL)
74921 + return ERR_PTR(-ENOMEM);
74922 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74923 + return ERR_PTR(-EFAULT);
74924 +
74925 + s_tmp->group_transitions = gidlist;
74926 + }
74927 +
74928 + /* set up object hash table */
74929 + num_objs = count_user_objs(ghash.first);
74930 +
74931 + s_tmp->obj_hash_size = num_objs;
74932 + s_tmp->obj_hash =
74933 + (struct acl_object_label **)
74934 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74935 +
74936 + if (!s_tmp->obj_hash)
74937 + return ERR_PTR(-ENOMEM);
74938 +
74939 + memset(s_tmp->obj_hash, 0,
74940 + s_tmp->obj_hash_size *
74941 + sizeof (struct acl_object_label *));
74942 +
74943 + /* add in objects */
74944 + err = copy_user_objs(ghash.first, s_tmp, role);
74945 +
74946 + if (err)
74947 + return ERR_PTR(err);
74948 +
74949 + /* set pointer for parent subject */
74950 + if (s_tmp->parent_subject) {
74951 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74952 +
74953 + if (IS_ERR(s_tmp2))
74954 + return s_tmp2;
74955 +
74956 + s_tmp->parent_subject = s_tmp2;
74957 + }
74958 +
74959 + /* add in ip acls */
74960 +
74961 + if (!s_tmp->ip_num) {
74962 + s_tmp->ips = NULL;
74963 + goto insert;
74964 + }
74965 +
74966 + i_tmp =
74967 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74968 + sizeof (struct acl_ip_label *));
74969 +
74970 + if (!i_tmp)
74971 + return ERR_PTR(-ENOMEM);
74972 +
74973 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74974 + *(i_tmp + i_num) =
74975 + (struct acl_ip_label *)
74976 + acl_alloc(sizeof (struct acl_ip_label));
74977 + if (!*(i_tmp + i_num))
74978 + return ERR_PTR(-ENOMEM);
74979 +
74980 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74981 + return ERR_PTR(-EFAULT);
74982 +
74983 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74984 + return ERR_PTR(-EFAULT);
74985 +
74986 + if ((*(i_tmp + i_num))->iface == NULL)
74987 + continue;
74988 +
74989 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74990 + if (err)
74991 + return ERR_PTR(err);
74992 + }
74993 +
74994 + s_tmp->ips = i_tmp;
74995 +
74996 +insert:
74997 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74998 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74999 + return ERR_PTR(-ENOMEM);
75000 +
75001 + return s_tmp;
75002 +}
75003 +
75004 +static int
75005 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75006 +{
75007 + struct acl_subject_label s_pre;
75008 + struct acl_subject_label * ret;
75009 + int err;
75010 +
75011 + while (userp) {
75012 + if (copy_acl_subject_label(&s_pre, userp))
75013 + return -EFAULT;
75014 +
75015 + ret = do_copy_user_subj(userp, role, NULL);
75016 +
75017 + err = PTR_ERR(ret);
75018 + if (IS_ERR(ret))
75019 + return err;
75020 +
75021 + insert_acl_subj_label(ret, role);
75022 +
75023 + userp = s_pre.prev;
75024 + }
75025 +
75026 + return 0;
75027 +}
75028 +
75029 +static int
75030 +copy_user_acl(struct gr_arg *arg)
75031 +{
75032 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75033 + struct acl_subject_label *subj_list;
75034 + struct sprole_pw *sptmp;
75035 + struct gr_hash_struct *ghash;
75036 + uid_t *domainlist;
75037 + unsigned int r_num;
75038 + int err = 0;
75039 + __u16 i;
75040 + __u32 num_subjs;
75041 +
75042 + /* we need a default and kernel role */
75043 + if (arg->role_db.num_roles < 2)
75044 + return -EINVAL;
75045 +
75046 + /* copy special role authentication info from userspace */
75047 +
75048 + polstate->num_sprole_pws = arg->num_sprole_pws;
75049 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75050 +
75051 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75052 + return -ENOMEM;
75053 +
75054 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75055 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75056 + if (!sptmp)
75057 + return -ENOMEM;
75058 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75059 + return -EFAULT;
75060 +
75061 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75062 + if (err)
75063 + return err;
75064 +
75065 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75066 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75067 +#endif
75068 +
75069 + polstate->acl_special_roles[i] = sptmp;
75070 + }
75071 +
75072 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75073 +
75074 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75075 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
75076 +
75077 + if (!r_tmp)
75078 + return -ENOMEM;
75079 +
75080 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75081 + return -EFAULT;
75082 +
75083 + if (copy_acl_role_label(r_tmp, r_utmp2))
75084 + return -EFAULT;
75085 +
75086 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75087 + if (err)
75088 + return err;
75089 +
75090 + if (!strcmp(r_tmp->rolename, "default")
75091 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75092 + polstate->default_role = r_tmp;
75093 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75094 + polstate->kernel_role = r_tmp;
75095 + }
75096 +
75097 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75098 + return -ENOMEM;
75099 +
75100 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75101 + return -EFAULT;
75102 +
75103 + r_tmp->hash = ghash;
75104 +
75105 + num_subjs = count_user_subjs(r_tmp->hash->first);
75106 +
75107 + r_tmp->subj_hash_size = num_subjs;
75108 + r_tmp->subj_hash =
75109 + (struct acl_subject_label **)
75110 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75111 +
75112 + if (!r_tmp->subj_hash)
75113 + return -ENOMEM;
75114 +
75115 + err = copy_user_allowedips(r_tmp);
75116 + if (err)
75117 + return err;
75118 +
75119 + /* copy domain info */
75120 + if (r_tmp->domain_children != NULL) {
75121 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75122 + if (domainlist == NULL)
75123 + return -ENOMEM;
75124 +
75125 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75126 + return -EFAULT;
75127 +
75128 + r_tmp->domain_children = domainlist;
75129 + }
75130 +
75131 + err = copy_user_transitions(r_tmp);
75132 + if (err)
75133 + return err;
75134 +
75135 + memset(r_tmp->subj_hash, 0,
75136 + r_tmp->subj_hash_size *
75137 + sizeof (struct acl_subject_label *));
75138 +
75139 + /* acquire the list of subjects, then NULL out
75140 + the list prior to parsing the subjects for this role,
75141 + as during this parsing the list is replaced with a list
75142 + of *nested* subjects for the role
75143 + */
75144 + subj_list = r_tmp->hash->first;
75145 +
75146 + /* set nested subject list to null */
75147 + r_tmp->hash->first = NULL;
75148 +
75149 + err = copy_user_subjs(subj_list, r_tmp);
75150 +
75151 + if (err)
75152 + return err;
75153 +
75154 + insert_acl_role_label(r_tmp);
75155 + }
75156 +
75157 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75158 + return -EINVAL;
75159 +
75160 + return err;
75161 +}
75162 +
75163 +static int gracl_reload_apply_policies(void *reload)
75164 +{
75165 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75166 + struct task_struct *task, *task2;
75167 + struct acl_role_label *role, *rtmp;
75168 + struct acl_subject_label *subj;
75169 + const struct cred *cred;
75170 + int role_applied;
75171 + int ret = 0;
75172 +
75173 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75174 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75175 +
75176 + /* first make sure we'll be able to apply the new policy cleanly */
75177 + do_each_thread(task2, task) {
75178 + if (task->exec_file == NULL)
75179 + continue;
75180 + role_applied = 0;
75181 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75182 + /* preserve special roles */
75183 + FOR_EACH_ROLE_START(role)
75184 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75185 + rtmp = task->role;
75186 + task->role = role;
75187 + role_applied = 1;
75188 + break;
75189 + }
75190 + FOR_EACH_ROLE_END(role)
75191 + }
75192 + if (!role_applied) {
75193 + cred = __task_cred(task);
75194 + rtmp = task->role;
75195 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75196 + }
75197 + /* this handles non-nested inherited subjects, nested subjects will still
75198 + be dropped currently */
75199 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75200 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75201 + /* change the role back so that we've made no modifications to the policy */
75202 + task->role = rtmp;
75203 +
75204 + if (subj == NULL || task->tmpacl == NULL) {
75205 + ret = -EINVAL;
75206 + goto out;
75207 + }
75208 + } while_each_thread(task2, task);
75209 +
75210 + /* now actually apply the policy */
75211 +
75212 + do_each_thread(task2, task) {
75213 + if (task->exec_file) {
75214 + role_applied = 0;
75215 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75216 + /* preserve special roles */
75217 + FOR_EACH_ROLE_START(role)
75218 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75219 + task->role = role;
75220 + role_applied = 1;
75221 + break;
75222 + }
75223 + FOR_EACH_ROLE_END(role)
75224 + }
75225 + if (!role_applied) {
75226 + cred = __task_cred(task);
75227 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75228 + }
75229 + /* this handles non-nested inherited subjects, nested subjects will still
75230 + be dropped currently */
75231 + if (!reload_state->oldmode && task->inherited)
75232 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75233 + else {
75234 + /* looked up and tagged to the task previously */
75235 + subj = task->tmpacl;
75236 + }
75237 + /* subj will be non-null */
75238 + __gr_apply_subject_to_task(polstate, task, subj);
75239 + if (reload_state->oldmode) {
75240 + task->acl_role_id = 0;
75241 + task->acl_sp_role = 0;
75242 + task->inherited = 0;
75243 + }
75244 + } else {
75245 + // it's a kernel process
75246 + task->role = polstate->kernel_role;
75247 + task->acl = polstate->kernel_role->root_label;
75248 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75249 + task->acl->mode &= ~GR_PROCFIND;
75250 +#endif
75251 + }
75252 + } while_each_thread(task2, task);
75253 +
75254 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75255 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75256 +
75257 +out:
75258 +
75259 + return ret;
75260 +}
75261 +
75262 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75263 +{
75264 + struct gr_reload_state new_reload_state = { };
75265 + int err;
75266 +
75267 + new_reload_state.oldpolicy_ptr = polstate;
75268 + new_reload_state.oldalloc_ptr = current_alloc_state;
75269 + new_reload_state.oldmode = oldmode;
75270 +
75271 + current_alloc_state = &new_reload_state.newalloc;
75272 + polstate = &new_reload_state.newpolicy;
75273 +
75274 + /* everything relevant is now saved off, copy in the new policy */
75275 + if (init_variables(args, true)) {
75276 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75277 + err = -ENOMEM;
75278 + goto error;
75279 + }
75280 +
75281 + err = copy_user_acl(args);
75282 + free_init_variables();
75283 + if (err)
75284 + goto error;
75285 + /* the new policy is copied in, with the old policy available via saved_state
75286 + first go through applying roles, making sure to preserve special roles
75287 + then apply new subjects, making sure to preserve inherited and nested subjects,
75288 + though currently only inherited subjects will be preserved
75289 + */
75290 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75291 + if (err)
75292 + goto error;
75293 +
75294 + /* we've now applied the new policy, so restore the old policy state to free it */
75295 + polstate = &new_reload_state.oldpolicy;
75296 + current_alloc_state = &new_reload_state.oldalloc;
75297 + free_variables(true);
75298 +
75299 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75300 + to running_polstate/current_alloc_state inside stop_machine
75301 + */
75302 + err = 0;
75303 + goto out;
75304 +error:
75305 + /* on error of loading the new policy, we'll just keep the previous
75306 + policy set around
75307 + */
75308 + free_variables(true);
75309 +
75310 + /* doesn't affect runtime, but maintains consistent state */
75311 +out:
75312 + polstate = new_reload_state.oldpolicy_ptr;
75313 + current_alloc_state = new_reload_state.oldalloc_ptr;
75314 +
75315 + return err;
75316 +}
75317 +
75318 +static int
75319 +gracl_init(struct gr_arg *args)
75320 +{
75321 + int error = 0;
75322 +
75323 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75324 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75325 +
75326 + if (init_variables(args, false)) {
75327 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75328 + error = -ENOMEM;
75329 + goto out;
75330 + }
75331 +
75332 + error = copy_user_acl(args);
75333 + free_init_variables();
75334 + if (error)
75335 + goto out;
75336 +
75337 + error = gr_set_acls(0);
75338 + if (error)
75339 + goto out;
75340 +
75341 + gr_enable_rbac_system();
75342 +
75343 + return 0;
75344 +
75345 +out:
75346 + free_variables(false);
75347 + return error;
75348 +}
75349 +
75350 +static int
75351 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75352 + unsigned char **sum)
75353 +{
75354 + struct acl_role_label *r;
75355 + struct role_allowed_ip *ipp;
75356 + struct role_transition *trans;
75357 + unsigned int i;
75358 + int found = 0;
75359 + u32 curr_ip = current->signal->curr_ip;
75360 +
75361 + current->signal->saved_ip = curr_ip;
75362 +
75363 + /* check transition table */
75364 +
75365 + for (trans = current->role->transitions; trans; trans = trans->next) {
75366 + if (!strcmp(rolename, trans->rolename)) {
75367 + found = 1;
75368 + break;
75369 + }
75370 + }
75371 +
75372 + if (!found)
75373 + return 0;
75374 +
75375 + /* handle special roles that do not require authentication
75376 + and check ip */
75377 +
75378 + FOR_EACH_ROLE_START(r)
75379 + if (!strcmp(rolename, r->rolename) &&
75380 + (r->roletype & GR_ROLE_SPECIAL)) {
75381 + found = 0;
75382 + if (r->allowed_ips != NULL) {
75383 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75384 + if ((ntohl(curr_ip) & ipp->netmask) ==
75385 + (ntohl(ipp->addr) & ipp->netmask))
75386 + found = 1;
75387 + }
75388 + } else
75389 + found = 2;
75390 + if (!found)
75391 + return 0;
75392 +
75393 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75394 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75395 + *salt = NULL;
75396 + *sum = NULL;
75397 + return 1;
75398 + }
75399 + }
75400 + FOR_EACH_ROLE_END(r)
75401 +
75402 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75403 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75404 + *salt = polstate->acl_special_roles[i]->salt;
75405 + *sum = polstate->acl_special_roles[i]->sum;
75406 + return 1;
75407 + }
75408 + }
75409 +
75410 + return 0;
75411 +}
75412 +
75413 +int gr_check_secure_terminal(struct task_struct *task)
75414 +{
75415 + struct task_struct *p, *p2, *p3;
75416 + struct files_struct *files;
75417 + struct fdtable *fdt;
75418 + struct file *our_file = NULL, *file;
75419 + int i;
75420 +
75421 + if (task->signal->tty == NULL)
75422 + return 1;
75423 +
75424 + files = get_files_struct(task);
75425 + if (files != NULL) {
75426 + rcu_read_lock();
75427 + fdt = files_fdtable(files);
75428 + for (i=0; i < fdt->max_fds; i++) {
75429 + file = fcheck_files(files, i);
75430 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75431 + get_file(file);
75432 + our_file = file;
75433 + }
75434 + }
75435 + rcu_read_unlock();
75436 + put_files_struct(files);
75437 + }
75438 +
75439 + if (our_file == NULL)
75440 + return 1;
75441 +
75442 + read_lock(&tasklist_lock);
75443 + do_each_thread(p2, p) {
75444 + files = get_files_struct(p);
75445 + if (files == NULL ||
75446 + (p->signal && p->signal->tty == task->signal->tty)) {
75447 + if (files != NULL)
75448 + put_files_struct(files);
75449 + continue;
75450 + }
75451 + rcu_read_lock();
75452 + fdt = files_fdtable(files);
75453 + for (i=0; i < fdt->max_fds; i++) {
75454 + file = fcheck_files(files, i);
75455 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75456 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75457 + p3 = task;
75458 + while (task_pid_nr(p3) > 0) {
75459 + if (p3 == p)
75460 + break;
75461 + p3 = p3->real_parent;
75462 + }
75463 + if (p3 == p)
75464 + break;
75465 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75466 + gr_handle_alertkill(p);
75467 + rcu_read_unlock();
75468 + put_files_struct(files);
75469 + read_unlock(&tasklist_lock);
75470 + fput(our_file);
75471 + return 0;
75472 + }
75473 + }
75474 + rcu_read_unlock();
75475 + put_files_struct(files);
75476 + } while_each_thread(p2, p);
75477 + read_unlock(&tasklist_lock);
75478 +
75479 + fput(our_file);
75480 + return 1;
75481 +}
75482 +
75483 +ssize_t
75484 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75485 +{
75486 + struct gr_arg_wrapper uwrap;
75487 + unsigned char *sprole_salt = NULL;
75488 + unsigned char *sprole_sum = NULL;
75489 + int error = 0;
75490 + int error2 = 0;
75491 + size_t req_count = 0;
75492 + unsigned char oldmode = 0;
75493 +
75494 + mutex_lock(&gr_dev_mutex);
75495 +
75496 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75497 + error = -EPERM;
75498 + goto out;
75499 + }
75500 +
75501 +#ifdef CONFIG_COMPAT
75502 + pax_open_kernel();
75503 + if (is_compat_task()) {
75504 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75505 + copy_gr_arg = &copy_gr_arg_compat;
75506 + copy_acl_object_label = &copy_acl_object_label_compat;
75507 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75508 + copy_acl_role_label = &copy_acl_role_label_compat;
75509 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75510 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75511 + copy_role_transition = &copy_role_transition_compat;
75512 + copy_sprole_pw = &copy_sprole_pw_compat;
75513 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75514 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75515 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75516 + } else {
75517 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75518 + copy_gr_arg = &copy_gr_arg_normal;
75519 + copy_acl_object_label = &copy_acl_object_label_normal;
75520 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75521 + copy_acl_role_label = &copy_acl_role_label_normal;
75522 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75523 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75524 + copy_role_transition = &copy_role_transition_normal;
75525 + copy_sprole_pw = &copy_sprole_pw_normal;
75526 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75527 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75528 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75529 + }
75530 + pax_close_kernel();
75531 +#endif
75532 +
75533 + req_count = get_gr_arg_wrapper_size();
75534 +
75535 + if (count != req_count) {
75536 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75537 + error = -EINVAL;
75538 + goto out;
75539 + }
75540 +
75541 +
75542 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75543 + gr_auth_expires = 0;
75544 + gr_auth_attempts = 0;
75545 + }
75546 +
75547 + error = copy_gr_arg_wrapper(buf, &uwrap);
75548 + if (error)
75549 + goto out;
75550 +
75551 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75552 + if (error)
75553 + goto out;
75554 +
75555 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75556 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75557 + time_after(gr_auth_expires, get_seconds())) {
75558 + error = -EBUSY;
75559 + goto out;
75560 + }
75561 +
75562 + /* if non-root trying to do anything other than use a special role,
75563 + do not attempt authentication, do not count towards authentication
75564 + locking
75565 + */
75566 +
75567 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75568 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75569 + gr_is_global_nonroot(current_uid())) {
75570 + error = -EPERM;
75571 + goto out;
75572 + }
75573 +
75574 + /* ensure pw and special role name are null terminated */
75575 +
75576 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75577 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75578 +
75579 + /* Okay.
75580 + * We have our enough of the argument structure..(we have yet
75581 + * to copy_from_user the tables themselves) . Copy the tables
75582 + * only if we need them, i.e. for loading operations. */
75583 +
75584 + switch (gr_usermode->mode) {
75585 + case GR_STATUS:
75586 + if (gr_acl_is_enabled()) {
75587 + error = 1;
75588 + if (!gr_check_secure_terminal(current))
75589 + error = 3;
75590 + } else
75591 + error = 2;
75592 + goto out;
75593 + case GR_SHUTDOWN:
75594 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75595 + stop_machine(gr_rbac_disable, NULL, NULL);
75596 + free_variables(false);
75597 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75598 + memset(gr_system_salt, 0, GR_SALT_LEN);
75599 + memset(gr_system_sum, 0, GR_SHA_LEN);
75600 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75601 + } else if (gr_acl_is_enabled()) {
75602 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75603 + error = -EPERM;
75604 + } else {
75605 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75606 + error = -EAGAIN;
75607 + }
75608 + break;
75609 + case GR_ENABLE:
75610 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75611 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75612 + else {
75613 + if (gr_acl_is_enabled())
75614 + error = -EAGAIN;
75615 + else
75616 + error = error2;
75617 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75618 + }
75619 + break;
75620 + case GR_OLDRELOAD:
75621 + oldmode = 1;
75622 + case GR_RELOAD:
75623 + if (!gr_acl_is_enabled()) {
75624 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75625 + error = -EAGAIN;
75626 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75627 + error2 = gracl_reload(gr_usermode, oldmode);
75628 + if (!error2)
75629 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75630 + else {
75631 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75632 + error = error2;
75633 + }
75634 + } else {
75635 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75636 + error = -EPERM;
75637 + }
75638 + break;
75639 + case GR_SEGVMOD:
75640 + if (unlikely(!gr_acl_is_enabled())) {
75641 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75642 + error = -EAGAIN;
75643 + break;
75644 + }
75645 +
75646 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75647 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75648 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75649 + struct acl_subject_label *segvacl;
75650 + segvacl =
75651 + lookup_acl_subj_label(gr_usermode->segv_inode,
75652 + gr_usermode->segv_device,
75653 + current->role);
75654 + if (segvacl) {
75655 + segvacl->crashes = 0;
75656 + segvacl->expires = 0;
75657 + }
75658 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75659 + gr_remove_uid(gr_usermode->segv_uid);
75660 + }
75661 + } else {
75662 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75663 + error = -EPERM;
75664 + }
75665 + break;
75666 + case GR_SPROLE:
75667 + case GR_SPROLEPAM:
75668 + if (unlikely(!gr_acl_is_enabled())) {
75669 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75670 + error = -EAGAIN;
75671 + break;
75672 + }
75673 +
75674 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75675 + current->role->expires = 0;
75676 + current->role->auth_attempts = 0;
75677 + }
75678 +
75679 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75680 + time_after(current->role->expires, get_seconds())) {
75681 + error = -EBUSY;
75682 + goto out;
75683 + }
75684 +
75685 + if (lookup_special_role_auth
75686 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75687 + && ((!sprole_salt && !sprole_sum)
75688 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75689 + char *p = "";
75690 + assign_special_role(gr_usermode->sp_role);
75691 + read_lock(&tasklist_lock);
75692 + if (current->real_parent)
75693 + p = current->real_parent->role->rolename;
75694 + read_unlock(&tasklist_lock);
75695 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75696 + p, acl_sp_role_value);
75697 + } else {
75698 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75699 + error = -EPERM;
75700 + if(!(current->role->auth_attempts++))
75701 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75702 +
75703 + goto out;
75704 + }
75705 + break;
75706 + case GR_UNSPROLE:
75707 + if (unlikely(!gr_acl_is_enabled())) {
75708 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75709 + error = -EAGAIN;
75710 + break;
75711 + }
75712 +
75713 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75714 + char *p = "";
75715 + int i = 0;
75716 +
75717 + read_lock(&tasklist_lock);
75718 + if (current->real_parent) {
75719 + p = current->real_parent->role->rolename;
75720 + i = current->real_parent->acl_role_id;
75721 + }
75722 + read_unlock(&tasklist_lock);
75723 +
75724 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75725 + gr_set_acls(1);
75726 + } else {
75727 + error = -EPERM;
75728 + goto out;
75729 + }
75730 + break;
75731 + default:
75732 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75733 + error = -EINVAL;
75734 + break;
75735 + }
75736 +
75737 + if (error != -EPERM)
75738 + goto out;
75739 +
75740 + if(!(gr_auth_attempts++))
75741 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75742 +
75743 + out:
75744 + mutex_unlock(&gr_dev_mutex);
75745 +
75746 + if (!error)
75747 + error = req_count;
75748 +
75749 + return error;
75750 +}
75751 +
75752 +int
75753 +gr_set_acls(const int type)
75754 +{
75755 + struct task_struct *task, *task2;
75756 + struct acl_role_label *role = current->role;
75757 + struct acl_subject_label *subj;
75758 + __u16 acl_role_id = current->acl_role_id;
75759 + const struct cred *cred;
75760 + int ret;
75761 +
75762 + rcu_read_lock();
75763 + read_lock(&tasklist_lock);
75764 + read_lock(&grsec_exec_file_lock);
75765 + do_each_thread(task2, task) {
75766 + /* check to see if we're called from the exit handler,
75767 + if so, only replace ACLs that have inherited the admin
75768 + ACL */
75769 +
75770 + if (type && (task->role != role ||
75771 + task->acl_role_id != acl_role_id))
75772 + continue;
75773 +
75774 + task->acl_role_id = 0;
75775 + task->acl_sp_role = 0;
75776 + task->inherited = 0;
75777 +
75778 + if (task->exec_file) {
75779 + cred = __task_cred(task);
75780 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75781 + subj = __gr_get_subject_for_task(polstate, task, NULL);
75782 + if (subj == NULL) {
75783 + ret = -EINVAL;
75784 + read_unlock(&grsec_exec_file_lock);
75785 + read_unlock(&tasklist_lock);
75786 + rcu_read_unlock();
75787 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75788 + return ret;
75789 + }
75790 + __gr_apply_subject_to_task(polstate, task, subj);
75791 + } else {
75792 + // it's a kernel process
75793 + task->role = polstate->kernel_role;
75794 + task->acl = polstate->kernel_role->root_label;
75795 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75796 + task->acl->mode &= ~GR_PROCFIND;
75797 +#endif
75798 + }
75799 + } while_each_thread(task2, task);
75800 + read_unlock(&grsec_exec_file_lock);
75801 + read_unlock(&tasklist_lock);
75802 + rcu_read_unlock();
75803 +
75804 + return 0;
75805 +}
75806 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75807 new file mode 100644
75808 index 0000000..39645c9
75809 --- /dev/null
75810 +++ b/grsecurity/gracl_res.c
75811 @@ -0,0 +1,68 @@
75812 +#include <linux/kernel.h>
75813 +#include <linux/sched.h>
75814 +#include <linux/gracl.h>
75815 +#include <linux/grinternal.h>
75816 +
75817 +static const char *restab_log[] = {
75818 + [RLIMIT_CPU] = "RLIMIT_CPU",
75819 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75820 + [RLIMIT_DATA] = "RLIMIT_DATA",
75821 + [RLIMIT_STACK] = "RLIMIT_STACK",
75822 + [RLIMIT_CORE] = "RLIMIT_CORE",
75823 + [RLIMIT_RSS] = "RLIMIT_RSS",
75824 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75825 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75826 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75827 + [RLIMIT_AS] = "RLIMIT_AS",
75828 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75829 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75830 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75831 + [RLIMIT_NICE] = "RLIMIT_NICE",
75832 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75833 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75834 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75835 +};
75836 +
75837 +void
75838 +gr_log_resource(const struct task_struct *task,
75839 + const int res, const unsigned long wanted, const int gt)
75840 +{
75841 + const struct cred *cred;
75842 + unsigned long rlim;
75843 +
75844 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75845 + return;
75846 +
75847 + // not yet supported resource
75848 + if (unlikely(!restab_log[res]))
75849 + return;
75850 +
75851 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75852 + rlim = task_rlimit_max(task, res);
75853 + else
75854 + rlim = task_rlimit(task, res);
75855 +
75856 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75857 + return;
75858 +
75859 + rcu_read_lock();
75860 + cred = __task_cred(task);
75861 +
75862 + if (res == RLIMIT_NPROC &&
75863 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75864 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75865 + goto out_rcu_unlock;
75866 + else if (res == RLIMIT_MEMLOCK &&
75867 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75868 + goto out_rcu_unlock;
75869 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75870 + goto out_rcu_unlock;
75871 + rcu_read_unlock();
75872 +
75873 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75874 +
75875 + return;
75876 +out_rcu_unlock:
75877 + rcu_read_unlock();
75878 + return;
75879 +}
75880 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75881 new file mode 100644
75882 index 0000000..2040e61
75883 --- /dev/null
75884 +++ b/grsecurity/gracl_segv.c
75885 @@ -0,0 +1,313 @@
75886 +#include <linux/kernel.h>
75887 +#include <linux/mm.h>
75888 +#include <asm/uaccess.h>
75889 +#include <asm/errno.h>
75890 +#include <asm/mman.h>
75891 +#include <net/sock.h>
75892 +#include <linux/file.h>
75893 +#include <linux/fs.h>
75894 +#include <linux/net.h>
75895 +#include <linux/in.h>
75896 +#include <linux/slab.h>
75897 +#include <linux/types.h>
75898 +#include <linux/sched.h>
75899 +#include <linux/timer.h>
75900 +#include <linux/gracl.h>
75901 +#include <linux/grsecurity.h>
75902 +#include <linux/grinternal.h>
75903 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75904 +#include <linux/magic.h>
75905 +#include <linux/pagemap.h>
75906 +#include "../fs/btrfs/async-thread.h"
75907 +#include "../fs/btrfs/ctree.h"
75908 +#include "../fs/btrfs/btrfs_inode.h"
75909 +#endif
75910 +
75911 +static struct crash_uid *uid_set;
75912 +static unsigned short uid_used;
75913 +static DEFINE_SPINLOCK(gr_uid_lock);
75914 +extern rwlock_t gr_inode_lock;
75915 +extern struct acl_subject_label *
75916 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75917 + struct acl_role_label *role);
75918 +
75919 +static inline dev_t __get_dev(const struct dentry *dentry)
75920 +{
75921 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75922 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75923 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75924 + else
75925 +#endif
75926 + return dentry->d_sb->s_dev;
75927 +}
75928 +
75929 +int
75930 +gr_init_uidset(void)
75931 +{
75932 + uid_set =
75933 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75934 + uid_used = 0;
75935 +
75936 + return uid_set ? 1 : 0;
75937 +}
75938 +
75939 +void
75940 +gr_free_uidset(void)
75941 +{
75942 + if (uid_set) {
75943 + struct crash_uid *tmpset;
75944 + spin_lock(&gr_uid_lock);
75945 + tmpset = uid_set;
75946 + uid_set = NULL;
75947 + uid_used = 0;
75948 + spin_unlock(&gr_uid_lock);
75949 + if (tmpset)
75950 + kfree(tmpset);
75951 + }
75952 +
75953 + return;
75954 +}
75955 +
75956 +int
75957 +gr_find_uid(const uid_t uid)
75958 +{
75959 + struct crash_uid *tmp = uid_set;
75960 + uid_t buid;
75961 + int low = 0, high = uid_used - 1, mid;
75962 +
75963 + while (high >= low) {
75964 + mid = (low + high) >> 1;
75965 + buid = tmp[mid].uid;
75966 + if (buid == uid)
75967 + return mid;
75968 + if (buid > uid)
75969 + high = mid - 1;
75970 + if (buid < uid)
75971 + low = mid + 1;
75972 + }
75973 +
75974 + return -1;
75975 +}
75976 +
75977 +static __inline__ void
75978 +gr_insertsort(void)
75979 +{
75980 + unsigned short i, j;
75981 + struct crash_uid index;
75982 +
75983 + for (i = 1; i < uid_used; i++) {
75984 + index = uid_set[i];
75985 + j = i;
75986 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75987 + uid_set[j] = uid_set[j - 1];
75988 + j--;
75989 + }
75990 + uid_set[j] = index;
75991 + }
75992 +
75993 + return;
75994 +}
75995 +
75996 +static __inline__ void
75997 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75998 +{
75999 + int loc;
76000 + uid_t uid = GR_GLOBAL_UID(kuid);
76001 +
76002 + if (uid_used == GR_UIDTABLE_MAX)
76003 + return;
76004 +
76005 + loc = gr_find_uid(uid);
76006 +
76007 + if (loc >= 0) {
76008 + uid_set[loc].expires = expires;
76009 + return;
76010 + }
76011 +
76012 + uid_set[uid_used].uid = uid;
76013 + uid_set[uid_used].expires = expires;
76014 + uid_used++;
76015 +
76016 + gr_insertsort();
76017 +
76018 + return;
76019 +}
76020 +
76021 +void
76022 +gr_remove_uid(const unsigned short loc)
76023 +{
76024 + unsigned short i;
76025 +
76026 + for (i = loc + 1; i < uid_used; i++)
76027 + uid_set[i - 1] = uid_set[i];
76028 +
76029 + uid_used--;
76030 +
76031 + return;
76032 +}
76033 +
76034 +int
76035 +gr_check_crash_uid(const kuid_t kuid)
76036 +{
76037 + int loc;
76038 + int ret = 0;
76039 + uid_t uid;
76040 +
76041 + if (unlikely(!gr_acl_is_enabled()))
76042 + return 0;
76043 +
76044 + uid = GR_GLOBAL_UID(kuid);
76045 +
76046 + spin_lock(&gr_uid_lock);
76047 + loc = gr_find_uid(uid);
76048 +
76049 + if (loc < 0)
76050 + goto out_unlock;
76051 +
76052 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
76053 + gr_remove_uid(loc);
76054 + else
76055 + ret = 1;
76056 +
76057 +out_unlock:
76058 + spin_unlock(&gr_uid_lock);
76059 + return ret;
76060 +}
76061 +
76062 +static __inline__ int
76063 +proc_is_setxid(const struct cred *cred)
76064 +{
76065 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76066 + !uid_eq(cred->uid, cred->fsuid))
76067 + return 1;
76068 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76069 + !gid_eq(cred->gid, cred->fsgid))
76070 + return 1;
76071 +
76072 + return 0;
76073 +}
76074 +
76075 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
76076 +
76077 +void
76078 +gr_handle_crash(struct task_struct *task, const int sig)
76079 +{
76080 + struct acl_subject_label *curr;
76081 + struct task_struct *tsk, *tsk2;
76082 + const struct cred *cred;
76083 + const struct cred *cred2;
76084 +
76085 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76086 + return;
76087 +
76088 + if (unlikely(!gr_acl_is_enabled()))
76089 + return;
76090 +
76091 + curr = task->acl;
76092 +
76093 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76094 + return;
76095 +
76096 + if (time_before_eq(curr->expires, get_seconds())) {
76097 + curr->expires = 0;
76098 + curr->crashes = 0;
76099 + }
76100 +
76101 + curr->crashes++;
76102 +
76103 + if (!curr->expires)
76104 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76105 +
76106 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76107 + time_after(curr->expires, get_seconds())) {
76108 + rcu_read_lock();
76109 + cred = __task_cred(task);
76110 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76111 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76112 + spin_lock(&gr_uid_lock);
76113 + gr_insert_uid(cred->uid, curr->expires);
76114 + spin_unlock(&gr_uid_lock);
76115 + curr->expires = 0;
76116 + curr->crashes = 0;
76117 + read_lock(&tasklist_lock);
76118 + do_each_thread(tsk2, tsk) {
76119 + cred2 = __task_cred(tsk);
76120 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76121 + gr_fake_force_sig(SIGKILL, tsk);
76122 + } while_each_thread(tsk2, tsk);
76123 + read_unlock(&tasklist_lock);
76124 + } else {
76125 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76126 + read_lock(&tasklist_lock);
76127 + read_lock(&grsec_exec_file_lock);
76128 + do_each_thread(tsk2, tsk) {
76129 + if (likely(tsk != task)) {
76130 + // if this thread has the same subject as the one that triggered
76131 + // RES_CRASH and it's the same binary, kill it
76132 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76133 + gr_fake_force_sig(SIGKILL, tsk);
76134 + }
76135 + } while_each_thread(tsk2, tsk);
76136 + read_unlock(&grsec_exec_file_lock);
76137 + read_unlock(&tasklist_lock);
76138 + }
76139 + rcu_read_unlock();
76140 + }
76141 +
76142 + return;
76143 +}
76144 +
76145 +int
76146 +gr_check_crash_exec(const struct file *filp)
76147 +{
76148 + struct acl_subject_label *curr;
76149 +
76150 + if (unlikely(!gr_acl_is_enabled()))
76151 + return 0;
76152 +
76153 + read_lock(&gr_inode_lock);
76154 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76155 + __get_dev(filp->f_path.dentry),
76156 + current->role);
76157 + read_unlock(&gr_inode_lock);
76158 +
76159 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76160 + (!curr->crashes && !curr->expires))
76161 + return 0;
76162 +
76163 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76164 + time_after(curr->expires, get_seconds()))
76165 + return 1;
76166 + else if (time_before_eq(curr->expires, get_seconds())) {
76167 + curr->crashes = 0;
76168 + curr->expires = 0;
76169 + }
76170 +
76171 + return 0;
76172 +}
76173 +
76174 +void
76175 +gr_handle_alertkill(struct task_struct *task)
76176 +{
76177 + struct acl_subject_label *curracl;
76178 + __u32 curr_ip;
76179 + struct task_struct *p, *p2;
76180 +
76181 + if (unlikely(!gr_acl_is_enabled()))
76182 + return;
76183 +
76184 + curracl = task->acl;
76185 + curr_ip = task->signal->curr_ip;
76186 +
76187 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76188 + read_lock(&tasklist_lock);
76189 + do_each_thread(p2, p) {
76190 + if (p->signal->curr_ip == curr_ip)
76191 + gr_fake_force_sig(SIGKILL, p);
76192 + } while_each_thread(p2, p);
76193 + read_unlock(&tasklist_lock);
76194 + } else if (curracl->mode & GR_KILLPROC)
76195 + gr_fake_force_sig(SIGKILL, task);
76196 +
76197 + return;
76198 +}
76199 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76200 new file mode 100644
76201 index 0000000..6b0c9cc
76202 --- /dev/null
76203 +++ b/grsecurity/gracl_shm.c
76204 @@ -0,0 +1,40 @@
76205 +#include <linux/kernel.h>
76206 +#include <linux/mm.h>
76207 +#include <linux/sched.h>
76208 +#include <linux/file.h>
76209 +#include <linux/ipc.h>
76210 +#include <linux/gracl.h>
76211 +#include <linux/grsecurity.h>
76212 +#include <linux/grinternal.h>
76213 +
76214 +int
76215 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76216 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76217 +{
76218 + struct task_struct *task;
76219 +
76220 + if (!gr_acl_is_enabled())
76221 + return 1;
76222 +
76223 + rcu_read_lock();
76224 + read_lock(&tasklist_lock);
76225 +
76226 + task = find_task_by_vpid(shm_cprid);
76227 +
76228 + if (unlikely(!task))
76229 + task = find_task_by_vpid(shm_lapid);
76230 +
76231 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76232 + (task_pid_nr(task) == shm_lapid)) &&
76233 + (task->acl->mode & GR_PROTSHM) &&
76234 + (task->acl != current->acl))) {
76235 + read_unlock(&tasklist_lock);
76236 + rcu_read_unlock();
76237 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76238 + return 0;
76239 + }
76240 + read_unlock(&tasklist_lock);
76241 + rcu_read_unlock();
76242 +
76243 + return 1;
76244 +}
76245 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76246 new file mode 100644
76247 index 0000000..bc0be01
76248 --- /dev/null
76249 +++ b/grsecurity/grsec_chdir.c
76250 @@ -0,0 +1,19 @@
76251 +#include <linux/kernel.h>
76252 +#include <linux/sched.h>
76253 +#include <linux/fs.h>
76254 +#include <linux/file.h>
76255 +#include <linux/grsecurity.h>
76256 +#include <linux/grinternal.h>
76257 +
76258 +void
76259 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76260 +{
76261 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76262 + if ((grsec_enable_chdir && grsec_enable_group &&
76263 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76264 + !grsec_enable_group)) {
76265 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76266 + }
76267 +#endif
76268 + return;
76269 +}
76270 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76271 new file mode 100644
76272 index 0000000..6d99cec
76273 --- /dev/null
76274 +++ b/grsecurity/grsec_chroot.c
76275 @@ -0,0 +1,385 @@
76276 +#include <linux/kernel.h>
76277 +#include <linux/module.h>
76278 +#include <linux/sched.h>
76279 +#include <linux/file.h>
76280 +#include <linux/fs.h>
76281 +#include <linux/mount.h>
76282 +#include <linux/types.h>
76283 +#include "../fs/mount.h"
76284 +#include <linux/grsecurity.h>
76285 +#include <linux/grinternal.h>
76286 +
76287 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76288 +int gr_init_ran;
76289 +#endif
76290 +
76291 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76292 +{
76293 +#ifdef CONFIG_GRKERNSEC
76294 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76295 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76296 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76297 + && gr_init_ran
76298 +#endif
76299 + )
76300 + task->gr_is_chrooted = 1;
76301 + else {
76302 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76303 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76304 + gr_init_ran = 1;
76305 +#endif
76306 + task->gr_is_chrooted = 0;
76307 + }
76308 +
76309 + task->gr_chroot_dentry = path->dentry;
76310 +#endif
76311 + return;
76312 +}
76313 +
76314 +void gr_clear_chroot_entries(struct task_struct *task)
76315 +{
76316 +#ifdef CONFIG_GRKERNSEC
76317 + task->gr_is_chrooted = 0;
76318 + task->gr_chroot_dentry = NULL;
76319 +#endif
76320 + return;
76321 +}
76322 +
76323 +int
76324 +gr_handle_chroot_unix(const pid_t pid)
76325 +{
76326 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76327 + struct task_struct *p;
76328 +
76329 + if (unlikely(!grsec_enable_chroot_unix))
76330 + return 1;
76331 +
76332 + if (likely(!proc_is_chrooted(current)))
76333 + return 1;
76334 +
76335 + rcu_read_lock();
76336 + read_lock(&tasklist_lock);
76337 + p = find_task_by_vpid_unrestricted(pid);
76338 + if (unlikely(p && !have_same_root(current, p))) {
76339 + read_unlock(&tasklist_lock);
76340 + rcu_read_unlock();
76341 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76342 + return 0;
76343 + }
76344 + read_unlock(&tasklist_lock);
76345 + rcu_read_unlock();
76346 +#endif
76347 + return 1;
76348 +}
76349 +
76350 +int
76351 +gr_handle_chroot_nice(void)
76352 +{
76353 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76354 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76355 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76356 + return -EPERM;
76357 + }
76358 +#endif
76359 + return 0;
76360 +}
76361 +
76362 +int
76363 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76364 +{
76365 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76366 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76367 + && proc_is_chrooted(current)) {
76368 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76369 + return -EACCES;
76370 + }
76371 +#endif
76372 + return 0;
76373 +}
76374 +
76375 +int
76376 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76377 +{
76378 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76379 + struct task_struct *p;
76380 + int ret = 0;
76381 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76382 + return ret;
76383 +
76384 + read_lock(&tasklist_lock);
76385 + do_each_pid_task(pid, type, p) {
76386 + if (!have_same_root(current, p)) {
76387 + ret = 1;
76388 + goto out;
76389 + }
76390 + } while_each_pid_task(pid, type, p);
76391 +out:
76392 + read_unlock(&tasklist_lock);
76393 + return ret;
76394 +#endif
76395 + return 0;
76396 +}
76397 +
76398 +int
76399 +gr_pid_is_chrooted(struct task_struct *p)
76400 +{
76401 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76402 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76403 + return 0;
76404 +
76405 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76406 + !have_same_root(current, p)) {
76407 + return 1;
76408 + }
76409 +#endif
76410 + return 0;
76411 +}
76412 +
76413 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76414 +
76415 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76416 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76417 +{
76418 + struct path path, currentroot;
76419 + int ret = 0;
76420 +
76421 + path.dentry = (struct dentry *)u_dentry;
76422 + path.mnt = (struct vfsmount *)u_mnt;
76423 + get_fs_root(current->fs, &currentroot);
76424 + if (path_is_under(&path, &currentroot))
76425 + ret = 1;
76426 + path_put(&currentroot);
76427 +
76428 + return ret;
76429 +}
76430 +#endif
76431 +
76432 +int
76433 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76434 +{
76435 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76436 + if (!grsec_enable_chroot_fchdir)
76437 + return 1;
76438 +
76439 + if (!proc_is_chrooted(current))
76440 + return 1;
76441 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76442 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76443 + return 0;
76444 + }
76445 +#endif
76446 + return 1;
76447 +}
76448 +
76449 +int
76450 +gr_chroot_fhandle(void)
76451 +{
76452 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76453 + if (!grsec_enable_chroot_fchdir)
76454 + return 1;
76455 +
76456 + if (!proc_is_chrooted(current))
76457 + return 1;
76458 + else {
76459 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76460 + return 0;
76461 + }
76462 +#endif
76463 + return 1;
76464 +}
76465 +
76466 +int
76467 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76468 + const u64 shm_createtime)
76469 +{
76470 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76471 + struct task_struct *p;
76472 +
76473 + if (unlikely(!grsec_enable_chroot_shmat))
76474 + return 1;
76475 +
76476 + if (likely(!proc_is_chrooted(current)))
76477 + return 1;
76478 +
76479 + rcu_read_lock();
76480 + read_lock(&tasklist_lock);
76481 +
76482 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76483 + if (time_before_eq64(p->start_time, shm_createtime)) {
76484 + if (have_same_root(current, p)) {
76485 + goto allow;
76486 + } else {
76487 + read_unlock(&tasklist_lock);
76488 + rcu_read_unlock();
76489 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76490 + return 0;
76491 + }
76492 + }
76493 + /* creator exited, pid reuse, fall through to next check */
76494 + }
76495 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76496 + if (unlikely(!have_same_root(current, p))) {
76497 + read_unlock(&tasklist_lock);
76498 + rcu_read_unlock();
76499 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76500 + return 0;
76501 + }
76502 + }
76503 +
76504 +allow:
76505 + read_unlock(&tasklist_lock);
76506 + rcu_read_unlock();
76507 +#endif
76508 + return 1;
76509 +}
76510 +
76511 +void
76512 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76513 +{
76514 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76515 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76516 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76517 +#endif
76518 + return;
76519 +}
76520 +
76521 +int
76522 +gr_handle_chroot_mknod(const struct dentry *dentry,
76523 + const struct vfsmount *mnt, const int mode)
76524 +{
76525 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76526 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76527 + proc_is_chrooted(current)) {
76528 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76529 + return -EPERM;
76530 + }
76531 +#endif
76532 + return 0;
76533 +}
76534 +
76535 +int
76536 +gr_handle_chroot_mount(const struct dentry *dentry,
76537 + const struct vfsmount *mnt, const char *dev_name)
76538 +{
76539 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76540 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76541 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76542 + return -EPERM;
76543 + }
76544 +#endif
76545 + return 0;
76546 +}
76547 +
76548 +int
76549 +gr_handle_chroot_pivot(void)
76550 +{
76551 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76552 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76553 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76554 + return -EPERM;
76555 + }
76556 +#endif
76557 + return 0;
76558 +}
76559 +
76560 +int
76561 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76562 +{
76563 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76564 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76565 + !gr_is_outside_chroot(dentry, mnt)) {
76566 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76567 + return -EPERM;
76568 + }
76569 +#endif
76570 + return 0;
76571 +}
76572 +
76573 +extern const char *captab_log[];
76574 +extern int captab_log_entries;
76575 +
76576 +int
76577 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76578 +{
76579 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76580 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76581 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76582 + if (cap_raised(chroot_caps, cap)) {
76583 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76584 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76585 + }
76586 + return 0;
76587 + }
76588 + }
76589 +#endif
76590 + return 1;
76591 +}
76592 +
76593 +int
76594 +gr_chroot_is_capable(const int cap)
76595 +{
76596 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76597 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76598 +#endif
76599 + return 1;
76600 +}
76601 +
76602 +int
76603 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76604 +{
76605 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76606 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76607 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76608 + if (cap_raised(chroot_caps, cap)) {
76609 + return 0;
76610 + }
76611 + }
76612 +#endif
76613 + return 1;
76614 +}
76615 +
76616 +int
76617 +gr_chroot_is_capable_nolog(const int cap)
76618 +{
76619 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76620 + return gr_task_chroot_is_capable_nolog(current, cap);
76621 +#endif
76622 + return 1;
76623 +}
76624 +
76625 +int
76626 +gr_handle_chroot_sysctl(const int op)
76627 +{
76628 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76629 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76630 + proc_is_chrooted(current))
76631 + return -EACCES;
76632 +#endif
76633 + return 0;
76634 +}
76635 +
76636 +void
76637 +gr_handle_chroot_chdir(const struct path *path)
76638 +{
76639 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76640 + if (grsec_enable_chroot_chdir)
76641 + set_fs_pwd(current->fs, path);
76642 +#endif
76643 + return;
76644 +}
76645 +
76646 +int
76647 +gr_handle_chroot_chmod(const struct dentry *dentry,
76648 + const struct vfsmount *mnt, const int mode)
76649 +{
76650 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76651 + /* allow chmod +s on directories, but not files */
76652 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76653 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76654 + proc_is_chrooted(current)) {
76655 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76656 + return -EPERM;
76657 + }
76658 +#endif
76659 + return 0;
76660 +}
76661 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76662 new file mode 100644
76663 index 0000000..0f9ac91
76664 --- /dev/null
76665 +++ b/grsecurity/grsec_disabled.c
76666 @@ -0,0 +1,440 @@
76667 +#include <linux/kernel.h>
76668 +#include <linux/module.h>
76669 +#include <linux/sched.h>
76670 +#include <linux/file.h>
76671 +#include <linux/fs.h>
76672 +#include <linux/kdev_t.h>
76673 +#include <linux/net.h>
76674 +#include <linux/in.h>
76675 +#include <linux/ip.h>
76676 +#include <linux/skbuff.h>
76677 +#include <linux/sysctl.h>
76678 +
76679 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76680 +void
76681 +pax_set_initial_flags(struct linux_binprm *bprm)
76682 +{
76683 + return;
76684 +}
76685 +#endif
76686 +
76687 +#ifdef CONFIG_SYSCTL
76688 +__u32
76689 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76690 +{
76691 + return 0;
76692 +}
76693 +#endif
76694 +
76695 +#ifdef CONFIG_TASKSTATS
76696 +int gr_is_taskstats_denied(int pid)
76697 +{
76698 + return 0;
76699 +}
76700 +#endif
76701 +
76702 +int
76703 +gr_acl_is_enabled(void)
76704 +{
76705 + return 0;
76706 +}
76707 +
76708 +int
76709 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76710 +{
76711 + return 0;
76712 +}
76713 +
76714 +void
76715 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76716 +{
76717 + return;
76718 +}
76719 +
76720 +int
76721 +gr_handle_rawio(const struct inode *inode)
76722 +{
76723 + return 0;
76724 +}
76725 +
76726 +void
76727 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76728 +{
76729 + return;
76730 +}
76731 +
76732 +int
76733 +gr_handle_ptrace(struct task_struct *task, const long request)
76734 +{
76735 + return 0;
76736 +}
76737 +
76738 +int
76739 +gr_handle_proc_ptrace(struct task_struct *task)
76740 +{
76741 + return 0;
76742 +}
76743 +
76744 +int
76745 +gr_set_acls(const int type)
76746 +{
76747 + return 0;
76748 +}
76749 +
76750 +int
76751 +gr_check_hidden_task(const struct task_struct *tsk)
76752 +{
76753 + return 0;
76754 +}
76755 +
76756 +int
76757 +gr_check_protected_task(const struct task_struct *task)
76758 +{
76759 + return 0;
76760 +}
76761 +
76762 +int
76763 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76764 +{
76765 + return 0;
76766 +}
76767 +
76768 +void
76769 +gr_copy_label(struct task_struct *tsk)
76770 +{
76771 + return;
76772 +}
76773 +
76774 +void
76775 +gr_set_pax_flags(struct task_struct *task)
76776 +{
76777 + return;
76778 +}
76779 +
76780 +int
76781 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76782 + const int unsafe_share)
76783 +{
76784 + return 0;
76785 +}
76786 +
76787 +void
76788 +gr_handle_delete(const ino_t ino, const dev_t dev)
76789 +{
76790 + return;
76791 +}
76792 +
76793 +void
76794 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76795 +{
76796 + return;
76797 +}
76798 +
76799 +void
76800 +gr_handle_crash(struct task_struct *task, const int sig)
76801 +{
76802 + return;
76803 +}
76804 +
76805 +int
76806 +gr_check_crash_exec(const struct file *filp)
76807 +{
76808 + return 0;
76809 +}
76810 +
76811 +int
76812 +gr_check_crash_uid(const kuid_t uid)
76813 +{
76814 + return 0;
76815 +}
76816 +
76817 +void
76818 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76819 + struct dentry *old_dentry,
76820 + struct dentry *new_dentry,
76821 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76822 +{
76823 + return;
76824 +}
76825 +
76826 +int
76827 +gr_search_socket(const int family, const int type, const int protocol)
76828 +{
76829 + return 1;
76830 +}
76831 +
76832 +int
76833 +gr_search_connectbind(const int mode, const struct socket *sock,
76834 + const struct sockaddr_in *addr)
76835 +{
76836 + return 0;
76837 +}
76838 +
76839 +void
76840 +gr_handle_alertkill(struct task_struct *task)
76841 +{
76842 + return;
76843 +}
76844 +
76845 +__u32
76846 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76847 +{
76848 + return 1;
76849 +}
76850 +
76851 +__u32
76852 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76853 + const struct vfsmount * mnt)
76854 +{
76855 + return 1;
76856 +}
76857 +
76858 +__u32
76859 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76860 + int acc_mode)
76861 +{
76862 + return 1;
76863 +}
76864 +
76865 +__u32
76866 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76867 +{
76868 + return 1;
76869 +}
76870 +
76871 +__u32
76872 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76873 +{
76874 + return 1;
76875 +}
76876 +
76877 +int
76878 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76879 + unsigned int *vm_flags)
76880 +{
76881 + return 1;
76882 +}
76883 +
76884 +__u32
76885 +gr_acl_handle_truncate(const struct dentry * dentry,
76886 + const struct vfsmount * mnt)
76887 +{
76888 + return 1;
76889 +}
76890 +
76891 +__u32
76892 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76893 +{
76894 + return 1;
76895 +}
76896 +
76897 +__u32
76898 +gr_acl_handle_access(const struct dentry * dentry,
76899 + const struct vfsmount * mnt, const int fmode)
76900 +{
76901 + return 1;
76902 +}
76903 +
76904 +__u32
76905 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76906 + umode_t *mode)
76907 +{
76908 + return 1;
76909 +}
76910 +
76911 +__u32
76912 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76913 +{
76914 + return 1;
76915 +}
76916 +
76917 +__u32
76918 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76919 +{
76920 + return 1;
76921 +}
76922 +
76923 +__u32
76924 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76925 +{
76926 + return 1;
76927 +}
76928 +
76929 +void
76930 +grsecurity_init(void)
76931 +{
76932 + return;
76933 +}
76934 +
76935 +umode_t gr_acl_umask(void)
76936 +{
76937 + return 0;
76938 +}
76939 +
76940 +__u32
76941 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76942 + const struct dentry * parent_dentry,
76943 + const struct vfsmount * parent_mnt,
76944 + const int mode)
76945 +{
76946 + return 1;
76947 +}
76948 +
76949 +__u32
76950 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76951 + const struct dentry * parent_dentry,
76952 + const struct vfsmount * parent_mnt)
76953 +{
76954 + return 1;
76955 +}
76956 +
76957 +__u32
76958 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76959 + const struct dentry * parent_dentry,
76960 + const struct vfsmount * parent_mnt, const struct filename *from)
76961 +{
76962 + return 1;
76963 +}
76964 +
76965 +__u32
76966 +gr_acl_handle_link(const struct dentry * new_dentry,
76967 + const struct dentry * parent_dentry,
76968 + const struct vfsmount * parent_mnt,
76969 + const struct dentry * old_dentry,
76970 + const struct vfsmount * old_mnt, const struct filename *to)
76971 +{
76972 + return 1;
76973 +}
76974 +
76975 +int
76976 +gr_acl_handle_rename(const struct dentry *new_dentry,
76977 + const struct dentry *parent_dentry,
76978 + const struct vfsmount *parent_mnt,
76979 + const struct dentry *old_dentry,
76980 + const struct inode *old_parent_inode,
76981 + const struct vfsmount *old_mnt, const struct filename *newname,
76982 + unsigned int flags)
76983 +{
76984 + return 0;
76985 +}
76986 +
76987 +int
76988 +gr_acl_handle_filldir(const struct file *file, const char *name,
76989 + const int namelen, const ino_t ino)
76990 +{
76991 + return 1;
76992 +}
76993 +
76994 +int
76995 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76996 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76997 +{
76998 + return 1;
76999 +}
77000 +
77001 +int
77002 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77003 +{
77004 + return 0;
77005 +}
77006 +
77007 +int
77008 +gr_search_accept(const struct socket *sock)
77009 +{
77010 + return 0;
77011 +}
77012 +
77013 +int
77014 +gr_search_listen(const struct socket *sock)
77015 +{
77016 + return 0;
77017 +}
77018 +
77019 +int
77020 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77021 +{
77022 + return 0;
77023 +}
77024 +
77025 +__u32
77026 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77027 +{
77028 + return 1;
77029 +}
77030 +
77031 +__u32
77032 +gr_acl_handle_creat(const struct dentry * dentry,
77033 + const struct dentry * p_dentry,
77034 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77035 + const int imode)
77036 +{
77037 + return 1;
77038 +}
77039 +
77040 +void
77041 +gr_acl_handle_exit(void)
77042 +{
77043 + return;
77044 +}
77045 +
77046 +int
77047 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77048 +{
77049 + return 1;
77050 +}
77051 +
77052 +void
77053 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77054 +{
77055 + return;
77056 +}
77057 +
77058 +int
77059 +gr_acl_handle_procpidmem(const struct task_struct *task)
77060 +{
77061 + return 0;
77062 +}
77063 +
77064 +int
77065 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77066 +{
77067 + return 0;
77068 +}
77069 +
77070 +int
77071 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77072 +{
77073 + return 0;
77074 +}
77075 +
77076 +int
77077 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77078 +{
77079 + return 0;
77080 +}
77081 +
77082 +int
77083 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77084 +{
77085 + return 0;
77086 +}
77087 +
77088 +int gr_acl_enable_at_secure(void)
77089 +{
77090 + return 0;
77091 +}
77092 +
77093 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77094 +{
77095 + return dentry->d_sb->s_dev;
77096 +}
77097 +
77098 +void gr_put_exec_file(struct task_struct *task)
77099 +{
77100 + return;
77101 +}
77102 +
77103 +#ifdef CONFIG_SECURITY
77104 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77105 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77106 +#endif
77107 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77108 new file mode 100644
77109 index 0000000..14638ff
77110 --- /dev/null
77111 +++ b/grsecurity/grsec_exec.c
77112 @@ -0,0 +1,188 @@
77113 +#include <linux/kernel.h>
77114 +#include <linux/sched.h>
77115 +#include <linux/file.h>
77116 +#include <linux/binfmts.h>
77117 +#include <linux/fs.h>
77118 +#include <linux/types.h>
77119 +#include <linux/grdefs.h>
77120 +#include <linux/grsecurity.h>
77121 +#include <linux/grinternal.h>
77122 +#include <linux/capability.h>
77123 +#include <linux/module.h>
77124 +#include <linux/compat.h>
77125 +
77126 +#include <asm/uaccess.h>
77127 +
77128 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77129 +static char gr_exec_arg_buf[132];
77130 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77131 +#endif
77132 +
77133 +struct user_arg_ptr {
77134 +#ifdef CONFIG_COMPAT
77135 + bool is_compat;
77136 +#endif
77137 + union {
77138 + const char __user *const __user *native;
77139 +#ifdef CONFIG_COMPAT
77140 + const compat_uptr_t __user *compat;
77141 +#endif
77142 + } ptr;
77143 +};
77144 +
77145 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77146 +
77147 +void
77148 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77149 +{
77150 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77151 + char *grarg = gr_exec_arg_buf;
77152 + unsigned int i, x, execlen = 0;
77153 + char c;
77154 +
77155 + if (!((grsec_enable_execlog && grsec_enable_group &&
77156 + in_group_p(grsec_audit_gid))
77157 + || (grsec_enable_execlog && !grsec_enable_group)))
77158 + return;
77159 +
77160 + mutex_lock(&gr_exec_arg_mutex);
77161 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77162 +
77163 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77164 + const char __user *p;
77165 + unsigned int len;
77166 +
77167 + p = get_user_arg_ptr(argv, i);
77168 + if (IS_ERR(p))
77169 + goto log;
77170 +
77171 + len = strnlen_user(p, 128 - execlen);
77172 + if (len > 128 - execlen)
77173 + len = 128 - execlen;
77174 + else if (len > 0)
77175 + len--;
77176 + if (copy_from_user(grarg + execlen, p, len))
77177 + goto log;
77178 +
77179 + /* rewrite unprintable characters */
77180 + for (x = 0; x < len; x++) {
77181 + c = *(grarg + execlen + x);
77182 + if (c < 32 || c > 126)
77183 + *(grarg + execlen + x) = ' ';
77184 + }
77185 +
77186 + execlen += len;
77187 + *(grarg + execlen) = ' ';
77188 + *(grarg + execlen + 1) = '\0';
77189 + execlen++;
77190 + }
77191 +
77192 + log:
77193 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77194 + bprm->file->f_path.mnt, grarg);
77195 + mutex_unlock(&gr_exec_arg_mutex);
77196 +#endif
77197 + return;
77198 +}
77199 +
77200 +#ifdef CONFIG_GRKERNSEC
77201 +extern int gr_acl_is_capable(const int cap);
77202 +extern int gr_acl_is_capable_nolog(const int cap);
77203 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77204 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77205 +extern int gr_chroot_is_capable(const int cap);
77206 +extern int gr_chroot_is_capable_nolog(const int cap);
77207 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77208 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77209 +#endif
77210 +
77211 +const char *captab_log[] = {
77212 + "CAP_CHOWN",
77213 + "CAP_DAC_OVERRIDE",
77214 + "CAP_DAC_READ_SEARCH",
77215 + "CAP_FOWNER",
77216 + "CAP_FSETID",
77217 + "CAP_KILL",
77218 + "CAP_SETGID",
77219 + "CAP_SETUID",
77220 + "CAP_SETPCAP",
77221 + "CAP_LINUX_IMMUTABLE",
77222 + "CAP_NET_BIND_SERVICE",
77223 + "CAP_NET_BROADCAST",
77224 + "CAP_NET_ADMIN",
77225 + "CAP_NET_RAW",
77226 + "CAP_IPC_LOCK",
77227 + "CAP_IPC_OWNER",
77228 + "CAP_SYS_MODULE",
77229 + "CAP_SYS_RAWIO",
77230 + "CAP_SYS_CHROOT",
77231 + "CAP_SYS_PTRACE",
77232 + "CAP_SYS_PACCT",
77233 + "CAP_SYS_ADMIN",
77234 + "CAP_SYS_BOOT",
77235 + "CAP_SYS_NICE",
77236 + "CAP_SYS_RESOURCE",
77237 + "CAP_SYS_TIME",
77238 + "CAP_SYS_TTY_CONFIG",
77239 + "CAP_MKNOD",
77240 + "CAP_LEASE",
77241 + "CAP_AUDIT_WRITE",
77242 + "CAP_AUDIT_CONTROL",
77243 + "CAP_SETFCAP",
77244 + "CAP_MAC_OVERRIDE",
77245 + "CAP_MAC_ADMIN",
77246 + "CAP_SYSLOG",
77247 + "CAP_WAKE_ALARM",
77248 + "CAP_BLOCK_SUSPEND"
77249 +};
77250 +
77251 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77252 +
77253 +int gr_is_capable(const int cap)
77254 +{
77255 +#ifdef CONFIG_GRKERNSEC
77256 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77257 + return 1;
77258 + return 0;
77259 +#else
77260 + return 1;
77261 +#endif
77262 +}
77263 +
77264 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77265 +{
77266 +#ifdef CONFIG_GRKERNSEC
77267 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77268 + return 1;
77269 + return 0;
77270 +#else
77271 + return 1;
77272 +#endif
77273 +}
77274 +
77275 +int gr_is_capable_nolog(const int cap)
77276 +{
77277 +#ifdef CONFIG_GRKERNSEC
77278 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77279 + return 1;
77280 + return 0;
77281 +#else
77282 + return 1;
77283 +#endif
77284 +}
77285 +
77286 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77287 +{
77288 +#ifdef CONFIG_GRKERNSEC
77289 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77290 + return 1;
77291 + return 0;
77292 +#else
77293 + return 1;
77294 +#endif
77295 +}
77296 +
77297 +EXPORT_SYMBOL_GPL(gr_is_capable);
77298 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77299 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77300 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77301 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77302 new file mode 100644
77303 index 0000000..06cc6ea
77304 --- /dev/null
77305 +++ b/grsecurity/grsec_fifo.c
77306 @@ -0,0 +1,24 @@
77307 +#include <linux/kernel.h>
77308 +#include <linux/sched.h>
77309 +#include <linux/fs.h>
77310 +#include <linux/file.h>
77311 +#include <linux/grinternal.h>
77312 +
77313 +int
77314 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77315 + const struct dentry *dir, const int flag, const int acc_mode)
77316 +{
77317 +#ifdef CONFIG_GRKERNSEC_FIFO
77318 + const struct cred *cred = current_cred();
77319 +
77320 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77321 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77322 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77323 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77324 + if (!inode_permission(dentry->d_inode, acc_mode))
77325 + 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));
77326 + return -EACCES;
77327 + }
77328 +#endif
77329 + return 0;
77330 +}
77331 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77332 new file mode 100644
77333 index 0000000..8ca18bf
77334 --- /dev/null
77335 +++ b/grsecurity/grsec_fork.c
77336 @@ -0,0 +1,23 @@
77337 +#include <linux/kernel.h>
77338 +#include <linux/sched.h>
77339 +#include <linux/grsecurity.h>
77340 +#include <linux/grinternal.h>
77341 +#include <linux/errno.h>
77342 +
77343 +void
77344 +gr_log_forkfail(const int retval)
77345 +{
77346 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77347 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77348 + switch (retval) {
77349 + case -EAGAIN:
77350 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77351 + break;
77352 + case -ENOMEM:
77353 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77354 + break;
77355 + }
77356 + }
77357 +#endif
77358 + return;
77359 +}
77360 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77361 new file mode 100644
77362 index 0000000..b7cb191
77363 --- /dev/null
77364 +++ b/grsecurity/grsec_init.c
77365 @@ -0,0 +1,286 @@
77366 +#include <linux/kernel.h>
77367 +#include <linux/sched.h>
77368 +#include <linux/mm.h>
77369 +#include <linux/gracl.h>
77370 +#include <linux/slab.h>
77371 +#include <linux/vmalloc.h>
77372 +#include <linux/percpu.h>
77373 +#include <linux/module.h>
77374 +
77375 +int grsec_enable_ptrace_readexec;
77376 +int grsec_enable_setxid;
77377 +int grsec_enable_symlinkown;
77378 +kgid_t grsec_symlinkown_gid;
77379 +int grsec_enable_brute;
77380 +int grsec_enable_link;
77381 +int grsec_enable_dmesg;
77382 +int grsec_enable_harden_ptrace;
77383 +int grsec_enable_harden_ipc;
77384 +int grsec_enable_fifo;
77385 +int grsec_enable_execlog;
77386 +int grsec_enable_signal;
77387 +int grsec_enable_forkfail;
77388 +int grsec_enable_audit_ptrace;
77389 +int grsec_enable_time;
77390 +int grsec_enable_group;
77391 +kgid_t grsec_audit_gid;
77392 +int grsec_enable_chdir;
77393 +int grsec_enable_mount;
77394 +int grsec_enable_rofs;
77395 +int grsec_deny_new_usb;
77396 +int grsec_enable_chroot_findtask;
77397 +int grsec_enable_chroot_mount;
77398 +int grsec_enable_chroot_shmat;
77399 +int grsec_enable_chroot_fchdir;
77400 +int grsec_enable_chroot_double;
77401 +int grsec_enable_chroot_pivot;
77402 +int grsec_enable_chroot_chdir;
77403 +int grsec_enable_chroot_chmod;
77404 +int grsec_enable_chroot_mknod;
77405 +int grsec_enable_chroot_nice;
77406 +int grsec_enable_chroot_execlog;
77407 +int grsec_enable_chroot_caps;
77408 +int grsec_enable_chroot_sysctl;
77409 +int grsec_enable_chroot_unix;
77410 +int grsec_enable_tpe;
77411 +kgid_t grsec_tpe_gid;
77412 +int grsec_enable_blackhole;
77413 +#ifdef CONFIG_IPV6_MODULE
77414 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77415 +#endif
77416 +int grsec_lastack_retries;
77417 +int grsec_enable_tpe_all;
77418 +int grsec_enable_tpe_invert;
77419 +int grsec_enable_socket_all;
77420 +kgid_t grsec_socket_all_gid;
77421 +int grsec_enable_socket_client;
77422 +kgid_t grsec_socket_client_gid;
77423 +int grsec_enable_socket_server;
77424 +kgid_t grsec_socket_server_gid;
77425 +int grsec_resource_logging;
77426 +int grsec_disable_privio;
77427 +int grsec_enable_log_rwxmaps;
77428 +int grsec_lock;
77429 +
77430 +DEFINE_SPINLOCK(grsec_alert_lock);
77431 +unsigned long grsec_alert_wtime = 0;
77432 +unsigned long grsec_alert_fyet = 0;
77433 +
77434 +DEFINE_SPINLOCK(grsec_audit_lock);
77435 +
77436 +DEFINE_RWLOCK(grsec_exec_file_lock);
77437 +
77438 +char *gr_shared_page[4];
77439 +
77440 +char *gr_alert_log_fmt;
77441 +char *gr_audit_log_fmt;
77442 +char *gr_alert_log_buf;
77443 +char *gr_audit_log_buf;
77444 +
77445 +extern struct gr_arg *gr_usermode;
77446 +extern unsigned char *gr_system_salt;
77447 +extern unsigned char *gr_system_sum;
77448 +
77449 +void __init
77450 +grsecurity_init(void)
77451 +{
77452 + int j;
77453 + /* create the per-cpu shared pages */
77454 +
77455 +#ifdef CONFIG_X86
77456 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77457 +#endif
77458 +
77459 + for (j = 0; j < 4; j++) {
77460 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77461 + if (gr_shared_page[j] == NULL) {
77462 + panic("Unable to allocate grsecurity shared page");
77463 + return;
77464 + }
77465 + }
77466 +
77467 + /* allocate log buffers */
77468 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77469 + if (!gr_alert_log_fmt) {
77470 + panic("Unable to allocate grsecurity alert log format buffer");
77471 + return;
77472 + }
77473 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77474 + if (!gr_audit_log_fmt) {
77475 + panic("Unable to allocate grsecurity audit log format buffer");
77476 + return;
77477 + }
77478 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77479 + if (!gr_alert_log_buf) {
77480 + panic("Unable to allocate grsecurity alert log buffer");
77481 + return;
77482 + }
77483 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77484 + if (!gr_audit_log_buf) {
77485 + panic("Unable to allocate grsecurity audit log buffer");
77486 + return;
77487 + }
77488 +
77489 + /* allocate memory for authentication structure */
77490 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77491 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77492 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77493 +
77494 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77495 + panic("Unable to allocate grsecurity authentication structure");
77496 + return;
77497 + }
77498 +
77499 +#ifdef CONFIG_GRKERNSEC_IO
77500 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77501 + grsec_disable_privio = 1;
77502 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77503 + grsec_disable_privio = 1;
77504 +#else
77505 + grsec_disable_privio = 0;
77506 +#endif
77507 +#endif
77508 +
77509 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77510 + /* for backward compatibility, tpe_invert always defaults to on if
77511 + enabled in the kernel
77512 + */
77513 + grsec_enable_tpe_invert = 1;
77514 +#endif
77515 +
77516 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77517 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77518 + grsec_lock = 1;
77519 +#endif
77520 +
77521 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77522 + grsec_enable_log_rwxmaps = 1;
77523 +#endif
77524 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77525 + grsec_enable_group = 1;
77526 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77527 +#endif
77528 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77529 + grsec_enable_ptrace_readexec = 1;
77530 +#endif
77531 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77532 + grsec_enable_chdir = 1;
77533 +#endif
77534 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77535 + grsec_enable_harden_ptrace = 1;
77536 +#endif
77537 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77538 + grsec_enable_harden_ipc = 1;
77539 +#endif
77540 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77541 + grsec_enable_mount = 1;
77542 +#endif
77543 +#ifdef CONFIG_GRKERNSEC_LINK
77544 + grsec_enable_link = 1;
77545 +#endif
77546 +#ifdef CONFIG_GRKERNSEC_BRUTE
77547 + grsec_enable_brute = 1;
77548 +#endif
77549 +#ifdef CONFIG_GRKERNSEC_DMESG
77550 + grsec_enable_dmesg = 1;
77551 +#endif
77552 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77553 + grsec_enable_blackhole = 1;
77554 + grsec_lastack_retries = 4;
77555 +#endif
77556 +#ifdef CONFIG_GRKERNSEC_FIFO
77557 + grsec_enable_fifo = 1;
77558 +#endif
77559 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77560 + grsec_enable_execlog = 1;
77561 +#endif
77562 +#ifdef CONFIG_GRKERNSEC_SETXID
77563 + grsec_enable_setxid = 1;
77564 +#endif
77565 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77566 + grsec_enable_signal = 1;
77567 +#endif
77568 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77569 + grsec_enable_forkfail = 1;
77570 +#endif
77571 +#ifdef CONFIG_GRKERNSEC_TIME
77572 + grsec_enable_time = 1;
77573 +#endif
77574 +#ifdef CONFIG_GRKERNSEC_RESLOG
77575 + grsec_resource_logging = 1;
77576 +#endif
77577 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77578 + grsec_enable_chroot_findtask = 1;
77579 +#endif
77580 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77581 + grsec_enable_chroot_unix = 1;
77582 +#endif
77583 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77584 + grsec_enable_chroot_mount = 1;
77585 +#endif
77586 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77587 + grsec_enable_chroot_fchdir = 1;
77588 +#endif
77589 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77590 + grsec_enable_chroot_shmat = 1;
77591 +#endif
77592 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77593 + grsec_enable_audit_ptrace = 1;
77594 +#endif
77595 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77596 + grsec_enable_chroot_double = 1;
77597 +#endif
77598 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77599 + grsec_enable_chroot_pivot = 1;
77600 +#endif
77601 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77602 + grsec_enable_chroot_chdir = 1;
77603 +#endif
77604 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77605 + grsec_enable_chroot_chmod = 1;
77606 +#endif
77607 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77608 + grsec_enable_chroot_mknod = 1;
77609 +#endif
77610 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77611 + grsec_enable_chroot_nice = 1;
77612 +#endif
77613 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77614 + grsec_enable_chroot_execlog = 1;
77615 +#endif
77616 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77617 + grsec_enable_chroot_caps = 1;
77618 +#endif
77619 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77620 + grsec_enable_chroot_sysctl = 1;
77621 +#endif
77622 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77623 + grsec_enable_symlinkown = 1;
77624 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77625 +#endif
77626 +#ifdef CONFIG_GRKERNSEC_TPE
77627 + grsec_enable_tpe = 1;
77628 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77629 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77630 + grsec_enable_tpe_all = 1;
77631 +#endif
77632 +#endif
77633 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77634 + grsec_enable_socket_all = 1;
77635 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77636 +#endif
77637 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77638 + grsec_enable_socket_client = 1;
77639 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77640 +#endif
77641 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77642 + grsec_enable_socket_server = 1;
77643 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77644 +#endif
77645 +#endif
77646 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77647 + grsec_deny_new_usb = 1;
77648 +#endif
77649 +
77650 + return;
77651 +}
77652 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77653 new file mode 100644
77654 index 0000000..1773300
77655 --- /dev/null
77656 +++ b/grsecurity/grsec_ipc.c
77657 @@ -0,0 +1,48 @@
77658 +#include <linux/kernel.h>
77659 +#include <linux/mm.h>
77660 +#include <linux/sched.h>
77661 +#include <linux/file.h>
77662 +#include <linux/ipc.h>
77663 +#include <linux/ipc_namespace.h>
77664 +#include <linux/grsecurity.h>
77665 +#include <linux/grinternal.h>
77666 +
77667 +int
77668 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77669 +{
77670 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77671 + int write;
77672 + int orig_granted_mode;
77673 + kuid_t euid;
77674 + kgid_t egid;
77675 +
77676 + if (!grsec_enable_harden_ipc)
77677 + return 1;
77678 +
77679 + euid = current_euid();
77680 + egid = current_egid();
77681 +
77682 + write = requested_mode & 00002;
77683 + orig_granted_mode = ipcp->mode;
77684 +
77685 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77686 + orig_granted_mode >>= 6;
77687 + else {
77688 + /* if likely wrong permissions, lock to user */
77689 + if (orig_granted_mode & 0007)
77690 + orig_granted_mode = 0;
77691 + /* otherwise do a egid-only check */
77692 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77693 + orig_granted_mode >>= 3;
77694 + /* otherwise, no access */
77695 + else
77696 + orig_granted_mode = 0;
77697 + }
77698 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77699 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77700 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77701 + return 0;
77702 + }
77703 +#endif
77704 + return 1;
77705 +}
77706 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77707 new file mode 100644
77708 index 0000000..5e05e20
77709 --- /dev/null
77710 +++ b/grsecurity/grsec_link.c
77711 @@ -0,0 +1,58 @@
77712 +#include <linux/kernel.h>
77713 +#include <linux/sched.h>
77714 +#include <linux/fs.h>
77715 +#include <linux/file.h>
77716 +#include <linux/grinternal.h>
77717 +
77718 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77719 +{
77720 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77721 + const struct inode *link_inode = link->dentry->d_inode;
77722 +
77723 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77724 + /* ignore root-owned links, e.g. /proc/self */
77725 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77726 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77727 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77728 + return 1;
77729 + }
77730 +#endif
77731 + return 0;
77732 +}
77733 +
77734 +int
77735 +gr_handle_follow_link(const struct inode *parent,
77736 + const struct inode *inode,
77737 + const struct dentry *dentry, const struct vfsmount *mnt)
77738 +{
77739 +#ifdef CONFIG_GRKERNSEC_LINK
77740 + const struct cred *cred = current_cred();
77741 +
77742 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77743 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77744 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77745 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77746 + return -EACCES;
77747 + }
77748 +#endif
77749 + return 0;
77750 +}
77751 +
77752 +int
77753 +gr_handle_hardlink(const struct dentry *dentry,
77754 + const struct vfsmount *mnt,
77755 + struct inode *inode, const int mode, const struct filename *to)
77756 +{
77757 +#ifdef CONFIG_GRKERNSEC_LINK
77758 + const struct cred *cred = current_cred();
77759 +
77760 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77761 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77762 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77763 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77764 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77765 + return -EPERM;
77766 + }
77767 +#endif
77768 + return 0;
77769 +}
77770 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77771 new file mode 100644
77772 index 0000000..dbe0a6b
77773 --- /dev/null
77774 +++ b/grsecurity/grsec_log.c
77775 @@ -0,0 +1,341 @@
77776 +#include <linux/kernel.h>
77777 +#include <linux/sched.h>
77778 +#include <linux/file.h>
77779 +#include <linux/tty.h>
77780 +#include <linux/fs.h>
77781 +#include <linux/mm.h>
77782 +#include <linux/grinternal.h>
77783 +
77784 +#ifdef CONFIG_TREE_PREEMPT_RCU
77785 +#define DISABLE_PREEMPT() preempt_disable()
77786 +#define ENABLE_PREEMPT() preempt_enable()
77787 +#else
77788 +#define DISABLE_PREEMPT()
77789 +#define ENABLE_PREEMPT()
77790 +#endif
77791 +
77792 +#define BEGIN_LOCKS(x) \
77793 + DISABLE_PREEMPT(); \
77794 + rcu_read_lock(); \
77795 + read_lock(&tasklist_lock); \
77796 + read_lock(&grsec_exec_file_lock); \
77797 + if (x != GR_DO_AUDIT) \
77798 + spin_lock(&grsec_alert_lock); \
77799 + else \
77800 + spin_lock(&grsec_audit_lock)
77801 +
77802 +#define END_LOCKS(x) \
77803 + if (x != GR_DO_AUDIT) \
77804 + spin_unlock(&grsec_alert_lock); \
77805 + else \
77806 + spin_unlock(&grsec_audit_lock); \
77807 + read_unlock(&grsec_exec_file_lock); \
77808 + read_unlock(&tasklist_lock); \
77809 + rcu_read_unlock(); \
77810 + ENABLE_PREEMPT(); \
77811 + if (x == GR_DONT_AUDIT) \
77812 + gr_handle_alertkill(current)
77813 +
77814 +enum {
77815 + FLOODING,
77816 + NO_FLOODING
77817 +};
77818 +
77819 +extern char *gr_alert_log_fmt;
77820 +extern char *gr_audit_log_fmt;
77821 +extern char *gr_alert_log_buf;
77822 +extern char *gr_audit_log_buf;
77823 +
77824 +static int gr_log_start(int audit)
77825 +{
77826 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77827 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77828 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77829 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77830 + unsigned long curr_secs = get_seconds();
77831 +
77832 + if (audit == GR_DO_AUDIT)
77833 + goto set_fmt;
77834 +
77835 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77836 + grsec_alert_wtime = curr_secs;
77837 + grsec_alert_fyet = 0;
77838 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77839 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77840 + grsec_alert_fyet++;
77841 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77842 + grsec_alert_wtime = curr_secs;
77843 + grsec_alert_fyet++;
77844 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77845 + return FLOODING;
77846 + }
77847 + else return FLOODING;
77848 +
77849 +set_fmt:
77850 +#endif
77851 + memset(buf, 0, PAGE_SIZE);
77852 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77853 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77854 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77855 + } else if (current->signal->curr_ip) {
77856 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77857 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77858 + } else if (gr_acl_is_enabled()) {
77859 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77860 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77861 + } else {
77862 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77863 + strcpy(buf, fmt);
77864 + }
77865 +
77866 + return NO_FLOODING;
77867 +}
77868 +
77869 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77870 + __attribute__ ((format (printf, 2, 0)));
77871 +
77872 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77873 +{
77874 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77875 + unsigned int len = strlen(buf);
77876 +
77877 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77878 +
77879 + return;
77880 +}
77881 +
77882 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77883 + __attribute__ ((format (printf, 2, 3)));
77884 +
77885 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77886 +{
77887 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77888 + unsigned int len = strlen(buf);
77889 + va_list ap;
77890 +
77891 + va_start(ap, msg);
77892 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77893 + va_end(ap);
77894 +
77895 + return;
77896 +}
77897 +
77898 +static void gr_log_end(int audit, int append_default)
77899 +{
77900 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77901 + if (append_default) {
77902 + struct task_struct *task = current;
77903 + struct task_struct *parent = task->real_parent;
77904 + const struct cred *cred = __task_cred(task);
77905 + const struct cred *pcred = __task_cred(parent);
77906 + unsigned int len = strlen(buf);
77907 +
77908 + 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));
77909 + }
77910 +
77911 + printk("%s\n", buf);
77912 +
77913 + return;
77914 +}
77915 +
77916 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77917 +{
77918 + int logtype;
77919 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77920 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77921 + void *voidptr = NULL;
77922 + int num1 = 0, num2 = 0;
77923 + unsigned long ulong1 = 0, ulong2 = 0;
77924 + struct dentry *dentry = NULL;
77925 + struct vfsmount *mnt = NULL;
77926 + struct file *file = NULL;
77927 + struct task_struct *task = NULL;
77928 + struct vm_area_struct *vma = NULL;
77929 + const struct cred *cred, *pcred;
77930 + va_list ap;
77931 +
77932 + BEGIN_LOCKS(audit);
77933 + logtype = gr_log_start(audit);
77934 + if (logtype == FLOODING) {
77935 + END_LOCKS(audit);
77936 + return;
77937 + }
77938 + va_start(ap, argtypes);
77939 + switch (argtypes) {
77940 + case GR_TTYSNIFF:
77941 + task = va_arg(ap, struct task_struct *);
77942 + 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));
77943 + break;
77944 + case GR_SYSCTL_HIDDEN:
77945 + str1 = va_arg(ap, char *);
77946 + gr_log_middle_varargs(audit, msg, result, str1);
77947 + break;
77948 + case GR_RBAC:
77949 + dentry = va_arg(ap, struct dentry *);
77950 + mnt = va_arg(ap, struct vfsmount *);
77951 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77952 + break;
77953 + case GR_RBAC_STR:
77954 + dentry = va_arg(ap, struct dentry *);
77955 + mnt = va_arg(ap, struct vfsmount *);
77956 + str1 = va_arg(ap, char *);
77957 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77958 + break;
77959 + case GR_STR_RBAC:
77960 + str1 = va_arg(ap, char *);
77961 + dentry = va_arg(ap, struct dentry *);
77962 + mnt = va_arg(ap, struct vfsmount *);
77963 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77964 + break;
77965 + case GR_RBAC_MODE2:
77966 + dentry = va_arg(ap, struct dentry *);
77967 + mnt = va_arg(ap, struct vfsmount *);
77968 + str1 = va_arg(ap, char *);
77969 + str2 = va_arg(ap, char *);
77970 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77971 + break;
77972 + case GR_RBAC_MODE3:
77973 + dentry = va_arg(ap, struct dentry *);
77974 + mnt = va_arg(ap, struct vfsmount *);
77975 + str1 = va_arg(ap, char *);
77976 + str2 = va_arg(ap, char *);
77977 + str3 = va_arg(ap, char *);
77978 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77979 + break;
77980 + case GR_FILENAME:
77981 + dentry = va_arg(ap, struct dentry *);
77982 + mnt = va_arg(ap, struct vfsmount *);
77983 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77984 + break;
77985 + case GR_STR_FILENAME:
77986 + str1 = va_arg(ap, char *);
77987 + dentry = va_arg(ap, struct dentry *);
77988 + mnt = va_arg(ap, struct vfsmount *);
77989 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77990 + break;
77991 + case GR_FILENAME_STR:
77992 + dentry = va_arg(ap, struct dentry *);
77993 + mnt = va_arg(ap, struct vfsmount *);
77994 + str1 = va_arg(ap, char *);
77995 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77996 + break;
77997 + case GR_FILENAME_TWO_INT:
77998 + dentry = va_arg(ap, struct dentry *);
77999 + mnt = va_arg(ap, struct vfsmount *);
78000 + num1 = va_arg(ap, int);
78001 + num2 = va_arg(ap, int);
78002 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78003 + break;
78004 + case GR_FILENAME_TWO_INT_STR:
78005 + dentry = va_arg(ap, struct dentry *);
78006 + mnt = va_arg(ap, struct vfsmount *);
78007 + num1 = va_arg(ap, int);
78008 + num2 = va_arg(ap, int);
78009 + str1 = va_arg(ap, char *);
78010 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78011 + break;
78012 + case GR_TEXTREL:
78013 + file = va_arg(ap, struct file *);
78014 + ulong1 = va_arg(ap, unsigned long);
78015 + ulong2 = va_arg(ap, unsigned long);
78016 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78017 + break;
78018 + case GR_PTRACE:
78019 + task = va_arg(ap, struct task_struct *);
78020 + 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));
78021 + break;
78022 + case GR_RESOURCE:
78023 + task = va_arg(ap, struct task_struct *);
78024 + cred = __task_cred(task);
78025 + pcred = __task_cred(task->real_parent);
78026 + ulong1 = va_arg(ap, unsigned long);
78027 + str1 = va_arg(ap, char *);
78028 + ulong2 = va_arg(ap, unsigned long);
78029 + 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));
78030 + break;
78031 + case GR_CAP:
78032 + task = va_arg(ap, struct task_struct *);
78033 + cred = __task_cred(task);
78034 + pcred = __task_cred(task->real_parent);
78035 + str1 = va_arg(ap, char *);
78036 + 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));
78037 + break;
78038 + case GR_SIG:
78039 + str1 = va_arg(ap, char *);
78040 + voidptr = va_arg(ap, void *);
78041 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78042 + break;
78043 + case GR_SIG2:
78044 + task = va_arg(ap, struct task_struct *);
78045 + cred = __task_cred(task);
78046 + pcred = __task_cred(task->real_parent);
78047 + num1 = va_arg(ap, int);
78048 + 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));
78049 + break;
78050 + case GR_CRASH1:
78051 + task = va_arg(ap, struct task_struct *);
78052 + cred = __task_cred(task);
78053 + pcred = __task_cred(task->real_parent);
78054 + ulong1 = va_arg(ap, unsigned long);
78055 + 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);
78056 + break;
78057 + case GR_CRASH2:
78058 + task = va_arg(ap, struct task_struct *);
78059 + cred = __task_cred(task);
78060 + pcred = __task_cred(task->real_parent);
78061 + ulong1 = va_arg(ap, unsigned long);
78062 + 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);
78063 + break;
78064 + case GR_RWXMAP:
78065 + file = va_arg(ap, struct file *);
78066 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78067 + break;
78068 + case GR_RWXMAPVMA:
78069 + vma = va_arg(ap, struct vm_area_struct *);
78070 + if (vma->vm_file)
78071 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78072 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78073 + str1 = "<stack>";
78074 + else if (vma->vm_start <= current->mm->brk &&
78075 + vma->vm_end >= current->mm->start_brk)
78076 + str1 = "<heap>";
78077 + else
78078 + str1 = "<anonymous mapping>";
78079 + gr_log_middle_varargs(audit, msg, str1);
78080 + break;
78081 + case GR_PSACCT:
78082 + {
78083 + unsigned int wday, cday;
78084 + __u8 whr, chr;
78085 + __u8 wmin, cmin;
78086 + __u8 wsec, csec;
78087 + char cur_tty[64] = { 0 };
78088 + char parent_tty[64] = { 0 };
78089 +
78090 + task = va_arg(ap, struct task_struct *);
78091 + wday = va_arg(ap, unsigned int);
78092 + cday = va_arg(ap, unsigned int);
78093 + whr = va_arg(ap, int);
78094 + chr = va_arg(ap, int);
78095 + wmin = va_arg(ap, int);
78096 + cmin = va_arg(ap, int);
78097 + wsec = va_arg(ap, int);
78098 + csec = va_arg(ap, int);
78099 + ulong1 = va_arg(ap, unsigned long);
78100 + cred = __task_cred(task);
78101 + pcred = __task_cred(task->real_parent);
78102 +
78103 + 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));
78104 + }
78105 + break;
78106 + default:
78107 + gr_log_middle(audit, msg, ap);
78108 + }
78109 + va_end(ap);
78110 + // these don't need DEFAULTSECARGS printed on the end
78111 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78112 + gr_log_end(audit, 0);
78113 + else
78114 + gr_log_end(audit, 1);
78115 + END_LOCKS(audit);
78116 +}
78117 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78118 new file mode 100644
78119 index 0000000..0e39d8c
78120 --- /dev/null
78121 +++ b/grsecurity/grsec_mem.c
78122 @@ -0,0 +1,48 @@
78123 +#include <linux/kernel.h>
78124 +#include <linux/sched.h>
78125 +#include <linux/mm.h>
78126 +#include <linux/mman.h>
78127 +#include <linux/module.h>
78128 +#include <linux/grinternal.h>
78129 +
78130 +void gr_handle_msr_write(void)
78131 +{
78132 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78133 + return;
78134 +}
78135 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78136 +
78137 +void
78138 +gr_handle_ioperm(void)
78139 +{
78140 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78141 + return;
78142 +}
78143 +
78144 +void
78145 +gr_handle_iopl(void)
78146 +{
78147 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78148 + return;
78149 +}
78150 +
78151 +void
78152 +gr_handle_mem_readwrite(u64 from, u64 to)
78153 +{
78154 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78155 + return;
78156 +}
78157 +
78158 +void
78159 +gr_handle_vm86(void)
78160 +{
78161 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78162 + return;
78163 +}
78164 +
78165 +void
78166 +gr_log_badprocpid(const char *entry)
78167 +{
78168 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78169 + return;
78170 +}
78171 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78172 new file mode 100644
78173 index 0000000..cd9e124
78174 --- /dev/null
78175 +++ b/grsecurity/grsec_mount.c
78176 @@ -0,0 +1,65 @@
78177 +#include <linux/kernel.h>
78178 +#include <linux/sched.h>
78179 +#include <linux/mount.h>
78180 +#include <linux/major.h>
78181 +#include <linux/grsecurity.h>
78182 +#include <linux/grinternal.h>
78183 +
78184 +void
78185 +gr_log_remount(const char *devname, const int retval)
78186 +{
78187 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78188 + if (grsec_enable_mount && (retval >= 0))
78189 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78190 +#endif
78191 + return;
78192 +}
78193 +
78194 +void
78195 +gr_log_unmount(const char *devname, const int retval)
78196 +{
78197 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78198 + if (grsec_enable_mount && (retval >= 0))
78199 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78200 +#endif
78201 + return;
78202 +}
78203 +
78204 +void
78205 +gr_log_mount(const char *from, const char *to, const int retval)
78206 +{
78207 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78208 + if (grsec_enable_mount && (retval >= 0))
78209 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78210 +#endif
78211 + return;
78212 +}
78213 +
78214 +int
78215 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78216 +{
78217 +#ifdef CONFIG_GRKERNSEC_ROFS
78218 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78219 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78220 + return -EPERM;
78221 + } else
78222 + return 0;
78223 +#endif
78224 + return 0;
78225 +}
78226 +
78227 +int
78228 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78229 +{
78230 +#ifdef CONFIG_GRKERNSEC_ROFS
78231 + struct inode *inode = dentry->d_inode;
78232 +
78233 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78234 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78235 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78236 + return -EPERM;
78237 + } else
78238 + return 0;
78239 +#endif
78240 + return 0;
78241 +}
78242 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78243 new file mode 100644
78244 index 0000000..6ee9d50
78245 --- /dev/null
78246 +++ b/grsecurity/grsec_pax.c
78247 @@ -0,0 +1,45 @@
78248 +#include <linux/kernel.h>
78249 +#include <linux/sched.h>
78250 +#include <linux/mm.h>
78251 +#include <linux/file.h>
78252 +#include <linux/grinternal.h>
78253 +#include <linux/grsecurity.h>
78254 +
78255 +void
78256 +gr_log_textrel(struct vm_area_struct * vma)
78257 +{
78258 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78259 + if (grsec_enable_log_rwxmaps)
78260 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78261 +#endif
78262 + return;
78263 +}
78264 +
78265 +void gr_log_ptgnustack(struct file *file)
78266 +{
78267 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78268 + if (grsec_enable_log_rwxmaps)
78269 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78270 +#endif
78271 + return;
78272 +}
78273 +
78274 +void
78275 +gr_log_rwxmmap(struct file *file)
78276 +{
78277 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78278 + if (grsec_enable_log_rwxmaps)
78279 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78280 +#endif
78281 + return;
78282 +}
78283 +
78284 +void
78285 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78286 +{
78287 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78288 + if (grsec_enable_log_rwxmaps)
78289 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78290 +#endif
78291 + return;
78292 +}
78293 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78294 new file mode 100644
78295 index 0000000..2005a3a
78296 --- /dev/null
78297 +++ b/grsecurity/grsec_proc.c
78298 @@ -0,0 +1,20 @@
78299 +#include <linux/kernel.h>
78300 +#include <linux/sched.h>
78301 +#include <linux/grsecurity.h>
78302 +#include <linux/grinternal.h>
78303 +
78304 +int gr_proc_is_restricted(void)
78305 +{
78306 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78307 + const struct cred *cred = current_cred();
78308 +#endif
78309 +
78310 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78311 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78312 + return -EACCES;
78313 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78314 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78315 + return -EACCES;
78316 +#endif
78317 + return 0;
78318 +}
78319 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78320 new file mode 100644
78321 index 0000000..f7f29aa
78322 --- /dev/null
78323 +++ b/grsecurity/grsec_ptrace.c
78324 @@ -0,0 +1,30 @@
78325 +#include <linux/kernel.h>
78326 +#include <linux/sched.h>
78327 +#include <linux/grinternal.h>
78328 +#include <linux/security.h>
78329 +
78330 +void
78331 +gr_audit_ptrace(struct task_struct *task)
78332 +{
78333 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78334 + if (grsec_enable_audit_ptrace)
78335 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78336 +#endif
78337 + return;
78338 +}
78339 +
78340 +int
78341 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78342 +{
78343 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78344 + const struct dentry *dentry = file->f_path.dentry;
78345 + const struct vfsmount *mnt = file->f_path.mnt;
78346 +
78347 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78348 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78349 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78350 + return -EACCES;
78351 + }
78352 +#endif
78353 + return 0;
78354 +}
78355 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78356 new file mode 100644
78357 index 0000000..3860c7e
78358 --- /dev/null
78359 +++ b/grsecurity/grsec_sig.c
78360 @@ -0,0 +1,236 @@
78361 +#include <linux/kernel.h>
78362 +#include <linux/sched.h>
78363 +#include <linux/fs.h>
78364 +#include <linux/delay.h>
78365 +#include <linux/grsecurity.h>
78366 +#include <linux/grinternal.h>
78367 +#include <linux/hardirq.h>
78368 +
78369 +char *signames[] = {
78370 + [SIGSEGV] = "Segmentation fault",
78371 + [SIGILL] = "Illegal instruction",
78372 + [SIGABRT] = "Abort",
78373 + [SIGBUS] = "Invalid alignment/Bus error"
78374 +};
78375 +
78376 +void
78377 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78378 +{
78379 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78380 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78381 + (sig == SIGABRT) || (sig == SIGBUS))) {
78382 + if (task_pid_nr(t) == task_pid_nr(current)) {
78383 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78384 + } else {
78385 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78386 + }
78387 + }
78388 +#endif
78389 + return;
78390 +}
78391 +
78392 +int
78393 +gr_handle_signal(const struct task_struct *p, const int sig)
78394 +{
78395 +#ifdef CONFIG_GRKERNSEC
78396 + /* ignore the 0 signal for protected task checks */
78397 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78398 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78399 + return -EPERM;
78400 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78401 + return -EPERM;
78402 + }
78403 +#endif
78404 + return 0;
78405 +}
78406 +
78407 +#ifdef CONFIG_GRKERNSEC
78408 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78409 +
78410 +int gr_fake_force_sig(int sig, struct task_struct *t)
78411 +{
78412 + unsigned long int flags;
78413 + int ret, blocked, ignored;
78414 + struct k_sigaction *action;
78415 +
78416 + spin_lock_irqsave(&t->sighand->siglock, flags);
78417 + action = &t->sighand->action[sig-1];
78418 + ignored = action->sa.sa_handler == SIG_IGN;
78419 + blocked = sigismember(&t->blocked, sig);
78420 + if (blocked || ignored) {
78421 + action->sa.sa_handler = SIG_DFL;
78422 + if (blocked) {
78423 + sigdelset(&t->blocked, sig);
78424 + recalc_sigpending_and_wake(t);
78425 + }
78426 + }
78427 + if (action->sa.sa_handler == SIG_DFL)
78428 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78429 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78430 +
78431 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78432 +
78433 + return ret;
78434 +}
78435 +#endif
78436 +
78437 +#define GR_USER_BAN_TIME (15 * 60)
78438 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78439 +
78440 +void gr_handle_brute_attach(int dumpable)
78441 +{
78442 +#ifdef CONFIG_GRKERNSEC_BRUTE
78443 + struct task_struct *p = current;
78444 + kuid_t uid = GLOBAL_ROOT_UID;
78445 + int daemon = 0;
78446 +
78447 + if (!grsec_enable_brute)
78448 + return;
78449 +
78450 + rcu_read_lock();
78451 + read_lock(&tasklist_lock);
78452 + read_lock(&grsec_exec_file_lock);
78453 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78454 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78455 + p->real_parent->brute = 1;
78456 + daemon = 1;
78457 + } else {
78458 + const struct cred *cred = __task_cred(p), *cred2;
78459 + struct task_struct *tsk, *tsk2;
78460 +
78461 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78462 + struct user_struct *user;
78463 +
78464 + uid = cred->uid;
78465 +
78466 + /* this is put upon execution past expiration */
78467 + user = find_user(uid);
78468 + if (user == NULL)
78469 + goto unlock;
78470 + user->suid_banned = 1;
78471 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78472 + if (user->suid_ban_expires == ~0UL)
78473 + user->suid_ban_expires--;
78474 +
78475 + /* only kill other threads of the same binary, from the same user */
78476 + do_each_thread(tsk2, tsk) {
78477 + cred2 = __task_cred(tsk);
78478 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78479 + gr_fake_force_sig(SIGKILL, tsk);
78480 + } while_each_thread(tsk2, tsk);
78481 + }
78482 + }
78483 +unlock:
78484 + read_unlock(&grsec_exec_file_lock);
78485 + read_unlock(&tasklist_lock);
78486 + rcu_read_unlock();
78487 +
78488 + if (gr_is_global_nonroot(uid))
78489 + 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);
78490 + else if (daemon)
78491 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78492 +
78493 +#endif
78494 + return;
78495 +}
78496 +
78497 +void gr_handle_brute_check(void)
78498 +{
78499 +#ifdef CONFIG_GRKERNSEC_BRUTE
78500 + struct task_struct *p = current;
78501 +
78502 + if (unlikely(p->brute)) {
78503 + if (!grsec_enable_brute)
78504 + p->brute = 0;
78505 + else if (time_before(get_seconds(), p->brute_expires))
78506 + msleep(30 * 1000);
78507 + }
78508 +#endif
78509 + return;
78510 +}
78511 +
78512 +void gr_handle_kernel_exploit(void)
78513 +{
78514 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78515 + const struct cred *cred;
78516 + struct task_struct *tsk, *tsk2;
78517 + struct user_struct *user;
78518 + kuid_t uid;
78519 +
78520 + if (in_irq() || in_serving_softirq() || in_nmi())
78521 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78522 +
78523 + uid = current_uid();
78524 +
78525 + if (gr_is_global_root(uid))
78526 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78527 + else {
78528 + /* kill all the processes of this user, hold a reference
78529 + to their creds struct, and prevent them from creating
78530 + another process until system reset
78531 + */
78532 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78533 + GR_GLOBAL_UID(uid));
78534 + /* we intentionally leak this ref */
78535 + user = get_uid(current->cred->user);
78536 + if (user)
78537 + user->kernel_banned = 1;
78538 +
78539 + /* kill all processes of this user */
78540 + read_lock(&tasklist_lock);
78541 + do_each_thread(tsk2, tsk) {
78542 + cred = __task_cred(tsk);
78543 + if (uid_eq(cred->uid, uid))
78544 + gr_fake_force_sig(SIGKILL, tsk);
78545 + } while_each_thread(tsk2, tsk);
78546 + read_unlock(&tasklist_lock);
78547 + }
78548 +#endif
78549 +}
78550 +
78551 +#ifdef CONFIG_GRKERNSEC_BRUTE
78552 +static bool suid_ban_expired(struct user_struct *user)
78553 +{
78554 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78555 + user->suid_banned = 0;
78556 + user->suid_ban_expires = 0;
78557 + free_uid(user);
78558 + return true;
78559 + }
78560 +
78561 + return false;
78562 +}
78563 +#endif
78564 +
78565 +int gr_process_kernel_exec_ban(void)
78566 +{
78567 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78568 + if (unlikely(current->cred->user->kernel_banned))
78569 + return -EPERM;
78570 +#endif
78571 + return 0;
78572 +}
78573 +
78574 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78575 +{
78576 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78577 + if (unlikely(user->kernel_banned))
78578 + gr_fake_force_sig(SIGKILL, current);
78579 +#endif
78580 + return 0;
78581 +}
78582 +
78583 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78584 +{
78585 +#ifdef CONFIG_GRKERNSEC_BRUTE
78586 + struct user_struct *user = current->cred->user;
78587 + if (unlikely(user->suid_banned)) {
78588 + if (suid_ban_expired(user))
78589 + return 0;
78590 + /* disallow execution of suid binaries only */
78591 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78592 + return -EPERM;
78593 + }
78594 +#endif
78595 + return 0;
78596 +}
78597 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78598 new file mode 100644
78599 index 0000000..e3650b6
78600 --- /dev/null
78601 +++ b/grsecurity/grsec_sock.c
78602 @@ -0,0 +1,244 @@
78603 +#include <linux/kernel.h>
78604 +#include <linux/module.h>
78605 +#include <linux/sched.h>
78606 +#include <linux/file.h>
78607 +#include <linux/net.h>
78608 +#include <linux/in.h>
78609 +#include <linux/ip.h>
78610 +#include <net/sock.h>
78611 +#include <net/inet_sock.h>
78612 +#include <linux/grsecurity.h>
78613 +#include <linux/grinternal.h>
78614 +#include <linux/gracl.h>
78615 +
78616 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78617 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78618 +
78619 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78620 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78621 +
78622 +#ifdef CONFIG_UNIX_MODULE
78623 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78624 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78625 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78626 +EXPORT_SYMBOL_GPL(gr_handle_create);
78627 +#endif
78628 +
78629 +#ifdef CONFIG_GRKERNSEC
78630 +#define gr_conn_table_size 32749
78631 +struct conn_table_entry {
78632 + struct conn_table_entry *next;
78633 + struct signal_struct *sig;
78634 +};
78635 +
78636 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78637 +DEFINE_SPINLOCK(gr_conn_table_lock);
78638 +
78639 +extern const char * gr_socktype_to_name(unsigned char type);
78640 +extern const char * gr_proto_to_name(unsigned char proto);
78641 +extern const char * gr_sockfamily_to_name(unsigned char family);
78642 +
78643 +static __inline__ int
78644 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78645 +{
78646 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78647 +}
78648 +
78649 +static __inline__ int
78650 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78651 + __u16 sport, __u16 dport)
78652 +{
78653 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78654 + sig->gr_sport == sport && sig->gr_dport == dport))
78655 + return 1;
78656 + else
78657 + return 0;
78658 +}
78659 +
78660 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78661 +{
78662 + struct conn_table_entry **match;
78663 + unsigned int index;
78664 +
78665 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78666 + sig->gr_sport, sig->gr_dport,
78667 + gr_conn_table_size);
78668 +
78669 + newent->sig = sig;
78670 +
78671 + match = &gr_conn_table[index];
78672 + newent->next = *match;
78673 + *match = newent;
78674 +
78675 + return;
78676 +}
78677 +
78678 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78679 +{
78680 + struct conn_table_entry *match, *last = NULL;
78681 + unsigned int index;
78682 +
78683 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78684 + sig->gr_sport, sig->gr_dport,
78685 + gr_conn_table_size);
78686 +
78687 + match = gr_conn_table[index];
78688 + while (match && !conn_match(match->sig,
78689 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78690 + sig->gr_dport)) {
78691 + last = match;
78692 + match = match->next;
78693 + }
78694 +
78695 + if (match) {
78696 + if (last)
78697 + last->next = match->next;
78698 + else
78699 + gr_conn_table[index] = NULL;
78700 + kfree(match);
78701 + }
78702 +
78703 + return;
78704 +}
78705 +
78706 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78707 + __u16 sport, __u16 dport)
78708 +{
78709 + struct conn_table_entry *match;
78710 + unsigned int index;
78711 +
78712 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78713 +
78714 + match = gr_conn_table[index];
78715 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78716 + match = match->next;
78717 +
78718 + if (match)
78719 + return match->sig;
78720 + else
78721 + return NULL;
78722 +}
78723 +
78724 +#endif
78725 +
78726 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78727 +{
78728 +#ifdef CONFIG_GRKERNSEC
78729 + struct signal_struct *sig = current->signal;
78730 + struct conn_table_entry *newent;
78731 +
78732 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78733 + if (newent == NULL)
78734 + return;
78735 + /* no bh lock needed since we are called with bh disabled */
78736 + spin_lock(&gr_conn_table_lock);
78737 + gr_del_task_from_ip_table_nolock(sig);
78738 + sig->gr_saddr = inet->inet_rcv_saddr;
78739 + sig->gr_daddr = inet->inet_daddr;
78740 + sig->gr_sport = inet->inet_sport;
78741 + sig->gr_dport = inet->inet_dport;
78742 + gr_add_to_task_ip_table_nolock(sig, newent);
78743 + spin_unlock(&gr_conn_table_lock);
78744 +#endif
78745 + return;
78746 +}
78747 +
78748 +void gr_del_task_from_ip_table(struct task_struct *task)
78749 +{
78750 +#ifdef CONFIG_GRKERNSEC
78751 + spin_lock_bh(&gr_conn_table_lock);
78752 + gr_del_task_from_ip_table_nolock(task->signal);
78753 + spin_unlock_bh(&gr_conn_table_lock);
78754 +#endif
78755 + return;
78756 +}
78757 +
78758 +void
78759 +gr_attach_curr_ip(const struct sock *sk)
78760 +{
78761 +#ifdef CONFIG_GRKERNSEC
78762 + struct signal_struct *p, *set;
78763 + const struct inet_sock *inet = inet_sk(sk);
78764 +
78765 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78766 + return;
78767 +
78768 + set = current->signal;
78769 +
78770 + spin_lock_bh(&gr_conn_table_lock);
78771 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78772 + inet->inet_dport, inet->inet_sport);
78773 + if (unlikely(p != NULL)) {
78774 + set->curr_ip = p->curr_ip;
78775 + set->used_accept = 1;
78776 + gr_del_task_from_ip_table_nolock(p);
78777 + spin_unlock_bh(&gr_conn_table_lock);
78778 + return;
78779 + }
78780 + spin_unlock_bh(&gr_conn_table_lock);
78781 +
78782 + set->curr_ip = inet->inet_daddr;
78783 + set->used_accept = 1;
78784 +#endif
78785 + return;
78786 +}
78787 +
78788 +int
78789 +gr_handle_sock_all(const int family, const int type, const int protocol)
78790 +{
78791 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78792 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78793 + (family != AF_UNIX)) {
78794 + if (family == AF_INET)
78795 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78796 + else
78797 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78798 + return -EACCES;
78799 + }
78800 +#endif
78801 + return 0;
78802 +}
78803 +
78804 +int
78805 +gr_handle_sock_server(const struct sockaddr *sck)
78806 +{
78807 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78808 + if (grsec_enable_socket_server &&
78809 + in_group_p(grsec_socket_server_gid) &&
78810 + sck && (sck->sa_family != AF_UNIX) &&
78811 + (sck->sa_family != AF_LOCAL)) {
78812 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78813 + return -EACCES;
78814 + }
78815 +#endif
78816 + return 0;
78817 +}
78818 +
78819 +int
78820 +gr_handle_sock_server_other(const struct sock *sck)
78821 +{
78822 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78823 + if (grsec_enable_socket_server &&
78824 + in_group_p(grsec_socket_server_gid) &&
78825 + sck && (sck->sk_family != AF_UNIX) &&
78826 + (sck->sk_family != AF_LOCAL)) {
78827 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78828 + return -EACCES;
78829 + }
78830 +#endif
78831 + return 0;
78832 +}
78833 +
78834 +int
78835 +gr_handle_sock_client(const struct sockaddr *sck)
78836 +{
78837 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78838 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78839 + sck && (sck->sa_family != AF_UNIX) &&
78840 + (sck->sa_family != AF_LOCAL)) {
78841 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78842 + return -EACCES;
78843 + }
78844 +#endif
78845 + return 0;
78846 +}
78847 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78848 new file mode 100644
78849 index 0000000..8159888
78850 --- /dev/null
78851 +++ b/grsecurity/grsec_sysctl.c
78852 @@ -0,0 +1,479 @@
78853 +#include <linux/kernel.h>
78854 +#include <linux/sched.h>
78855 +#include <linux/sysctl.h>
78856 +#include <linux/grsecurity.h>
78857 +#include <linux/grinternal.h>
78858 +
78859 +int
78860 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78861 +{
78862 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78863 + if (dirname == NULL || name == NULL)
78864 + return 0;
78865 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78866 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78867 + return -EACCES;
78868 + }
78869 +#endif
78870 + return 0;
78871 +}
78872 +
78873 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78874 +static int __maybe_unused __read_only one = 1;
78875 +#endif
78876 +
78877 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78878 + defined(CONFIG_GRKERNSEC_DENYUSB)
78879 +struct ctl_table grsecurity_table[] = {
78880 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78881 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78882 +#ifdef CONFIG_GRKERNSEC_IO
78883 + {
78884 + .procname = "disable_priv_io",
78885 + .data = &grsec_disable_privio,
78886 + .maxlen = sizeof(int),
78887 + .mode = 0600,
78888 + .proc_handler = &proc_dointvec,
78889 + },
78890 +#endif
78891 +#endif
78892 +#ifdef CONFIG_GRKERNSEC_LINK
78893 + {
78894 + .procname = "linking_restrictions",
78895 + .data = &grsec_enable_link,
78896 + .maxlen = sizeof(int),
78897 + .mode = 0600,
78898 + .proc_handler = &proc_dointvec,
78899 + },
78900 +#endif
78901 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78902 + {
78903 + .procname = "enforce_symlinksifowner",
78904 + .data = &grsec_enable_symlinkown,
78905 + .maxlen = sizeof(int),
78906 + .mode = 0600,
78907 + .proc_handler = &proc_dointvec,
78908 + },
78909 + {
78910 + .procname = "symlinkown_gid",
78911 + .data = &grsec_symlinkown_gid,
78912 + .maxlen = sizeof(int),
78913 + .mode = 0600,
78914 + .proc_handler = &proc_dointvec,
78915 + },
78916 +#endif
78917 +#ifdef CONFIG_GRKERNSEC_BRUTE
78918 + {
78919 + .procname = "deter_bruteforce",
78920 + .data = &grsec_enable_brute,
78921 + .maxlen = sizeof(int),
78922 + .mode = 0600,
78923 + .proc_handler = &proc_dointvec,
78924 + },
78925 +#endif
78926 +#ifdef CONFIG_GRKERNSEC_FIFO
78927 + {
78928 + .procname = "fifo_restrictions",
78929 + .data = &grsec_enable_fifo,
78930 + .maxlen = sizeof(int),
78931 + .mode = 0600,
78932 + .proc_handler = &proc_dointvec,
78933 + },
78934 +#endif
78935 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78936 + {
78937 + .procname = "ptrace_readexec",
78938 + .data = &grsec_enable_ptrace_readexec,
78939 + .maxlen = sizeof(int),
78940 + .mode = 0600,
78941 + .proc_handler = &proc_dointvec,
78942 + },
78943 +#endif
78944 +#ifdef CONFIG_GRKERNSEC_SETXID
78945 + {
78946 + .procname = "consistent_setxid",
78947 + .data = &grsec_enable_setxid,
78948 + .maxlen = sizeof(int),
78949 + .mode = 0600,
78950 + .proc_handler = &proc_dointvec,
78951 + },
78952 +#endif
78953 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78954 + {
78955 + .procname = "ip_blackhole",
78956 + .data = &grsec_enable_blackhole,
78957 + .maxlen = sizeof(int),
78958 + .mode = 0600,
78959 + .proc_handler = &proc_dointvec,
78960 + },
78961 + {
78962 + .procname = "lastack_retries",
78963 + .data = &grsec_lastack_retries,
78964 + .maxlen = sizeof(int),
78965 + .mode = 0600,
78966 + .proc_handler = &proc_dointvec,
78967 + },
78968 +#endif
78969 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78970 + {
78971 + .procname = "exec_logging",
78972 + .data = &grsec_enable_execlog,
78973 + .maxlen = sizeof(int),
78974 + .mode = 0600,
78975 + .proc_handler = &proc_dointvec,
78976 + },
78977 +#endif
78978 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78979 + {
78980 + .procname = "rwxmap_logging",
78981 + .data = &grsec_enable_log_rwxmaps,
78982 + .maxlen = sizeof(int),
78983 + .mode = 0600,
78984 + .proc_handler = &proc_dointvec,
78985 + },
78986 +#endif
78987 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78988 + {
78989 + .procname = "signal_logging",
78990 + .data = &grsec_enable_signal,
78991 + .maxlen = sizeof(int),
78992 + .mode = 0600,
78993 + .proc_handler = &proc_dointvec,
78994 + },
78995 +#endif
78996 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78997 + {
78998 + .procname = "forkfail_logging",
78999 + .data = &grsec_enable_forkfail,
79000 + .maxlen = sizeof(int),
79001 + .mode = 0600,
79002 + .proc_handler = &proc_dointvec,
79003 + },
79004 +#endif
79005 +#ifdef CONFIG_GRKERNSEC_TIME
79006 + {
79007 + .procname = "timechange_logging",
79008 + .data = &grsec_enable_time,
79009 + .maxlen = sizeof(int),
79010 + .mode = 0600,
79011 + .proc_handler = &proc_dointvec,
79012 + },
79013 +#endif
79014 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79015 + {
79016 + .procname = "chroot_deny_shmat",
79017 + .data = &grsec_enable_chroot_shmat,
79018 + .maxlen = sizeof(int),
79019 + .mode = 0600,
79020 + .proc_handler = &proc_dointvec,
79021 + },
79022 +#endif
79023 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79024 + {
79025 + .procname = "chroot_deny_unix",
79026 + .data = &grsec_enable_chroot_unix,
79027 + .maxlen = sizeof(int),
79028 + .mode = 0600,
79029 + .proc_handler = &proc_dointvec,
79030 + },
79031 +#endif
79032 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79033 + {
79034 + .procname = "chroot_deny_mount",
79035 + .data = &grsec_enable_chroot_mount,
79036 + .maxlen = sizeof(int),
79037 + .mode = 0600,
79038 + .proc_handler = &proc_dointvec,
79039 + },
79040 +#endif
79041 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79042 + {
79043 + .procname = "chroot_deny_fchdir",
79044 + .data = &grsec_enable_chroot_fchdir,
79045 + .maxlen = sizeof(int),
79046 + .mode = 0600,
79047 + .proc_handler = &proc_dointvec,
79048 + },
79049 +#endif
79050 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79051 + {
79052 + .procname = "chroot_deny_chroot",
79053 + .data = &grsec_enable_chroot_double,
79054 + .maxlen = sizeof(int),
79055 + .mode = 0600,
79056 + .proc_handler = &proc_dointvec,
79057 + },
79058 +#endif
79059 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79060 + {
79061 + .procname = "chroot_deny_pivot",
79062 + .data = &grsec_enable_chroot_pivot,
79063 + .maxlen = sizeof(int),
79064 + .mode = 0600,
79065 + .proc_handler = &proc_dointvec,
79066 + },
79067 +#endif
79068 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79069 + {
79070 + .procname = "chroot_enforce_chdir",
79071 + .data = &grsec_enable_chroot_chdir,
79072 + .maxlen = sizeof(int),
79073 + .mode = 0600,
79074 + .proc_handler = &proc_dointvec,
79075 + },
79076 +#endif
79077 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79078 + {
79079 + .procname = "chroot_deny_chmod",
79080 + .data = &grsec_enable_chroot_chmod,
79081 + .maxlen = sizeof(int),
79082 + .mode = 0600,
79083 + .proc_handler = &proc_dointvec,
79084 + },
79085 +#endif
79086 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79087 + {
79088 + .procname = "chroot_deny_mknod",
79089 + .data = &grsec_enable_chroot_mknod,
79090 + .maxlen = sizeof(int),
79091 + .mode = 0600,
79092 + .proc_handler = &proc_dointvec,
79093 + },
79094 +#endif
79095 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79096 + {
79097 + .procname = "chroot_restrict_nice",
79098 + .data = &grsec_enable_chroot_nice,
79099 + .maxlen = sizeof(int),
79100 + .mode = 0600,
79101 + .proc_handler = &proc_dointvec,
79102 + },
79103 +#endif
79104 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79105 + {
79106 + .procname = "chroot_execlog",
79107 + .data = &grsec_enable_chroot_execlog,
79108 + .maxlen = sizeof(int),
79109 + .mode = 0600,
79110 + .proc_handler = &proc_dointvec,
79111 + },
79112 +#endif
79113 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79114 + {
79115 + .procname = "chroot_caps",
79116 + .data = &grsec_enable_chroot_caps,
79117 + .maxlen = sizeof(int),
79118 + .mode = 0600,
79119 + .proc_handler = &proc_dointvec,
79120 + },
79121 +#endif
79122 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79123 + {
79124 + .procname = "chroot_deny_sysctl",
79125 + .data = &grsec_enable_chroot_sysctl,
79126 + .maxlen = sizeof(int),
79127 + .mode = 0600,
79128 + .proc_handler = &proc_dointvec,
79129 + },
79130 +#endif
79131 +#ifdef CONFIG_GRKERNSEC_TPE
79132 + {
79133 + .procname = "tpe",
79134 + .data = &grsec_enable_tpe,
79135 + .maxlen = sizeof(int),
79136 + .mode = 0600,
79137 + .proc_handler = &proc_dointvec,
79138 + },
79139 + {
79140 + .procname = "tpe_gid",
79141 + .data = &grsec_tpe_gid,
79142 + .maxlen = sizeof(int),
79143 + .mode = 0600,
79144 + .proc_handler = &proc_dointvec,
79145 + },
79146 +#endif
79147 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79148 + {
79149 + .procname = "tpe_invert",
79150 + .data = &grsec_enable_tpe_invert,
79151 + .maxlen = sizeof(int),
79152 + .mode = 0600,
79153 + .proc_handler = &proc_dointvec,
79154 + },
79155 +#endif
79156 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79157 + {
79158 + .procname = "tpe_restrict_all",
79159 + .data = &grsec_enable_tpe_all,
79160 + .maxlen = sizeof(int),
79161 + .mode = 0600,
79162 + .proc_handler = &proc_dointvec,
79163 + },
79164 +#endif
79165 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79166 + {
79167 + .procname = "socket_all",
79168 + .data = &grsec_enable_socket_all,
79169 + .maxlen = sizeof(int),
79170 + .mode = 0600,
79171 + .proc_handler = &proc_dointvec,
79172 + },
79173 + {
79174 + .procname = "socket_all_gid",
79175 + .data = &grsec_socket_all_gid,
79176 + .maxlen = sizeof(int),
79177 + .mode = 0600,
79178 + .proc_handler = &proc_dointvec,
79179 + },
79180 +#endif
79181 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79182 + {
79183 + .procname = "socket_client",
79184 + .data = &grsec_enable_socket_client,
79185 + .maxlen = sizeof(int),
79186 + .mode = 0600,
79187 + .proc_handler = &proc_dointvec,
79188 + },
79189 + {
79190 + .procname = "socket_client_gid",
79191 + .data = &grsec_socket_client_gid,
79192 + .maxlen = sizeof(int),
79193 + .mode = 0600,
79194 + .proc_handler = &proc_dointvec,
79195 + },
79196 +#endif
79197 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79198 + {
79199 + .procname = "socket_server",
79200 + .data = &grsec_enable_socket_server,
79201 + .maxlen = sizeof(int),
79202 + .mode = 0600,
79203 + .proc_handler = &proc_dointvec,
79204 + },
79205 + {
79206 + .procname = "socket_server_gid",
79207 + .data = &grsec_socket_server_gid,
79208 + .maxlen = sizeof(int),
79209 + .mode = 0600,
79210 + .proc_handler = &proc_dointvec,
79211 + },
79212 +#endif
79213 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79214 + {
79215 + .procname = "audit_group",
79216 + .data = &grsec_enable_group,
79217 + .maxlen = sizeof(int),
79218 + .mode = 0600,
79219 + .proc_handler = &proc_dointvec,
79220 + },
79221 + {
79222 + .procname = "audit_gid",
79223 + .data = &grsec_audit_gid,
79224 + .maxlen = sizeof(int),
79225 + .mode = 0600,
79226 + .proc_handler = &proc_dointvec,
79227 + },
79228 +#endif
79229 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79230 + {
79231 + .procname = "audit_chdir",
79232 + .data = &grsec_enable_chdir,
79233 + .maxlen = sizeof(int),
79234 + .mode = 0600,
79235 + .proc_handler = &proc_dointvec,
79236 + },
79237 +#endif
79238 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79239 + {
79240 + .procname = "audit_mount",
79241 + .data = &grsec_enable_mount,
79242 + .maxlen = sizeof(int),
79243 + .mode = 0600,
79244 + .proc_handler = &proc_dointvec,
79245 + },
79246 +#endif
79247 +#ifdef CONFIG_GRKERNSEC_DMESG
79248 + {
79249 + .procname = "dmesg",
79250 + .data = &grsec_enable_dmesg,
79251 + .maxlen = sizeof(int),
79252 + .mode = 0600,
79253 + .proc_handler = &proc_dointvec,
79254 + },
79255 +#endif
79256 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79257 + {
79258 + .procname = "chroot_findtask",
79259 + .data = &grsec_enable_chroot_findtask,
79260 + .maxlen = sizeof(int),
79261 + .mode = 0600,
79262 + .proc_handler = &proc_dointvec,
79263 + },
79264 +#endif
79265 +#ifdef CONFIG_GRKERNSEC_RESLOG
79266 + {
79267 + .procname = "resource_logging",
79268 + .data = &grsec_resource_logging,
79269 + .maxlen = sizeof(int),
79270 + .mode = 0600,
79271 + .proc_handler = &proc_dointvec,
79272 + },
79273 +#endif
79274 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79275 + {
79276 + .procname = "audit_ptrace",
79277 + .data = &grsec_enable_audit_ptrace,
79278 + .maxlen = sizeof(int),
79279 + .mode = 0600,
79280 + .proc_handler = &proc_dointvec,
79281 + },
79282 +#endif
79283 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79284 + {
79285 + .procname = "harden_ptrace",
79286 + .data = &grsec_enable_harden_ptrace,
79287 + .maxlen = sizeof(int),
79288 + .mode = 0600,
79289 + .proc_handler = &proc_dointvec,
79290 + },
79291 +#endif
79292 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79293 + {
79294 + .procname = "harden_ipc",
79295 + .data = &grsec_enable_harden_ipc,
79296 + .maxlen = sizeof(int),
79297 + .mode = 0600,
79298 + .proc_handler = &proc_dointvec,
79299 + },
79300 +#endif
79301 + {
79302 + .procname = "grsec_lock",
79303 + .data = &grsec_lock,
79304 + .maxlen = sizeof(int),
79305 + .mode = 0600,
79306 + .proc_handler = &proc_dointvec,
79307 + },
79308 +#endif
79309 +#ifdef CONFIG_GRKERNSEC_ROFS
79310 + {
79311 + .procname = "romount_protect",
79312 + .data = &grsec_enable_rofs,
79313 + .maxlen = sizeof(int),
79314 + .mode = 0600,
79315 + .proc_handler = &proc_dointvec_minmax,
79316 + .extra1 = &one,
79317 + .extra2 = &one,
79318 + },
79319 +#endif
79320 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79321 + {
79322 + .procname = "deny_new_usb",
79323 + .data = &grsec_deny_new_usb,
79324 + .maxlen = sizeof(int),
79325 + .mode = 0600,
79326 + .proc_handler = &proc_dointvec,
79327 + },
79328 +#endif
79329 + { }
79330 +};
79331 +#endif
79332 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79333 new file mode 100644
79334 index 0000000..61b514e
79335 --- /dev/null
79336 +++ b/grsecurity/grsec_time.c
79337 @@ -0,0 +1,16 @@
79338 +#include <linux/kernel.h>
79339 +#include <linux/sched.h>
79340 +#include <linux/grinternal.h>
79341 +#include <linux/module.h>
79342 +
79343 +void
79344 +gr_log_timechange(void)
79345 +{
79346 +#ifdef CONFIG_GRKERNSEC_TIME
79347 + if (grsec_enable_time)
79348 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79349 +#endif
79350 + return;
79351 +}
79352 +
79353 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79354 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79355 new file mode 100644
79356 index 0000000..d1953de
79357 --- /dev/null
79358 +++ b/grsecurity/grsec_tpe.c
79359 @@ -0,0 +1,78 @@
79360 +#include <linux/kernel.h>
79361 +#include <linux/sched.h>
79362 +#include <linux/file.h>
79363 +#include <linux/fs.h>
79364 +#include <linux/grinternal.h>
79365 +
79366 +extern int gr_acl_tpe_check(void);
79367 +
79368 +int
79369 +gr_tpe_allow(const struct file *file)
79370 +{
79371 +#ifdef CONFIG_GRKERNSEC
79372 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79373 + struct inode *file_inode = file->f_path.dentry->d_inode;
79374 + const struct cred *cred = current_cred();
79375 + char *msg = NULL;
79376 + char *msg2 = NULL;
79377 +
79378 + // never restrict root
79379 + if (gr_is_global_root(cred->uid))
79380 + return 1;
79381 +
79382 + if (grsec_enable_tpe) {
79383 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79384 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79385 + msg = "not being in trusted group";
79386 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79387 + msg = "being in untrusted group";
79388 +#else
79389 + if (in_group_p(grsec_tpe_gid))
79390 + msg = "being in untrusted group";
79391 +#endif
79392 + }
79393 + if (!msg && gr_acl_tpe_check())
79394 + msg = "being in untrusted role";
79395 +
79396 + // not in any affected group/role
79397 + if (!msg)
79398 + goto next_check;
79399 +
79400 + if (gr_is_global_nonroot(inode->i_uid))
79401 + msg2 = "file in non-root-owned directory";
79402 + else if (inode->i_mode & S_IWOTH)
79403 + msg2 = "file in world-writable directory";
79404 + else if (inode->i_mode & S_IWGRP)
79405 + msg2 = "file in group-writable directory";
79406 + else if (file_inode->i_mode & S_IWOTH)
79407 + msg2 = "file is world-writable";
79408 +
79409 + if (msg && msg2) {
79410 + char fullmsg[70] = {0};
79411 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79412 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79413 + return 0;
79414 + }
79415 + msg = NULL;
79416 +next_check:
79417 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79418 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79419 + return 1;
79420 +
79421 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79422 + msg = "directory not owned by user";
79423 + else if (inode->i_mode & S_IWOTH)
79424 + msg = "file in world-writable directory";
79425 + else if (inode->i_mode & S_IWGRP)
79426 + msg = "file in group-writable directory";
79427 + else if (file_inode->i_mode & S_IWOTH)
79428 + msg = "file is world-writable";
79429 +
79430 + if (msg) {
79431 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79432 + return 0;
79433 + }
79434 +#endif
79435 +#endif
79436 + return 1;
79437 +}
79438 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79439 new file mode 100644
79440 index 0000000..ae02d8e
79441 --- /dev/null
79442 +++ b/grsecurity/grsec_usb.c
79443 @@ -0,0 +1,15 @@
79444 +#include <linux/kernel.h>
79445 +#include <linux/grinternal.h>
79446 +#include <linux/module.h>
79447 +
79448 +int gr_handle_new_usb(void)
79449 +{
79450 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79451 + if (grsec_deny_new_usb) {
79452 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79453 + return 1;
79454 + }
79455 +#endif
79456 + return 0;
79457 +}
79458 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79459 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79460 new file mode 100644
79461 index 0000000..158b330
79462 --- /dev/null
79463 +++ b/grsecurity/grsum.c
79464 @@ -0,0 +1,64 @@
79465 +#include <linux/err.h>
79466 +#include <linux/kernel.h>
79467 +#include <linux/sched.h>
79468 +#include <linux/mm.h>
79469 +#include <linux/scatterlist.h>
79470 +#include <linux/crypto.h>
79471 +#include <linux/gracl.h>
79472 +
79473 +
79474 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79475 +#error "crypto and sha256 must be built into the kernel"
79476 +#endif
79477 +
79478 +int
79479 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79480 +{
79481 + struct crypto_hash *tfm;
79482 + struct hash_desc desc;
79483 + struct scatterlist sg[2];
79484 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79485 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79486 + unsigned long *sumptr = (unsigned long *)sum;
79487 + int cryptres;
79488 + int retval = 1;
79489 + volatile int mismatched = 0;
79490 + volatile int dummy = 0;
79491 + unsigned int i;
79492 +
79493 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79494 + if (IS_ERR(tfm)) {
79495 + /* should never happen, since sha256 should be built in */
79496 + memset(entry->pw, 0, GR_PW_LEN);
79497 + return 1;
79498 + }
79499 +
79500 + sg_init_table(sg, 2);
79501 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79502 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79503 +
79504 + desc.tfm = tfm;
79505 + desc.flags = 0;
79506 +
79507 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79508 + temp_sum);
79509 +
79510 + memset(entry->pw, 0, GR_PW_LEN);
79511 +
79512 + if (cryptres)
79513 + goto out;
79514 +
79515 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79516 + if (sumptr[i] != tmpsumptr[i])
79517 + mismatched = 1;
79518 + else
79519 + dummy = 1; // waste a cycle
79520 +
79521 + if (!mismatched)
79522 + retval = dummy - 1;
79523 +
79524 +out:
79525 + crypto_free_hash(tfm);
79526 +
79527 + return retval;
79528 +}
79529 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79530 index 77ff547..181834f 100644
79531 --- a/include/asm-generic/4level-fixup.h
79532 +++ b/include/asm-generic/4level-fixup.h
79533 @@ -13,8 +13,10 @@
79534 #define pmd_alloc(mm, pud, address) \
79535 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79536 NULL: pmd_offset(pud, address))
79537 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79538
79539 #define pud_alloc(mm, pgd, address) (pgd)
79540 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79541 #define pud_offset(pgd, start) (pgd)
79542 #define pud_none(pud) 0
79543 #define pud_bad(pud) 0
79544 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79545 index b7babf0..97f4c4f 100644
79546 --- a/include/asm-generic/atomic-long.h
79547 +++ b/include/asm-generic/atomic-long.h
79548 @@ -22,6 +22,12 @@
79549
79550 typedef atomic64_t atomic_long_t;
79551
79552 +#ifdef CONFIG_PAX_REFCOUNT
79553 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79554 +#else
79555 +typedef atomic64_t atomic_long_unchecked_t;
79556 +#endif
79557 +
79558 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79559
79560 static inline long atomic_long_read(atomic_long_t *l)
79561 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79562 return (long)atomic64_read(v);
79563 }
79564
79565 +#ifdef CONFIG_PAX_REFCOUNT
79566 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79567 +{
79568 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79569 +
79570 + return (long)atomic64_read_unchecked(v);
79571 +}
79572 +#endif
79573 +
79574 static inline void atomic_long_set(atomic_long_t *l, long i)
79575 {
79576 atomic64_t *v = (atomic64_t *)l;
79577 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79578 atomic64_set(v, i);
79579 }
79580
79581 +#ifdef CONFIG_PAX_REFCOUNT
79582 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79583 +{
79584 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79585 +
79586 + atomic64_set_unchecked(v, i);
79587 +}
79588 +#endif
79589 +
79590 static inline void atomic_long_inc(atomic_long_t *l)
79591 {
79592 atomic64_t *v = (atomic64_t *)l;
79593 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79594 atomic64_inc(v);
79595 }
79596
79597 +#ifdef CONFIG_PAX_REFCOUNT
79598 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79599 +{
79600 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79601 +
79602 + atomic64_inc_unchecked(v);
79603 +}
79604 +#endif
79605 +
79606 static inline void atomic_long_dec(atomic_long_t *l)
79607 {
79608 atomic64_t *v = (atomic64_t *)l;
79609 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79610 atomic64_dec(v);
79611 }
79612
79613 +#ifdef CONFIG_PAX_REFCOUNT
79614 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79615 +{
79616 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79617 +
79618 + atomic64_dec_unchecked(v);
79619 +}
79620 +#endif
79621 +
79622 static inline void atomic_long_add(long i, atomic_long_t *l)
79623 {
79624 atomic64_t *v = (atomic64_t *)l;
79625 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79626 atomic64_add(i, v);
79627 }
79628
79629 +#ifdef CONFIG_PAX_REFCOUNT
79630 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79631 +{
79632 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79633 +
79634 + atomic64_add_unchecked(i, v);
79635 +}
79636 +#endif
79637 +
79638 static inline void atomic_long_sub(long i, atomic_long_t *l)
79639 {
79640 atomic64_t *v = (atomic64_t *)l;
79641 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79642 atomic64_sub(i, v);
79643 }
79644
79645 +#ifdef CONFIG_PAX_REFCOUNT
79646 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79647 +{
79648 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79649 +
79650 + atomic64_sub_unchecked(i, v);
79651 +}
79652 +#endif
79653 +
79654 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79655 {
79656 atomic64_t *v = (atomic64_t *)l;
79657 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79658 return atomic64_add_negative(i, v);
79659 }
79660
79661 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79662 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79663 {
79664 atomic64_t *v = (atomic64_t *)l;
79665
79666 return (long)atomic64_add_return(i, v);
79667 }
79668
79669 +#ifdef CONFIG_PAX_REFCOUNT
79670 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79671 +{
79672 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79673 +
79674 + return (long)atomic64_add_return_unchecked(i, v);
79675 +}
79676 +#endif
79677 +
79678 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79679 {
79680 atomic64_t *v = (atomic64_t *)l;
79681 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79682 return (long)atomic64_inc_return(v);
79683 }
79684
79685 +#ifdef CONFIG_PAX_REFCOUNT
79686 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79687 +{
79688 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79689 +
79690 + return (long)atomic64_inc_return_unchecked(v);
79691 +}
79692 +#endif
79693 +
79694 static inline long atomic_long_dec_return(atomic_long_t *l)
79695 {
79696 atomic64_t *v = (atomic64_t *)l;
79697 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79698
79699 typedef atomic_t atomic_long_t;
79700
79701 +#ifdef CONFIG_PAX_REFCOUNT
79702 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79703 +#else
79704 +typedef atomic_t atomic_long_unchecked_t;
79705 +#endif
79706 +
79707 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79708 static inline long atomic_long_read(atomic_long_t *l)
79709 {
79710 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79711 return (long)atomic_read(v);
79712 }
79713
79714 +#ifdef CONFIG_PAX_REFCOUNT
79715 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79716 +{
79717 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79718 +
79719 + return (long)atomic_read_unchecked(v);
79720 +}
79721 +#endif
79722 +
79723 static inline void atomic_long_set(atomic_long_t *l, long i)
79724 {
79725 atomic_t *v = (atomic_t *)l;
79726 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79727 atomic_set(v, i);
79728 }
79729
79730 +#ifdef CONFIG_PAX_REFCOUNT
79731 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79732 +{
79733 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79734 +
79735 + atomic_set_unchecked(v, i);
79736 +}
79737 +#endif
79738 +
79739 static inline void atomic_long_inc(atomic_long_t *l)
79740 {
79741 atomic_t *v = (atomic_t *)l;
79742 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79743 atomic_inc(v);
79744 }
79745
79746 +#ifdef CONFIG_PAX_REFCOUNT
79747 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79748 +{
79749 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79750 +
79751 + atomic_inc_unchecked(v);
79752 +}
79753 +#endif
79754 +
79755 static inline void atomic_long_dec(atomic_long_t *l)
79756 {
79757 atomic_t *v = (atomic_t *)l;
79758 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79759 atomic_dec(v);
79760 }
79761
79762 +#ifdef CONFIG_PAX_REFCOUNT
79763 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79764 +{
79765 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79766 +
79767 + atomic_dec_unchecked(v);
79768 +}
79769 +#endif
79770 +
79771 static inline void atomic_long_add(long i, atomic_long_t *l)
79772 {
79773 atomic_t *v = (atomic_t *)l;
79774 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79775 atomic_add(i, v);
79776 }
79777
79778 +#ifdef CONFIG_PAX_REFCOUNT
79779 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79780 +{
79781 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79782 +
79783 + atomic_add_unchecked(i, v);
79784 +}
79785 +#endif
79786 +
79787 static inline void atomic_long_sub(long i, atomic_long_t *l)
79788 {
79789 atomic_t *v = (atomic_t *)l;
79790 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79791 atomic_sub(i, v);
79792 }
79793
79794 +#ifdef CONFIG_PAX_REFCOUNT
79795 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79796 +{
79797 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79798 +
79799 + atomic_sub_unchecked(i, v);
79800 +}
79801 +#endif
79802 +
79803 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79804 {
79805 atomic_t *v = (atomic_t *)l;
79806 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
79807 return (long)atomic_add_return(i, v);
79808 }
79809
79810 +#ifdef CONFIG_PAX_REFCOUNT
79811 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79812 +{
79813 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79814 +
79815 + return (long)atomic_add_return_unchecked(i, v);
79816 +}
79817 +
79818 +#endif
79819 +
79820 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79821 {
79822 atomic_t *v = (atomic_t *)l;
79823 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79824 return (long)atomic_inc_return(v);
79825 }
79826
79827 +#ifdef CONFIG_PAX_REFCOUNT
79828 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79829 +{
79830 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79831 +
79832 + return (long)atomic_inc_return_unchecked(v);
79833 +}
79834 +#endif
79835 +
79836 static inline long atomic_long_dec_return(atomic_long_t *l)
79837 {
79838 atomic_t *v = (atomic_t *)l;
79839 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79840
79841 #endif /* BITS_PER_LONG == 64 */
79842
79843 +#ifdef CONFIG_PAX_REFCOUNT
79844 +static inline void pax_refcount_needs_these_functions(void)
79845 +{
79846 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79847 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79848 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79849 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79850 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79851 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79852 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79853 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79854 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79855 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79856 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79857 +#ifdef CONFIG_X86
79858 + atomic_clear_mask_unchecked(0, NULL);
79859 + atomic_set_mask_unchecked(0, NULL);
79860 +#endif
79861 +
79862 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79863 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79864 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79865 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79866 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79867 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79868 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79869 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79870 +}
79871 +#else
79872 +#define atomic_read_unchecked(v) atomic_read(v)
79873 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79874 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79875 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79876 +#define atomic_inc_unchecked(v) atomic_inc(v)
79877 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79878 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79879 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79880 +#define atomic_dec_unchecked(v) atomic_dec(v)
79881 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79882 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79883 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79884 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79885 +
79886 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79887 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79888 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79889 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79890 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79891 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79892 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79893 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79894 +#endif
79895 +
79896 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79897 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
79898 index 9c79e76..9f7827d 100644
79899 --- a/include/asm-generic/atomic.h
79900 +++ b/include/asm-generic/atomic.h
79901 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
79902 * Atomically clears the bits set in @mask from @v
79903 */
79904 #ifndef atomic_clear_mask
79905 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
79906 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
79907 {
79908 unsigned long flags;
79909
79910 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79911 index b18ce4f..2ee2843 100644
79912 --- a/include/asm-generic/atomic64.h
79913 +++ b/include/asm-generic/atomic64.h
79914 @@ -16,6 +16,8 @@ typedef struct {
79915 long long counter;
79916 } atomic64_t;
79917
79918 +typedef atomic64_t atomic64_unchecked_t;
79919 +
79920 #define ATOMIC64_INIT(i) { (i) }
79921
79922 extern long long atomic64_read(const atomic64_t *v);
79923 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79924 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79925 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79926
79927 +#define atomic64_read_unchecked(v) atomic64_read(v)
79928 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79929 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79930 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79931 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79932 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79933 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79934 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79935 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79936 +
79937 #endif /* _ASM_GENERIC_ATOMIC64_H */
79938 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79939 index 1402fa8..025a736 100644
79940 --- a/include/asm-generic/barrier.h
79941 +++ b/include/asm-generic/barrier.h
79942 @@ -74,7 +74,7 @@
79943 do { \
79944 compiletime_assert_atomic_type(*p); \
79945 smp_mb(); \
79946 - ACCESS_ONCE(*p) = (v); \
79947 + ACCESS_ONCE_RW(*p) = (v); \
79948 } while (0)
79949
79950 #define smp_load_acquire(p) \
79951 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79952 index a60a7cc..0fe12f2 100644
79953 --- a/include/asm-generic/bitops/__fls.h
79954 +++ b/include/asm-generic/bitops/__fls.h
79955 @@ -9,7 +9,7 @@
79956 *
79957 * Undefined if no set bit exists, so code should check against 0 first.
79958 */
79959 -static __always_inline unsigned long __fls(unsigned long word)
79960 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79961 {
79962 int num = BITS_PER_LONG - 1;
79963
79964 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79965 index 0576d1f..dad6c71 100644
79966 --- a/include/asm-generic/bitops/fls.h
79967 +++ b/include/asm-generic/bitops/fls.h
79968 @@ -9,7 +9,7 @@
79969 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79970 */
79971
79972 -static __always_inline int fls(int x)
79973 +static __always_inline int __intentional_overflow(-1) fls(int x)
79974 {
79975 int r = 32;
79976
79977 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79978 index b097cf8..3d40e14 100644
79979 --- a/include/asm-generic/bitops/fls64.h
79980 +++ b/include/asm-generic/bitops/fls64.h
79981 @@ -15,7 +15,7 @@
79982 * at position 64.
79983 */
79984 #if BITS_PER_LONG == 32
79985 -static __always_inline int fls64(__u64 x)
79986 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79987 {
79988 __u32 h = x >> 32;
79989 if (h)
79990 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79991 return fls(x);
79992 }
79993 #elif BITS_PER_LONG == 64
79994 -static __always_inline int fls64(__u64 x)
79995 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79996 {
79997 if (x == 0)
79998 return 0;
79999 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80000 index 1bfcfe5..e04c5c9 100644
80001 --- a/include/asm-generic/cache.h
80002 +++ b/include/asm-generic/cache.h
80003 @@ -6,7 +6,7 @@
80004 * cache lines need to provide their own cache.h.
80005 */
80006
80007 -#define L1_CACHE_SHIFT 5
80008 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80009 +#define L1_CACHE_SHIFT 5UL
80010 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80011
80012 #endif /* __ASM_GENERIC_CACHE_H */
80013 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80014 index 0d68a1e..b74a761 100644
80015 --- a/include/asm-generic/emergency-restart.h
80016 +++ b/include/asm-generic/emergency-restart.h
80017 @@ -1,7 +1,7 @@
80018 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80019 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80020
80021 -static inline void machine_emergency_restart(void)
80022 +static inline __noreturn void machine_emergency_restart(void)
80023 {
80024 machine_restart(NULL);
80025 }
80026 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80027 index 975e1cc..0b8a083 100644
80028 --- a/include/asm-generic/io.h
80029 +++ b/include/asm-generic/io.h
80030 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80031 * These are pretty trivial
80032 */
80033 #ifndef virt_to_phys
80034 -static inline unsigned long virt_to_phys(volatile void *address)
80035 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80036 {
80037 return __pa((unsigned long)address);
80038 }
80039 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80040 index 90f99c7..00ce236 100644
80041 --- a/include/asm-generic/kmap_types.h
80042 +++ b/include/asm-generic/kmap_types.h
80043 @@ -2,9 +2,9 @@
80044 #define _ASM_GENERIC_KMAP_TYPES_H
80045
80046 #ifdef __WITH_KM_FENCE
80047 -# define KM_TYPE_NR 41
80048 +# define KM_TYPE_NR 42
80049 #else
80050 -# define KM_TYPE_NR 20
80051 +# define KM_TYPE_NR 21
80052 #endif
80053
80054 #endif
80055 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80056 index 9ceb03b..62b0b8f 100644
80057 --- a/include/asm-generic/local.h
80058 +++ b/include/asm-generic/local.h
80059 @@ -23,24 +23,37 @@ typedef struct
80060 atomic_long_t a;
80061 } local_t;
80062
80063 +typedef struct {
80064 + atomic_long_unchecked_t a;
80065 +} local_unchecked_t;
80066 +
80067 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80068
80069 #define local_read(l) atomic_long_read(&(l)->a)
80070 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80071 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80072 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80073 #define local_inc(l) atomic_long_inc(&(l)->a)
80074 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80075 #define local_dec(l) atomic_long_dec(&(l)->a)
80076 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80077 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80078 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80079 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80080 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80081
80082 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80083 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80084 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80085 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80086 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80087 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80088 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80089 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80090 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80091
80092 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80093 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80094 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80095 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80096 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80097 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80098 index 725612b..9cc513a 100644
80099 --- a/include/asm-generic/pgtable-nopmd.h
80100 +++ b/include/asm-generic/pgtable-nopmd.h
80101 @@ -1,14 +1,19 @@
80102 #ifndef _PGTABLE_NOPMD_H
80103 #define _PGTABLE_NOPMD_H
80104
80105 -#ifndef __ASSEMBLY__
80106 -
80107 #include <asm-generic/pgtable-nopud.h>
80108
80109 -struct mm_struct;
80110 -
80111 #define __PAGETABLE_PMD_FOLDED
80112
80113 +#define PMD_SHIFT PUD_SHIFT
80114 +#define PTRS_PER_PMD 1
80115 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80116 +#define PMD_MASK (~(PMD_SIZE-1))
80117 +
80118 +#ifndef __ASSEMBLY__
80119 +
80120 +struct mm_struct;
80121 +
80122 /*
80123 * Having the pmd type consist of a pud gets the size right, and allows
80124 * us to conceptually access the pud entry that this pmd is folded into
80125 @@ -16,11 +21,6 @@ struct mm_struct;
80126 */
80127 typedef struct { pud_t pud; } pmd_t;
80128
80129 -#define PMD_SHIFT PUD_SHIFT
80130 -#define PTRS_PER_PMD 1
80131 -#define PMD_SIZE (1UL << PMD_SHIFT)
80132 -#define PMD_MASK (~(PMD_SIZE-1))
80133 -
80134 /*
80135 * The "pud_xxx()" functions here are trivial for a folded two-level
80136 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80137 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80138 index 810431d..0ec4804f 100644
80139 --- a/include/asm-generic/pgtable-nopud.h
80140 +++ b/include/asm-generic/pgtable-nopud.h
80141 @@ -1,10 +1,15 @@
80142 #ifndef _PGTABLE_NOPUD_H
80143 #define _PGTABLE_NOPUD_H
80144
80145 -#ifndef __ASSEMBLY__
80146 -
80147 #define __PAGETABLE_PUD_FOLDED
80148
80149 +#define PUD_SHIFT PGDIR_SHIFT
80150 +#define PTRS_PER_PUD 1
80151 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80152 +#define PUD_MASK (~(PUD_SIZE-1))
80153 +
80154 +#ifndef __ASSEMBLY__
80155 +
80156 /*
80157 * Having the pud type consist of a pgd gets the size right, and allows
80158 * us to conceptually access the pgd entry that this pud is folded into
80159 @@ -12,11 +17,6 @@
80160 */
80161 typedef struct { pgd_t pgd; } pud_t;
80162
80163 -#define PUD_SHIFT PGDIR_SHIFT
80164 -#define PTRS_PER_PUD 1
80165 -#define PUD_SIZE (1UL << PUD_SHIFT)
80166 -#define PUD_MASK (~(PUD_SIZE-1))
80167 -
80168 /*
80169 * The "pgd_xxx()" functions here are trivial for a folded two-level
80170 * setup: the pud is never bad, and a pud always exists (as it's folded
80171 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80172 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80173
80174 #define pgd_populate(mm, pgd, pud) do { } while (0)
80175 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80176 /*
80177 * (puds are folded into pgds so this doesn't get actually called,
80178 * but the define is needed for a generic inline function.)
80179 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80180 index 53b2acc..f4568e7 100644
80181 --- a/include/asm-generic/pgtable.h
80182 +++ b/include/asm-generic/pgtable.h
80183 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80184 }
80185 #endif /* CONFIG_NUMA_BALANCING */
80186
80187 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80188 +#ifdef CONFIG_PAX_KERNEXEC
80189 +#error KERNEXEC requires pax_open_kernel
80190 +#else
80191 +static inline unsigned long pax_open_kernel(void) { return 0; }
80192 +#endif
80193 +#endif
80194 +
80195 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80196 +#ifdef CONFIG_PAX_KERNEXEC
80197 +#error KERNEXEC requires pax_close_kernel
80198 +#else
80199 +static inline unsigned long pax_close_kernel(void) { return 0; }
80200 +#endif
80201 +#endif
80202 +
80203 #endif /* CONFIG_MMU */
80204
80205 #endif /* !__ASSEMBLY__ */
80206 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80207 index 72d8803..cb9749c 100644
80208 --- a/include/asm-generic/uaccess.h
80209 +++ b/include/asm-generic/uaccess.h
80210 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80211 return __clear_user(to, n);
80212 }
80213
80214 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80216 +#error UDEREF requires pax_open_userland
80217 +#else
80218 +static inline unsigned long pax_open_userland(void) { return 0; }
80219 +#endif
80220 +#endif
80221 +
80222 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80224 +#error UDEREF requires pax_close_userland
80225 +#else
80226 +static inline unsigned long pax_close_userland(void) { return 0; }
80227 +#endif
80228 +#endif
80229 +
80230 #endif /* __ASM_GENERIC_UACCESS_H */
80231 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80232 index 5ba0360..e85c934 100644
80233 --- a/include/asm-generic/vmlinux.lds.h
80234 +++ b/include/asm-generic/vmlinux.lds.h
80235 @@ -231,6 +231,7 @@
80236 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80237 VMLINUX_SYMBOL(__start_rodata) = .; \
80238 *(.rodata) *(.rodata.*) \
80239 + *(.data..read_only) \
80240 *(__vermagic) /* Kernel version magic */ \
80241 . = ALIGN(8); \
80242 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80243 @@ -722,17 +723,18 @@
80244 * section in the linker script will go there too. @phdr should have
80245 * a leading colon.
80246 *
80247 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80248 + * Note that this macros defines per_cpu_load as an absolute symbol.
80249 * If there is no need to put the percpu section at a predetermined
80250 * address, use PERCPU_SECTION.
80251 */
80252 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80253 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80254 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80255 + per_cpu_load = .; \
80256 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80257 - LOAD_OFFSET) { \
80258 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80259 PERCPU_INPUT(cacheline) \
80260 } phdr \
80261 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80262 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80263
80264 /**
80265 * PERCPU_SECTION - define output section for percpu area, simple version
80266 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80267 index 623a59c..1e79ab9 100644
80268 --- a/include/crypto/algapi.h
80269 +++ b/include/crypto/algapi.h
80270 @@ -34,7 +34,7 @@ struct crypto_type {
80271 unsigned int maskclear;
80272 unsigned int maskset;
80273 unsigned int tfmsize;
80274 -};
80275 +} __do_const;
80276
80277 struct crypto_instance {
80278 struct crypto_alg alg;
80279 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80280 index 1968907..7d9ed9f 100644
80281 --- a/include/drm/drmP.h
80282 +++ b/include/drm/drmP.h
80283 @@ -68,6 +68,7 @@
80284 #include <linux/workqueue.h>
80285 #include <linux/poll.h>
80286 #include <asm/pgalloc.h>
80287 +#include <asm/local.h>
80288 #include <drm/drm.h>
80289 #include <drm/drm_sarea.h>
80290 #include <drm/drm_vma_manager.h>
80291 @@ -260,10 +261,12 @@ do { \
80292 * \param cmd command.
80293 * \param arg argument.
80294 */
80295 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80296 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80297 + struct drm_file *file_priv);
80298 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80299 struct drm_file *file_priv);
80300
80301 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80302 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80303 unsigned long arg);
80304
80305 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80306 @@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80307 struct drm_ioctl_desc {
80308 unsigned int cmd;
80309 int flags;
80310 - drm_ioctl_t *func;
80311 + drm_ioctl_t func;
80312 unsigned int cmd_drv;
80313 const char *name;
80314 -};
80315 +} __do_const;
80316
80317 /**
80318 * Creates a driver or general drm_ioctl_desc array entry for the given
80319 @@ -946,7 +949,8 @@ struct drm_info_list {
80320 int (*show)(struct seq_file*, void*); /** show callback */
80321 u32 driver_features; /**< Required driver features for this entry */
80322 void *data;
80323 -};
80324 +} __do_const;
80325 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80326
80327 /**
80328 * debugfs node structure. This structure represents a debugfs file.
80329 @@ -1030,7 +1034,7 @@ struct drm_device {
80330
80331 /** \name Usage Counters */
80332 /*@{ */
80333 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80334 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80335 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80336 int buf_use; /**< Buffers in use -- cannot alloc */
80337 atomic_t buf_alloc; /**< Buffer allocation in progress */
80338 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80339 index a3d75fe..6802f9c 100644
80340 --- a/include/drm/drm_crtc_helper.h
80341 +++ b/include/drm/drm_crtc_helper.h
80342 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80343 struct drm_connector *connector);
80344 /* disable encoder when not in use - more explicit than dpms off */
80345 void (*disable)(struct drm_encoder *encoder);
80346 -};
80347 +} __no_const;
80348
80349 /**
80350 * drm_connector_helper_funcs - helper operations for connectors
80351 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80352 index a70d456..6ea07cd 100644
80353 --- a/include/drm/i915_pciids.h
80354 +++ b/include/drm/i915_pciids.h
80355 @@ -37,7 +37,7 @@
80356 */
80357 #define INTEL_VGA_DEVICE(id, info) { \
80358 0x8086, id, \
80359 - ~0, ~0, \
80360 + PCI_ANY_ID, PCI_ANY_ID, \
80361 0x030000, 0xff0000, \
80362 (unsigned long) info }
80363
80364 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80365 index 72dcbe8..8db58d7 100644
80366 --- a/include/drm/ttm/ttm_memory.h
80367 +++ b/include/drm/ttm/ttm_memory.h
80368 @@ -48,7 +48,7 @@
80369
80370 struct ttm_mem_shrink {
80371 int (*do_shrink) (struct ttm_mem_shrink *);
80372 -};
80373 +} __no_const;
80374
80375 /**
80376 * struct ttm_mem_global - Global memory accounting structure.
80377 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80378 index 49a8284..9643967 100644
80379 --- a/include/drm/ttm/ttm_page_alloc.h
80380 +++ b/include/drm/ttm/ttm_page_alloc.h
80381 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80382 */
80383 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80384
80385 +struct device;
80386 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80387 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80388
80389 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80390 index 4b840e8..155d235 100644
80391 --- a/include/keys/asymmetric-subtype.h
80392 +++ b/include/keys/asymmetric-subtype.h
80393 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80394 /* Verify the signature on a key of this subtype (optional) */
80395 int (*verify_signature)(const struct key *key,
80396 const struct public_key_signature *sig);
80397 -};
80398 +} __do_const;
80399
80400 /**
80401 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80402 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80403 index c1da539..1dcec55 100644
80404 --- a/include/linux/atmdev.h
80405 +++ b/include/linux/atmdev.h
80406 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80407 #endif
80408
80409 struct k_atm_aal_stats {
80410 -#define __HANDLE_ITEM(i) atomic_t i
80411 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80412 __AAL_STAT_ITEMS
80413 #undef __HANDLE_ITEM
80414 };
80415 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80416 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80417 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80418 struct module *owner;
80419 -};
80420 +} __do_const ;
80421
80422 struct atmphy_ops {
80423 int (*start)(struct atm_dev *dev);
80424 diff --git a/include/linux/audit.h b/include/linux/audit.h
80425 index 22cfddb..1514eef 100644
80426 --- a/include/linux/audit.h
80427 +++ b/include/linux/audit.h
80428 @@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80429 extern unsigned compat_chattr_class[];
80430 extern unsigned compat_signal_class[];
80431
80432 -extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80433 +extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80434
80435 /* audit_names->type values */
80436 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80437 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80438 extern unsigned int audit_serial(void);
80439 extern int auditsc_get_stamp(struct audit_context *ctx,
80440 struct timespec *t, unsigned int *serial);
80441 -extern int audit_set_loginuid(kuid_t loginuid);
80442 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80443
80444 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80445 {
80446 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80447 index 61f29e5..e67c658 100644
80448 --- a/include/linux/binfmts.h
80449 +++ b/include/linux/binfmts.h
80450 @@ -44,7 +44,7 @@ struct linux_binprm {
80451 unsigned interp_flags;
80452 unsigned interp_data;
80453 unsigned long loader, exec;
80454 -};
80455 +} __randomize_layout;
80456
80457 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80458 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80459 @@ -73,8 +73,10 @@ struct linux_binfmt {
80460 int (*load_binary)(struct linux_binprm *);
80461 int (*load_shlib)(struct file *);
80462 int (*core_dump)(struct coredump_params *cprm);
80463 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80464 + void (*handle_mmap)(struct file *);
80465 unsigned long min_coredump; /* minimal dump size */
80466 -};
80467 +} __do_const __randomize_layout;
80468
80469 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80470
80471 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80472 index cbc5833..8123ebc 100644
80473 --- a/include/linux/bitops.h
80474 +++ b/include/linux/bitops.h
80475 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80476 * @word: value to rotate
80477 * @shift: bits to roll
80478 */
80479 -static inline __u32 rol32(__u32 word, unsigned int shift)
80480 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80481 {
80482 return (word << shift) | (word >> (32 - shift));
80483 }
80484 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80485 * @word: value to rotate
80486 * @shift: bits to roll
80487 */
80488 -static inline __u32 ror32(__u32 word, unsigned int shift)
80489 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80490 {
80491 return (word >> shift) | (word << (32 - shift));
80492 }
80493 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80494 return (__s32)(value << shift) >> shift;
80495 }
80496
80497 -static inline unsigned fls_long(unsigned long l)
80498 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80499 {
80500 if (sizeof(l) == 4)
80501 return fls(l);
80502 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80503 index 518b465..11953e6 100644
80504 --- a/include/linux/blkdev.h
80505 +++ b/include/linux/blkdev.h
80506 @@ -1627,7 +1627,7 @@ struct block_device_operations {
80507 /* this callback is with swap_lock and sometimes page table lock held */
80508 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80509 struct module *owner;
80510 -};
80511 +} __do_const;
80512
80513 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80514 unsigned long);
80515 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80516 index afc1343..9735539 100644
80517 --- a/include/linux/blktrace_api.h
80518 +++ b/include/linux/blktrace_api.h
80519 @@ -25,7 +25,7 @@ struct blk_trace {
80520 struct dentry *dropped_file;
80521 struct dentry *msg_file;
80522 struct list_head running_list;
80523 - atomic_t dropped;
80524 + atomic_unchecked_t dropped;
80525 };
80526
80527 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80528 diff --git a/include/linux/cache.h b/include/linux/cache.h
80529 index 17e7e82..1d7da26 100644
80530 --- a/include/linux/cache.h
80531 +++ b/include/linux/cache.h
80532 @@ -16,6 +16,14 @@
80533 #define __read_mostly
80534 #endif
80535
80536 +#ifndef __read_only
80537 +#ifdef CONFIG_PAX_KERNEXEC
80538 +#error KERNEXEC requires __read_only
80539 +#else
80540 +#define __read_only __read_mostly
80541 +#endif
80542 +#endif
80543 +
80544 #ifndef ____cacheline_aligned
80545 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80546 #endif
80547 diff --git a/include/linux/capability.h b/include/linux/capability.h
80548 index aa93e5e..985a1b0 100644
80549 --- a/include/linux/capability.h
80550 +++ b/include/linux/capability.h
80551 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80552 extern bool capable(int cap);
80553 extern bool ns_capable(struct user_namespace *ns, int cap);
80554 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80555 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80556 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80557 +extern bool capable_nolog(int cap);
80558 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80559
80560 /* audit system wants to get cap info from files as well */
80561 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80562
80563 +extern int is_privileged_binary(const struct dentry *dentry);
80564 +
80565 #endif /* !_LINUX_CAPABILITY_H */
80566 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80567 index 8609d57..86e4d79 100644
80568 --- a/include/linux/cdrom.h
80569 +++ b/include/linux/cdrom.h
80570 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80571
80572 /* driver specifications */
80573 const int capability; /* capability flags */
80574 - int n_minors; /* number of active minor devices */
80575 /* handle uniform packets for scsi type devices (scsi,atapi) */
80576 int (*generic_packet) (struct cdrom_device_info *,
80577 struct packet_command *);
80578 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80579 index 4ce9056..86caac6 100644
80580 --- a/include/linux/cleancache.h
80581 +++ b/include/linux/cleancache.h
80582 @@ -31,7 +31,7 @@ struct cleancache_ops {
80583 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80584 void (*invalidate_inode)(int, struct cleancache_filekey);
80585 void (*invalidate_fs)(int);
80586 -};
80587 +} __no_const;
80588
80589 extern struct cleancache_ops *
80590 cleancache_register_ops(struct cleancache_ops *ops);
80591 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80592 index 411dd7e..ee38878 100644
80593 --- a/include/linux/clk-provider.h
80594 +++ b/include/linux/clk-provider.h
80595 @@ -180,6 +180,7 @@ struct clk_ops {
80596 void (*init)(struct clk_hw *hw);
80597 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80598 };
80599 +typedef struct clk_ops __no_const clk_ops_no_const;
80600
80601 /**
80602 * struct clk_init_data - holds init data that's common to all clocks and is
80603 diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
80604 index 653f0e2..abcafaa 100644
80605 --- a/include/linux/clocksource.h
80606 +++ b/include/linux/clocksource.h
80607 @@ -287,7 +287,7 @@ extern struct clocksource* clocksource_get_next(void);
80608 extern void clocksource_change_rating(struct clocksource *cs, int rating);
80609 extern void clocksource_suspend(void);
80610 extern void clocksource_resume(void);
80611 -extern struct clocksource * __init __weak clocksource_default_clock(void);
80612 +extern struct clocksource * __init clocksource_default_clock(void);
80613 extern void clocksource_mark_unstable(struct clocksource *cs);
80614
80615 extern u64
80616 diff --git a/include/linux/compat.h b/include/linux/compat.h
80617 index e649426..a74047b 100644
80618 --- a/include/linux/compat.h
80619 +++ b/include/linux/compat.h
80620 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80621 compat_size_t __user *len_ptr);
80622
80623 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80624 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80625 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80626 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80627 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80628 compat_ssize_t msgsz, int msgflg);
80629 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80630 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80631 compat_ulong_t addr, compat_ulong_t data);
80632 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80633 - compat_long_t addr, compat_long_t data);
80634 + compat_ulong_t addr, compat_ulong_t data);
80635
80636 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80637 /*
80638 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80639 index 2507fd2..55203f8 100644
80640 --- a/include/linux/compiler-gcc4.h
80641 +++ b/include/linux/compiler-gcc4.h
80642 @@ -39,9 +39,34 @@
80643 # define __compiletime_warning(message) __attribute__((warning(message)))
80644 # define __compiletime_error(message) __attribute__((error(message)))
80645 #endif /* __CHECKER__ */
80646 +
80647 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80648 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80649 +#define __bos0(ptr) __bos((ptr), 0)
80650 +#define __bos1(ptr) __bos((ptr), 1)
80651 #endif /* GCC_VERSION >= 40300 */
80652
80653 #if GCC_VERSION >= 40500
80654 +
80655 +#ifdef RANDSTRUCT_PLUGIN
80656 +#define __randomize_layout __attribute__((randomize_layout))
80657 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80658 +#endif
80659 +
80660 +#ifdef CONSTIFY_PLUGIN
80661 +#define __no_const __attribute__((no_const))
80662 +#define __do_const __attribute__((do_const))
80663 +#endif
80664 +
80665 +#ifdef SIZE_OVERFLOW_PLUGIN
80666 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80667 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80668 +#endif
80669 +
80670 +#ifdef LATENT_ENTROPY_PLUGIN
80671 +#define __latent_entropy __attribute__((latent_entropy))
80672 +#endif
80673 +
80674 /*
80675 * Mark a position in code as unreachable. This can be used to
80676 * suppress control flow warnings after asm blocks that transfer
80677 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80678 index d5ad7b1..3b74638 100644
80679 --- a/include/linux/compiler.h
80680 +++ b/include/linux/compiler.h
80681 @@ -5,11 +5,14 @@
80682
80683 #ifdef __CHECKER__
80684 # define __user __attribute__((noderef, address_space(1)))
80685 +# define __force_user __force __user
80686 # define __kernel __attribute__((address_space(0)))
80687 +# define __force_kernel __force __kernel
80688 # define __safe __attribute__((safe))
80689 # define __force __attribute__((force))
80690 # define __nocast __attribute__((nocast))
80691 # define __iomem __attribute__((noderef, address_space(2)))
80692 +# define __force_iomem __force __iomem
80693 # define __must_hold(x) __attribute__((context(x,1,1)))
80694 # define __acquires(x) __attribute__((context(x,0,1)))
80695 # define __releases(x) __attribute__((context(x,1,0)))
80696 @@ -17,20 +20,37 @@
80697 # define __release(x) __context__(x,-1)
80698 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80699 # define __percpu __attribute__((noderef, address_space(3)))
80700 +# define __force_percpu __force __percpu
80701 #ifdef CONFIG_SPARSE_RCU_POINTER
80702 # define __rcu __attribute__((noderef, address_space(4)))
80703 +# define __force_rcu __force __rcu
80704 #else
80705 # define __rcu
80706 +# define __force_rcu
80707 #endif
80708 extern void __chk_user_ptr(const volatile void __user *);
80709 extern void __chk_io_ptr(const volatile void __iomem *);
80710 #else
80711 -# define __user
80712 -# define __kernel
80713 +# ifdef CHECKER_PLUGIN
80714 +//# define __user
80715 +//# define __force_user
80716 +//# define __kernel
80717 +//# define __force_kernel
80718 +# else
80719 +# ifdef STRUCTLEAK_PLUGIN
80720 +# define __user __attribute__((user))
80721 +# else
80722 +# define __user
80723 +# endif
80724 +# define __force_user
80725 +# define __kernel
80726 +# define __force_kernel
80727 +# endif
80728 # define __safe
80729 # define __force
80730 # define __nocast
80731 # define __iomem
80732 +# define __force_iomem
80733 # define __chk_user_ptr(x) (void)0
80734 # define __chk_io_ptr(x) (void)0
80735 # define __builtin_warning(x, y...) (1)
80736 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80737 # define __release(x) (void)0
80738 # define __cond_lock(x,c) (c)
80739 # define __percpu
80740 +# define __force_percpu
80741 # define __rcu
80742 +# define __force_rcu
80743 #endif
80744
80745 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80746 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80747 # define __attribute_const__ /* unimplemented */
80748 #endif
80749
80750 +#ifndef __randomize_layout
80751 +# define __randomize_layout
80752 +#endif
80753 +
80754 +#ifndef __no_randomize_layout
80755 +# define __no_randomize_layout
80756 +#endif
80757 +
80758 +#ifndef __no_const
80759 +# define __no_const
80760 +#endif
80761 +
80762 +#ifndef __do_const
80763 +# define __do_const
80764 +#endif
80765 +
80766 +#ifndef __size_overflow
80767 +# define __size_overflow(...)
80768 +#endif
80769 +
80770 +#ifndef __intentional_overflow
80771 +# define __intentional_overflow(...)
80772 +#endif
80773 +
80774 +#ifndef __latent_entropy
80775 +# define __latent_entropy
80776 +#endif
80777 +
80778 /*
80779 * Tell gcc if a function is cold. The compiler will assume any path
80780 * directly leading to the call is unlikely.
80781 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80782 #define __cold
80783 #endif
80784
80785 +#ifndef __alloc_size
80786 +#define __alloc_size(...)
80787 +#endif
80788 +
80789 +#ifndef __bos
80790 +#define __bos(ptr, arg)
80791 +#endif
80792 +
80793 +#ifndef __bos0
80794 +#define __bos0(ptr)
80795 +#endif
80796 +
80797 +#ifndef __bos1
80798 +#define __bos1(ptr)
80799 +#endif
80800 +
80801 /* Simple shorthand for a section definition */
80802 #ifndef __section
80803 # define __section(S) __attribute__ ((__section__(#S)))
80804 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80805 * use is to mediate communication between process-level code and irq/NMI
80806 * handlers, all running on the same CPU.
80807 */
80808 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80809 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80810 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80811
80812 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80813 #ifdef CONFIG_KPROBES
80814 diff --git a/include/linux/completion.h b/include/linux/completion.h
80815 index 5d5aaae..0ea9b84 100644
80816 --- a/include/linux/completion.h
80817 +++ b/include/linux/completion.h
80818 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80819
80820 extern void wait_for_completion(struct completion *);
80821 extern void wait_for_completion_io(struct completion *);
80822 -extern int wait_for_completion_interruptible(struct completion *x);
80823 -extern int wait_for_completion_killable(struct completion *x);
80824 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80825 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80826 extern unsigned long wait_for_completion_timeout(struct completion *x,
80827 - unsigned long timeout);
80828 + unsigned long timeout) __intentional_overflow(-1);
80829 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80830 - unsigned long timeout);
80831 + unsigned long timeout) __intentional_overflow(-1);
80832 extern long wait_for_completion_interruptible_timeout(
80833 - struct completion *x, unsigned long timeout);
80834 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80835 extern long wait_for_completion_killable_timeout(
80836 - struct completion *x, unsigned long timeout);
80837 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80838 extern bool try_wait_for_completion(struct completion *x);
80839 extern bool completion_done(struct completion *x);
80840
80841 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80842 index 34025df..d94bbbc 100644
80843 --- a/include/linux/configfs.h
80844 +++ b/include/linux/configfs.h
80845 @@ -125,7 +125,7 @@ struct configfs_attribute {
80846 const char *ca_name;
80847 struct module *ca_owner;
80848 umode_t ca_mode;
80849 -};
80850 +} __do_const;
80851
80852 /*
80853 * Users often need to create attribute structures for their configurable
80854 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80855 index 7d1955a..d86a3ca 100644
80856 --- a/include/linux/cpufreq.h
80857 +++ b/include/linux/cpufreq.h
80858 @@ -203,6 +203,7 @@ struct global_attr {
80859 ssize_t (*store)(struct kobject *a, struct attribute *b,
80860 const char *c, size_t count);
80861 };
80862 +typedef struct global_attr __no_const global_attr_no_const;
80863
80864 #define define_one_global_ro(_name) \
80865 static struct global_attr _name = \
80866 @@ -269,7 +270,7 @@ struct cpufreq_driver {
80867 bool boost_supported;
80868 bool boost_enabled;
80869 int (*set_boost) (int state);
80870 -};
80871 +} __do_const;
80872
80873 /* flags */
80874 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80875 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80876 index 25e0df6..952dffd 100644
80877 --- a/include/linux/cpuidle.h
80878 +++ b/include/linux/cpuidle.h
80879 @@ -50,7 +50,8 @@ struct cpuidle_state {
80880 int index);
80881
80882 int (*enter_dead) (struct cpuidle_device *dev, int index);
80883 -};
80884 +} __do_const;
80885 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80886
80887 /* Idle State Flags */
80888 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80889 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80890 void (*reflect) (struct cpuidle_device *dev, int index);
80891
80892 struct module *owner;
80893 -};
80894 +} __do_const;
80895
80896 #ifdef CONFIG_CPU_IDLE
80897 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80898 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80899 index 2997af6..424ddc1 100644
80900 --- a/include/linux/cpumask.h
80901 +++ b/include/linux/cpumask.h
80902 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80903 }
80904
80905 /* Valid inputs for n are -1 and 0. */
80906 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80907 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80908 {
80909 return n+1;
80910 }
80911
80912 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80913 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80914 {
80915 return n+1;
80916 }
80917
80918 -static inline unsigned int cpumask_next_and(int n,
80919 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80920 const struct cpumask *srcp,
80921 const struct cpumask *andp)
80922 {
80923 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80924 *
80925 * Returns >= nr_cpu_ids if no further cpus set.
80926 */
80927 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80928 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80929 {
80930 /* -1 is a legal arg here. */
80931 if (n != -1)
80932 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80933 *
80934 * Returns >= nr_cpu_ids if no further cpus unset.
80935 */
80936 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80937 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80938 {
80939 /* -1 is a legal arg here. */
80940 if (n != -1)
80941 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80942 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80943 }
80944
80945 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80946 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80947 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80948 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80949
80950 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
80951 index 72ab536..3849fce 100644
80952 --- a/include/linux/crash_dump.h
80953 +++ b/include/linux/crash_dump.h
80954 @@ -14,14 +14,13 @@
80955 extern unsigned long long elfcorehdr_addr;
80956 extern unsigned long long elfcorehdr_size;
80957
80958 -extern int __weak elfcorehdr_alloc(unsigned long long *addr,
80959 - unsigned long long *size);
80960 -extern void __weak elfcorehdr_free(unsigned long long addr);
80961 -extern ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos);
80962 -extern ssize_t __weak elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
80963 -extern int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
80964 - unsigned long from, unsigned long pfn,
80965 - unsigned long size, pgprot_t prot);
80966 +extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size);
80967 +extern void elfcorehdr_free(unsigned long long addr);
80968 +extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos);
80969 +extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
80970 +extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
80971 + unsigned long from, unsigned long pfn,
80972 + unsigned long size, pgprot_t prot);
80973
80974 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
80975 unsigned long, int);
80976 diff --git a/include/linux/cred.h b/include/linux/cred.h
80977 index b2d0820..2ecafd3 100644
80978 --- a/include/linux/cred.h
80979 +++ b/include/linux/cred.h
80980 @@ -35,7 +35,7 @@ struct group_info {
80981 int nblocks;
80982 kgid_t small_block[NGROUPS_SMALL];
80983 kgid_t *blocks[0];
80984 -};
80985 +} __randomize_layout;
80986
80987 /**
80988 * get_group_info - Get a reference to a group info structure
80989 @@ -136,7 +136,7 @@ struct cred {
80990 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80991 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80992 struct rcu_head rcu; /* RCU deletion hook */
80993 -};
80994 +} __randomize_layout;
80995
80996 extern void __put_cred(struct cred *);
80997 extern void exit_creds(struct task_struct *);
80998 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80999 static inline void validate_process_creds(void)
81000 {
81001 }
81002 +static inline void validate_task_creds(struct task_struct *task)
81003 +{
81004 +}
81005 #endif
81006
81007 /**
81008 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
81009
81010 #define task_uid(task) (task_cred_xxx((task), uid))
81011 #define task_euid(task) (task_cred_xxx((task), euid))
81012 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81013
81014 #define current_cred_xxx(xxx) \
81015 ({ \
81016 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81017 index d45e949..51cf5ea 100644
81018 --- a/include/linux/crypto.h
81019 +++ b/include/linux/crypto.h
81020 @@ -373,7 +373,7 @@ struct cipher_tfm {
81021 const u8 *key, unsigned int keylen);
81022 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81023 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81024 -};
81025 +} __no_const;
81026
81027 struct hash_tfm {
81028 int (*init)(struct hash_desc *desc);
81029 @@ -394,13 +394,13 @@ struct compress_tfm {
81030 int (*cot_decompress)(struct crypto_tfm *tfm,
81031 const u8 *src, unsigned int slen,
81032 u8 *dst, unsigned int *dlen);
81033 -};
81034 +} __no_const;
81035
81036 struct rng_tfm {
81037 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81038 unsigned int dlen);
81039 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81040 -};
81041 +} __no_const;
81042
81043 #define crt_ablkcipher crt_u.ablkcipher
81044 #define crt_aead crt_u.aead
81045 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81046 index 653589e..4ef254a 100644
81047 --- a/include/linux/ctype.h
81048 +++ b/include/linux/ctype.h
81049 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81050 * Fast implementation of tolower() for internal usage. Do not use in your
81051 * code.
81052 */
81053 -static inline char _tolower(const char c)
81054 +static inline unsigned char _tolower(const unsigned char c)
81055 {
81056 return c | 0x20;
81057 }
81058 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81059 index 75a227c..1456987 100644
81060 --- a/include/linux/dcache.h
81061 +++ b/include/linux/dcache.h
81062 @@ -134,7 +134,7 @@ struct dentry {
81063 } d_u;
81064 struct list_head d_subdirs; /* our children */
81065 struct hlist_node d_alias; /* inode alias list */
81066 -};
81067 +} __randomize_layout;
81068
81069 /*
81070 * dentry->d_lock spinlock nesting subclasses:
81071 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81072 index 7925bf0..d5143d2 100644
81073 --- a/include/linux/decompress/mm.h
81074 +++ b/include/linux/decompress/mm.h
81075 @@ -77,7 +77,7 @@ static void free(void *where)
81076 * warnings when not needed (indeed large_malloc / large_free are not
81077 * needed by inflate */
81078
81079 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81080 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81081 #define free(a) kfree(a)
81082
81083 #define large_malloc(a) vmalloc(a)
81084 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81085 index f1863dc..5c26074 100644
81086 --- a/include/linux/devfreq.h
81087 +++ b/include/linux/devfreq.h
81088 @@ -114,7 +114,7 @@ struct devfreq_governor {
81089 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81090 int (*event_handler)(struct devfreq *devfreq,
81091 unsigned int event, void *data);
81092 -};
81093 +} __do_const;
81094
81095 /**
81096 * struct devfreq - Device devfreq structure
81097 diff --git a/include/linux/device.h b/include/linux/device.h
81098 index 43d183a..03b6ba2 100644
81099 --- a/include/linux/device.h
81100 +++ b/include/linux/device.h
81101 @@ -310,7 +310,7 @@ struct subsys_interface {
81102 struct list_head node;
81103 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81104 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81105 -};
81106 +} __do_const;
81107
81108 int subsys_interface_register(struct subsys_interface *sif);
81109 void subsys_interface_unregister(struct subsys_interface *sif);
81110 @@ -506,7 +506,7 @@ struct device_type {
81111 void (*release)(struct device *dev);
81112
81113 const struct dev_pm_ops *pm;
81114 -};
81115 +} __do_const;
81116
81117 /* interface for exporting device attributes */
81118 struct device_attribute {
81119 @@ -516,11 +516,12 @@ struct device_attribute {
81120 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81121 const char *buf, size_t count);
81122 };
81123 +typedef struct device_attribute __no_const device_attribute_no_const;
81124
81125 struct dev_ext_attribute {
81126 struct device_attribute attr;
81127 void *var;
81128 -};
81129 +} __do_const;
81130
81131 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81132 char *buf);
81133 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81134 index 931b709..89b2d89 100644
81135 --- a/include/linux/dma-mapping.h
81136 +++ b/include/linux/dma-mapping.h
81137 @@ -60,7 +60,7 @@ struct dma_map_ops {
81138 u64 (*get_required_mask)(struct device *dev);
81139 #endif
81140 int is_phys;
81141 -};
81142 +} __do_const;
81143
81144 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81145
81146 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81147 index 1f9e642..39e4263 100644
81148 --- a/include/linux/dmaengine.h
81149 +++ b/include/linux/dmaengine.h
81150 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81151 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81152 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81153
81154 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81155 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81156 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81157 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81158 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81159 struct dma_pinned_list *pinned_list, struct page *page,
81160 unsigned int offset, size_t len);
81161
81162 diff --git a/include/linux/efi.h b/include/linux/efi.h
81163 index 45cb4ff..c9b4912 100644
81164 --- a/include/linux/efi.h
81165 +++ b/include/linux/efi.h
81166 @@ -1036,6 +1036,7 @@ struct efivar_operations {
81167 efi_set_variable_t *set_variable;
81168 efi_query_variable_store_t *query_variable_store;
81169 };
81170 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81171
81172 struct efivars {
81173 /*
81174 diff --git a/include/linux/elf.h b/include/linux/elf.h
81175 index 67a5fa7..b817372 100644
81176 --- a/include/linux/elf.h
81177 +++ b/include/linux/elf.h
81178 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81179 #define elf_note elf32_note
81180 #define elf_addr_t Elf32_Off
81181 #define Elf_Half Elf32_Half
81182 +#define elf_dyn Elf32_Dyn
81183
81184 #else
81185
81186 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81187 #define elf_note elf64_note
81188 #define elf_addr_t Elf64_Off
81189 #define Elf_Half Elf64_Half
81190 +#define elf_dyn Elf64_Dyn
81191
81192 #endif
81193
81194 diff --git a/include/linux/err.h b/include/linux/err.h
81195 index a729120..6ede2c9 100644
81196 --- a/include/linux/err.h
81197 +++ b/include/linux/err.h
81198 @@ -20,12 +20,12 @@
81199
81200 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81201
81202 -static inline void * __must_check ERR_PTR(long error)
81203 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81204 {
81205 return (void *) error;
81206 }
81207
81208 -static inline long __must_check PTR_ERR(__force const void *ptr)
81209 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81210 {
81211 return (long) ptr;
81212 }
81213 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81214 index 36f49c4..a2a1f4c 100644
81215 --- a/include/linux/extcon.h
81216 +++ b/include/linux/extcon.h
81217 @@ -135,7 +135,7 @@ struct extcon_dev {
81218 /* /sys/class/extcon/.../mutually_exclusive/... */
81219 struct attribute_group attr_g_muex;
81220 struct attribute **attrs_muex;
81221 - struct device_attribute *d_attrs_muex;
81222 + device_attribute_no_const *d_attrs_muex;
81223 };
81224
81225 /**
81226 diff --git a/include/linux/fb.h b/include/linux/fb.h
81227 index 09bb7a1..d98870a 100644
81228 --- a/include/linux/fb.h
81229 +++ b/include/linux/fb.h
81230 @@ -305,7 +305,7 @@ struct fb_ops {
81231 /* called at KDB enter and leave time to prepare the console */
81232 int (*fb_debug_enter)(struct fb_info *info);
81233 int (*fb_debug_leave)(struct fb_info *info);
81234 -};
81235 +} __do_const;
81236
81237 #ifdef CONFIG_FB_TILEBLITTING
81238 #define FB_TILE_CURSOR_NONE 0
81239 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81240 index 230f87b..1fd0485 100644
81241 --- a/include/linux/fdtable.h
81242 +++ b/include/linux/fdtable.h
81243 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81244 void put_files_struct(struct files_struct *fs);
81245 void reset_files_struct(struct files_struct *);
81246 int unshare_files(struct files_struct **);
81247 -struct files_struct *dup_fd(struct files_struct *, int *);
81248 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81249 void do_close_on_exec(struct files_struct *);
81250 int iterate_fd(struct files_struct *, unsigned,
81251 int (*)(const void *, struct file *, unsigned),
81252 diff --git a/include/linux/filter.h b/include/linux/filter.h
81253 index a5227ab..c789945 100644
81254 --- a/include/linux/filter.h
81255 +++ b/include/linux/filter.h
81256 @@ -9,6 +9,11 @@
81257 #include <linux/skbuff.h>
81258 #include <linux/workqueue.h>
81259 #include <uapi/linux/filter.h>
81260 +#include <asm/cacheflush.h>
81261 +
81262 +struct sk_buff;
81263 +struct sock;
81264 +struct seccomp_data;
81265
81266 /* Internally used and optimized filter representation with extended
81267 * instruction set based on top of classic BPF.
81268 @@ -320,20 +325,23 @@ struct sock_fprog_kern {
81269 struct sock_filter *filter;
81270 };
81271
81272 -struct sk_buff;
81273 -struct sock;
81274 -struct seccomp_data;
81275 +struct bpf_work_struct {
81276 + struct bpf_prog *prog;
81277 + struct work_struct work;
81278 +};
81279
81280 struct bpf_prog {
81281 + u32 pages; /* Number of allocated pages */
81282 u32 jited:1, /* Is our filter JIT'ed? */
81283 len:31; /* Number of filter blocks */
81284 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81285 + struct bpf_work_struct *work; /* Deferred free work struct */
81286 unsigned int (*bpf_func)(const struct sk_buff *skb,
81287 const struct bpf_insn *filter);
81288 + /* Instructions for interpreter */
81289 union {
81290 struct sock_filter insns[0];
81291 struct bpf_insn insnsi[0];
81292 - struct work_struct work;
81293 };
81294 };
81295
81296 @@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81297
81298 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81299
81300 +#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81301 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81302 +{
81303 + set_memory_ro((unsigned long)fp, fp->pages);
81304 +}
81305 +
81306 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81307 +{
81308 + set_memory_rw((unsigned long)fp, fp->pages);
81309 +}
81310 +#else
81311 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81312 +{
81313 +}
81314 +
81315 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81316 +{
81317 +}
81318 +#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81319 +
81320 int sk_filter(struct sock *sk, struct sk_buff *skb);
81321
81322 void bpf_prog_select_runtime(struct bpf_prog *fp);
81323 @@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81324 int bpf_convert_filter(struct sock_filter *prog, int len,
81325 struct bpf_insn *new_prog, int *new_len);
81326
81327 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81328 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81329 + gfp_t gfp_extra_flags);
81330 +void __bpf_prog_free(struct bpf_prog *fp);
81331 +
81332 +static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81333 +{
81334 + bpf_prog_unlock_ro(fp);
81335 + __bpf_prog_free(fp);
81336 +}
81337 +
81338 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81339 void bpf_prog_destroy(struct bpf_prog *fp);
81340
81341 @@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81342
81343 static inline void bpf_jit_free(struct bpf_prog *fp)
81344 {
81345 - kfree(fp);
81346 + bpf_prog_unlock_free(fp);
81347 }
81348 #endif /* CONFIG_BPF_JIT */
81349
81350 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81351 index 8293262..2b3b8bd 100644
81352 --- a/include/linux/frontswap.h
81353 +++ b/include/linux/frontswap.h
81354 @@ -11,7 +11,7 @@ struct frontswap_ops {
81355 int (*load)(unsigned, pgoff_t, struct page *);
81356 void (*invalidate_page)(unsigned, pgoff_t);
81357 void (*invalidate_area)(unsigned);
81358 -};
81359 +} __no_const;
81360
81361 extern bool frontswap_enabled;
81362 extern struct frontswap_ops *
81363 diff --git a/include/linux/fs.h b/include/linux/fs.h
81364 index 9418772..0155807 100644
81365 --- a/include/linux/fs.h
81366 +++ b/include/linux/fs.h
81367 @@ -401,7 +401,7 @@ struct address_space {
81368 spinlock_t private_lock; /* for use by the address_space */
81369 struct list_head private_list; /* ditto */
81370 void *private_data; /* ditto */
81371 -} __attribute__((aligned(sizeof(long))));
81372 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81373 /*
81374 * On most architectures that alignment is already the case; but
81375 * must be enforced here for CRIS, to let the least significant bit
81376 @@ -444,7 +444,7 @@ struct block_device {
81377 int bd_fsfreeze_count;
81378 /* Mutex for freeze */
81379 struct mutex bd_fsfreeze_mutex;
81380 -};
81381 +} __randomize_layout;
81382
81383 /*
81384 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81385 @@ -613,7 +613,7 @@ struct inode {
81386 #endif
81387
81388 void *i_private; /* fs or device private pointer */
81389 -};
81390 +} __randomize_layout;
81391
81392 static inline int inode_unhashed(struct inode *inode)
81393 {
81394 @@ -806,7 +806,7 @@ struct file {
81395 struct list_head f_tfile_llink;
81396 #endif /* #ifdef CONFIG_EPOLL */
81397 struct address_space *f_mapping;
81398 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81399 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81400
81401 struct file_handle {
81402 __u32 handle_bytes;
81403 @@ -934,7 +934,7 @@ struct file_lock {
81404 int state; /* state of grant or error if -ve */
81405 } afs;
81406 } fl_u;
81407 -};
81408 +} __randomize_layout;
81409
81410 /* The following constant reflects the upper bound of the file/locking space */
81411 #ifndef OFFSET_MAX
81412 @@ -1284,7 +1284,7 @@ struct super_block {
81413 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81414 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81415 struct rcu_head rcu;
81416 -};
81417 +} __randomize_layout;
81418
81419 extern struct timespec current_fs_time(struct super_block *sb);
81420
81421 @@ -1510,7 +1510,8 @@ struct file_operations {
81422 long (*fallocate)(struct file *file, int mode, loff_t offset,
81423 loff_t len);
81424 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81425 -};
81426 +} __do_const __randomize_layout;
81427 +typedef struct file_operations __no_const file_operations_no_const;
81428
81429 struct inode_operations {
81430 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81431 @@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81432 return !IS_DEADDIR(inode);
81433 }
81434
81435 +static inline bool is_sidechannel_device(const struct inode *inode)
81436 +{
81437 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81438 + umode_t mode = inode->i_mode;
81439 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81440 +#else
81441 + return false;
81442 +#endif
81443 +}
81444 +
81445 #endif /* _LINUX_FS_H */
81446 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81447 index 0efc3e6..fd23610 100644
81448 --- a/include/linux/fs_struct.h
81449 +++ b/include/linux/fs_struct.h
81450 @@ -6,13 +6,13 @@
81451 #include <linux/seqlock.h>
81452
81453 struct fs_struct {
81454 - int users;
81455 + atomic_t users;
81456 spinlock_t lock;
81457 seqcount_t seq;
81458 int umask;
81459 int in_exec;
81460 struct path root, pwd;
81461 -};
81462 +} __randomize_layout;
81463
81464 extern struct kmem_cache *fs_cachep;
81465
81466 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81467 index 7714849..a4a5c7a 100644
81468 --- a/include/linux/fscache-cache.h
81469 +++ b/include/linux/fscache-cache.h
81470 @@ -113,7 +113,7 @@ struct fscache_operation {
81471 fscache_operation_release_t release;
81472 };
81473
81474 -extern atomic_t fscache_op_debug_id;
81475 +extern atomic_unchecked_t fscache_op_debug_id;
81476 extern void fscache_op_work_func(struct work_struct *work);
81477
81478 extern void fscache_enqueue_operation(struct fscache_operation *);
81479 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81480 INIT_WORK(&op->work, fscache_op_work_func);
81481 atomic_set(&op->usage, 1);
81482 op->state = FSCACHE_OP_ST_INITIALISED;
81483 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81484 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81485 op->processor = processor;
81486 op->release = release;
81487 INIT_LIST_HEAD(&op->pend_link);
81488 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81489 index 115bb81..e7b812b 100644
81490 --- a/include/linux/fscache.h
81491 +++ b/include/linux/fscache.h
81492 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81493 * - this is mandatory for any object that may have data
81494 */
81495 void (*now_uncached)(void *cookie_netfs_data);
81496 -};
81497 +} __do_const;
81498
81499 /*
81500 * fscache cached network filesystem type
81501 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81502 index 1c804b0..1432c2b 100644
81503 --- a/include/linux/fsnotify.h
81504 +++ b/include/linux/fsnotify.h
81505 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81506 struct inode *inode = file_inode(file);
81507 __u32 mask = FS_ACCESS;
81508
81509 + if (is_sidechannel_device(inode))
81510 + return;
81511 +
81512 if (S_ISDIR(inode->i_mode))
81513 mask |= FS_ISDIR;
81514
81515 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81516 struct inode *inode = file_inode(file);
81517 __u32 mask = FS_MODIFY;
81518
81519 + if (is_sidechannel_device(inode))
81520 + return;
81521 +
81522 if (S_ISDIR(inode->i_mode))
81523 mask |= FS_ISDIR;
81524
81525 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81526 */
81527 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81528 {
81529 - return kstrdup(name, GFP_KERNEL);
81530 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81531 }
81532
81533 /*
81534 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81535 index ec274e0..e678159 100644
81536 --- a/include/linux/genhd.h
81537 +++ b/include/linux/genhd.h
81538 @@ -194,7 +194,7 @@ struct gendisk {
81539 struct kobject *slave_dir;
81540
81541 struct timer_rand_state *random;
81542 - atomic_t sync_io; /* RAID */
81543 + atomic_unchecked_t sync_io; /* RAID */
81544 struct disk_events *ev;
81545 #ifdef CONFIG_BLK_DEV_INTEGRITY
81546 struct blk_integrity *integrity;
81547 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81548 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81549
81550 /* drivers/char/random.c */
81551 -extern void add_disk_randomness(struct gendisk *disk);
81552 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81553 extern void rand_initialize_disk(struct gendisk *disk);
81554
81555 static inline sector_t get_start_sect(struct block_device *bdev)
81556 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81557 index c0894dd..2fbf10c 100644
81558 --- a/include/linux/genl_magic_func.h
81559 +++ b/include/linux/genl_magic_func.h
81560 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81561 },
81562
81563 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81564 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81565 +static struct genl_ops ZZZ_genl_ops[] = {
81566 #include GENL_MAGIC_INCLUDE_FILE
81567 };
81568
81569 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81570 index 5e7219d..b1ed627 100644
81571 --- a/include/linux/gfp.h
81572 +++ b/include/linux/gfp.h
81573 @@ -34,6 +34,13 @@ struct vm_area_struct;
81574 #define ___GFP_NO_KSWAPD 0x400000u
81575 #define ___GFP_OTHER_NODE 0x800000u
81576 #define ___GFP_WRITE 0x1000000u
81577 +
81578 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81579 +#define ___GFP_USERCOPY 0x2000000u
81580 +#else
81581 +#define ___GFP_USERCOPY 0
81582 +#endif
81583 +
81584 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81585
81586 /*
81587 @@ -90,6 +97,7 @@ struct vm_area_struct;
81588 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81589 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81590 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81591 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81592
81593 /*
81594 * This may seem redundant, but it's a way of annotating false positives vs.
81595 @@ -97,7 +105,7 @@ struct vm_area_struct;
81596 */
81597 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81598
81599 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81600 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81601 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81602
81603 /* This equals 0, but use constants in case they ever change */
81604 @@ -155,6 +163,8 @@ struct vm_area_struct;
81605 /* 4GB DMA on some platforms */
81606 #define GFP_DMA32 __GFP_DMA32
81607
81608 +#define GFP_USERCOPY __GFP_USERCOPY
81609 +
81610 /* Convert GFP flags to their corresponding migrate type */
81611 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81612 {
81613 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81614 new file mode 100644
81615 index 0000000..edb2cb6
81616 --- /dev/null
81617 +++ b/include/linux/gracl.h
81618 @@ -0,0 +1,340 @@
81619 +#ifndef GR_ACL_H
81620 +#define GR_ACL_H
81621 +
81622 +#include <linux/grdefs.h>
81623 +#include <linux/resource.h>
81624 +#include <linux/capability.h>
81625 +#include <linux/dcache.h>
81626 +#include <asm/resource.h>
81627 +
81628 +/* Major status information */
81629 +
81630 +#define GR_VERSION "grsecurity 3.0"
81631 +#define GRSECURITY_VERSION 0x3000
81632 +
81633 +enum {
81634 + GR_SHUTDOWN = 0,
81635 + GR_ENABLE = 1,
81636 + GR_SPROLE = 2,
81637 + GR_OLDRELOAD = 3,
81638 + GR_SEGVMOD = 4,
81639 + GR_STATUS = 5,
81640 + GR_UNSPROLE = 6,
81641 + GR_PASSSET = 7,
81642 + GR_SPROLEPAM = 8,
81643 + GR_RELOAD = 9,
81644 +};
81645 +
81646 +/* Password setup definitions
81647 + * kernel/grhash.c */
81648 +enum {
81649 + GR_PW_LEN = 128,
81650 + GR_SALT_LEN = 16,
81651 + GR_SHA_LEN = 32,
81652 +};
81653 +
81654 +enum {
81655 + GR_SPROLE_LEN = 64,
81656 +};
81657 +
81658 +enum {
81659 + GR_NO_GLOB = 0,
81660 + GR_REG_GLOB,
81661 + GR_CREATE_GLOB
81662 +};
81663 +
81664 +#define GR_NLIMITS 32
81665 +
81666 +/* Begin Data Structures */
81667 +
81668 +struct sprole_pw {
81669 + unsigned char *rolename;
81670 + unsigned char salt[GR_SALT_LEN];
81671 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81672 +};
81673 +
81674 +struct name_entry {
81675 + __u32 key;
81676 + ino_t inode;
81677 + dev_t device;
81678 + char *name;
81679 + __u16 len;
81680 + __u8 deleted;
81681 + struct name_entry *prev;
81682 + struct name_entry *next;
81683 +};
81684 +
81685 +struct inodev_entry {
81686 + struct name_entry *nentry;
81687 + struct inodev_entry *prev;
81688 + struct inodev_entry *next;
81689 +};
81690 +
81691 +struct acl_role_db {
81692 + struct acl_role_label **r_hash;
81693 + __u32 r_size;
81694 +};
81695 +
81696 +struct inodev_db {
81697 + struct inodev_entry **i_hash;
81698 + __u32 i_size;
81699 +};
81700 +
81701 +struct name_db {
81702 + struct name_entry **n_hash;
81703 + __u32 n_size;
81704 +};
81705 +
81706 +struct crash_uid {
81707 + uid_t uid;
81708 + unsigned long expires;
81709 +};
81710 +
81711 +struct gr_hash_struct {
81712 + void **table;
81713 + void **nametable;
81714 + void *first;
81715 + __u32 table_size;
81716 + __u32 used_size;
81717 + int type;
81718 +};
81719 +
81720 +/* Userspace Grsecurity ACL data structures */
81721 +
81722 +struct acl_subject_label {
81723 + char *filename;
81724 + ino_t inode;
81725 + dev_t device;
81726 + __u32 mode;
81727 + kernel_cap_t cap_mask;
81728 + kernel_cap_t cap_lower;
81729 + kernel_cap_t cap_invert_audit;
81730 +
81731 + struct rlimit res[GR_NLIMITS];
81732 + __u32 resmask;
81733 +
81734 + __u8 user_trans_type;
81735 + __u8 group_trans_type;
81736 + uid_t *user_transitions;
81737 + gid_t *group_transitions;
81738 + __u16 user_trans_num;
81739 + __u16 group_trans_num;
81740 +
81741 + __u32 sock_families[2];
81742 + __u32 ip_proto[8];
81743 + __u32 ip_type;
81744 + struct acl_ip_label **ips;
81745 + __u32 ip_num;
81746 + __u32 inaddr_any_override;
81747 +
81748 + __u32 crashes;
81749 + unsigned long expires;
81750 +
81751 + struct acl_subject_label *parent_subject;
81752 + struct gr_hash_struct *hash;
81753 + struct acl_subject_label *prev;
81754 + struct acl_subject_label *next;
81755 +
81756 + struct acl_object_label **obj_hash;
81757 + __u32 obj_hash_size;
81758 + __u16 pax_flags;
81759 +};
81760 +
81761 +struct role_allowed_ip {
81762 + __u32 addr;
81763 + __u32 netmask;
81764 +
81765 + struct role_allowed_ip *prev;
81766 + struct role_allowed_ip *next;
81767 +};
81768 +
81769 +struct role_transition {
81770 + char *rolename;
81771 +
81772 + struct role_transition *prev;
81773 + struct role_transition *next;
81774 +};
81775 +
81776 +struct acl_role_label {
81777 + char *rolename;
81778 + uid_t uidgid;
81779 + __u16 roletype;
81780 +
81781 + __u16 auth_attempts;
81782 + unsigned long expires;
81783 +
81784 + struct acl_subject_label *root_label;
81785 + struct gr_hash_struct *hash;
81786 +
81787 + struct acl_role_label *prev;
81788 + struct acl_role_label *next;
81789 +
81790 + struct role_transition *transitions;
81791 + struct role_allowed_ip *allowed_ips;
81792 + uid_t *domain_children;
81793 + __u16 domain_child_num;
81794 +
81795 + umode_t umask;
81796 +
81797 + struct acl_subject_label **subj_hash;
81798 + __u32 subj_hash_size;
81799 +};
81800 +
81801 +struct user_acl_role_db {
81802 + struct acl_role_label **r_table;
81803 + __u32 num_pointers; /* Number of allocations to track */
81804 + __u32 num_roles; /* Number of roles */
81805 + __u32 num_domain_children; /* Number of domain children */
81806 + __u32 num_subjects; /* Number of subjects */
81807 + __u32 num_objects; /* Number of objects */
81808 +};
81809 +
81810 +struct acl_object_label {
81811 + char *filename;
81812 + ino_t inode;
81813 + dev_t device;
81814 + __u32 mode;
81815 +
81816 + struct acl_subject_label *nested;
81817 + struct acl_object_label *globbed;
81818 +
81819 + /* next two structures not used */
81820 +
81821 + struct acl_object_label *prev;
81822 + struct acl_object_label *next;
81823 +};
81824 +
81825 +struct acl_ip_label {
81826 + char *iface;
81827 + __u32 addr;
81828 + __u32 netmask;
81829 + __u16 low, high;
81830 + __u8 mode;
81831 + __u32 type;
81832 + __u32 proto[8];
81833 +
81834 + /* next two structures not used */
81835 +
81836 + struct acl_ip_label *prev;
81837 + struct acl_ip_label *next;
81838 +};
81839 +
81840 +struct gr_arg {
81841 + struct user_acl_role_db role_db;
81842 + unsigned char pw[GR_PW_LEN];
81843 + unsigned char salt[GR_SALT_LEN];
81844 + unsigned char sum[GR_SHA_LEN];
81845 + unsigned char sp_role[GR_SPROLE_LEN];
81846 + struct sprole_pw *sprole_pws;
81847 + dev_t segv_device;
81848 + ino_t segv_inode;
81849 + uid_t segv_uid;
81850 + __u16 num_sprole_pws;
81851 + __u16 mode;
81852 +};
81853 +
81854 +struct gr_arg_wrapper {
81855 + struct gr_arg *arg;
81856 + __u32 version;
81857 + __u32 size;
81858 +};
81859 +
81860 +struct subject_map {
81861 + struct acl_subject_label *user;
81862 + struct acl_subject_label *kernel;
81863 + struct subject_map *prev;
81864 + struct subject_map *next;
81865 +};
81866 +
81867 +struct acl_subj_map_db {
81868 + struct subject_map **s_hash;
81869 + __u32 s_size;
81870 +};
81871 +
81872 +struct gr_policy_state {
81873 + struct sprole_pw **acl_special_roles;
81874 + __u16 num_sprole_pws;
81875 + struct acl_role_label *kernel_role;
81876 + struct acl_role_label *role_list;
81877 + struct acl_role_label *default_role;
81878 + struct acl_role_db acl_role_set;
81879 + struct acl_subj_map_db subj_map_set;
81880 + struct name_db name_set;
81881 + struct inodev_db inodev_set;
81882 +};
81883 +
81884 +struct gr_alloc_state {
81885 + unsigned long alloc_stack_next;
81886 + unsigned long alloc_stack_size;
81887 + void **alloc_stack;
81888 +};
81889 +
81890 +struct gr_reload_state {
81891 + struct gr_policy_state oldpolicy;
81892 + struct gr_alloc_state oldalloc;
81893 + struct gr_policy_state newpolicy;
81894 + struct gr_alloc_state newalloc;
81895 + struct gr_policy_state *oldpolicy_ptr;
81896 + struct gr_alloc_state *oldalloc_ptr;
81897 + unsigned char oldmode;
81898 +};
81899 +
81900 +/* End Data Structures Section */
81901 +
81902 +/* Hash functions generated by empirical testing by Brad Spengler
81903 + Makes good use of the low bits of the inode. Generally 0-1 times
81904 + in loop for successful match. 0-3 for unsuccessful match.
81905 + Shift/add algorithm with modulus of table size and an XOR*/
81906 +
81907 +static __inline__ unsigned int
81908 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81909 +{
81910 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81911 +}
81912 +
81913 + static __inline__ unsigned int
81914 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81915 +{
81916 + return ((const unsigned long)userp % sz);
81917 +}
81918 +
81919 +static __inline__ unsigned int
81920 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81921 +{
81922 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81923 +}
81924 +
81925 +static __inline__ unsigned int
81926 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81927 +{
81928 + return full_name_hash((const unsigned char *)name, len) % sz;
81929 +}
81930 +
81931 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81932 + subj = NULL; \
81933 + iter = 0; \
81934 + while (iter < role->subj_hash_size) { \
81935 + if (subj == NULL) \
81936 + subj = role->subj_hash[iter]; \
81937 + if (subj == NULL) { \
81938 + iter++; \
81939 + continue; \
81940 + }
81941 +
81942 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81943 + subj = subj->next; \
81944 + if (subj == NULL) \
81945 + iter++; \
81946 + }
81947 +
81948 +
81949 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81950 + subj = role->hash->first; \
81951 + while (subj != NULL) {
81952 +
81953 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81954 + subj = subj->next; \
81955 + }
81956 +
81957 +#endif
81958 +
81959 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81960 new file mode 100644
81961 index 0000000..33ebd1f
81962 --- /dev/null
81963 +++ b/include/linux/gracl_compat.h
81964 @@ -0,0 +1,156 @@
81965 +#ifndef GR_ACL_COMPAT_H
81966 +#define GR_ACL_COMPAT_H
81967 +
81968 +#include <linux/resource.h>
81969 +#include <asm/resource.h>
81970 +
81971 +struct sprole_pw_compat {
81972 + compat_uptr_t rolename;
81973 + unsigned char salt[GR_SALT_LEN];
81974 + unsigned char sum[GR_SHA_LEN];
81975 +};
81976 +
81977 +struct gr_hash_struct_compat {
81978 + compat_uptr_t table;
81979 + compat_uptr_t nametable;
81980 + compat_uptr_t first;
81981 + __u32 table_size;
81982 + __u32 used_size;
81983 + int type;
81984 +};
81985 +
81986 +struct acl_subject_label_compat {
81987 + compat_uptr_t filename;
81988 + compat_ino_t inode;
81989 + __u32 device;
81990 + __u32 mode;
81991 + kernel_cap_t cap_mask;
81992 + kernel_cap_t cap_lower;
81993 + kernel_cap_t cap_invert_audit;
81994 +
81995 + struct compat_rlimit res[GR_NLIMITS];
81996 + __u32 resmask;
81997 +
81998 + __u8 user_trans_type;
81999 + __u8 group_trans_type;
82000 + compat_uptr_t user_transitions;
82001 + compat_uptr_t group_transitions;
82002 + __u16 user_trans_num;
82003 + __u16 group_trans_num;
82004 +
82005 + __u32 sock_families[2];
82006 + __u32 ip_proto[8];
82007 + __u32 ip_type;
82008 + compat_uptr_t ips;
82009 + __u32 ip_num;
82010 + __u32 inaddr_any_override;
82011 +
82012 + __u32 crashes;
82013 + compat_ulong_t expires;
82014 +
82015 + compat_uptr_t parent_subject;
82016 + compat_uptr_t hash;
82017 + compat_uptr_t prev;
82018 + compat_uptr_t next;
82019 +
82020 + compat_uptr_t obj_hash;
82021 + __u32 obj_hash_size;
82022 + __u16 pax_flags;
82023 +};
82024 +
82025 +struct role_allowed_ip_compat {
82026 + __u32 addr;
82027 + __u32 netmask;
82028 +
82029 + compat_uptr_t prev;
82030 + compat_uptr_t next;
82031 +};
82032 +
82033 +struct role_transition_compat {
82034 + compat_uptr_t rolename;
82035 +
82036 + compat_uptr_t prev;
82037 + compat_uptr_t next;
82038 +};
82039 +
82040 +struct acl_role_label_compat {
82041 + compat_uptr_t rolename;
82042 + uid_t uidgid;
82043 + __u16 roletype;
82044 +
82045 + __u16 auth_attempts;
82046 + compat_ulong_t expires;
82047 +
82048 + compat_uptr_t root_label;
82049 + compat_uptr_t hash;
82050 +
82051 + compat_uptr_t prev;
82052 + compat_uptr_t next;
82053 +
82054 + compat_uptr_t transitions;
82055 + compat_uptr_t allowed_ips;
82056 + compat_uptr_t domain_children;
82057 + __u16 domain_child_num;
82058 +
82059 + umode_t umask;
82060 +
82061 + compat_uptr_t subj_hash;
82062 + __u32 subj_hash_size;
82063 +};
82064 +
82065 +struct user_acl_role_db_compat {
82066 + compat_uptr_t r_table;
82067 + __u32 num_pointers;
82068 + __u32 num_roles;
82069 + __u32 num_domain_children;
82070 + __u32 num_subjects;
82071 + __u32 num_objects;
82072 +};
82073 +
82074 +struct acl_object_label_compat {
82075 + compat_uptr_t filename;
82076 + compat_ino_t inode;
82077 + __u32 device;
82078 + __u32 mode;
82079 +
82080 + compat_uptr_t nested;
82081 + compat_uptr_t globbed;
82082 +
82083 + compat_uptr_t prev;
82084 + compat_uptr_t next;
82085 +};
82086 +
82087 +struct acl_ip_label_compat {
82088 + compat_uptr_t iface;
82089 + __u32 addr;
82090 + __u32 netmask;
82091 + __u16 low, high;
82092 + __u8 mode;
82093 + __u32 type;
82094 + __u32 proto[8];
82095 +
82096 + compat_uptr_t prev;
82097 + compat_uptr_t next;
82098 +};
82099 +
82100 +struct gr_arg_compat {
82101 + struct user_acl_role_db_compat role_db;
82102 + unsigned char pw[GR_PW_LEN];
82103 + unsigned char salt[GR_SALT_LEN];
82104 + unsigned char sum[GR_SHA_LEN];
82105 + unsigned char sp_role[GR_SPROLE_LEN];
82106 + compat_uptr_t sprole_pws;
82107 + __u32 segv_device;
82108 + compat_ino_t segv_inode;
82109 + uid_t segv_uid;
82110 + __u16 num_sprole_pws;
82111 + __u16 mode;
82112 +};
82113 +
82114 +struct gr_arg_wrapper_compat {
82115 + compat_uptr_t arg;
82116 + __u32 version;
82117 + __u32 size;
82118 +};
82119 +
82120 +#endif
82121 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82122 new file mode 100644
82123 index 0000000..323ecf2
82124 --- /dev/null
82125 +++ b/include/linux/gralloc.h
82126 @@ -0,0 +1,9 @@
82127 +#ifndef __GRALLOC_H
82128 +#define __GRALLOC_H
82129 +
82130 +void acl_free_all(void);
82131 +int acl_alloc_stack_init(unsigned long size);
82132 +void *acl_alloc(unsigned long len);
82133 +void *acl_alloc_num(unsigned long num, unsigned long len);
82134 +
82135 +#endif
82136 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82137 new file mode 100644
82138 index 0000000..be66033
82139 --- /dev/null
82140 +++ b/include/linux/grdefs.h
82141 @@ -0,0 +1,140 @@
82142 +#ifndef GRDEFS_H
82143 +#define GRDEFS_H
82144 +
82145 +/* Begin grsecurity status declarations */
82146 +
82147 +enum {
82148 + GR_READY = 0x01,
82149 + GR_STATUS_INIT = 0x00 // disabled state
82150 +};
82151 +
82152 +/* Begin ACL declarations */
82153 +
82154 +/* Role flags */
82155 +
82156 +enum {
82157 + GR_ROLE_USER = 0x0001,
82158 + GR_ROLE_GROUP = 0x0002,
82159 + GR_ROLE_DEFAULT = 0x0004,
82160 + GR_ROLE_SPECIAL = 0x0008,
82161 + GR_ROLE_AUTH = 0x0010,
82162 + GR_ROLE_NOPW = 0x0020,
82163 + GR_ROLE_GOD = 0x0040,
82164 + GR_ROLE_LEARN = 0x0080,
82165 + GR_ROLE_TPE = 0x0100,
82166 + GR_ROLE_DOMAIN = 0x0200,
82167 + GR_ROLE_PAM = 0x0400,
82168 + GR_ROLE_PERSIST = 0x0800
82169 +};
82170 +
82171 +/* ACL Subject and Object mode flags */
82172 +enum {
82173 + GR_DELETED = 0x80000000
82174 +};
82175 +
82176 +/* ACL Object-only mode flags */
82177 +enum {
82178 + GR_READ = 0x00000001,
82179 + GR_APPEND = 0x00000002,
82180 + GR_WRITE = 0x00000004,
82181 + GR_EXEC = 0x00000008,
82182 + GR_FIND = 0x00000010,
82183 + GR_INHERIT = 0x00000020,
82184 + GR_SETID = 0x00000040,
82185 + GR_CREATE = 0x00000080,
82186 + GR_DELETE = 0x00000100,
82187 + GR_LINK = 0x00000200,
82188 + GR_AUDIT_READ = 0x00000400,
82189 + GR_AUDIT_APPEND = 0x00000800,
82190 + GR_AUDIT_WRITE = 0x00001000,
82191 + GR_AUDIT_EXEC = 0x00002000,
82192 + GR_AUDIT_FIND = 0x00004000,
82193 + GR_AUDIT_INHERIT= 0x00008000,
82194 + GR_AUDIT_SETID = 0x00010000,
82195 + GR_AUDIT_CREATE = 0x00020000,
82196 + GR_AUDIT_DELETE = 0x00040000,
82197 + GR_AUDIT_LINK = 0x00080000,
82198 + GR_PTRACERD = 0x00100000,
82199 + GR_NOPTRACE = 0x00200000,
82200 + GR_SUPPRESS = 0x00400000,
82201 + GR_NOLEARN = 0x00800000,
82202 + GR_INIT_TRANSFER= 0x01000000
82203 +};
82204 +
82205 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82206 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82207 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82208 +
82209 +/* ACL subject-only mode flags */
82210 +enum {
82211 + GR_KILL = 0x00000001,
82212 + GR_VIEW = 0x00000002,
82213 + GR_PROTECTED = 0x00000004,
82214 + GR_LEARN = 0x00000008,
82215 + GR_OVERRIDE = 0x00000010,
82216 + /* just a placeholder, this mode is only used in userspace */
82217 + GR_DUMMY = 0x00000020,
82218 + GR_PROTSHM = 0x00000040,
82219 + GR_KILLPROC = 0x00000080,
82220 + GR_KILLIPPROC = 0x00000100,
82221 + /* just a placeholder, this mode is only used in userspace */
82222 + GR_NOTROJAN = 0x00000200,
82223 + GR_PROTPROCFD = 0x00000400,
82224 + GR_PROCACCT = 0x00000800,
82225 + GR_RELAXPTRACE = 0x00001000,
82226 + //GR_NESTED = 0x00002000,
82227 + GR_INHERITLEARN = 0x00004000,
82228 + GR_PROCFIND = 0x00008000,
82229 + GR_POVERRIDE = 0x00010000,
82230 + GR_KERNELAUTH = 0x00020000,
82231 + GR_ATSECURE = 0x00040000,
82232 + GR_SHMEXEC = 0x00080000
82233 +};
82234 +
82235 +enum {
82236 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82237 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82238 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82239 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82240 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82241 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82242 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82243 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82244 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82245 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82246 +};
82247 +
82248 +enum {
82249 + GR_ID_USER = 0x01,
82250 + GR_ID_GROUP = 0x02,
82251 +};
82252 +
82253 +enum {
82254 + GR_ID_ALLOW = 0x01,
82255 + GR_ID_DENY = 0x02,
82256 +};
82257 +
82258 +#define GR_CRASH_RES 31
82259 +#define GR_UIDTABLE_MAX 500
82260 +
82261 +/* begin resource learning section */
82262 +enum {
82263 + GR_RLIM_CPU_BUMP = 60,
82264 + GR_RLIM_FSIZE_BUMP = 50000,
82265 + GR_RLIM_DATA_BUMP = 10000,
82266 + GR_RLIM_STACK_BUMP = 1000,
82267 + GR_RLIM_CORE_BUMP = 10000,
82268 + GR_RLIM_RSS_BUMP = 500000,
82269 + GR_RLIM_NPROC_BUMP = 1,
82270 + GR_RLIM_NOFILE_BUMP = 5,
82271 + GR_RLIM_MEMLOCK_BUMP = 50000,
82272 + GR_RLIM_AS_BUMP = 500000,
82273 + GR_RLIM_LOCKS_BUMP = 2,
82274 + GR_RLIM_SIGPENDING_BUMP = 5,
82275 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82276 + GR_RLIM_NICE_BUMP = 1,
82277 + GR_RLIM_RTPRIO_BUMP = 1,
82278 + GR_RLIM_RTTIME_BUMP = 1000000
82279 +};
82280 +
82281 +#endif
82282 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82283 new file mode 100644
82284 index 0000000..d25522e
82285 --- /dev/null
82286 +++ b/include/linux/grinternal.h
82287 @@ -0,0 +1,229 @@
82288 +#ifndef __GRINTERNAL_H
82289 +#define __GRINTERNAL_H
82290 +
82291 +#ifdef CONFIG_GRKERNSEC
82292 +
82293 +#include <linux/fs.h>
82294 +#include <linux/mnt_namespace.h>
82295 +#include <linux/nsproxy.h>
82296 +#include <linux/gracl.h>
82297 +#include <linux/grdefs.h>
82298 +#include <linux/grmsg.h>
82299 +
82300 +void gr_add_learn_entry(const char *fmt, ...)
82301 + __attribute__ ((format (printf, 1, 2)));
82302 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82303 + const struct vfsmount *mnt);
82304 +__u32 gr_check_create(const struct dentry *new_dentry,
82305 + const struct dentry *parent,
82306 + const struct vfsmount *mnt, const __u32 mode);
82307 +int gr_check_protected_task(const struct task_struct *task);
82308 +__u32 to_gr_audit(const __u32 reqmode);
82309 +int gr_set_acls(const int type);
82310 +int gr_acl_is_enabled(void);
82311 +char gr_roletype_to_char(void);
82312 +
82313 +void gr_handle_alertkill(struct task_struct *task);
82314 +char *gr_to_filename(const struct dentry *dentry,
82315 + const struct vfsmount *mnt);
82316 +char *gr_to_filename1(const struct dentry *dentry,
82317 + const struct vfsmount *mnt);
82318 +char *gr_to_filename2(const struct dentry *dentry,
82319 + const struct vfsmount *mnt);
82320 +char *gr_to_filename3(const struct dentry *dentry,
82321 + const struct vfsmount *mnt);
82322 +
82323 +extern int grsec_enable_ptrace_readexec;
82324 +extern int grsec_enable_harden_ptrace;
82325 +extern int grsec_enable_link;
82326 +extern int grsec_enable_fifo;
82327 +extern int grsec_enable_execve;
82328 +extern int grsec_enable_shm;
82329 +extern int grsec_enable_execlog;
82330 +extern int grsec_enable_signal;
82331 +extern int grsec_enable_audit_ptrace;
82332 +extern int grsec_enable_forkfail;
82333 +extern int grsec_enable_time;
82334 +extern int grsec_enable_rofs;
82335 +extern int grsec_deny_new_usb;
82336 +extern int grsec_enable_chroot_shmat;
82337 +extern int grsec_enable_chroot_mount;
82338 +extern int grsec_enable_chroot_double;
82339 +extern int grsec_enable_chroot_pivot;
82340 +extern int grsec_enable_chroot_chdir;
82341 +extern int grsec_enable_chroot_chmod;
82342 +extern int grsec_enable_chroot_mknod;
82343 +extern int grsec_enable_chroot_fchdir;
82344 +extern int grsec_enable_chroot_nice;
82345 +extern int grsec_enable_chroot_execlog;
82346 +extern int grsec_enable_chroot_caps;
82347 +extern int grsec_enable_chroot_sysctl;
82348 +extern int grsec_enable_chroot_unix;
82349 +extern int grsec_enable_symlinkown;
82350 +extern kgid_t grsec_symlinkown_gid;
82351 +extern int grsec_enable_tpe;
82352 +extern kgid_t grsec_tpe_gid;
82353 +extern int grsec_enable_tpe_all;
82354 +extern int grsec_enable_tpe_invert;
82355 +extern int grsec_enable_socket_all;
82356 +extern kgid_t grsec_socket_all_gid;
82357 +extern int grsec_enable_socket_client;
82358 +extern kgid_t grsec_socket_client_gid;
82359 +extern int grsec_enable_socket_server;
82360 +extern kgid_t grsec_socket_server_gid;
82361 +extern kgid_t grsec_audit_gid;
82362 +extern int grsec_enable_group;
82363 +extern int grsec_enable_log_rwxmaps;
82364 +extern int grsec_enable_mount;
82365 +extern int grsec_enable_chdir;
82366 +extern int grsec_resource_logging;
82367 +extern int grsec_enable_blackhole;
82368 +extern int grsec_lastack_retries;
82369 +extern int grsec_enable_brute;
82370 +extern int grsec_enable_harden_ipc;
82371 +extern int grsec_lock;
82372 +
82373 +extern spinlock_t grsec_alert_lock;
82374 +extern unsigned long grsec_alert_wtime;
82375 +extern unsigned long grsec_alert_fyet;
82376 +
82377 +extern spinlock_t grsec_audit_lock;
82378 +
82379 +extern rwlock_t grsec_exec_file_lock;
82380 +
82381 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82382 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82383 + (tsk)->exec_file->f_path.mnt) : "/")
82384 +
82385 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82386 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82387 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82388 +
82389 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82390 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82391 + (tsk)->exec_file->f_path.mnt) : "/")
82392 +
82393 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82394 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82395 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82396 +
82397 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82398 +
82399 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82400 +
82401 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82402 +{
82403 + if (file1 && file2) {
82404 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82405 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82406 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82407 + return true;
82408 + }
82409 +
82410 + return false;
82411 +}
82412 +
82413 +#define GR_CHROOT_CAPS {{ \
82414 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82415 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82416 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82417 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82418 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82419 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82420 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82421 +
82422 +#define security_learn(normal_msg,args...) \
82423 +({ \
82424 + read_lock(&grsec_exec_file_lock); \
82425 + gr_add_learn_entry(normal_msg "\n", ## args); \
82426 + read_unlock(&grsec_exec_file_lock); \
82427 +})
82428 +
82429 +enum {
82430 + GR_DO_AUDIT,
82431 + GR_DONT_AUDIT,
82432 + /* used for non-audit messages that we shouldn't kill the task on */
82433 + GR_DONT_AUDIT_GOOD
82434 +};
82435 +
82436 +enum {
82437 + GR_TTYSNIFF,
82438 + GR_RBAC,
82439 + GR_RBAC_STR,
82440 + GR_STR_RBAC,
82441 + GR_RBAC_MODE2,
82442 + GR_RBAC_MODE3,
82443 + GR_FILENAME,
82444 + GR_SYSCTL_HIDDEN,
82445 + GR_NOARGS,
82446 + GR_ONE_INT,
82447 + GR_ONE_INT_TWO_STR,
82448 + GR_ONE_STR,
82449 + GR_STR_INT,
82450 + GR_TWO_STR_INT,
82451 + GR_TWO_INT,
82452 + GR_TWO_U64,
82453 + GR_THREE_INT,
82454 + GR_FIVE_INT_TWO_STR,
82455 + GR_TWO_STR,
82456 + GR_THREE_STR,
82457 + GR_FOUR_STR,
82458 + GR_STR_FILENAME,
82459 + GR_FILENAME_STR,
82460 + GR_FILENAME_TWO_INT,
82461 + GR_FILENAME_TWO_INT_STR,
82462 + GR_TEXTREL,
82463 + GR_PTRACE,
82464 + GR_RESOURCE,
82465 + GR_CAP,
82466 + GR_SIG,
82467 + GR_SIG2,
82468 + GR_CRASH1,
82469 + GR_CRASH2,
82470 + GR_PSACCT,
82471 + GR_RWXMAP,
82472 + GR_RWXMAPVMA
82473 +};
82474 +
82475 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82476 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82477 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82478 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82479 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82480 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82481 +#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)
82482 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82483 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82484 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82485 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82486 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82487 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82488 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82489 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82490 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82491 +#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)
82492 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82493 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82494 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82495 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82496 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82497 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82498 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82499 +#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)
82500 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82501 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82502 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82503 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82504 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82505 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82506 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82507 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82508 +#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)
82509 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82510 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82511 +
82512 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82513 +
82514 +#endif
82515 +
82516 +#endif
82517 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82518 new file mode 100644
82519 index 0000000..b02ba9d
82520 --- /dev/null
82521 +++ b/include/linux/grmsg.h
82522 @@ -0,0 +1,117 @@
82523 +#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"
82524 +#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"
82525 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82526 +#define GR_STOPMOD_MSG "denied modification of module state by "
82527 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82528 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82529 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82530 +#define GR_IOPL_MSG "denied use of iopl() by "
82531 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82532 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82533 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82534 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82535 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82536 +#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"
82537 +#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"
82538 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82539 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82540 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82541 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82542 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82543 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82544 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82545 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82546 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82547 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82548 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82549 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82550 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82551 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82552 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82553 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82554 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82555 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82556 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82557 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82558 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82559 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82560 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82561 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82562 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82563 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82564 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82565 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82566 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82567 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82568 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82569 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82570 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82571 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82572 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82573 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82574 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82575 +#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"
82576 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82577 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82578 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82579 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82580 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82581 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82582 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82583 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82584 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82585 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82586 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82587 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82588 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82589 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82590 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82591 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82592 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82593 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82594 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82595 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82596 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82597 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82598 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82599 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82600 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82601 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82602 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82603 +#define GR_TIME_MSG "time set by "
82604 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82605 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82606 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82607 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82608 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82609 +#define GR_BIND_MSG "denied bind() by "
82610 +#define GR_CONNECT_MSG "denied connect() by "
82611 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82612 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82613 +#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"
82614 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82615 +#define GR_CAP_ACL_MSG "use of %s denied for "
82616 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82617 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82618 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82619 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82620 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82621 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82622 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82623 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82624 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82625 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82626 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82627 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82628 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82629 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82630 +#define GR_VM86_MSG "denied use of vm86 by "
82631 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82632 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82633 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82634 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82635 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82636 +#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 "
82637 +#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 "
82638 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82639 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82640 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82641 new file mode 100644
82642 index 0000000..10b9635
82643 --- /dev/null
82644 +++ b/include/linux/grsecurity.h
82645 @@ -0,0 +1,254 @@
82646 +#ifndef GR_SECURITY_H
82647 +#define GR_SECURITY_H
82648 +#include <linux/fs.h>
82649 +#include <linux/fs_struct.h>
82650 +#include <linux/binfmts.h>
82651 +#include <linux/gracl.h>
82652 +
82653 +/* notify of brain-dead configs */
82654 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82655 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82656 +#endif
82657 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82658 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82659 +#endif
82660 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82661 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82662 +#endif
82663 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82664 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82665 +#endif
82666 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82667 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82668 +#endif
82669 +
82670 +int gr_handle_new_usb(void);
82671 +
82672 +void gr_handle_brute_attach(int dumpable);
82673 +void gr_handle_brute_check(void);
82674 +void gr_handle_kernel_exploit(void);
82675 +
82676 +char gr_roletype_to_char(void);
82677 +
82678 +int gr_proc_is_restricted(void);
82679 +
82680 +int gr_acl_enable_at_secure(void);
82681 +
82682 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82683 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82684 +
82685 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82686 +
82687 +void gr_del_task_from_ip_table(struct task_struct *p);
82688 +
82689 +int gr_pid_is_chrooted(struct task_struct *p);
82690 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82691 +int gr_handle_chroot_nice(void);
82692 +int gr_handle_chroot_sysctl(const int op);
82693 +int gr_handle_chroot_setpriority(struct task_struct *p,
82694 + const int niceval);
82695 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82696 +int gr_chroot_fhandle(void);
82697 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82698 + const struct vfsmount *mnt);
82699 +void gr_handle_chroot_chdir(const struct path *path);
82700 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82701 + const struct vfsmount *mnt, const int mode);
82702 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82703 + const struct vfsmount *mnt, const int mode);
82704 +int gr_handle_chroot_mount(const struct dentry *dentry,
82705 + const struct vfsmount *mnt,
82706 + const char *dev_name);
82707 +int gr_handle_chroot_pivot(void);
82708 +int gr_handle_chroot_unix(const pid_t pid);
82709 +
82710 +int gr_handle_rawio(const struct inode *inode);
82711 +
82712 +void gr_handle_ioperm(void);
82713 +void gr_handle_iopl(void);
82714 +void gr_handle_msr_write(void);
82715 +
82716 +umode_t gr_acl_umask(void);
82717 +
82718 +int gr_tpe_allow(const struct file *file);
82719 +
82720 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82721 +void gr_clear_chroot_entries(struct task_struct *task);
82722 +
82723 +void gr_log_forkfail(const int retval);
82724 +void gr_log_timechange(void);
82725 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82726 +void gr_log_chdir(const struct dentry *dentry,
82727 + const struct vfsmount *mnt);
82728 +void gr_log_chroot_exec(const struct dentry *dentry,
82729 + const struct vfsmount *mnt);
82730 +void gr_log_remount(const char *devname, const int retval);
82731 +void gr_log_unmount(const char *devname, const int retval);
82732 +void gr_log_mount(const char *from, const char *to, const int retval);
82733 +void gr_log_textrel(struct vm_area_struct *vma);
82734 +void gr_log_ptgnustack(struct file *file);
82735 +void gr_log_rwxmmap(struct file *file);
82736 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82737 +
82738 +int gr_handle_follow_link(const struct inode *parent,
82739 + const struct inode *inode,
82740 + const struct dentry *dentry,
82741 + const struct vfsmount *mnt);
82742 +int gr_handle_fifo(const struct dentry *dentry,
82743 + const struct vfsmount *mnt,
82744 + const struct dentry *dir, const int flag,
82745 + const int acc_mode);
82746 +int gr_handle_hardlink(const struct dentry *dentry,
82747 + const struct vfsmount *mnt,
82748 + struct inode *inode,
82749 + const int mode, const struct filename *to);
82750 +
82751 +int gr_is_capable(const int cap);
82752 +int gr_is_capable_nolog(const int cap);
82753 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82754 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82755 +
82756 +void gr_copy_label(struct task_struct *tsk);
82757 +void gr_handle_crash(struct task_struct *task, const int sig);
82758 +int gr_handle_signal(const struct task_struct *p, const int sig);
82759 +int gr_check_crash_uid(const kuid_t uid);
82760 +int gr_check_protected_task(const struct task_struct *task);
82761 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82762 +int gr_acl_handle_mmap(const struct file *file,
82763 + const unsigned long prot);
82764 +int gr_acl_handle_mprotect(const struct file *file,
82765 + const unsigned long prot);
82766 +int gr_check_hidden_task(const struct task_struct *tsk);
82767 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82768 + const struct vfsmount *mnt);
82769 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82770 + const struct vfsmount *mnt);
82771 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82772 + const struct vfsmount *mnt, const int fmode);
82773 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82774 + const struct vfsmount *mnt, umode_t *mode);
82775 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82776 + const struct vfsmount *mnt);
82777 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82778 + const struct vfsmount *mnt);
82779 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82780 + const struct vfsmount *mnt);
82781 +int gr_handle_ptrace(struct task_struct *task, const long request);
82782 +int gr_handle_proc_ptrace(struct task_struct *task);
82783 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82784 + const struct vfsmount *mnt);
82785 +int gr_check_crash_exec(const struct file *filp);
82786 +int gr_acl_is_enabled(void);
82787 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82788 + const kgid_t gid);
82789 +int gr_set_proc_label(const struct dentry *dentry,
82790 + const struct vfsmount *mnt,
82791 + const int unsafe_flags);
82792 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82793 + const struct vfsmount *mnt);
82794 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82795 + const struct vfsmount *mnt, int acc_mode);
82796 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82797 + const struct dentry *p_dentry,
82798 + const struct vfsmount *p_mnt,
82799 + int open_flags, int acc_mode, const int imode);
82800 +void gr_handle_create(const struct dentry *dentry,
82801 + const struct vfsmount *mnt);
82802 +void gr_handle_proc_create(const struct dentry *dentry,
82803 + const struct inode *inode);
82804 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82805 + const struct dentry *parent_dentry,
82806 + const struct vfsmount *parent_mnt,
82807 + const int mode);
82808 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82809 + const struct dentry *parent_dentry,
82810 + const struct vfsmount *parent_mnt);
82811 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82812 + const struct vfsmount *mnt);
82813 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82814 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82815 + const struct vfsmount *mnt);
82816 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82817 + const struct dentry *parent_dentry,
82818 + const struct vfsmount *parent_mnt,
82819 + const struct filename *from);
82820 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82821 + const struct dentry *parent_dentry,
82822 + const struct vfsmount *parent_mnt,
82823 + const struct dentry *old_dentry,
82824 + const struct vfsmount *old_mnt, const struct filename *to);
82825 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82826 +int gr_acl_handle_rename(struct dentry *new_dentry,
82827 + struct dentry *parent_dentry,
82828 + const struct vfsmount *parent_mnt,
82829 + struct dentry *old_dentry,
82830 + struct inode *old_parent_inode,
82831 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82832 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82833 + struct dentry *old_dentry,
82834 + struct dentry *new_dentry,
82835 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82836 +__u32 gr_check_link(const struct dentry *new_dentry,
82837 + const struct dentry *parent_dentry,
82838 + const struct vfsmount *parent_mnt,
82839 + const struct dentry *old_dentry,
82840 + const struct vfsmount *old_mnt);
82841 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82842 + const unsigned int namelen, const ino_t ino);
82843 +
82844 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82845 + const struct vfsmount *mnt);
82846 +void gr_acl_handle_exit(void);
82847 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82848 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82849 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82850 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82851 +void gr_audit_ptrace(struct task_struct *task);
82852 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82853 +void gr_put_exec_file(struct task_struct *task);
82854 +
82855 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82856 +
82857 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82858 +extern void gr_learn_resource(const struct task_struct *task, const int res,
82859 + const unsigned long wanted, const int gt);
82860 +#else
82861 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
82862 + const unsigned long wanted, const int gt)
82863 +{
82864 +}
82865 +#endif
82866 +
82867 +#ifdef CONFIG_GRKERNSEC_RESLOG
82868 +extern void gr_log_resource(const struct task_struct *task, const int res,
82869 + const unsigned long wanted, const int gt);
82870 +#else
82871 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82872 + const unsigned long wanted, const int gt)
82873 +{
82874 +}
82875 +#endif
82876 +
82877 +#ifdef CONFIG_GRKERNSEC
82878 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82879 +void gr_handle_vm86(void);
82880 +void gr_handle_mem_readwrite(u64 from, u64 to);
82881 +
82882 +void gr_log_badprocpid(const char *entry);
82883 +
82884 +extern int grsec_enable_dmesg;
82885 +extern int grsec_disable_privio;
82886 +
82887 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82888 +extern kgid_t grsec_proc_gid;
82889 +#endif
82890 +
82891 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82892 +extern int grsec_enable_chroot_findtask;
82893 +#endif
82894 +#ifdef CONFIG_GRKERNSEC_SETXID
82895 +extern int grsec_enable_setxid;
82896 +#endif
82897 +#endif
82898 +
82899 +#endif
82900 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82901 new file mode 100644
82902 index 0000000..e7ffaaf
82903 --- /dev/null
82904 +++ b/include/linux/grsock.h
82905 @@ -0,0 +1,19 @@
82906 +#ifndef __GRSOCK_H
82907 +#define __GRSOCK_H
82908 +
82909 +extern void gr_attach_curr_ip(const struct sock *sk);
82910 +extern int gr_handle_sock_all(const int family, const int type,
82911 + const int protocol);
82912 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82913 +extern int gr_handle_sock_server_other(const struct sock *sck);
82914 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82915 +extern int gr_search_connect(struct socket * sock,
82916 + struct sockaddr_in * addr);
82917 +extern int gr_search_bind(struct socket * sock,
82918 + struct sockaddr_in * addr);
82919 +extern int gr_search_listen(struct socket * sock);
82920 +extern int gr_search_accept(struct socket * sock);
82921 +extern int gr_search_socket(const int domain, const int type,
82922 + const int protocol);
82923 +
82924 +#endif
82925 diff --git a/include/linux/hash.h b/include/linux/hash.h
82926 index d0494c3..69b7715 100644
82927 --- a/include/linux/hash.h
82928 +++ b/include/linux/hash.h
82929 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82930 struct fast_hash_ops {
82931 u32 (*hash)(const void *data, u32 len, u32 seed);
82932 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82933 -};
82934 +} __no_const;
82935
82936 /**
82937 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82938 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82939 index 9286a46..373f27f 100644
82940 --- a/include/linux/highmem.h
82941 +++ b/include/linux/highmem.h
82942 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82943 kunmap_atomic(kaddr);
82944 }
82945
82946 +static inline void sanitize_highpage(struct page *page)
82947 +{
82948 + void *kaddr;
82949 + unsigned long flags;
82950 +
82951 + local_irq_save(flags);
82952 + kaddr = kmap_atomic(page);
82953 + clear_page(kaddr);
82954 + kunmap_atomic(kaddr);
82955 + local_irq_restore(flags);
82956 +}
82957 +
82958 static inline void zero_user_segments(struct page *page,
82959 unsigned start1, unsigned end1,
82960 unsigned start2, unsigned end2)
82961 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82962 index 1c7b89a..7dda400 100644
82963 --- a/include/linux/hwmon-sysfs.h
82964 +++ b/include/linux/hwmon-sysfs.h
82965 @@ -25,7 +25,8 @@
82966 struct sensor_device_attribute{
82967 struct device_attribute dev_attr;
82968 int index;
82969 -};
82970 +} __do_const;
82971 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82972 #define to_sensor_dev_attr(_dev_attr) \
82973 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82974
82975 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82976 struct device_attribute dev_attr;
82977 u8 index;
82978 u8 nr;
82979 -};
82980 +} __do_const;
82981 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82982 #define to_sensor_dev_attr_2(_dev_attr) \
82983 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82984
82985 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82986 index b556e0a..c10a515 100644
82987 --- a/include/linux/i2c.h
82988 +++ b/include/linux/i2c.h
82989 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82990 /* To determine what the adapter supports */
82991 u32 (*functionality) (struct i2c_adapter *);
82992 };
82993 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82994
82995 /**
82996 * struct i2c_bus_recovery_info - I2C bus recovery information
82997 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82998 index d23c3c2..eb63c81 100644
82999 --- a/include/linux/i2o.h
83000 +++ b/include/linux/i2o.h
83001 @@ -565,7 +565,7 @@ struct i2o_controller {
83002 struct i2o_device *exec; /* Executive */
83003 #if BITS_PER_LONG == 64
83004 spinlock_t context_list_lock; /* lock for context_list */
83005 - atomic_t context_list_counter; /* needed for unique contexts */
83006 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
83007 struct list_head context_list; /* list of context id's
83008 and pointers */
83009 #endif
83010 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
83011 index aff7ad8..3942bbd 100644
83012 --- a/include/linux/if_pppox.h
83013 +++ b/include/linux/if_pppox.h
83014 @@ -76,7 +76,7 @@ struct pppox_proto {
83015 int (*ioctl)(struct socket *sock, unsigned int cmd,
83016 unsigned long arg);
83017 struct module *owner;
83018 -};
83019 +} __do_const;
83020
83021 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
83022 extern void unregister_pppox_proto(int proto_num);
83023 diff --git a/include/linux/init.h b/include/linux/init.h
83024 index 2df8e8d..3e1280d 100644
83025 --- a/include/linux/init.h
83026 +++ b/include/linux/init.h
83027 @@ -37,9 +37,17 @@
83028 * section.
83029 */
83030
83031 +#define add_init_latent_entropy __latent_entropy
83032 +
83033 +#ifdef CONFIG_MEMORY_HOTPLUG
83034 +#define add_meminit_latent_entropy
83035 +#else
83036 +#define add_meminit_latent_entropy __latent_entropy
83037 +#endif
83038 +
83039 /* These are for everybody (although not all archs will actually
83040 discard it in modules) */
83041 -#define __init __section(.init.text) __cold notrace
83042 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
83043 #define __initdata __section(.init.data)
83044 #define __initconst __constsection(.init.rodata)
83045 #define __exitdata __section(.exit.data)
83046 @@ -100,7 +108,7 @@
83047 #define __cpuexitconst
83048
83049 /* Used for MEMORY_HOTPLUG */
83050 -#define __meminit __section(.meminit.text) __cold notrace
83051 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
83052 #define __meminitdata __section(.meminit.data)
83053 #define __meminitconst __constsection(.meminit.rodata)
83054 #define __memexit __section(.memexit.text) __exitused __cold notrace
83055 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
83056 index 2bb4c4f3..e0fac69 100644
83057 --- a/include/linux/init_task.h
83058 +++ b/include/linux/init_task.h
83059 @@ -149,6 +149,12 @@ extern struct task_group root_task_group;
83060
83061 #define INIT_TASK_COMM "swapper"
83062
83063 +#ifdef CONFIG_X86
83064 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
83065 +#else
83066 +#define INIT_TASK_THREAD_INFO
83067 +#endif
83068 +
83069 #ifdef CONFIG_RT_MUTEXES
83070 # define INIT_RT_MUTEXES(tsk) \
83071 .pi_waiters = RB_ROOT, \
83072 @@ -196,6 +202,7 @@ extern struct task_group root_task_group;
83073 RCU_POINTER_INITIALIZER(cred, &init_cred), \
83074 .comm = INIT_TASK_COMM, \
83075 .thread = INIT_THREAD, \
83076 + INIT_TASK_THREAD_INFO \
83077 .fs = &init_fs, \
83078 .files = &init_files, \
83079 .signal = &init_signals, \
83080 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
83081 index 698ad05..8601bb7 100644
83082 --- a/include/linux/interrupt.h
83083 +++ b/include/linux/interrupt.h
83084 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83085
83086 struct softirq_action
83087 {
83088 - void (*action)(struct softirq_action *);
83089 -};
83090 + void (*action)(void);
83091 +} __no_const;
83092
83093 asmlinkage void do_softirq(void);
83094 asmlinkage void __do_softirq(void);
83095 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
83096 }
83097 #endif
83098
83099 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83100 +extern void open_softirq(int nr, void (*action)(void));
83101 extern void softirq_init(void);
83102 extern void __raise_softirq_irqoff(unsigned int nr);
83103
83104 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83105 index 20f9a52..63ee2e3 100644
83106 --- a/include/linux/iommu.h
83107 +++ b/include/linux/iommu.h
83108 @@ -131,7 +131,7 @@ struct iommu_ops {
83109 u32 (*domain_get_windows)(struct iommu_domain *domain);
83110
83111 unsigned long pgsize_bitmap;
83112 -};
83113 +} __do_const;
83114
83115 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83116 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83117 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83118 index 142ec54..873e033 100644
83119 --- a/include/linux/ioport.h
83120 +++ b/include/linux/ioport.h
83121 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83122 int adjust_resource(struct resource *res, resource_size_t start,
83123 resource_size_t size);
83124 resource_size_t resource_alignment(struct resource *res);
83125 -static inline resource_size_t resource_size(const struct resource *res)
83126 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83127 {
83128 return res->end - res->start + 1;
83129 }
83130 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83131 index 35e7eca..6afb7ad 100644
83132 --- a/include/linux/ipc_namespace.h
83133 +++ b/include/linux/ipc_namespace.h
83134 @@ -69,7 +69,7 @@ struct ipc_namespace {
83135 struct user_namespace *user_ns;
83136
83137 unsigned int proc_inum;
83138 -};
83139 +} __randomize_layout;
83140
83141 extern struct ipc_namespace init_ipc_ns;
83142 extern atomic_t nr_ipc_ns;
83143 diff --git a/include/linux/irq.h b/include/linux/irq.h
83144 index 62af592..cc3b0d0 100644
83145 --- a/include/linux/irq.h
83146 +++ b/include/linux/irq.h
83147 @@ -344,7 +344,8 @@ struct irq_chip {
83148 void (*irq_release_resources)(struct irq_data *data);
83149
83150 unsigned long flags;
83151 -};
83152 +} __do_const;
83153 +typedef struct irq_chip __no_const irq_chip_no_const;
83154
83155 /*
83156 * irq_chip specific flags
83157 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83158 index 45e2d8c..26d85da 100644
83159 --- a/include/linux/irqchip/arm-gic.h
83160 +++ b/include/linux/irqchip/arm-gic.h
83161 @@ -75,9 +75,11 @@
83162
83163 #ifndef __ASSEMBLY__
83164
83165 +#include <linux/irq.h>
83166 +
83167 struct device_node;
83168
83169 -extern struct irq_chip gic_arch_extn;
83170 +extern irq_chip_no_const gic_arch_extn;
83171
83172 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83173 u32 offset, struct device_node *);
83174 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83175 index c367cbd..c9b79e6 100644
83176 --- a/include/linux/jiffies.h
83177 +++ b/include/linux/jiffies.h
83178 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83179 /*
83180 * Convert various time units to each other:
83181 */
83182 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83183 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83184 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83185 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83186
83187 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83188 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83189 {
83190 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83191 }
83192
83193 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83194 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83195 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83196 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83197 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83198 extern void jiffies_to_timespec(const unsigned long jiffies,
83199 - struct timespec *value);
83200 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83201 + struct timespec *value) __intentional_overflow(-1);
83202 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83203 extern void jiffies_to_timeval(const unsigned long jiffies,
83204 struct timeval *value);
83205
83206 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83207 index 6883e19..e854fcb 100644
83208 --- a/include/linux/kallsyms.h
83209 +++ b/include/linux/kallsyms.h
83210 @@ -15,7 +15,8 @@
83211
83212 struct module;
83213
83214 -#ifdef CONFIG_KALLSYMS
83215 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83216 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83217 /* Lookup the address for a symbol. Returns 0 if not found. */
83218 unsigned long kallsyms_lookup_name(const char *name);
83219
83220 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83221 /* Stupid that this does nothing, but I didn't create this mess. */
83222 #define __print_symbol(fmt, addr)
83223 #endif /*CONFIG_KALLSYMS*/
83224 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83225 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83226 +extern unsigned long kallsyms_lookup_name(const char *name);
83227 +extern void __print_symbol(const char *fmt, unsigned long address);
83228 +extern int sprint_backtrace(char *buffer, unsigned long address);
83229 +extern int sprint_symbol(char *buffer, unsigned long address);
83230 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83231 +const char *kallsyms_lookup(unsigned long addr,
83232 + unsigned long *symbolsize,
83233 + unsigned long *offset,
83234 + char **modname, char *namebuf);
83235 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83236 + unsigned long *symbolsize,
83237 + unsigned long *offset);
83238 +#endif
83239
83240 /* This macro allows us to keep printk typechecking */
83241 static __printf(1, 2)
83242 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83243 index 44792ee..6172f2a 100644
83244 --- a/include/linux/key-type.h
83245 +++ b/include/linux/key-type.h
83246 @@ -132,7 +132,7 @@ struct key_type {
83247 /* internal fields */
83248 struct list_head link; /* link in types list */
83249 struct lock_class_key lock_class; /* key->sem lock class */
83250 -};
83251 +} __do_const;
83252
83253 extern struct key_type key_type_keyring;
83254
83255 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83256 index 6b06d37..19f605f 100644
83257 --- a/include/linux/kgdb.h
83258 +++ b/include/linux/kgdb.h
83259 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83260 extern int kgdb_io_module_registered;
83261
83262 extern atomic_t kgdb_setting_breakpoint;
83263 -extern atomic_t kgdb_cpu_doing_single_step;
83264 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83265
83266 extern struct task_struct *kgdb_usethread;
83267 extern struct task_struct *kgdb_contthread;
83268 @@ -254,7 +254,7 @@ struct kgdb_arch {
83269 void (*correct_hw_break)(void);
83270
83271 void (*enable_nmi)(bool on);
83272 -};
83273 +} __do_const;
83274
83275 /**
83276 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83277 @@ -279,11 +279,11 @@ struct kgdb_io {
83278 void (*pre_exception) (void);
83279 void (*post_exception) (void);
83280 int is_console;
83281 -};
83282 +} __do_const;
83283
83284 extern struct kgdb_arch arch_kgdb_ops;
83285
83286 -extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
83287 +extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
83288
83289 #ifdef CONFIG_SERIAL_KGDB_NMI
83290 extern int kgdb_register_nmi_console(void);
83291 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83292 index 0555cc6..40116ce 100644
83293 --- a/include/linux/kmod.h
83294 +++ b/include/linux/kmod.h
83295 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83296 * usually useless though. */
83297 extern __printf(2, 3)
83298 int __request_module(bool wait, const char *name, ...);
83299 +extern __printf(3, 4)
83300 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83301 #define request_module(mod...) __request_module(true, mod)
83302 #define request_module_nowait(mod...) __request_module(false, mod)
83303 #define try_then_request_module(x, mod...) \
83304 @@ -57,6 +59,9 @@ struct subprocess_info {
83305 struct work_struct work;
83306 struct completion *complete;
83307 char *path;
83308 +#ifdef CONFIG_GRKERNSEC
83309 + char *origpath;
83310 +#endif
83311 char **argv;
83312 char **envp;
83313 int wait;
83314 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83315 index 2d61b90..a1d0a13 100644
83316 --- a/include/linux/kobject.h
83317 +++ b/include/linux/kobject.h
83318 @@ -118,7 +118,7 @@ struct kobj_type {
83319 struct attribute **default_attrs;
83320 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83321 const void *(*namespace)(struct kobject *kobj);
83322 -};
83323 +} __do_const;
83324
83325 struct kobj_uevent_env {
83326 char *argv[3];
83327 @@ -142,6 +142,7 @@ struct kobj_attribute {
83328 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83329 const char *buf, size_t count);
83330 };
83331 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83332
83333 extern const struct sysfs_ops kobj_sysfs_ops;
83334
83335 @@ -169,7 +170,7 @@ struct kset {
83336 spinlock_t list_lock;
83337 struct kobject kobj;
83338 const struct kset_uevent_ops *uevent_ops;
83339 -};
83340 +} __randomize_layout;
83341
83342 extern void kset_init(struct kset *kset);
83343 extern int __must_check kset_register(struct kset *kset);
83344 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83345 index df32d25..fb52e27 100644
83346 --- a/include/linux/kobject_ns.h
83347 +++ b/include/linux/kobject_ns.h
83348 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83349 const void *(*netlink_ns)(struct sock *sk);
83350 const void *(*initial_ns)(void);
83351 void (*drop_ns)(void *);
83352 -};
83353 +} __do_const;
83354
83355 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83356 int kobj_ns_type_registered(enum kobj_ns_type type);
83357 diff --git a/include/linux/kref.h b/include/linux/kref.h
83358 index 484604d..0f6c5b6 100644
83359 --- a/include/linux/kref.h
83360 +++ b/include/linux/kref.h
83361 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83362 static inline int kref_sub(struct kref *kref, unsigned int count,
83363 void (*release)(struct kref *kref))
83364 {
83365 - WARN_ON(release == NULL);
83366 + BUG_ON(release == NULL);
83367
83368 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83369 release(kref);
83370 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83371 index a4c33b3..e854710 100644
83372 --- a/include/linux/kvm_host.h
83373 +++ b/include/linux/kvm_host.h
83374 @@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83375 {
83376 }
83377 #endif
83378 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83379 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83380 struct module *module);
83381 void kvm_exit(void);
83382
83383 @@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83384 struct kvm_guest_debug *dbg);
83385 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83386
83387 -int kvm_arch_init(void *opaque);
83388 +int kvm_arch_init(const void *opaque);
83389 void kvm_arch_exit(void);
83390
83391 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83392 diff --git a/include/linux/libata.h b/include/linux/libata.h
83393 index 92abb49..e7fff2a 100644
83394 --- a/include/linux/libata.h
83395 +++ b/include/linux/libata.h
83396 @@ -976,7 +976,7 @@ struct ata_port_operations {
83397 * fields must be pointers.
83398 */
83399 const struct ata_port_operations *inherits;
83400 -};
83401 +} __do_const;
83402
83403 struct ata_port_info {
83404 unsigned long flags;
83405 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83406 index a6a42dd..6c5ebce 100644
83407 --- a/include/linux/linkage.h
83408 +++ b/include/linux/linkage.h
83409 @@ -36,6 +36,7 @@
83410 #endif
83411
83412 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83413 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83414 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83415
83416 /*
83417 diff --git a/include/linux/list.h b/include/linux/list.h
83418 index cbbb96f..602d023 100644
83419 --- a/include/linux/list.h
83420 +++ b/include/linux/list.h
83421 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83422 extern void list_del(struct list_head *entry);
83423 #endif
83424
83425 +extern void __pax_list_add(struct list_head *new,
83426 + struct list_head *prev,
83427 + struct list_head *next);
83428 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83429 +{
83430 + __pax_list_add(new, head, head->next);
83431 +}
83432 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83433 +{
83434 + __pax_list_add(new, head->prev, head);
83435 +}
83436 +extern void pax_list_del(struct list_head *entry);
83437 +
83438 /**
83439 * list_replace - replace old entry by new one
83440 * @old : the element to be replaced
83441 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83442 INIT_LIST_HEAD(entry);
83443 }
83444
83445 +extern void pax_list_del_init(struct list_head *entry);
83446 +
83447 /**
83448 * list_move - delete from one list and add as another's head
83449 * @list: the entry to move
83450 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83451 index 4bfde0e..d6e2e09 100644
83452 --- a/include/linux/lockref.h
83453 +++ b/include/linux/lockref.h
83454 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83455 return ((int)l->count < 0);
83456 }
83457
83458 +static inline unsigned int __lockref_read(struct lockref *lockref)
83459 +{
83460 + return lockref->count;
83461 +}
83462 +
83463 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83464 +{
83465 + lockref->count = count;
83466 +}
83467 +
83468 +static inline void __lockref_inc(struct lockref *lockref)
83469 +{
83470 +
83471 +#ifdef CONFIG_PAX_REFCOUNT
83472 + atomic_inc((atomic_t *)&lockref->count);
83473 +#else
83474 + lockref->count++;
83475 +#endif
83476 +
83477 +}
83478 +
83479 +static inline void __lockref_dec(struct lockref *lockref)
83480 +{
83481 +
83482 +#ifdef CONFIG_PAX_REFCOUNT
83483 + atomic_dec((atomic_t *)&lockref->count);
83484 +#else
83485 + lockref->count--;
83486 +#endif
83487 +
83488 +}
83489 +
83490 #endif /* __LINUX_LOCKREF_H */
83491 diff --git a/include/linux/math64.h b/include/linux/math64.h
83492 index c45c089..298841c 100644
83493 --- a/include/linux/math64.h
83494 +++ b/include/linux/math64.h
83495 @@ -15,7 +15,7 @@
83496 * This is commonly provided by 32bit archs to provide an optimized 64bit
83497 * divide.
83498 */
83499 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83500 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83501 {
83502 *remainder = dividend % divisor;
83503 return dividend / divisor;
83504 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83505 /**
83506 * div64_u64 - unsigned 64bit divide with 64bit divisor
83507 */
83508 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83509 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83510 {
83511 return dividend / divisor;
83512 }
83513 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83514 #define div64_ul(x, y) div_u64((x), (y))
83515
83516 #ifndef div_u64_rem
83517 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83518 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83519 {
83520 *remainder = do_div(dividend, divisor);
83521 return dividend;
83522 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83523 #endif
83524
83525 #ifndef div64_u64
83526 -extern u64 div64_u64(u64 dividend, u64 divisor);
83527 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83528 #endif
83529
83530 #ifndef div64_s64
83531 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83532 * divide.
83533 */
83534 #ifndef div_u64
83535 -static inline u64 div_u64(u64 dividend, u32 divisor)
83536 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83537 {
83538 u32 remainder;
83539 return div_u64_rem(dividend, divisor, &remainder);
83540 diff --git a/include/linux/memory.h b/include/linux/memory.h
83541 index bb7384e..8b8d8d1 100644
83542 --- a/include/linux/memory.h
83543 +++ b/include/linux/memory.h
83544 @@ -35,7 +35,7 @@ struct memory_block {
83545 };
83546
83547 int arch_get_memory_phys_device(unsigned long start_pfn);
83548 -unsigned long __weak memory_block_size_bytes(void);
83549 +unsigned long memory_block_size_bytes(void);
83550
83551 /* These states are exposed to userspace as text strings in sysfs */
83552 #define MEM_ONLINE (1<<0) /* exposed to userspace */
83553 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83554 index f230a97..714c006 100644
83555 --- a/include/linux/mempolicy.h
83556 +++ b/include/linux/mempolicy.h
83557 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83558 }
83559
83560 #define vma_policy(vma) ((vma)->vm_policy)
83561 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83562 +{
83563 + vma->vm_policy = pol;
83564 +}
83565
83566 static inline void mpol_get(struct mempolicy *pol)
83567 {
83568 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83569 }
83570
83571 #define vma_policy(vma) NULL
83572 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83573 +{
83574 +}
83575
83576 static inline int
83577 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83578 diff --git a/include/linux/mm.h b/include/linux/mm.h
83579 index 8981cc8..76fd8c2 100644
83580 --- a/include/linux/mm.h
83581 +++ b/include/linux/mm.h
83582 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83583 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83584 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83585 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83586 +
83587 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83588 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83589 +#endif
83590 +
83591 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83592
83593 #ifdef CONFIG_MEM_SOFT_DIRTY
83594 @@ -237,8 +242,8 @@ struct vm_operations_struct {
83595 /* called by access_process_vm when get_user_pages() fails, typically
83596 * for use by special VMAs that can switch between memory and hardware
83597 */
83598 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83599 - void *buf, int len, int write);
83600 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83601 + void *buf, size_t len, int write);
83602
83603 /* Called by the /proc/PID/maps code to ask the vma whether it
83604 * has a special name. Returning non-NULL will also cause this
83605 @@ -274,6 +279,7 @@ struct vm_operations_struct {
83606 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83607 unsigned long size, pgoff_t pgoff);
83608 };
83609 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83610
83611 struct mmu_gather;
83612 struct inode;
83613 @@ -1144,8 +1150,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83614 unsigned long *pfn);
83615 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83616 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83617 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83618 - void *buf, int len, int write);
83619 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83620 + void *buf, size_t len, int write);
83621
83622 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83623 loff_t const holebegin, loff_t const holelen)
83624 @@ -1184,9 +1190,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83625 }
83626 #endif
83627
83628 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83629 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83630 - void *buf, int len, int write);
83631 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83632 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83633 + void *buf, size_t len, int write);
83634
83635 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83636 unsigned long start, unsigned long nr_pages,
83637 @@ -1219,34 +1225,6 @@ int set_page_dirty_lock(struct page *page);
83638 int clear_page_dirty_for_io(struct page *page);
83639 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83640
83641 -/* Is the vma a continuation of the stack vma above it? */
83642 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83643 -{
83644 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83645 -}
83646 -
83647 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83648 - unsigned long addr)
83649 -{
83650 - return (vma->vm_flags & VM_GROWSDOWN) &&
83651 - (vma->vm_start == addr) &&
83652 - !vma_growsdown(vma->vm_prev, addr);
83653 -}
83654 -
83655 -/* Is the vma a continuation of the stack vma below it? */
83656 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83657 -{
83658 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83659 -}
83660 -
83661 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83662 - unsigned long addr)
83663 -{
83664 - return (vma->vm_flags & VM_GROWSUP) &&
83665 - (vma->vm_end == addr) &&
83666 - !vma_growsup(vma->vm_next, addr);
83667 -}
83668 -
83669 extern pid_t
83670 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83671
83672 @@ -1346,6 +1324,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83673 }
83674 #endif
83675
83676 +#ifdef CONFIG_MMU
83677 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83678 +#else
83679 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83680 +{
83681 + return __pgprot(0);
83682 +}
83683 +#endif
83684 +
83685 int vma_wants_writenotify(struct vm_area_struct *vma);
83686
83687 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83688 @@ -1364,8 +1351,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83689 {
83690 return 0;
83691 }
83692 +
83693 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83694 + unsigned long address)
83695 +{
83696 + return 0;
83697 +}
83698 #else
83699 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83700 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83701 #endif
83702
83703 #ifdef __PAGETABLE_PMD_FOLDED
83704 @@ -1374,8 +1368,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83705 {
83706 return 0;
83707 }
83708 +
83709 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83710 + unsigned long address)
83711 +{
83712 + return 0;
83713 +}
83714 #else
83715 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83716 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83717 #endif
83718
83719 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83720 @@ -1393,11 +1394,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83721 NULL: pud_offset(pgd, address);
83722 }
83723
83724 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83725 +{
83726 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83727 + NULL: pud_offset(pgd, address);
83728 +}
83729 +
83730 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83731 {
83732 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83733 NULL: pmd_offset(pud, address);
83734 }
83735 +
83736 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83737 +{
83738 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83739 + NULL: pmd_offset(pud, address);
83740 +}
83741 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83742
83743 #if USE_SPLIT_PTE_PTLOCKS
83744 @@ -1796,7 +1809,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83745 unsigned long addr, unsigned long len,
83746 unsigned long flags, struct page **pages);
83747
83748 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83749 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83750
83751 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83752 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83753 @@ -1804,6 +1817,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83754 unsigned long len, unsigned long prot, unsigned long flags,
83755 unsigned long pgoff, unsigned long *populate);
83756 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83757 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83758
83759 #ifdef CONFIG_MMU
83760 extern int __mm_populate(unsigned long addr, unsigned long len,
83761 @@ -1832,10 +1846,11 @@ struct vm_unmapped_area_info {
83762 unsigned long high_limit;
83763 unsigned long align_mask;
83764 unsigned long align_offset;
83765 + unsigned long threadstack_offset;
83766 };
83767
83768 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83769 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83770 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83771 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83772
83773 /*
83774 * Search for an unmapped address range.
83775 @@ -1847,7 +1862,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83776 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83777 */
83778 static inline unsigned long
83779 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83780 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83781 {
83782 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83783 return unmapped_area(info);
83784 @@ -1909,6 +1924,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83785 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83786 struct vm_area_struct **pprev);
83787
83788 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83789 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83790 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83791 +
83792 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83793 NULL if none. Assume start_addr < end_addr. */
83794 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83795 @@ -1937,15 +1956,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83796 return vma;
83797 }
83798
83799 -#ifdef CONFIG_MMU
83800 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83801 -#else
83802 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83803 -{
83804 - return __pgprot(0);
83805 -}
83806 -#endif
83807 -
83808 #ifdef CONFIG_NUMA_BALANCING
83809 unsigned long change_prot_numa(struct vm_area_struct *vma,
83810 unsigned long start, unsigned long end);
83811 @@ -1997,6 +2007,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83812 static inline void vm_stat_account(struct mm_struct *mm,
83813 unsigned long flags, struct file *file, long pages)
83814 {
83815 +
83816 +#ifdef CONFIG_PAX_RANDMMAP
83817 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83818 +#endif
83819 +
83820 mm->total_vm += pages;
83821 }
83822 #endif /* CONFIG_PROC_FS */
83823 @@ -2085,7 +2100,7 @@ extern int unpoison_memory(unsigned long pfn);
83824 extern int sysctl_memory_failure_early_kill;
83825 extern int sysctl_memory_failure_recovery;
83826 extern void shake_page(struct page *p, int access);
83827 -extern atomic_long_t num_poisoned_pages;
83828 +extern atomic_long_unchecked_t num_poisoned_pages;
83829 extern int soft_offline_page(struct page *page, int flags);
83830
83831 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83832 @@ -2120,5 +2135,11 @@ void __init setup_nr_node_ids(void);
83833 static inline void setup_nr_node_ids(void) {}
83834 #endif
83835
83836 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83837 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83838 +#else
83839 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83840 +#endif
83841 +
83842 #endif /* __KERNEL__ */
83843 #endif /* _LINUX_MM_H */
83844 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83845 index 6e0b286..90d9c0d 100644
83846 --- a/include/linux/mm_types.h
83847 +++ b/include/linux/mm_types.h
83848 @@ -308,7 +308,9 @@ struct vm_area_struct {
83849 #ifdef CONFIG_NUMA
83850 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83851 #endif
83852 -};
83853 +
83854 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83855 +} __randomize_layout;
83856
83857 struct core_thread {
83858 struct task_struct *task;
83859 @@ -454,7 +456,25 @@ struct mm_struct {
83860 bool tlb_flush_pending;
83861 #endif
83862 struct uprobes_state uprobes_state;
83863 -};
83864 +
83865 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83866 + unsigned long pax_flags;
83867 +#endif
83868 +
83869 +#ifdef CONFIG_PAX_DLRESOLVE
83870 + unsigned long call_dl_resolve;
83871 +#endif
83872 +
83873 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83874 + unsigned long call_syscall;
83875 +#endif
83876 +
83877 +#ifdef CONFIG_PAX_ASLR
83878 + unsigned long delta_mmap; /* randomized offset */
83879 + unsigned long delta_stack; /* randomized offset */
83880 +#endif
83881 +
83882 +} __randomize_layout;
83883
83884 static inline void mm_init_cpumask(struct mm_struct *mm)
83885 {
83886 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83887 index c5d5278..f0b68c8 100644
83888 --- a/include/linux/mmiotrace.h
83889 +++ b/include/linux/mmiotrace.h
83890 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83891 /* Called from ioremap.c */
83892 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83893 void __iomem *addr);
83894 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83895 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83896
83897 /* For anyone to insert markers. Remember trailing newline. */
83898 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83899 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83900 {
83901 }
83902
83903 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83904 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83905 {
83906 }
83907
83908 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83909 index 318df70..b74ec01 100644
83910 --- a/include/linux/mmzone.h
83911 +++ b/include/linux/mmzone.h
83912 @@ -518,7 +518,7 @@ struct zone {
83913
83914 ZONE_PADDING(_pad3_)
83915 /* Zone statistics */
83916 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83917 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83918 } ____cacheline_internodealigned_in_smp;
83919
83920 typedef enum {
83921 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83922 index 44eeef0..a92d3f9 100644
83923 --- a/include/linux/mod_devicetable.h
83924 +++ b/include/linux/mod_devicetable.h
83925 @@ -139,7 +139,7 @@ struct usb_device_id {
83926 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83927 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83928
83929 -#define HID_ANY_ID (~0)
83930 +#define HID_ANY_ID (~0U)
83931 #define HID_BUS_ANY 0xffff
83932 #define HID_GROUP_ANY 0x0000
83933
83934 @@ -475,7 +475,7 @@ struct dmi_system_id {
83935 const char *ident;
83936 struct dmi_strmatch matches[4];
83937 void *driver_data;
83938 -};
83939 +} __do_const;
83940 /*
83941 * struct dmi_device_id appears during expansion of
83942 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83943 diff --git a/include/linux/module.h b/include/linux/module.h
83944 index 71f282a..b2387e2 100644
83945 --- a/include/linux/module.h
83946 +++ b/include/linux/module.h
83947 @@ -17,9 +17,11 @@
83948 #include <linux/moduleparam.h>
83949 #include <linux/jump_label.h>
83950 #include <linux/export.h>
83951 +#include <linux/fs.h>
83952
83953 #include <linux/percpu.h>
83954 #include <asm/module.h>
83955 +#include <asm/pgtable.h>
83956
83957 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83958 #define MODULE_SIG_STRING "~Module signature appended~\n"
83959 @@ -42,7 +44,7 @@ struct module_kobject {
83960 struct kobject *drivers_dir;
83961 struct module_param_attrs *mp;
83962 struct completion *kobj_completion;
83963 -};
83964 +} __randomize_layout;
83965
83966 struct module_attribute {
83967 struct attribute attr;
83968 @@ -54,12 +56,13 @@ struct module_attribute {
83969 int (*test)(struct module *);
83970 void (*free)(struct module *);
83971 };
83972 +typedef struct module_attribute __no_const module_attribute_no_const;
83973
83974 struct module_version_attribute {
83975 struct module_attribute mattr;
83976 const char *module_name;
83977 const char *version;
83978 -} __attribute__ ((__aligned__(sizeof(void *))));
83979 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83980
83981 extern ssize_t __modver_version_show(struct module_attribute *,
83982 struct module_kobject *, char *);
83983 @@ -235,7 +238,7 @@ struct module {
83984
83985 /* Sysfs stuff. */
83986 struct module_kobject mkobj;
83987 - struct module_attribute *modinfo_attrs;
83988 + module_attribute_no_const *modinfo_attrs;
83989 const char *version;
83990 const char *srcversion;
83991 struct kobject *holders_dir;
83992 @@ -284,19 +287,16 @@ struct module {
83993 int (*init)(void);
83994
83995 /* If this is non-NULL, vfree after init() returns */
83996 - void *module_init;
83997 + void *module_init_rx, *module_init_rw;
83998
83999 /* Here is the actual code + data, vfree'd on unload. */
84000 - void *module_core;
84001 + void *module_core_rx, *module_core_rw;
84002
84003 /* Here are the sizes of the init and core sections */
84004 - unsigned int init_size, core_size;
84005 + unsigned int init_size_rw, core_size_rw;
84006
84007 /* The size of the executable code in each section. */
84008 - unsigned int init_text_size, core_text_size;
84009 -
84010 - /* Size of RO sections of the module (text+rodata) */
84011 - unsigned int init_ro_size, core_ro_size;
84012 + unsigned int init_size_rx, core_size_rx;
84013
84014 /* Arch-specific module values */
84015 struct mod_arch_specific arch;
84016 @@ -352,6 +352,10 @@ struct module {
84017 #ifdef CONFIG_EVENT_TRACING
84018 struct ftrace_event_call **trace_events;
84019 unsigned int num_trace_events;
84020 + struct file_operations trace_id;
84021 + struct file_operations trace_enable;
84022 + struct file_operations trace_format;
84023 + struct file_operations trace_filter;
84024 #endif
84025 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
84026 unsigned int num_ftrace_callsites;
84027 @@ -375,7 +379,7 @@ struct module {
84028 ctor_fn_t *ctors;
84029 unsigned int num_ctors;
84030 #endif
84031 -};
84032 +} __randomize_layout;
84033 #ifndef MODULE_ARCH_INIT
84034 #define MODULE_ARCH_INIT {}
84035 #endif
84036 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
84037 bool is_module_percpu_address(unsigned long addr);
84038 bool is_module_text_address(unsigned long addr);
84039
84040 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
84041 +{
84042 +
84043 +#ifdef CONFIG_PAX_KERNEXEC
84044 + if (ktla_ktva(addr) >= (unsigned long)start &&
84045 + ktla_ktva(addr) < (unsigned long)start + size)
84046 + return 1;
84047 +#endif
84048 +
84049 + return ((void *)addr >= start && (void *)addr < start + size);
84050 +}
84051 +
84052 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
84053 +{
84054 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
84055 +}
84056 +
84057 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
84058 +{
84059 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
84060 +}
84061 +
84062 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
84063 +{
84064 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
84065 +}
84066 +
84067 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
84068 +{
84069 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
84070 +}
84071 +
84072 static inline bool within_module_core(unsigned long addr,
84073 const struct module *mod)
84074 {
84075 - return (unsigned long)mod->module_core <= addr &&
84076 - addr < (unsigned long)mod->module_core + mod->core_size;
84077 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84078 }
84079
84080 static inline bool within_module_init(unsigned long addr,
84081 const struct module *mod)
84082 {
84083 - return (unsigned long)mod->module_init <= addr &&
84084 - addr < (unsigned long)mod->module_init + mod->init_size;
84085 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84086 }
84087
84088 static inline bool within_module(unsigned long addr, const struct module *mod)
84089 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84090 index 7eeb9bb..68f37e0 100644
84091 --- a/include/linux/moduleloader.h
84092 +++ b/include/linux/moduleloader.h
84093 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84094 sections. Returns NULL on failure. */
84095 void *module_alloc(unsigned long size);
84096
84097 +#ifdef CONFIG_PAX_KERNEXEC
84098 +void *module_alloc_exec(unsigned long size);
84099 +#else
84100 +#define module_alloc_exec(x) module_alloc(x)
84101 +#endif
84102 +
84103 /* Free memory returned from module_alloc. */
84104 void module_free(struct module *mod, void *module_region);
84105
84106 +#ifdef CONFIG_PAX_KERNEXEC
84107 +void module_free_exec(struct module *mod, void *module_region);
84108 +#else
84109 +#define module_free_exec(x, y) module_free((x), (y))
84110 +#endif
84111 +
84112 /*
84113 * Apply the given relocation to the (simplified) ELF. Return -error
84114 * or 0.
84115 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84116 unsigned int relsec,
84117 struct module *me)
84118 {
84119 +#ifdef CONFIG_MODULES
84120 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84121 module_name(me));
84122 +#endif
84123 return -ENOEXEC;
84124 }
84125 #endif
84126 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84127 unsigned int relsec,
84128 struct module *me)
84129 {
84130 +#ifdef CONFIG_MODULES
84131 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84132 module_name(me));
84133 +#endif
84134 return -ENOEXEC;
84135 }
84136 #endif
84137 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84138 index 494f99e..5059f63 100644
84139 --- a/include/linux/moduleparam.h
84140 +++ b/include/linux/moduleparam.h
84141 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
84142 * @len is usually just sizeof(string).
84143 */
84144 #define module_param_string(name, string, len, perm) \
84145 - static const struct kparam_string __param_string_##name \
84146 + static const struct kparam_string __param_string_##name __used \
84147 = { len, string }; \
84148 __module_param_call(MODULE_PARAM_PREFIX, name, \
84149 &param_ops_string, \
84150 @@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84151 */
84152 #define module_param_array_named(name, array, type, nump, perm) \
84153 param_check_##type(name, &(array)[0]); \
84154 - static const struct kparam_array __param_arr_##name \
84155 + static const struct kparam_array __param_arr_##name __used \
84156 = { .max = ARRAY_SIZE(array), .num = nump, \
84157 .ops = &param_ops_##type, \
84158 .elemsize = sizeof(array[0]), .elem = array }; \
84159 diff --git a/include/linux/mount.h b/include/linux/mount.h
84160 index 9262e4b..0a45f98 100644
84161 --- a/include/linux/mount.h
84162 +++ b/include/linux/mount.h
84163 @@ -66,7 +66,7 @@ struct vfsmount {
84164 struct dentry *mnt_root; /* root of the mounted tree */
84165 struct super_block *mnt_sb; /* pointer to superblock */
84166 int mnt_flags;
84167 -};
84168 +} __randomize_layout;
84169
84170 struct file; /* forward dec */
84171 struct path;
84172 diff --git a/include/linux/namei.h b/include/linux/namei.h
84173 index 492de72..1bddcd4 100644
84174 --- a/include/linux/namei.h
84175 +++ b/include/linux/namei.h
84176 @@ -19,7 +19,7 @@ struct nameidata {
84177 unsigned seq, m_seq;
84178 int last_type;
84179 unsigned depth;
84180 - char *saved_names[MAX_NESTED_LINKS + 1];
84181 + const char *saved_names[MAX_NESTED_LINKS + 1];
84182 };
84183
84184 /*
84185 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84186
84187 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84188
84189 -static inline void nd_set_link(struct nameidata *nd, char *path)
84190 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84191 {
84192 nd->saved_names[nd->depth] = path;
84193 }
84194
84195 -static inline char *nd_get_link(struct nameidata *nd)
84196 +static inline const char *nd_get_link(const struct nameidata *nd)
84197 {
84198 return nd->saved_names[nd->depth];
84199 }
84200 diff --git a/include/linux/net.h b/include/linux/net.h
84201 index 17d8339..81656c0 100644
84202 --- a/include/linux/net.h
84203 +++ b/include/linux/net.h
84204 @@ -192,7 +192,7 @@ struct net_proto_family {
84205 int (*create)(struct net *net, struct socket *sock,
84206 int protocol, int kern);
84207 struct module *owner;
84208 -};
84209 +} __do_const;
84210
84211 struct iovec;
84212 struct kvec;
84213 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84214 index c8e388e..5d8cd9b 100644
84215 --- a/include/linux/netdevice.h
84216 +++ b/include/linux/netdevice.h
84217 @@ -1147,6 +1147,7 @@ struct net_device_ops {
84218 void *priv);
84219 int (*ndo_get_lock_subclass)(struct net_device *dev);
84220 };
84221 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84222
84223 /**
84224 * enum net_device_priv_flags - &struct net_device priv_flags
84225 @@ -1485,10 +1486,10 @@ struct net_device {
84226
84227 struct net_device_stats stats;
84228
84229 - atomic_long_t rx_dropped;
84230 - atomic_long_t tx_dropped;
84231 + atomic_long_unchecked_t rx_dropped;
84232 + atomic_long_unchecked_t tx_dropped;
84233
84234 - atomic_t carrier_changes;
84235 + atomic_unchecked_t carrier_changes;
84236
84237 #ifdef CONFIG_WIRELESS_EXT
84238 const struct iw_handler_def * wireless_handlers;
84239 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84240 index 2517ece..0bbfcfb 100644
84241 --- a/include/linux/netfilter.h
84242 +++ b/include/linux/netfilter.h
84243 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84244 #endif
84245 /* Use the module struct to lock set/get code in place */
84246 struct module *owner;
84247 -};
84248 +} __do_const;
84249
84250 /* Function to register/unregister hook points. */
84251 int nf_register_hook(struct nf_hook_ops *reg);
84252 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84253 index e955d47..04a5338 100644
84254 --- a/include/linux/netfilter/nfnetlink.h
84255 +++ b/include/linux/netfilter/nfnetlink.h
84256 @@ -19,7 +19,7 @@ struct nfnl_callback {
84257 const struct nlattr * const cda[]);
84258 const struct nla_policy *policy; /* netlink attribute policy */
84259 const u_int16_t attr_count; /* number of nlattr's */
84260 -};
84261 +} __do_const;
84262
84263 struct nfnetlink_subsystem {
84264 const char *name;
84265 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84266 new file mode 100644
84267 index 0000000..33f4af8
84268 --- /dev/null
84269 +++ b/include/linux/netfilter/xt_gradm.h
84270 @@ -0,0 +1,9 @@
84271 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84272 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84273 +
84274 +struct xt_gradm_mtinfo {
84275 + __u16 flags;
84276 + __u16 invflags;
84277 +};
84278 +
84279 +#endif
84280 diff --git a/include/linux/nls.h b/include/linux/nls.h
84281 index 520681b..2b7fabb 100644
84282 --- a/include/linux/nls.h
84283 +++ b/include/linux/nls.h
84284 @@ -31,7 +31,7 @@ struct nls_table {
84285 const unsigned char *charset2upper;
84286 struct module *owner;
84287 struct nls_table *next;
84288 -};
84289 +} __do_const;
84290
84291 /* this value hold the maximum octet of charset */
84292 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84293 @@ -46,7 +46,7 @@ enum utf16_endian {
84294 /* nls_base.c */
84295 extern int __register_nls(struct nls_table *, struct module *);
84296 extern int unregister_nls(struct nls_table *);
84297 -extern struct nls_table *load_nls(char *);
84298 +extern struct nls_table *load_nls(const char *);
84299 extern void unload_nls(struct nls_table *);
84300 extern struct nls_table *load_nls_default(void);
84301 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84302 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84303 index d14a4c3..a078786 100644
84304 --- a/include/linux/notifier.h
84305 +++ b/include/linux/notifier.h
84306 @@ -54,7 +54,8 @@ struct notifier_block {
84307 notifier_fn_t notifier_call;
84308 struct notifier_block __rcu *next;
84309 int priority;
84310 -};
84311 +} __do_const;
84312 +typedef struct notifier_block __no_const notifier_block_no_const;
84313
84314 struct atomic_notifier_head {
84315 spinlock_t lock;
84316 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84317 index b2a0f15..4d7da32 100644
84318 --- a/include/linux/oprofile.h
84319 +++ b/include/linux/oprofile.h
84320 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84321 int oprofilefs_create_ro_ulong(struct dentry * root,
84322 char const * name, ulong * val);
84323
84324 -/** Create a file for read-only access to an atomic_t. */
84325 +/** Create a file for read-only access to an atomic_unchecked_t. */
84326 int oprofilefs_create_ro_atomic(struct dentry * root,
84327 - char const * name, atomic_t * val);
84328 + char const * name, atomic_unchecked_t * val);
84329
84330 /** create a directory */
84331 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84332 diff --git a/include/linux/padata.h b/include/linux/padata.h
84333 index 4386946..f50c615 100644
84334 --- a/include/linux/padata.h
84335 +++ b/include/linux/padata.h
84336 @@ -129,7 +129,7 @@ struct parallel_data {
84337 struct padata_serial_queue __percpu *squeue;
84338 atomic_t reorder_objects;
84339 atomic_t refcnt;
84340 - atomic_t seq_nr;
84341 + atomic_unchecked_t seq_nr;
84342 struct padata_cpumask cpumask;
84343 spinlock_t lock ____cacheline_aligned;
84344 unsigned int processed;
84345 diff --git a/include/linux/path.h b/include/linux/path.h
84346 index d137218..be0c176 100644
84347 --- a/include/linux/path.h
84348 +++ b/include/linux/path.h
84349 @@ -1,13 +1,15 @@
84350 #ifndef _LINUX_PATH_H
84351 #define _LINUX_PATH_H
84352
84353 +#include <linux/compiler.h>
84354 +
84355 struct dentry;
84356 struct vfsmount;
84357
84358 struct path {
84359 struct vfsmount *mnt;
84360 struct dentry *dentry;
84361 -};
84362 +} __randomize_layout;
84363
84364 extern void path_get(const struct path *);
84365 extern void path_put(const struct path *);
84366 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84367 index 5f2e559..7d59314 100644
84368 --- a/include/linux/pci_hotplug.h
84369 +++ b/include/linux/pci_hotplug.h
84370 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84371 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84372 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84373 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84374 -};
84375 +} __do_const;
84376 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84377
84378 /**
84379 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84380 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84381 index 707617a..28a2e7e 100644
84382 --- a/include/linux/perf_event.h
84383 +++ b/include/linux/perf_event.h
84384 @@ -339,8 +339,8 @@ struct perf_event {
84385
84386 enum perf_event_active_state state;
84387 unsigned int attach_state;
84388 - local64_t count;
84389 - atomic64_t child_count;
84390 + local64_t count; /* PaX: fix it one day */
84391 + atomic64_unchecked_t child_count;
84392
84393 /*
84394 * These are the total time in nanoseconds that the event
84395 @@ -391,8 +391,8 @@ struct perf_event {
84396 * These accumulate total time (in nanoseconds) that children
84397 * events have been enabled and running, respectively.
84398 */
84399 - atomic64_t child_total_time_enabled;
84400 - atomic64_t child_total_time_running;
84401 + atomic64_unchecked_t child_total_time_enabled;
84402 + atomic64_unchecked_t child_total_time_running;
84403
84404 /*
84405 * Protect attach/detach and child_list:
84406 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84407 entry->ip[entry->nr++] = ip;
84408 }
84409
84410 -extern int sysctl_perf_event_paranoid;
84411 +extern int sysctl_perf_event_legitimately_concerned;
84412 extern int sysctl_perf_event_mlock;
84413 extern int sysctl_perf_event_sample_rate;
84414 extern int sysctl_perf_cpu_time_max_percent;
84415 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84416 loff_t *ppos);
84417
84418
84419 +static inline bool perf_paranoid_any(void)
84420 +{
84421 + return sysctl_perf_event_legitimately_concerned > 2;
84422 +}
84423 +
84424 static inline bool perf_paranoid_tracepoint_raw(void)
84425 {
84426 - return sysctl_perf_event_paranoid > -1;
84427 + return sysctl_perf_event_legitimately_concerned > -1;
84428 }
84429
84430 static inline bool perf_paranoid_cpu(void)
84431 {
84432 - return sysctl_perf_event_paranoid > 0;
84433 + return sysctl_perf_event_legitimately_concerned > 0;
84434 }
84435
84436 static inline bool perf_paranoid_kernel(void)
84437 {
84438 - return sysctl_perf_event_paranoid > 1;
84439 + return sysctl_perf_event_legitimately_concerned > 1;
84440 }
84441
84442 extern void perf_event_init(void);
84443 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84444 struct device_attribute attr;
84445 u64 id;
84446 const char *event_str;
84447 -};
84448 +} __do_const;
84449
84450 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84451 static struct perf_pmu_events_attr _var = { \
84452 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84453 index 1997ffc..4f1f44d 100644
84454 --- a/include/linux/pid_namespace.h
84455 +++ b/include/linux/pid_namespace.h
84456 @@ -44,7 +44,7 @@ struct pid_namespace {
84457 int hide_pid;
84458 int reboot; /* group exit code if this pidns was rebooted */
84459 unsigned int proc_inum;
84460 -};
84461 +} __randomize_layout;
84462
84463 extern struct pid_namespace init_pid_ns;
84464
84465 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84466 index eb8b8ac..62649e1 100644
84467 --- a/include/linux/pipe_fs_i.h
84468 +++ b/include/linux/pipe_fs_i.h
84469 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84470 struct mutex mutex;
84471 wait_queue_head_t wait;
84472 unsigned int nrbufs, curbuf, buffers;
84473 - unsigned int readers;
84474 - unsigned int writers;
84475 - unsigned int files;
84476 - unsigned int waiting_writers;
84477 + atomic_t readers;
84478 + atomic_t writers;
84479 + atomic_t files;
84480 + atomic_t waiting_writers;
84481 unsigned int r_counter;
84482 unsigned int w_counter;
84483 struct page *tmp_page;
84484 diff --git a/include/linux/pm.h b/include/linux/pm.h
84485 index 72c0fe0..26918ed 100644
84486 --- a/include/linux/pm.h
84487 +++ b/include/linux/pm.h
84488 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84489 struct dev_pm_domain {
84490 struct dev_pm_ops ops;
84491 };
84492 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84493
84494 /*
84495 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84496 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84497 index ebc4c76..7fab7b0 100644
84498 --- a/include/linux/pm_domain.h
84499 +++ b/include/linux/pm_domain.h
84500 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
84501 int (*thaw_early)(struct device *dev);
84502 int (*thaw)(struct device *dev);
84503 bool (*active_wakeup)(struct device *dev);
84504 -};
84505 +} __no_const;
84506
84507 struct gpd_cpu_data {
84508 unsigned int saved_exit_latency;
84509 - struct cpuidle_state *idle_state;
84510 + cpuidle_state_no_const *idle_state;
84511 };
84512
84513 struct generic_pm_domain {
84514 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84515 index 367f49b..d2f5a14 100644
84516 --- a/include/linux/pm_runtime.h
84517 +++ b/include/linux/pm_runtime.h
84518 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84519
84520 static inline void pm_runtime_mark_last_busy(struct device *dev)
84521 {
84522 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84523 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84524 }
84525
84526 #else /* !CONFIG_PM_RUNTIME */
84527 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84528 index 195aafc..49a7bc2 100644
84529 --- a/include/linux/pnp.h
84530 +++ b/include/linux/pnp.h
84531 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84532 struct pnp_fixup {
84533 char id[7];
84534 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84535 -};
84536 +} __do_const;
84537
84538 /* config parameters */
84539 #define PNP_CONFIG_NORMAL 0x0001
84540 diff --git a/include/linux/poison.h b/include/linux/poison.h
84541 index 2110a81..13a11bb 100644
84542 --- a/include/linux/poison.h
84543 +++ b/include/linux/poison.h
84544 @@ -19,8 +19,8 @@
84545 * under normal circumstances, used to verify that nobody uses
84546 * non-initialized list entries.
84547 */
84548 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84549 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84550 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84551 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84552
84553 /********** include/linux/timer.h **********/
84554 /*
84555 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84556 index d8b187c3..9a9257a 100644
84557 --- a/include/linux/power/smartreflex.h
84558 +++ b/include/linux/power/smartreflex.h
84559 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84560 int (*notify)(struct omap_sr *sr, u32 status);
84561 u8 notify_flags;
84562 u8 class_type;
84563 -};
84564 +} __do_const;
84565
84566 /**
84567 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84568 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84569 index 4ea1d37..80f4b33 100644
84570 --- a/include/linux/ppp-comp.h
84571 +++ b/include/linux/ppp-comp.h
84572 @@ -84,7 +84,7 @@ struct compressor {
84573 struct module *owner;
84574 /* Extra skb space needed by the compressor algorithm */
84575 unsigned int comp_extra;
84576 -};
84577 +} __do_const;
84578
84579 /*
84580 * The return value from decompress routine is the length of the
84581 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84582 index de83b4e..c4b997d 100644
84583 --- a/include/linux/preempt.h
84584 +++ b/include/linux/preempt.h
84585 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84586 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84587 #endif
84588
84589 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84590 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84591 +
84592 #define __preempt_count_inc() __preempt_count_add(1)
84593 #define __preempt_count_dec() __preempt_count_sub(1)
84594
84595 #define preempt_count_inc() preempt_count_add(1)
84596 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84597 #define preempt_count_dec() preempt_count_sub(1)
84598 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84599
84600 #ifdef CONFIG_PREEMPT_COUNT
84601
84602 @@ -41,6 +46,12 @@ do { \
84603 barrier(); \
84604 } while (0)
84605
84606 +#define raw_preempt_disable() \
84607 +do { \
84608 + raw_preempt_count_inc(); \
84609 + barrier(); \
84610 +} while (0)
84611 +
84612 #define sched_preempt_enable_no_resched() \
84613 do { \
84614 barrier(); \
84615 @@ -49,6 +60,12 @@ do { \
84616
84617 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84618
84619 +#define raw_preempt_enable_no_resched() \
84620 +do { \
84621 + barrier(); \
84622 + raw_preempt_count_dec(); \
84623 +} while (0)
84624 +
84625 #ifdef CONFIG_PREEMPT
84626 #define preempt_enable() \
84627 do { \
84628 @@ -113,8 +130,10 @@ do { \
84629 * region.
84630 */
84631 #define preempt_disable() barrier()
84632 +#define raw_preempt_disable() barrier()
84633 #define sched_preempt_enable_no_resched() barrier()
84634 #define preempt_enable_no_resched() barrier()
84635 +#define raw_preempt_enable_no_resched() barrier()
84636 #define preempt_enable() barrier()
84637 #define preempt_check_resched() do { } while (0)
84638
84639 @@ -128,11 +147,13 @@ do { \
84640 /*
84641 * Modules have no business playing preemption tricks.
84642 */
84643 +#ifndef CONFIG_PAX_KERNEXEC
84644 #undef sched_preempt_enable_no_resched
84645 #undef preempt_enable_no_resched
84646 #undef preempt_enable_no_resched_notrace
84647 #undef preempt_check_resched
84648 #endif
84649 +#endif
84650
84651 #define preempt_set_need_resched() \
84652 do { \
84653 diff --git a/include/linux/printk.h b/include/linux/printk.h
84654 index d78125f..7f36596 100644
84655 --- a/include/linux/printk.h
84656 +++ b/include/linux/printk.h
84657 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84658 void early_printk(const char *s, ...) { }
84659 #endif
84660
84661 +extern int kptr_restrict;
84662 +
84663 #ifdef CONFIG_PRINTK
84664 asmlinkage __printf(5, 0)
84665 int vprintk_emit(int facility, int level,
84666 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84667
84668 extern int printk_delay_msec;
84669 extern int dmesg_restrict;
84670 -extern int kptr_restrict;
84671
84672 extern void wake_up_klogd(void);
84673
84674 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84675 index 9d117f6..d832b31 100644
84676 --- a/include/linux/proc_fs.h
84677 +++ b/include/linux/proc_fs.h
84678 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84679 extern struct proc_dir_entry *proc_symlink(const char *,
84680 struct proc_dir_entry *, const char *);
84681 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84682 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84683 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84684 struct proc_dir_entry *, void *);
84685 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84686 + struct proc_dir_entry *, void *);
84687 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84688 struct proc_dir_entry *);
84689
84690 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84691 return proc_create_data(name, mode, parent, proc_fops, NULL);
84692 }
84693
84694 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84695 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84696 +{
84697 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84698 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84699 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84700 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84701 +#else
84702 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84703 +#endif
84704 +}
84705 +
84706 +
84707 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84708 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84709 extern void *PDE_DATA(const struct inode *);
84710 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84711 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84712 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84713 struct proc_dir_entry *parent) {return NULL;}
84714 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84715 + struct proc_dir_entry *parent) { return NULL; }
84716 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84717 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84718 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84719 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84720 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84721 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84722 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84723 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84724 static inline struct proc_dir_entry *proc_net_mkdir(
84725 struct net *net, const char *name, struct proc_dir_entry *parent)
84726 {
84727 - return proc_mkdir_data(name, 0, parent, net);
84728 + return proc_mkdir_data_restrict(name, 0, parent, net);
84729 }
84730
84731 #endif /* _LINUX_PROC_FS_H */
84732 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84733 index 34a1e10..70f6bde 100644
84734 --- a/include/linux/proc_ns.h
84735 +++ b/include/linux/proc_ns.h
84736 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84737 void (*put)(void *ns);
84738 int (*install)(struct nsproxy *nsproxy, void *ns);
84739 unsigned int (*inum)(void *ns);
84740 -};
84741 +} __do_const __randomize_layout;
84742
84743 struct proc_ns {
84744 void *ns;
84745 diff --git a/include/linux/quota.h b/include/linux/quota.h
84746 index 80d345a..9e89a9a 100644
84747 --- a/include/linux/quota.h
84748 +++ b/include/linux/quota.h
84749 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84750
84751 extern bool qid_eq(struct kqid left, struct kqid right);
84752 extern bool qid_lt(struct kqid left, struct kqid right);
84753 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84754 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84755 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84756 extern bool qid_valid(struct kqid qid);
84757
84758 diff --git a/include/linux/random.h b/include/linux/random.h
84759 index 57fbbff..2170304 100644
84760 --- a/include/linux/random.h
84761 +++ b/include/linux/random.h
84762 @@ -9,9 +9,19 @@
84763 #include <uapi/linux/random.h>
84764
84765 extern void add_device_randomness(const void *, unsigned int);
84766 +
84767 +static inline void add_latent_entropy(void)
84768 +{
84769 +
84770 +#ifdef LATENT_ENTROPY_PLUGIN
84771 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84772 +#endif
84773 +
84774 +}
84775 +
84776 extern void add_input_randomness(unsigned int type, unsigned int code,
84777 - unsigned int value);
84778 -extern void add_interrupt_randomness(int irq, int irq_flags);
84779 + unsigned int value) __latent_entropy;
84780 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84781
84782 extern void get_random_bytes(void *buf, int nbytes);
84783 extern void get_random_bytes_arch(void *buf, int nbytes);
84784 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84785 extern const struct file_operations random_fops, urandom_fops;
84786 #endif
84787
84788 -unsigned int get_random_int(void);
84789 +unsigned int __intentional_overflow(-1) get_random_int(void);
84790 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84791
84792 -u32 prandom_u32(void);
84793 +u32 prandom_u32(void) __intentional_overflow(-1);
84794 void prandom_bytes(void *buf, int nbytes);
84795 void prandom_seed(u32 seed);
84796 void prandom_reseed_late(void);
84797 @@ -37,6 +47,11 @@ struct rnd_state {
84798 u32 prandom_u32_state(struct rnd_state *state);
84799 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84800
84801 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84802 +{
84803 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84804 +}
84805 +
84806 /**
84807 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84808 * @ep_ro: right open interval endpoint
84809 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84810 *
84811 * Returns: pseudo-random number in interval [0, ep_ro)
84812 */
84813 -static inline u32 prandom_u32_max(u32 ep_ro)
84814 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84815 {
84816 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84817 }
84818 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84819 index fea49b5..2ac22bb 100644
84820 --- a/include/linux/rbtree_augmented.h
84821 +++ b/include/linux/rbtree_augmented.h
84822 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84823 old->rbaugmented = rbcompute(old); \
84824 } \
84825 rbstatic const struct rb_augment_callbacks rbname = { \
84826 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84827 + .propagate = rbname ## _propagate, \
84828 + .copy = rbname ## _copy, \
84829 + .rotate = rbname ## _rotate \
84830 };
84831
84832
84833 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84834 index 372ad5e..d4373f8 100644
84835 --- a/include/linux/rculist.h
84836 +++ b/include/linux/rculist.h
84837 @@ -29,8 +29,8 @@
84838 */
84839 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84840 {
84841 - ACCESS_ONCE(list->next) = list;
84842 - ACCESS_ONCE(list->prev) = list;
84843 + ACCESS_ONCE_RW(list->next) = list;
84844 + ACCESS_ONCE_RW(list->prev) = list;
84845 }
84846
84847 /*
84848 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84849 struct list_head *prev, struct list_head *next);
84850 #endif
84851
84852 +void __pax_list_add_rcu(struct list_head *new,
84853 + struct list_head *prev, struct list_head *next);
84854 +
84855 /**
84856 * list_add_rcu - add a new entry to rcu-protected list
84857 * @new: new entry to be added
84858 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84859 __list_add_rcu(new, head, head->next);
84860 }
84861
84862 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84863 +{
84864 + __pax_list_add_rcu(new, head, head->next);
84865 +}
84866 +
84867 /**
84868 * list_add_tail_rcu - add a new entry to rcu-protected list
84869 * @new: new entry to be added
84870 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84871 __list_add_rcu(new, head->prev, head);
84872 }
84873
84874 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84875 + struct list_head *head)
84876 +{
84877 + __pax_list_add_rcu(new, head->prev, head);
84878 +}
84879 +
84880 /**
84881 * list_del_rcu - deletes entry from list without re-initialization
84882 * @entry: the element to delete from the list.
84883 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84884 entry->prev = LIST_POISON2;
84885 }
84886
84887 +extern void pax_list_del_rcu(struct list_head *entry);
84888 +
84889 /**
84890 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84891 * @n: the element to delete from the hash list.
84892 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84893 index 48bf152..d38b785 100644
84894 --- a/include/linux/reboot.h
84895 +++ b/include/linux/reboot.h
84896 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
84897 */
84898
84899 extern void migrate_to_reboot_cpu(void);
84900 -extern void machine_restart(char *cmd);
84901 -extern void machine_halt(void);
84902 -extern void machine_power_off(void);
84903 +extern void machine_restart(char *cmd) __noreturn;
84904 +extern void machine_halt(void) __noreturn;
84905 +extern void machine_power_off(void) __noreturn;
84906
84907 extern void machine_shutdown(void);
84908 struct pt_regs;
84909 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84910 */
84911
84912 extern void kernel_restart_prepare(char *cmd);
84913 -extern void kernel_restart(char *cmd);
84914 -extern void kernel_halt(void);
84915 -extern void kernel_power_off(void);
84916 +extern void kernel_restart(char *cmd) __noreturn;
84917 +extern void kernel_halt(void) __noreturn;
84918 +extern void kernel_power_off(void) __noreturn;
84919
84920 extern int C_A_D; /* for sysctl */
84921 void ctrl_alt_del(void);
84922 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
84923 * Emergency restart, callable from an interrupt handler.
84924 */
84925
84926 -extern void emergency_restart(void);
84927 +extern void emergency_restart(void) __noreturn;
84928 #include <asm/emergency-restart.h>
84929
84930 #endif /* _LINUX_REBOOT_H */
84931 diff --git a/include/linux/regset.h b/include/linux/regset.h
84932 index 8e0c9fe..ac4d221 100644
84933 --- a/include/linux/regset.h
84934 +++ b/include/linux/regset.h
84935 @@ -161,7 +161,8 @@ struct user_regset {
84936 unsigned int align;
84937 unsigned int bias;
84938 unsigned int core_note_type;
84939 -};
84940 +} __do_const;
84941 +typedef struct user_regset __no_const user_regset_no_const;
84942
84943 /**
84944 * struct user_regset_view - available regsets
84945 diff --git a/include/linux/relay.h b/include/linux/relay.h
84946 index d7c8359..818daf5 100644
84947 --- a/include/linux/relay.h
84948 +++ b/include/linux/relay.h
84949 @@ -157,7 +157,7 @@ struct rchan_callbacks
84950 * The callback should return 0 if successful, negative if not.
84951 */
84952 int (*remove_buf_file)(struct dentry *dentry);
84953 -};
84954 +} __no_const;
84955
84956 /*
84957 * CONFIG_RELAY kernel API, kernel/relay.c
84958 diff --git a/include/linux/rio.h b/include/linux/rio.h
84959 index 6bda06f..bf39a9b 100644
84960 --- a/include/linux/rio.h
84961 +++ b/include/linux/rio.h
84962 @@ -358,7 +358,7 @@ struct rio_ops {
84963 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84964 u64 rstart, u32 size, u32 flags);
84965 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84966 -};
84967 +} __no_const;
84968
84969 #define RIO_RESOURCE_MEM 0x00000100
84970 #define RIO_RESOURCE_DOORBELL 0x00000200
84971 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84972 index be57450..31cf65e 100644
84973 --- a/include/linux/rmap.h
84974 +++ b/include/linux/rmap.h
84975 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84976 void anon_vma_init(void); /* create anon_vma_cachep */
84977 int anon_vma_prepare(struct vm_area_struct *);
84978 void unlink_anon_vmas(struct vm_area_struct *);
84979 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84980 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84981 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84982 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84983
84984 static inline void anon_vma_merge(struct vm_area_struct *vma,
84985 struct vm_area_struct *next)
84986 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84987 index ed8f9e7..999bc96 100644
84988 --- a/include/linux/scatterlist.h
84989 +++ b/include/linux/scatterlist.h
84990 @@ -1,6 +1,7 @@
84991 #ifndef _LINUX_SCATTERLIST_H
84992 #define _LINUX_SCATTERLIST_H
84993
84994 +#include <linux/sched.h>
84995 #include <linux/string.h>
84996 #include <linux/bug.h>
84997 #include <linux/mm.h>
84998 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84999 #ifdef CONFIG_DEBUG_SG
85000 BUG_ON(!virt_addr_valid(buf));
85001 #endif
85002 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85003 + if (object_starts_on_stack(buf)) {
85004 + void *adjbuf = buf - current->stack + current->lowmem_stack;
85005 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
85006 + } else
85007 +#endif
85008 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
85009 }
85010
85011 diff --git a/include/linux/sched.h b/include/linux/sched.h
85012 index b867a4d..84f03ad 100644
85013 --- a/include/linux/sched.h
85014 +++ b/include/linux/sched.h
85015 @@ -132,6 +132,7 @@ struct fs_struct;
85016 struct perf_event_context;
85017 struct blk_plug;
85018 struct filename;
85019 +struct linux_binprm;
85020
85021 #define VMACACHE_BITS 2
85022 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
85023 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
85024 extern int in_sched_functions(unsigned long addr);
85025
85026 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
85027 -extern signed long schedule_timeout(signed long timeout);
85028 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
85029 extern signed long schedule_timeout_interruptible(signed long timeout);
85030 extern signed long schedule_timeout_killable(signed long timeout);
85031 extern signed long schedule_timeout_uninterruptible(signed long timeout);
85032 @@ -385,6 +386,19 @@ struct nsproxy;
85033 struct user_namespace;
85034
85035 #ifdef CONFIG_MMU
85036 +
85037 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
85038 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
85039 +#else
85040 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
85041 +{
85042 + return 0;
85043 +}
85044 +#endif
85045 +
85046 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
85047 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
85048 +
85049 extern void arch_pick_mmap_layout(struct mm_struct *mm);
85050 extern unsigned long
85051 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
85052 @@ -682,6 +696,17 @@ struct signal_struct {
85053 #ifdef CONFIG_TASKSTATS
85054 struct taskstats *stats;
85055 #endif
85056 +
85057 +#ifdef CONFIG_GRKERNSEC
85058 + u32 curr_ip;
85059 + u32 saved_ip;
85060 + u32 gr_saddr;
85061 + u32 gr_daddr;
85062 + u16 gr_sport;
85063 + u16 gr_dport;
85064 + u8 used_accept:1;
85065 +#endif
85066 +
85067 #ifdef CONFIG_AUDIT
85068 unsigned audit_tty;
85069 unsigned audit_tty_log_passwd;
85070 @@ -708,7 +733,7 @@ struct signal_struct {
85071 struct mutex cred_guard_mutex; /* guard against foreign influences on
85072 * credential calculations
85073 * (notably. ptrace) */
85074 -};
85075 +} __randomize_layout;
85076
85077 /*
85078 * Bits in flags field of signal_struct.
85079 @@ -761,6 +786,14 @@ struct user_struct {
85080 struct key *session_keyring; /* UID's default session keyring */
85081 #endif
85082
85083 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85084 + unsigned char kernel_banned;
85085 +#endif
85086 +#ifdef CONFIG_GRKERNSEC_BRUTE
85087 + unsigned char suid_banned;
85088 + unsigned long suid_ban_expires;
85089 +#endif
85090 +
85091 /* Hash table maintenance information */
85092 struct hlist_node uidhash_node;
85093 kuid_t uid;
85094 @@ -768,7 +801,7 @@ struct user_struct {
85095 #ifdef CONFIG_PERF_EVENTS
85096 atomic_long_t locked_vm;
85097 #endif
85098 -};
85099 +} __randomize_layout;
85100
85101 extern int uids_sysfs_init(void);
85102
85103 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
85104 struct task_struct {
85105 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85106 void *stack;
85107 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85108 + void *lowmem_stack;
85109 +#endif
85110 atomic_t usage;
85111 unsigned int flags; /* per process flags, defined below */
85112 unsigned int ptrace;
85113 @@ -1345,8 +1381,8 @@ struct task_struct {
85114 struct list_head thread_node;
85115
85116 struct completion *vfork_done; /* for vfork() */
85117 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85118 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85119 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85120 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85121
85122 cputime_t utime, stime, utimescaled, stimescaled;
85123 cputime_t gtime;
85124 @@ -1371,11 +1407,6 @@ struct task_struct {
85125 struct task_cputime cputime_expires;
85126 struct list_head cpu_timers[3];
85127
85128 -/* process credentials */
85129 - const struct cred __rcu *real_cred; /* objective and real subjective task
85130 - * credentials (COW) */
85131 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85132 - * credentials (COW) */
85133 char comm[TASK_COMM_LEN]; /* executable name excluding path
85134 - access with [gs]et_task_comm (which lock
85135 it with task_lock())
85136 @@ -1393,6 +1424,10 @@ struct task_struct {
85137 #endif
85138 /* CPU-specific state of this task */
85139 struct thread_struct thread;
85140 +/* thread_info moved to task_struct */
85141 +#ifdef CONFIG_X86
85142 + struct thread_info tinfo;
85143 +#endif
85144 /* filesystem information */
85145 struct fs_struct *fs;
85146 /* open file information */
85147 @@ -1467,6 +1502,10 @@ struct task_struct {
85148 gfp_t lockdep_reclaim_gfp;
85149 #endif
85150
85151 +/* process credentials */
85152 + const struct cred __rcu *real_cred; /* objective and real subjective task
85153 + * credentials (COW) */
85154 +
85155 /* journalling filesystem info */
85156 void *journal_info;
85157
85158 @@ -1505,6 +1544,10 @@ struct task_struct {
85159 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85160 struct list_head cg_list;
85161 #endif
85162 +
85163 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85164 + * credentials (COW) */
85165 +
85166 #ifdef CONFIG_FUTEX
85167 struct robust_list_head __user *robust_list;
85168 #ifdef CONFIG_COMPAT
85169 @@ -1644,7 +1687,78 @@ struct task_struct {
85170 unsigned int sequential_io;
85171 unsigned int sequential_io_avg;
85172 #endif
85173 -};
85174 +
85175 +#ifdef CONFIG_GRKERNSEC
85176 + /* grsecurity */
85177 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85178 + u64 exec_id;
85179 +#endif
85180 +#ifdef CONFIG_GRKERNSEC_SETXID
85181 + const struct cred *delayed_cred;
85182 +#endif
85183 + struct dentry *gr_chroot_dentry;
85184 + struct acl_subject_label *acl;
85185 + struct acl_subject_label *tmpacl;
85186 + struct acl_role_label *role;
85187 + struct file *exec_file;
85188 + unsigned long brute_expires;
85189 + u16 acl_role_id;
85190 + u8 inherited;
85191 + /* is this the task that authenticated to the special role */
85192 + u8 acl_sp_role;
85193 + u8 is_writable;
85194 + u8 brute;
85195 + u8 gr_is_chrooted;
85196 +#endif
85197 +
85198 +} __randomize_layout;
85199 +
85200 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85201 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85202 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85203 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85204 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85205 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85206 +
85207 +#ifdef CONFIG_PAX_SOFTMODE
85208 +extern int pax_softmode;
85209 +#endif
85210 +
85211 +extern int pax_check_flags(unsigned long *);
85212 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85213 +
85214 +/* if tsk != current then task_lock must be held on it */
85215 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85216 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85217 +{
85218 + if (likely(tsk->mm))
85219 + return tsk->mm->pax_flags;
85220 + else
85221 + return 0UL;
85222 +}
85223 +
85224 +/* if tsk != current then task_lock must be held on it */
85225 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85226 +{
85227 + if (likely(tsk->mm)) {
85228 + tsk->mm->pax_flags = flags;
85229 + return 0;
85230 + }
85231 + return -EINVAL;
85232 +}
85233 +#endif
85234 +
85235 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85236 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85237 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85238 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85239 +#endif
85240 +
85241 +struct path;
85242 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85243 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85244 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85245 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85246
85247 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85248 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85249 @@ -1726,7 +1840,7 @@ struct pid_namespace;
85250 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85251 struct pid_namespace *ns);
85252
85253 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85254 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85255 {
85256 return tsk->pid;
85257 }
85258 @@ -2095,6 +2209,25 @@ extern u64 sched_clock_cpu(int cpu);
85259
85260 extern void sched_clock_init(void);
85261
85262 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85263 +static inline void populate_stack(void)
85264 +{
85265 + struct task_struct *curtask = current;
85266 + int c;
85267 + int *ptr = curtask->stack;
85268 + int *end = curtask->stack + THREAD_SIZE;
85269 +
85270 + while (ptr < end) {
85271 + c = *(volatile int *)ptr;
85272 + ptr += PAGE_SIZE/sizeof(int);
85273 + }
85274 +}
85275 +#else
85276 +static inline void populate_stack(void)
85277 +{
85278 +}
85279 +#endif
85280 +
85281 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85282 static inline void sched_clock_tick(void)
85283 {
85284 @@ -2228,7 +2361,9 @@ void yield(void);
85285 extern struct exec_domain default_exec_domain;
85286
85287 union thread_union {
85288 +#ifndef CONFIG_X86
85289 struct thread_info thread_info;
85290 +#endif
85291 unsigned long stack[THREAD_SIZE/sizeof(long)];
85292 };
85293
85294 @@ -2261,6 +2396,7 @@ extern struct pid_namespace init_pid_ns;
85295 */
85296
85297 extern struct task_struct *find_task_by_vpid(pid_t nr);
85298 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85299 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85300 struct pid_namespace *ns);
85301
85302 @@ -2425,7 +2561,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85303 extern void exit_itimers(struct signal_struct *);
85304 extern void flush_itimer_signals(void);
85305
85306 -extern void do_group_exit(int);
85307 +extern __noreturn void do_group_exit(int);
85308
85309 extern int do_execve(struct filename *,
85310 const char __user * const __user *,
85311 @@ -2640,9 +2776,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85312
85313 #endif
85314
85315 -static inline int object_is_on_stack(void *obj)
85316 +static inline int object_starts_on_stack(const void *obj)
85317 {
85318 - void *stack = task_stack_page(current);
85319 + const void *stack = task_stack_page(current);
85320
85321 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85322 }
85323 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85324 index 596a0e0..bea77ec 100644
85325 --- a/include/linux/sched/sysctl.h
85326 +++ b/include/linux/sched/sysctl.h
85327 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85328 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85329
85330 extern int sysctl_max_map_count;
85331 +extern unsigned long sysctl_heap_stack_gap;
85332
85333 extern unsigned int sysctl_sched_latency;
85334 extern unsigned int sysctl_sched_min_granularity;
85335 diff --git a/include/linux/security.h b/include/linux/security.h
85336 index 623f90e..90b39da 100644
85337 --- a/include/linux/security.h
85338 +++ b/include/linux/security.h
85339 @@ -27,6 +27,7 @@
85340 #include <linux/slab.h>
85341 #include <linux/err.h>
85342 #include <linux/string.h>
85343 +#include <linux/grsecurity.h>
85344
85345 struct linux_binprm;
85346 struct cred;
85347 @@ -116,8 +117,6 @@ struct seq_file;
85348
85349 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85350
85351 -void reset_security_ops(void);
85352 -
85353 #ifdef CONFIG_MMU
85354 extern unsigned long mmap_min_addr;
85355 extern unsigned long dac_mmap_min_addr;
85356 @@ -1729,7 +1728,7 @@ struct security_operations {
85357 struct audit_context *actx);
85358 void (*audit_rule_free) (void *lsmrule);
85359 #endif /* CONFIG_AUDIT */
85360 -};
85361 +} __randomize_layout;
85362
85363 /* prototypes */
85364 extern int security_init(void);
85365 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85366 index dc368b8..e895209 100644
85367 --- a/include/linux/semaphore.h
85368 +++ b/include/linux/semaphore.h
85369 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85370 }
85371
85372 extern void down(struct semaphore *sem);
85373 -extern int __must_check down_interruptible(struct semaphore *sem);
85374 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85375 extern int __must_check down_killable(struct semaphore *sem);
85376 extern int __must_check down_trylock(struct semaphore *sem);
85377 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85378 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85379 index 52e0097..383f21d 100644
85380 --- a/include/linux/seq_file.h
85381 +++ b/include/linux/seq_file.h
85382 @@ -27,6 +27,9 @@ struct seq_file {
85383 struct mutex lock;
85384 const struct seq_operations *op;
85385 int poll_event;
85386 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85387 + u64 exec_id;
85388 +#endif
85389 #ifdef CONFIG_USER_NS
85390 struct user_namespace *user_ns;
85391 #endif
85392 @@ -39,6 +42,7 @@ struct seq_operations {
85393 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85394 int (*show) (struct seq_file *m, void *v);
85395 };
85396 +typedef struct seq_operations __no_const seq_operations_no_const;
85397
85398 #define SEQ_SKIP 1
85399
85400 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85401
85402 char *mangle_path(char *s, const char *p, const char *esc);
85403 int seq_open(struct file *, const struct seq_operations *);
85404 +int seq_open_restrict(struct file *, const struct seq_operations *);
85405 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85406 loff_t seq_lseek(struct file *, loff_t, int);
85407 int seq_release(struct inode *, struct file *);
85408 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85409 }
85410
85411 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85412 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85413 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85414 int single_release(struct inode *, struct file *);
85415 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85416 diff --git a/include/linux/shm.h b/include/linux/shm.h
85417 index 6fb8016..ab4465e 100644
85418 --- a/include/linux/shm.h
85419 +++ b/include/linux/shm.h
85420 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85421 /* The task created the shm object. NULL if the task is dead. */
85422 struct task_struct *shm_creator;
85423 struct list_head shm_clist; /* list by creator */
85424 +#ifdef CONFIG_GRKERNSEC
85425 + u64 shm_createtime;
85426 + pid_t shm_lapid;
85427 +#endif
85428 };
85429
85430 /* shm_mode upper byte flags */
85431 diff --git a/include/linux/signal.h b/include/linux/signal.h
85432 index 750196f..ae7a3a4 100644
85433 --- a/include/linux/signal.h
85434 +++ b/include/linux/signal.h
85435 @@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85436 * know it'll be handled, so that they don't get converted to
85437 * SIGKILL or just silently dropped.
85438 */
85439 - kernel_sigaction(sig, (__force __sighandler_t)2);
85440 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85441 }
85442
85443 static inline void disallow_signal(int sig)
85444 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85445 index abde271..bc9ece1 100644
85446 --- a/include/linux/skbuff.h
85447 +++ b/include/linux/skbuff.h
85448 @@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85449 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85450 int node);
85451 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85452 -static inline struct sk_buff *alloc_skb(unsigned int size,
85453 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85454 gfp_t priority)
85455 {
85456 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85457 @@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85458 return skb->inner_transport_header - skb->inner_network_header;
85459 }
85460
85461 -static inline int skb_network_offset(const struct sk_buff *skb)
85462 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85463 {
85464 return skb_network_header(skb) - skb->data;
85465 }
85466 @@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85467 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85468 */
85469 #ifndef NET_SKB_PAD
85470 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85471 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85472 #endif
85473
85474 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85475 @@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85476 int *err);
85477 unsigned int datagram_poll(struct file *file, struct socket *sock,
85478 struct poll_table_struct *wait);
85479 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85480 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85481 struct iovec *to, int size);
85482 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85483 struct iovec *iov);
85484 @@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85485 nf_bridge_put(skb->nf_bridge);
85486 skb->nf_bridge = NULL;
85487 #endif
85488 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85489 + skb->nf_trace = 0;
85490 +#endif
85491 }
85492
85493 static inline void nf_reset_trace(struct sk_buff *skb)
85494 diff --git a/include/linux/slab.h b/include/linux/slab.h
85495 index 1d9abb7..b1e8b10 100644
85496 --- a/include/linux/slab.h
85497 +++ b/include/linux/slab.h
85498 @@ -14,15 +14,29 @@
85499 #include <linux/gfp.h>
85500 #include <linux/types.h>
85501 #include <linux/workqueue.h>
85502 -
85503 +#include <linux/err.h>
85504
85505 /*
85506 * Flags to pass to kmem_cache_create().
85507 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85508 */
85509 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85510 +
85511 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85512 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85513 +#else
85514 +#define SLAB_USERCOPY 0x00000000UL
85515 +#endif
85516 +
85517 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85518 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85519 +
85520 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85521 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85522 +#else
85523 +#define SLAB_NO_SANITIZE 0x00000000UL
85524 +#endif
85525 +
85526 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85527 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85528 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85529 @@ -98,10 +112,13 @@
85530 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85531 * Both make kfree a no-op.
85532 */
85533 -#define ZERO_SIZE_PTR ((void *)16)
85534 +#define ZERO_SIZE_PTR \
85535 +({ \
85536 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85537 + (void *)(-MAX_ERRNO-1L); \
85538 +})
85539
85540 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85541 - (unsigned long)ZERO_SIZE_PTR)
85542 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85543
85544 #include <linux/kmemleak.h>
85545
85546 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85547 void kfree(const void *);
85548 void kzfree(const void *);
85549 size_t ksize(const void *);
85550 +const char *check_heap_object(const void *ptr, unsigned long n);
85551 +bool is_usercopy_object(const void *ptr);
85552
85553 /*
85554 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85555 @@ -176,7 +195,7 @@ struct kmem_cache {
85556 unsigned int align; /* Alignment as calculated */
85557 unsigned long flags; /* Active flags on the slab */
85558 const char *name; /* Slab name for sysfs */
85559 - int refcount; /* Use counter */
85560 + atomic_t refcount; /* Use counter */
85561 void (*ctor)(void *); /* Called on object slot creation */
85562 struct list_head list; /* List of all slab caches on the system */
85563 };
85564 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85565 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85566 #endif
85567
85568 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85569 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85570 +#endif
85571 +
85572 /*
85573 * Figure out which kmalloc slab an allocation of a certain size
85574 * belongs to.
85575 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85576 * 2 = 120 .. 192 bytes
85577 * n = 2^(n-1) .. 2^n -1
85578 */
85579 -static __always_inline int kmalloc_index(size_t size)
85580 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85581 {
85582 if (!size)
85583 return 0;
85584 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85585 }
85586 #endif /* !CONFIG_SLOB */
85587
85588 -void *__kmalloc(size_t size, gfp_t flags);
85589 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85590 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85591
85592 #ifdef CONFIG_NUMA
85593 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85594 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85595 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85596 #else
85597 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85598 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85599 index 8235dfb..47ce586 100644
85600 --- a/include/linux/slab_def.h
85601 +++ b/include/linux/slab_def.h
85602 @@ -38,7 +38,7 @@ struct kmem_cache {
85603 /* 4) cache creation/removal */
85604 const char *name;
85605 struct list_head list;
85606 - int refcount;
85607 + atomic_t refcount;
85608 int object_size;
85609 int align;
85610
85611 @@ -54,10 +54,14 @@ struct kmem_cache {
85612 unsigned long node_allocs;
85613 unsigned long node_frees;
85614 unsigned long node_overflow;
85615 - atomic_t allochit;
85616 - atomic_t allocmiss;
85617 - atomic_t freehit;
85618 - atomic_t freemiss;
85619 + atomic_unchecked_t allochit;
85620 + atomic_unchecked_t allocmiss;
85621 + atomic_unchecked_t freehit;
85622 + atomic_unchecked_t freemiss;
85623 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85624 + atomic_unchecked_t sanitized;
85625 + atomic_unchecked_t not_sanitized;
85626 +#endif
85627
85628 /*
85629 * If debugging is enabled, then the allocator can add additional
85630 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85631 index d82abd4..408c3a0 100644
85632 --- a/include/linux/slub_def.h
85633 +++ b/include/linux/slub_def.h
85634 @@ -74,7 +74,7 @@ struct kmem_cache {
85635 struct kmem_cache_order_objects max;
85636 struct kmem_cache_order_objects min;
85637 gfp_t allocflags; /* gfp flags to use on each alloc */
85638 - int refcount; /* Refcount for slab cache destroy */
85639 + atomic_t refcount; /* Refcount for slab cache destroy */
85640 void (*ctor)(void *);
85641 int inuse; /* Offset to metadata */
85642 int align; /* Alignment */
85643 diff --git a/include/linux/smp.h b/include/linux/smp.h
85644 index 34347f2..8739978 100644
85645 --- a/include/linux/smp.h
85646 +++ b/include/linux/smp.h
85647 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85648 #endif
85649
85650 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85651 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85652 #define put_cpu() preempt_enable()
85653 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85654
85655 /*
85656 * Callback to arch code if there's nosmp or maxcpus=0 on the
85657 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85658 index 46cca4c..3323536 100644
85659 --- a/include/linux/sock_diag.h
85660 +++ b/include/linux/sock_diag.h
85661 @@ -11,7 +11,7 @@ struct sock;
85662 struct sock_diag_handler {
85663 __u8 family;
85664 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85665 -};
85666 +} __do_const;
85667
85668 int sock_diag_register(const struct sock_diag_handler *h);
85669 void sock_diag_unregister(const struct sock_diag_handler *h);
85670 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85671 index 680f9a3..f13aeb0 100644
85672 --- a/include/linux/sonet.h
85673 +++ b/include/linux/sonet.h
85674 @@ -7,7 +7,7 @@
85675 #include <uapi/linux/sonet.h>
85676
85677 struct k_sonet_stats {
85678 -#define __HANDLE_ITEM(i) atomic_t i
85679 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85680 __SONET_ITEMS
85681 #undef __HANDLE_ITEM
85682 };
85683 diff --git a/include/linux/string.h b/include/linux/string.h
85684 index d36977e..3b42b37 100644
85685 --- a/include/linux/string.h
85686 +++ b/include/linux/string.h
85687 @@ -132,7 +132,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
85688 #endif
85689
85690 extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
85691 - const void *from, size_t available);
85692 + const void *from, size_t available);
85693
85694 /**
85695 * strstarts - does @str start with @prefix?
85696 @@ -144,7 +144,8 @@ static inline bool strstarts(const char *str, const char *prefix)
85697 return strncmp(str, prefix, strlen(prefix)) == 0;
85698 }
85699
85700 -extern size_t memweight(const void *ptr, size_t bytes);
85701 +size_t memweight(const void *ptr, size_t bytes);
85702 +void memzero_explicit(void *s, size_t count);
85703
85704 /**
85705 * kbasename - return the last part of a pathname.
85706 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85707 index 07d8e53..dc934c9 100644
85708 --- a/include/linux/sunrpc/addr.h
85709 +++ b/include/linux/sunrpc/addr.h
85710 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85711 {
85712 switch (sap->sa_family) {
85713 case AF_INET:
85714 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85715 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85716 case AF_INET6:
85717 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85718 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85719 }
85720 return 0;
85721 }
85722 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85723 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85724 const struct sockaddr *src)
85725 {
85726 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85727 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85728 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85729
85730 dsin->sin_family = ssin->sin_family;
85731 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85732 if (sa->sa_family != AF_INET6)
85733 return 0;
85734
85735 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85736 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85737 }
85738
85739 #endif /* _LINUX_SUNRPC_ADDR_H */
85740 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85741 index 70736b9..37f33db 100644
85742 --- a/include/linux/sunrpc/clnt.h
85743 +++ b/include/linux/sunrpc/clnt.h
85744 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85745 unsigned int p_timer; /* Which RTT timer to use */
85746 u32 p_statidx; /* Which procedure to account */
85747 const char * p_name; /* name of procedure */
85748 -};
85749 +} __do_const;
85750
85751 #ifdef __KERNEL__
85752
85753 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85754 index cf61ecd..a4a9bc0 100644
85755 --- a/include/linux/sunrpc/svc.h
85756 +++ b/include/linux/sunrpc/svc.h
85757 @@ -417,7 +417,7 @@ struct svc_procedure {
85758 unsigned int pc_count; /* call count */
85759 unsigned int pc_cachetype; /* cache info (NFS) */
85760 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85761 -};
85762 +} __do_const;
85763
85764 /*
85765 * Function prototypes.
85766 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85767 index 975da75..318c083 100644
85768 --- a/include/linux/sunrpc/svc_rdma.h
85769 +++ b/include/linux/sunrpc/svc_rdma.h
85770 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85771 extern unsigned int svcrdma_max_requests;
85772 extern unsigned int svcrdma_max_req_size;
85773
85774 -extern atomic_t rdma_stat_recv;
85775 -extern atomic_t rdma_stat_read;
85776 -extern atomic_t rdma_stat_write;
85777 -extern atomic_t rdma_stat_sq_starve;
85778 -extern atomic_t rdma_stat_rq_starve;
85779 -extern atomic_t rdma_stat_rq_poll;
85780 -extern atomic_t rdma_stat_rq_prod;
85781 -extern atomic_t rdma_stat_sq_poll;
85782 -extern atomic_t rdma_stat_sq_prod;
85783 +extern atomic_unchecked_t rdma_stat_recv;
85784 +extern atomic_unchecked_t rdma_stat_read;
85785 +extern atomic_unchecked_t rdma_stat_write;
85786 +extern atomic_unchecked_t rdma_stat_sq_starve;
85787 +extern atomic_unchecked_t rdma_stat_rq_starve;
85788 +extern atomic_unchecked_t rdma_stat_rq_poll;
85789 +extern atomic_unchecked_t rdma_stat_rq_prod;
85790 +extern atomic_unchecked_t rdma_stat_sq_poll;
85791 +extern atomic_unchecked_t rdma_stat_sq_prod;
85792
85793 #define RPCRDMA_VERSION 1
85794
85795 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85796 index 8d71d65..f79586e 100644
85797 --- a/include/linux/sunrpc/svcauth.h
85798 +++ b/include/linux/sunrpc/svcauth.h
85799 @@ -120,7 +120,7 @@ struct auth_ops {
85800 int (*release)(struct svc_rqst *rq);
85801 void (*domain_release)(struct auth_domain *);
85802 int (*set_client)(struct svc_rqst *rq);
85803 -};
85804 +} __do_const;
85805
85806 #define SVC_GARBAGE 1
85807 #define SVC_SYSERR 2
85808 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85809 index e7a018e..49f8b17 100644
85810 --- a/include/linux/swiotlb.h
85811 +++ b/include/linux/swiotlb.h
85812 @@ -60,7 +60,8 @@ extern void
85813
85814 extern void
85815 swiotlb_free_coherent(struct device *hwdev, size_t size,
85816 - void *vaddr, dma_addr_t dma_handle);
85817 + void *vaddr, dma_addr_t dma_handle,
85818 + struct dma_attrs *attrs);
85819
85820 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85821 unsigned long offset, size_t size,
85822 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85823 index 0f86d85..dff3419 100644
85824 --- a/include/linux/syscalls.h
85825 +++ b/include/linux/syscalls.h
85826 @@ -98,10 +98,16 @@ struct sigaltstack;
85827 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85828
85829 #define __SC_DECL(t, a) t a
85830 +#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))
85831 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85832 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85833 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85834 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85835 +#define __SC_LONG(t, a) __typeof( \
85836 + __builtin_choose_expr( \
85837 + sizeof(t) > sizeof(int), \
85838 + (t) 0, \
85839 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85840 + )) a
85841 #define __SC_CAST(t, a) (t) a
85842 #define __SC_ARGS(t, a) a
85843 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85844 @@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85845 asmlinkage long sys_fsync(unsigned int fd);
85846 asmlinkage long sys_fdatasync(unsigned int fd);
85847 asmlinkage long sys_bdflush(int func, long data);
85848 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85849 - char __user *type, unsigned long flags,
85850 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85851 + const char __user *type, unsigned long flags,
85852 void __user *data);
85853 -asmlinkage long sys_umount(char __user *name, int flags);
85854 -asmlinkage long sys_oldumount(char __user *name);
85855 +asmlinkage long sys_umount(const char __user *name, int flags);
85856 +asmlinkage long sys_oldumount(const char __user *name);
85857 asmlinkage long sys_truncate(const char __user *path, long length);
85858 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85859 asmlinkage long sys_stat(const char __user *filename,
85860 @@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85861 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85862 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85863 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85864 - struct sockaddr __user *, int);
85865 + struct sockaddr __user *, int) __intentional_overflow(0);
85866 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85867 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85868 unsigned int vlen, unsigned flags);
85869 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85870 index 27b3b0b..e093dd9 100644
85871 --- a/include/linux/syscore_ops.h
85872 +++ b/include/linux/syscore_ops.h
85873 @@ -16,7 +16,7 @@ struct syscore_ops {
85874 int (*suspend)(void);
85875 void (*resume)(void);
85876 void (*shutdown)(void);
85877 -};
85878 +} __do_const;
85879
85880 extern void register_syscore_ops(struct syscore_ops *ops);
85881 extern void unregister_syscore_ops(struct syscore_ops *ops);
85882 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85883 index b7361f8..341a15a 100644
85884 --- a/include/linux/sysctl.h
85885 +++ b/include/linux/sysctl.h
85886 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85887
85888 extern int proc_dostring(struct ctl_table *, int,
85889 void __user *, size_t *, loff_t *);
85890 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85891 + void __user *, size_t *, loff_t *);
85892 extern int proc_dointvec(struct ctl_table *, int,
85893 void __user *, size_t *, loff_t *);
85894 extern int proc_dointvec_minmax(struct ctl_table *, int,
85895 @@ -113,7 +115,8 @@ struct ctl_table
85896 struct ctl_table_poll *poll;
85897 void *extra1;
85898 void *extra2;
85899 -};
85900 +} __do_const __randomize_layout;
85901 +typedef struct ctl_table __no_const ctl_table_no_const;
85902
85903 struct ctl_node {
85904 struct rb_node node;
85905 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85906 index f97d0db..c1187dc 100644
85907 --- a/include/linux/sysfs.h
85908 +++ b/include/linux/sysfs.h
85909 @@ -34,7 +34,8 @@ struct attribute {
85910 struct lock_class_key *key;
85911 struct lock_class_key skey;
85912 #endif
85913 -};
85914 +} __do_const;
85915 +typedef struct attribute __no_const attribute_no_const;
85916
85917 /**
85918 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85919 @@ -63,7 +64,8 @@ struct attribute_group {
85920 struct attribute *, int);
85921 struct attribute **attrs;
85922 struct bin_attribute **bin_attrs;
85923 -};
85924 +} __do_const;
85925 +typedef struct attribute_group __no_const attribute_group_no_const;
85926
85927 /**
85928 * Use these macros to make defining attributes easier. See include/linux/device.h
85929 @@ -128,7 +130,8 @@ struct bin_attribute {
85930 char *, loff_t, size_t);
85931 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85932 struct vm_area_struct *vma);
85933 -};
85934 +} __do_const;
85935 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85936
85937 /**
85938 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85939 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85940 index 387fa7d..3fcde6b 100644
85941 --- a/include/linux/sysrq.h
85942 +++ b/include/linux/sysrq.h
85943 @@ -16,6 +16,7 @@
85944
85945 #include <linux/errno.h>
85946 #include <linux/types.h>
85947 +#include <linux/compiler.h>
85948
85949 /* Possible values of bitmask for enabling sysrq functions */
85950 /* 0x0001 is reserved for enable everything */
85951 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85952 char *help_msg;
85953 char *action_msg;
85954 int enable_mask;
85955 -};
85956 +} __do_const;
85957
85958 #ifdef CONFIG_MAGIC_SYSRQ
85959
85960 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85961 index ff307b5..f1a4468 100644
85962 --- a/include/linux/thread_info.h
85963 +++ b/include/linux/thread_info.h
85964 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85965 #error "no set_restore_sigmask() provided and default one won't work"
85966 #endif
85967
85968 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85969 +
85970 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85971 +{
85972 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85973 +}
85974 +
85975 #endif /* __KERNEL__ */
85976
85977 #endif /* _LINUX_THREAD_INFO_H */
85978 diff --git a/include/linux/tty.h b/include/linux/tty.h
85979 index 8413294..44391c7 100644
85980 --- a/include/linux/tty.h
85981 +++ b/include/linux/tty.h
85982 @@ -202,7 +202,7 @@ struct tty_port {
85983 const struct tty_port_operations *ops; /* Port operations */
85984 spinlock_t lock; /* Lock protecting tty field */
85985 int blocked_open; /* Waiting to open */
85986 - int count; /* Usage count */
85987 + atomic_t count; /* Usage count */
85988 wait_queue_head_t open_wait; /* Open waiters */
85989 wait_queue_head_t close_wait; /* Close waiters */
85990 wait_queue_head_t delta_msr_wait; /* Modem status change */
85991 @@ -284,7 +284,7 @@ struct tty_struct {
85992 /* If the tty has a pending do_SAK, queue it here - akpm */
85993 struct work_struct SAK_work;
85994 struct tty_port *port;
85995 -};
85996 +} __randomize_layout;
85997
85998 /* Each of a tty's open files has private_data pointing to tty_file_private */
85999 struct tty_file_private {
86000 @@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
86001 struct tty_struct *tty, struct file *filp);
86002 static inline int tty_port_users(struct tty_port *port)
86003 {
86004 - return port->count + port->blocked_open;
86005 + return atomic_read(&port->count) + port->blocked_open;
86006 }
86007
86008 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
86009 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
86010 index e48c608..6a19af2 100644
86011 --- a/include/linux/tty_driver.h
86012 +++ b/include/linux/tty_driver.h
86013 @@ -287,7 +287,7 @@ struct tty_operations {
86014 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
86015 #endif
86016 const struct file_operations *proc_fops;
86017 -};
86018 +} __do_const __randomize_layout;
86019
86020 struct tty_driver {
86021 int magic; /* magic number for this structure */
86022 @@ -321,7 +321,7 @@ struct tty_driver {
86023
86024 const struct tty_operations *ops;
86025 struct list_head tty_drivers;
86026 -};
86027 +} __randomize_layout;
86028
86029 extern struct list_head tty_drivers;
86030
86031 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
86032 index 00c9d68..bc0188b 100644
86033 --- a/include/linux/tty_ldisc.h
86034 +++ b/include/linux/tty_ldisc.h
86035 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
86036
86037 struct module *owner;
86038
86039 - int refcount;
86040 + atomic_t refcount;
86041 };
86042
86043 struct tty_ldisc {
86044 diff --git a/include/linux/types.h b/include/linux/types.h
86045 index a0bb704..f511c77 100644
86046 --- a/include/linux/types.h
86047 +++ b/include/linux/types.h
86048 @@ -177,10 +177,26 @@ typedef struct {
86049 int counter;
86050 } atomic_t;
86051
86052 +#ifdef CONFIG_PAX_REFCOUNT
86053 +typedef struct {
86054 + int counter;
86055 +} atomic_unchecked_t;
86056 +#else
86057 +typedef atomic_t atomic_unchecked_t;
86058 +#endif
86059 +
86060 #ifdef CONFIG_64BIT
86061 typedef struct {
86062 long counter;
86063 } atomic64_t;
86064 +
86065 +#ifdef CONFIG_PAX_REFCOUNT
86066 +typedef struct {
86067 + long counter;
86068 +} atomic64_unchecked_t;
86069 +#else
86070 +typedef atomic64_t atomic64_unchecked_t;
86071 +#endif
86072 #endif
86073
86074 struct list_head {
86075 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
86076 index ecd3319..8a36ded 100644
86077 --- a/include/linux/uaccess.h
86078 +++ b/include/linux/uaccess.h
86079 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
86080 long ret; \
86081 mm_segment_t old_fs = get_fs(); \
86082 \
86083 - set_fs(KERNEL_DS); \
86084 pagefault_disable(); \
86085 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86086 - pagefault_enable(); \
86087 + set_fs(KERNEL_DS); \
86088 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86089 set_fs(old_fs); \
86090 + pagefault_enable(); \
86091 ret; \
86092 })
86093
86094 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86095 index 2d1f9b6..d7a9fce 100644
86096 --- a/include/linux/uidgid.h
86097 +++ b/include/linux/uidgid.h
86098 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86099
86100 #endif /* CONFIG_USER_NS */
86101
86102 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86103 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86104 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86105 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86106 +
86107 #endif /* _LINUX_UIDGID_H */
86108 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86109 index 99c1b4d..562e6f3 100644
86110 --- a/include/linux/unaligned/access_ok.h
86111 +++ b/include/linux/unaligned/access_ok.h
86112 @@ -4,34 +4,34 @@
86113 #include <linux/kernel.h>
86114 #include <asm/byteorder.h>
86115
86116 -static inline u16 get_unaligned_le16(const void *p)
86117 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86118 {
86119 - return le16_to_cpup((__le16 *)p);
86120 + return le16_to_cpup((const __le16 *)p);
86121 }
86122
86123 -static inline u32 get_unaligned_le32(const void *p)
86124 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86125 {
86126 - return le32_to_cpup((__le32 *)p);
86127 + return le32_to_cpup((const __le32 *)p);
86128 }
86129
86130 -static inline u64 get_unaligned_le64(const void *p)
86131 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86132 {
86133 - return le64_to_cpup((__le64 *)p);
86134 + return le64_to_cpup((const __le64 *)p);
86135 }
86136
86137 -static inline u16 get_unaligned_be16(const void *p)
86138 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86139 {
86140 - return be16_to_cpup((__be16 *)p);
86141 + return be16_to_cpup((const __be16 *)p);
86142 }
86143
86144 -static inline u32 get_unaligned_be32(const void *p)
86145 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86146 {
86147 - return be32_to_cpup((__be32 *)p);
86148 + return be32_to_cpup((const __be32 *)p);
86149 }
86150
86151 -static inline u64 get_unaligned_be64(const void *p)
86152 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86153 {
86154 - return be64_to_cpup((__be64 *)p);
86155 + return be64_to_cpup((const __be64 *)p);
86156 }
86157
86158 static inline void put_unaligned_le16(u16 val, void *p)
86159 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
86160 index 4f844c6..60beb5d 100644
86161 --- a/include/linux/uprobes.h
86162 +++ b/include/linux/uprobes.h
86163 @@ -98,11 +98,11 @@ struct uprobes_state {
86164 struct xol_area *xol_area;
86165 };
86166
86167 -extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86168 -extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86169 -extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
86170 -extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
86171 -extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
86172 +extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86173 +extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86174 +extern bool is_swbp_insn(uprobe_opcode_t *insn);
86175 +extern bool is_trap_insn(uprobe_opcode_t *insn);
86176 +extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
86177 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
86178 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
86179 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
86180 @@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
86181 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
86182 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
86183 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86184 -extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86185 -extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86186 +extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86187 +extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86188 void *src, unsigned long len);
86189 #else /* !CONFIG_UPROBES */
86190 struct uprobes_state {
86191 diff --git a/include/linux/usb.h b/include/linux/usb.h
86192 index d2465bc..5256de4 100644
86193 --- a/include/linux/usb.h
86194 +++ b/include/linux/usb.h
86195 @@ -571,7 +571,7 @@ struct usb_device {
86196 int maxchild;
86197
86198 u32 quirks;
86199 - atomic_t urbnum;
86200 + atomic_unchecked_t urbnum;
86201
86202 unsigned long active_duration;
86203
86204 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86205
86206 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86207 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86208 - void *data, __u16 size, int timeout);
86209 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
86210 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86211 void *data, int len, int *actual_length, int timeout);
86212 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86213 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86214 index d5952bb..9a626d4 100644
86215 --- a/include/linux/usb/renesas_usbhs.h
86216 +++ b/include/linux/usb/renesas_usbhs.h
86217 @@ -39,7 +39,7 @@ enum {
86218 */
86219 struct renesas_usbhs_driver_callback {
86220 int (*notify_hotplug)(struct platform_device *pdev);
86221 -};
86222 +} __no_const;
86223
86224 /*
86225 * callback functions for platform
86226 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86227 index e953726..8edb26a 100644
86228 --- a/include/linux/user_namespace.h
86229 +++ b/include/linux/user_namespace.h
86230 @@ -33,7 +33,7 @@ struct user_namespace {
86231 struct key *persistent_keyring_register;
86232 struct rw_semaphore persistent_keyring_register_sem;
86233 #endif
86234 -};
86235 +} __randomize_layout;
86236
86237 extern struct user_namespace init_user_ns;
86238
86239 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86240 index 239e277..22a5cf5 100644
86241 --- a/include/linux/utsname.h
86242 +++ b/include/linux/utsname.h
86243 @@ -24,7 +24,7 @@ struct uts_namespace {
86244 struct new_utsname name;
86245 struct user_namespace *user_ns;
86246 unsigned int proc_inum;
86247 -};
86248 +} __randomize_layout;
86249 extern struct uts_namespace init_uts_ns;
86250
86251 #ifdef CONFIG_UTS_NS
86252 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86253 index 6f8fbcf..4efc177 100644
86254 --- a/include/linux/vermagic.h
86255 +++ b/include/linux/vermagic.h
86256 @@ -25,9 +25,42 @@
86257 #define MODULE_ARCH_VERMAGIC ""
86258 #endif
86259
86260 +#ifdef CONFIG_PAX_REFCOUNT
86261 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86262 +#else
86263 +#define MODULE_PAX_REFCOUNT ""
86264 +#endif
86265 +
86266 +#ifdef CONSTIFY_PLUGIN
86267 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86268 +#else
86269 +#define MODULE_CONSTIFY_PLUGIN ""
86270 +#endif
86271 +
86272 +#ifdef STACKLEAK_PLUGIN
86273 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86274 +#else
86275 +#define MODULE_STACKLEAK_PLUGIN ""
86276 +#endif
86277 +
86278 +#ifdef RANDSTRUCT_PLUGIN
86279 +#include <generated/randomize_layout_hash.h>
86280 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86281 +#else
86282 +#define MODULE_RANDSTRUCT_PLUGIN
86283 +#endif
86284 +
86285 +#ifdef CONFIG_GRKERNSEC
86286 +#define MODULE_GRSEC "GRSEC "
86287 +#else
86288 +#define MODULE_GRSEC ""
86289 +#endif
86290 +
86291 #define VERMAGIC_STRING \
86292 UTS_RELEASE " " \
86293 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86294 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86295 - MODULE_ARCH_VERMAGIC
86296 + MODULE_ARCH_VERMAGIC \
86297 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86298 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86299
86300 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86301 index b483abd..af305ad 100644
86302 --- a/include/linux/vga_switcheroo.h
86303 +++ b/include/linux/vga_switcheroo.h
86304 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86305
86306 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86307
86308 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86309 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86310 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86311 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86312 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86313 #else
86314
86315 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86316 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86317
86318 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86319
86320 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86321 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86322 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86323 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86324 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86325
86326 #endif
86327 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86328 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86329 index b87696f..1d11de7 100644
86330 --- a/include/linux/vmalloc.h
86331 +++ b/include/linux/vmalloc.h
86332 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86333 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86334 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86335 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86336 +
86337 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86338 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86339 +#endif
86340 +
86341 /* bits [20..32] reserved for arch specific ioremap internals */
86342
86343 /*
86344 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86345 unsigned long flags, pgprot_t prot);
86346 extern void vunmap(const void *addr);
86347
86348 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86349 +extern void unmap_process_stacks(struct task_struct *task);
86350 +#endif
86351 +
86352 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86353 unsigned long uaddr, void *kaddr,
86354 unsigned long size);
86355 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86356
86357 /* for /dev/kmem */
86358 extern long vread(char *buf, char *addr, unsigned long count);
86359 -extern long vwrite(char *buf, char *addr, unsigned long count);
86360 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86361
86362 /*
86363 * Internals. Dont't use..
86364 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86365 index 82e7db7..f8ce3d0 100644
86366 --- a/include/linux/vmstat.h
86367 +++ b/include/linux/vmstat.h
86368 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86369 /*
86370 * Zone based page accounting with per cpu differentials.
86371 */
86372 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86373 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86374
86375 static inline void zone_page_state_add(long x, struct zone *zone,
86376 enum zone_stat_item item)
86377 {
86378 - atomic_long_add(x, &zone->vm_stat[item]);
86379 - atomic_long_add(x, &vm_stat[item]);
86380 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86381 + atomic_long_add_unchecked(x, &vm_stat[item]);
86382 }
86383
86384 -static inline unsigned long global_page_state(enum zone_stat_item item)
86385 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86386 {
86387 - long x = atomic_long_read(&vm_stat[item]);
86388 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86389 #ifdef CONFIG_SMP
86390 if (x < 0)
86391 x = 0;
86392 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86393 return x;
86394 }
86395
86396 -static inline unsigned long zone_page_state(struct zone *zone,
86397 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86398 enum zone_stat_item item)
86399 {
86400 - long x = atomic_long_read(&zone->vm_stat[item]);
86401 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86402 #ifdef CONFIG_SMP
86403 if (x < 0)
86404 x = 0;
86405 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86406 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86407 enum zone_stat_item item)
86408 {
86409 - long x = atomic_long_read(&zone->vm_stat[item]);
86410 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86411
86412 #ifdef CONFIG_SMP
86413 int cpu;
86414 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86415
86416 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86417 {
86418 - atomic_long_inc(&zone->vm_stat[item]);
86419 - atomic_long_inc(&vm_stat[item]);
86420 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86421 + atomic_long_inc_unchecked(&vm_stat[item]);
86422 }
86423
86424 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86425 {
86426 - atomic_long_dec(&zone->vm_stat[item]);
86427 - atomic_long_dec(&vm_stat[item]);
86428 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86429 + atomic_long_dec_unchecked(&vm_stat[item]);
86430 }
86431
86432 static inline void __inc_zone_page_state(struct page *page,
86433 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86434 index 91b0a68..0e9adf6 100644
86435 --- a/include/linux/xattr.h
86436 +++ b/include/linux/xattr.h
86437 @@ -28,7 +28,7 @@ struct xattr_handler {
86438 size_t size, int handler_flags);
86439 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86440 size_t size, int flags, int handler_flags);
86441 -};
86442 +} __do_const;
86443
86444 struct xattr {
86445 const char *name;
86446 @@ -37,6 +37,9 @@ struct xattr {
86447 };
86448
86449 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86450 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86451 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86452 +#endif
86453 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86454 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86455 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86456 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86457 index 92dbbd3..13ab0b3 100644
86458 --- a/include/linux/zlib.h
86459 +++ b/include/linux/zlib.h
86460 @@ -31,6 +31,7 @@
86461 #define _ZLIB_H
86462
86463 #include <linux/zconf.h>
86464 +#include <linux/compiler.h>
86465
86466 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86467 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86468 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86469
86470 /* basic functions */
86471
86472 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86473 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86474 /*
86475 Returns the number of bytes that needs to be allocated for a per-
86476 stream workspace with the specified parameters. A pointer to this
86477 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86478 index eb76cfd..9fd0e7c 100644
86479 --- a/include/media/v4l2-dev.h
86480 +++ b/include/media/v4l2-dev.h
86481 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86482 int (*mmap) (struct file *, struct vm_area_struct *);
86483 int (*open) (struct file *);
86484 int (*release) (struct file *);
86485 -};
86486 +} __do_const;
86487
86488 /*
86489 * Newer version of video_device, handled by videodev2.c
86490 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86491 index ffb69da..040393e 100644
86492 --- a/include/media/v4l2-device.h
86493 +++ b/include/media/v4l2-device.h
86494 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86495 this function returns 0. If the name ends with a digit (e.g. cx18),
86496 then the name will be set to cx18-0 since cx180 looks really odd. */
86497 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86498 - atomic_t *instance);
86499 + atomic_unchecked_t *instance);
86500
86501 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86502 Since the parent disappears this ensures that v4l2_dev doesn't have an
86503 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86504 index d9fa68f..45c88d1 100644
86505 --- a/include/net/9p/transport.h
86506 +++ b/include/net/9p/transport.h
86507 @@ -63,7 +63,7 @@ struct p9_trans_module {
86508 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86509 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86510 char *, char *, int , int, int, int);
86511 -};
86512 +} __do_const;
86513
86514 void v9fs_register_trans(struct p9_trans_module *m);
86515 void v9fs_unregister_trans(struct p9_trans_module *m);
86516 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86517 index a175ba4..196eb82 100644
86518 --- a/include/net/af_unix.h
86519 +++ b/include/net/af_unix.h
86520 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86521 u32 secid; /* Security ID */
86522 #endif
86523 u32 consumed;
86524 -};
86525 +} __randomize_layout;
86526
86527 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86528 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86529 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86530 index 8df15ad..837fbedd 100644
86531 --- a/include/net/bluetooth/l2cap.h
86532 +++ b/include/net/bluetooth/l2cap.h
86533 @@ -608,7 +608,7 @@ struct l2cap_ops {
86534 unsigned char *kdata,
86535 struct iovec *iov,
86536 int len);
86537 -};
86538 +} __do_const;
86539
86540 struct l2cap_conn {
86541 struct hci_conn *hcon;
86542 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86543 index f2ae33d..c457cf0 100644
86544 --- a/include/net/caif/cfctrl.h
86545 +++ b/include/net/caif/cfctrl.h
86546 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86547 void (*radioset_rsp)(void);
86548 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86549 struct cflayer *client_layer);
86550 -};
86551 +} __no_const;
86552
86553 /* Link Setup Parameters for CAIF-Links. */
86554 struct cfctrl_link_param {
86555 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86556 struct cfctrl {
86557 struct cfsrvl serv;
86558 struct cfctrl_rsp res;
86559 - atomic_t req_seq_no;
86560 - atomic_t rsp_seq_no;
86561 + atomic_unchecked_t req_seq_no;
86562 + atomic_unchecked_t rsp_seq_no;
86563 struct list_head list;
86564 /* Protects from simultaneous access to first_req list */
86565 spinlock_t info_list_lock;
86566 diff --git a/include/net/flow.h b/include/net/flow.h
86567 index 8109a15..504466d 100644
86568 --- a/include/net/flow.h
86569 +++ b/include/net/flow.h
86570 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86571
86572 void flow_cache_flush(struct net *net);
86573 void flow_cache_flush_deferred(struct net *net);
86574 -extern atomic_t flow_cache_genid;
86575 +extern atomic_unchecked_t flow_cache_genid;
86576
86577 #endif
86578 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86579 index af10c2c..a431cc5 100644
86580 --- a/include/net/genetlink.h
86581 +++ b/include/net/genetlink.h
86582 @@ -120,7 +120,7 @@ struct genl_ops {
86583 u8 cmd;
86584 u8 internal_flags;
86585 u8 flags;
86586 -};
86587 +} __do_const;
86588
86589 int __genl_register_family(struct genl_family *family);
86590
86591 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86592 index 734d9b5..48a9a4b 100644
86593 --- a/include/net/gro_cells.h
86594 +++ b/include/net/gro_cells.h
86595 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86596 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86597
86598 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86599 - atomic_long_inc(&dev->rx_dropped);
86600 + atomic_long_inc_unchecked(&dev->rx_dropped);
86601 kfree_skb(skb);
86602 return;
86603 }
86604 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86605 index 5fbe656..9ed3d8b 100644
86606 --- a/include/net/inet_connection_sock.h
86607 +++ b/include/net/inet_connection_sock.h
86608 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86609 int (*bind_conflict)(const struct sock *sk,
86610 const struct inet_bind_bucket *tb, bool relax);
86611 void (*mtu_reduced)(struct sock *sk);
86612 -};
86613 +} __do_const;
86614
86615 /** inet_connection_sock - INET connection oriented sock
86616 *
86617 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86618 index 01d590e..f69c61d 100644
86619 --- a/include/net/inetpeer.h
86620 +++ b/include/net/inetpeer.h
86621 @@ -47,7 +47,7 @@ struct inet_peer {
86622 */
86623 union {
86624 struct {
86625 - atomic_t rid; /* Frag reception counter */
86626 + atomic_unchecked_t rid; /* Frag reception counter */
86627 };
86628 struct rcu_head rcu;
86629 struct inet_peer *gc_next;
86630 diff --git a/include/net/ip.h b/include/net/ip.h
86631 index db4a771..965a42a 100644
86632 --- a/include/net/ip.h
86633 +++ b/include/net/ip.h
86634 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86635 }
86636 }
86637
86638 -u32 ip_idents_reserve(u32 hash, int segs);
86639 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86640 void __ip_select_ident(struct iphdr *iph, int segs);
86641
86642 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86643 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86644 index 9922093..a1755d6 100644
86645 --- a/include/net/ip_fib.h
86646 +++ b/include/net/ip_fib.h
86647 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86648
86649 #define FIB_RES_SADDR(net, res) \
86650 ((FIB_RES_NH(res).nh_saddr_genid == \
86651 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86652 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86653 FIB_RES_NH(res).nh_saddr : \
86654 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86655 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86656 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86657 index 624a8a5..b1e2a24 100644
86658 --- a/include/net/ip_vs.h
86659 +++ b/include/net/ip_vs.h
86660 @@ -558,7 +558,7 @@ struct ip_vs_conn {
86661 struct ip_vs_conn *control; /* Master control connection */
86662 atomic_t n_control; /* Number of controlled ones */
86663 struct ip_vs_dest *dest; /* real server */
86664 - atomic_t in_pkts; /* incoming packet counter */
86665 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86666
86667 /* packet transmitter for different forwarding methods. If it
86668 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86669 @@ -705,7 +705,7 @@ struct ip_vs_dest {
86670 __be16 port; /* port number of the server */
86671 union nf_inet_addr addr; /* IP address of the server */
86672 volatile unsigned int flags; /* dest status flags */
86673 - atomic_t conn_flags; /* flags to copy to conn */
86674 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86675 atomic_t weight; /* server weight */
86676
86677 atomic_t refcnt; /* reference counter */
86678 @@ -960,11 +960,11 @@ struct netns_ipvs {
86679 /* ip_vs_lblc */
86680 int sysctl_lblc_expiration;
86681 struct ctl_table_header *lblc_ctl_header;
86682 - struct ctl_table *lblc_ctl_table;
86683 + ctl_table_no_const *lblc_ctl_table;
86684 /* ip_vs_lblcr */
86685 int sysctl_lblcr_expiration;
86686 struct ctl_table_header *lblcr_ctl_header;
86687 - struct ctl_table *lblcr_ctl_table;
86688 + ctl_table_no_const *lblcr_ctl_table;
86689 /* ip_vs_est */
86690 struct list_head est_list; /* estimator list */
86691 spinlock_t est_lock;
86692 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86693 index 8d4f588..2e37ad2 100644
86694 --- a/include/net/irda/ircomm_tty.h
86695 +++ b/include/net/irda/ircomm_tty.h
86696 @@ -33,6 +33,7 @@
86697 #include <linux/termios.h>
86698 #include <linux/timer.h>
86699 #include <linux/tty.h> /* struct tty_struct */
86700 +#include <asm/local.h>
86701
86702 #include <net/irda/irias_object.h>
86703 #include <net/irda/ircomm_core.h>
86704 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86705 index 714cc9a..ea05f3e 100644
86706 --- a/include/net/iucv/af_iucv.h
86707 +++ b/include/net/iucv/af_iucv.h
86708 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86709 struct iucv_sock_list {
86710 struct hlist_head head;
86711 rwlock_t lock;
86712 - atomic_t autobind_name;
86713 + atomic_unchecked_t autobind_name;
86714 };
86715
86716 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86717 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86718 index f3be818..bf46196 100644
86719 --- a/include/net/llc_c_ac.h
86720 +++ b/include/net/llc_c_ac.h
86721 @@ -87,7 +87,7 @@
86722 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86723 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86724
86725 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86726 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86727
86728 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86729 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86730 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86731 index 3948cf1..83b28c4 100644
86732 --- a/include/net/llc_c_ev.h
86733 +++ b/include/net/llc_c_ev.h
86734 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86735 return (struct llc_conn_state_ev *)skb->cb;
86736 }
86737
86738 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86739 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86740 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86741 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86742
86743 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86744 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86745 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86746 index 0e79cfb..f46db31 100644
86747 --- a/include/net/llc_c_st.h
86748 +++ b/include/net/llc_c_st.h
86749 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86750 u8 next_state;
86751 llc_conn_ev_qfyr_t *ev_qualifiers;
86752 llc_conn_action_t *ev_actions;
86753 -};
86754 +} __do_const;
86755
86756 struct llc_conn_state {
86757 u8 current_state;
86758 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86759 index a61b98c..aade1eb 100644
86760 --- a/include/net/llc_s_ac.h
86761 +++ b/include/net/llc_s_ac.h
86762 @@ -23,7 +23,7 @@
86763 #define SAP_ACT_TEST_IND 9
86764
86765 /* All action functions must look like this */
86766 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86767 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86768
86769 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86770 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86771 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86772 index 567c681..cd73ac02 100644
86773 --- a/include/net/llc_s_st.h
86774 +++ b/include/net/llc_s_st.h
86775 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86776 llc_sap_ev_t ev;
86777 u8 next_state;
86778 llc_sap_action_t *ev_actions;
86779 -};
86780 +} __do_const;
86781
86782 struct llc_sap_state {
86783 u8 curr_state;
86784 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86785 index dae2e24..89336e6 100644
86786 --- a/include/net/mac80211.h
86787 +++ b/include/net/mac80211.h
86788 @@ -4650,7 +4650,7 @@ struct rate_control_ops {
86789 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86790
86791 u32 (*get_expected_throughput)(void *priv_sta);
86792 -};
86793 +} __do_const;
86794
86795 static inline int rate_supported(struct ieee80211_sta *sta,
86796 enum ieee80211_band band,
86797 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86798 index 47f4254..fd095bc 100644
86799 --- a/include/net/neighbour.h
86800 +++ b/include/net/neighbour.h
86801 @@ -163,7 +163,7 @@ struct neigh_ops {
86802 void (*error_report)(struct neighbour *, struct sk_buff *);
86803 int (*output)(struct neighbour *, struct sk_buff *);
86804 int (*connected_output)(struct neighbour *, struct sk_buff *);
86805 -};
86806 +} __do_const;
86807
86808 struct pneigh_entry {
86809 struct pneigh_entry *next;
86810 @@ -217,7 +217,7 @@ struct neigh_table {
86811 struct neigh_statistics __percpu *stats;
86812 struct neigh_hash_table __rcu *nht;
86813 struct pneigh_entry **phash_buckets;
86814 -};
86815 +} __randomize_layout;
86816
86817 static inline int neigh_parms_family(struct neigh_parms *p)
86818 {
86819 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86820 index e0d6466..e2f3003 100644
86821 --- a/include/net/net_namespace.h
86822 +++ b/include/net/net_namespace.h
86823 @@ -129,8 +129,8 @@ struct net {
86824 struct netns_ipvs *ipvs;
86825 #endif
86826 struct sock *diag_nlsk;
86827 - atomic_t fnhe_genid;
86828 -};
86829 + atomic_unchecked_t fnhe_genid;
86830 +} __randomize_layout;
86831
86832 #include <linux/seq_file_net.h>
86833
86834 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86835 #define __net_init __init
86836 #define __net_exit __exit_refok
86837 #define __net_initdata __initdata
86838 +#ifdef CONSTIFY_PLUGIN
86839 #define __net_initconst __initconst
86840 +#else
86841 +#define __net_initconst __initdata
86842 +#endif
86843 #endif
86844
86845 struct pernet_operations {
86846 @@ -296,7 +300,7 @@ struct pernet_operations {
86847 void (*exit_batch)(struct list_head *net_exit_list);
86848 int *id;
86849 size_t size;
86850 -};
86851 +} __do_const;
86852
86853 /*
86854 * Use these carefully. If you implement a network device and it
86855 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86856
86857 static inline int rt_genid_ipv4(struct net *net)
86858 {
86859 - return atomic_read(&net->ipv4.rt_genid);
86860 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86861 }
86862
86863 static inline void rt_genid_bump_ipv4(struct net *net)
86864 {
86865 - atomic_inc(&net->ipv4.rt_genid);
86866 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86867 }
86868
86869 extern void (*__fib6_flush_trees)(struct net *net);
86870 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86871
86872 static inline int fnhe_genid(struct net *net)
86873 {
86874 - return atomic_read(&net->fnhe_genid);
86875 + return atomic_read_unchecked(&net->fnhe_genid);
86876 }
86877
86878 static inline void fnhe_genid_bump(struct net *net)
86879 {
86880 - atomic_inc(&net->fnhe_genid);
86881 + atomic_inc_unchecked(&net->fnhe_genid);
86882 }
86883
86884 #endif /* __NET_NET_NAMESPACE_H */
86885 diff --git a/include/net/netdma.h b/include/net/netdma.h
86886 index 8ba8ce2..99b7fff 100644
86887 --- a/include/net/netdma.h
86888 +++ b/include/net/netdma.h
86889 @@ -24,7 +24,7 @@
86890 #include <linux/dmaengine.h>
86891 #include <linux/skbuff.h>
86892
86893 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86894 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86895 struct sk_buff *skb, int offset, struct iovec *to,
86896 size_t len, struct dma_pinned_list *pinned_list);
86897
86898 diff --git a/include/net/netlink.h b/include/net/netlink.h
86899 index 6c10762..3e5de0c 100644
86900 --- a/include/net/netlink.h
86901 +++ b/include/net/netlink.h
86902 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86903 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86904 {
86905 if (mark)
86906 - skb_trim(skb, (unsigned char *) mark - skb->data);
86907 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86908 }
86909
86910 /**
86911 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86912 index 29d6a94..235d3d8 100644
86913 --- a/include/net/netns/conntrack.h
86914 +++ b/include/net/netns/conntrack.h
86915 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86916 struct nf_proto_net {
86917 #ifdef CONFIG_SYSCTL
86918 struct ctl_table_header *ctl_table_header;
86919 - struct ctl_table *ctl_table;
86920 + ctl_table_no_const *ctl_table;
86921 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86922 struct ctl_table_header *ctl_compat_header;
86923 - struct ctl_table *ctl_compat_table;
86924 + ctl_table_no_const *ctl_compat_table;
86925 #endif
86926 #endif
86927 unsigned int users;
86928 @@ -60,7 +60,7 @@ struct nf_ip_net {
86929 struct nf_icmp_net icmpv6;
86930 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86931 struct ctl_table_header *ctl_table_header;
86932 - struct ctl_table *ctl_table;
86933 + ctl_table_no_const *ctl_table;
86934 #endif
86935 };
86936
86937 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86938 index aec5e12..807233f 100644
86939 --- a/include/net/netns/ipv4.h
86940 +++ b/include/net/netns/ipv4.h
86941 @@ -82,7 +82,7 @@ struct netns_ipv4 {
86942
86943 struct ping_group_range ping_group_range;
86944
86945 - atomic_t dev_addr_genid;
86946 + atomic_unchecked_t dev_addr_genid;
86947
86948 #ifdef CONFIG_SYSCTL
86949 unsigned long *sysctl_local_reserved_ports;
86950 @@ -96,6 +96,6 @@ struct netns_ipv4 {
86951 struct fib_rules_ops *mr_rules_ops;
86952 #endif
86953 #endif
86954 - atomic_t rt_genid;
86955 + atomic_unchecked_t rt_genid;
86956 };
86957 #endif
86958 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86959 index eade27a..42894dd 100644
86960 --- a/include/net/netns/ipv6.h
86961 +++ b/include/net/netns/ipv6.h
86962 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86963 struct fib_rules_ops *mr6_rules_ops;
86964 #endif
86965 #endif
86966 - atomic_t dev_addr_genid;
86967 - atomic_t rt_genid;
86968 + atomic_unchecked_t dev_addr_genid;
86969 + atomic_unchecked_t rt_genid;
86970 };
86971
86972 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86973 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86974 index 3492434..209f58c 100644
86975 --- a/include/net/netns/xfrm.h
86976 +++ b/include/net/netns/xfrm.h
86977 @@ -64,7 +64,7 @@ struct netns_xfrm {
86978
86979 /* flow cache part */
86980 struct flow_cache flow_cache_global;
86981 - atomic_t flow_cache_genid;
86982 + atomic_unchecked_t flow_cache_genid;
86983 struct list_head flow_cache_gc_list;
86984 spinlock_t flow_cache_gc_lock;
86985 struct work_struct flow_cache_gc_work;
86986 diff --git a/include/net/ping.h b/include/net/ping.h
86987 index 026479b..d9b2829 100644
86988 --- a/include/net/ping.h
86989 +++ b/include/net/ping.h
86990 @@ -54,7 +54,7 @@ struct ping_iter_state {
86991
86992 extern struct proto ping_prot;
86993 #if IS_ENABLED(CONFIG_IPV6)
86994 -extern struct pingv6_ops pingv6_ops;
86995 +extern struct pingv6_ops *pingv6_ops;
86996 #endif
86997
86998 struct pingfakehdr {
86999 diff --git a/include/net/protocol.h b/include/net/protocol.h
87000 index d6fcc1f..ca277058 100644
87001 --- a/include/net/protocol.h
87002 +++ b/include/net/protocol.h
87003 @@ -49,7 +49,7 @@ struct net_protocol {
87004 * socket lookup?
87005 */
87006 icmp_strict_tag_validation:1;
87007 -};
87008 +} __do_const;
87009
87010 #if IS_ENABLED(CONFIG_IPV6)
87011 struct inet6_protocol {
87012 @@ -62,7 +62,7 @@ struct inet6_protocol {
87013 u8 type, u8 code, int offset,
87014 __be32 info);
87015 unsigned int flags; /* INET6_PROTO_xxx */
87016 -};
87017 +} __do_const;
87018
87019 #define INET6_PROTO_NOPOLICY 0x1
87020 #define INET6_PROTO_FINAL 0x2
87021 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
87022 index e21b9f9..0191ef0 100644
87023 --- a/include/net/rtnetlink.h
87024 +++ b/include/net/rtnetlink.h
87025 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
87026 int (*fill_slave_info)(struct sk_buff *skb,
87027 const struct net_device *dev,
87028 const struct net_device *slave_dev);
87029 -};
87030 +} __do_const;
87031
87032 int __rtnl_link_register(struct rtnl_link_ops *ops);
87033 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
87034 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
87035 index 4a5b9a3..ca27d73 100644
87036 --- a/include/net/sctp/checksum.h
87037 +++ b/include/net/sctp/checksum.h
87038 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
87039 unsigned int offset)
87040 {
87041 struct sctphdr *sh = sctp_hdr(skb);
87042 - __le32 ret, old = sh->checksum;
87043 - const struct skb_checksum_ops ops = {
87044 + __le32 ret, old = sh->checksum;
87045 + static const struct skb_checksum_ops ops = {
87046 .update = sctp_csum_update,
87047 .combine = sctp_csum_combine,
87048 };
87049 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
87050 index 7f4eeb3..37e8fe1 100644
87051 --- a/include/net/sctp/sm.h
87052 +++ b/include/net/sctp/sm.h
87053 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
87054 typedef struct {
87055 sctp_state_fn_t *fn;
87056 const char *name;
87057 -} sctp_sm_table_entry_t;
87058 +} __do_const sctp_sm_table_entry_t;
87059
87060 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
87061 * currently in use.
87062 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
87063 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
87064
87065 /* Extern declarations for major data structures. */
87066 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87067 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87068
87069
87070 /* Get the size of a DATA chunk payload. */
87071 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
87072 index 4ff3f67..89ae38e 100644
87073 --- a/include/net/sctp/structs.h
87074 +++ b/include/net/sctp/structs.h
87075 @@ -509,7 +509,7 @@ struct sctp_pf {
87076 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
87077 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
87078 struct sctp_af *af;
87079 -};
87080 +} __do_const;
87081
87082
87083 /* Structure to track chunk fragments that have been acked, but peer
87084 diff --git a/include/net/sock.h b/include/net/sock.h
87085 index b9a5bd0..dcd5f3c 100644
87086 --- a/include/net/sock.h
87087 +++ b/include/net/sock.h
87088 @@ -356,7 +356,7 @@ struct sock {
87089 unsigned int sk_napi_id;
87090 unsigned int sk_ll_usec;
87091 #endif
87092 - atomic_t sk_drops;
87093 + atomic_unchecked_t sk_drops;
87094 int sk_rcvbuf;
87095
87096 struct sk_filter __rcu *sk_filter;
87097 @@ -1053,7 +1053,7 @@ struct proto {
87098 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87099 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87100 #endif
87101 -};
87102 +} __randomize_layout;
87103
87104 /*
87105 * Bits in struct cg_proto.flags
87106 @@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87107 return ret >> PAGE_SHIFT;
87108 }
87109
87110 -static inline long
87111 +static inline long __intentional_overflow(-1)
87112 sk_memory_allocated(const struct sock *sk)
87113 {
87114 struct proto *prot = sk->sk_prot;
87115 @@ -1385,7 +1385,7 @@ struct sock_iocb {
87116 struct scm_cookie *scm;
87117 struct msghdr *msg, async_msg;
87118 struct kiocb *kiocb;
87119 -};
87120 +} __randomize_layout;
87121
87122 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87123 {
87124 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87125 }
87126
87127 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87128 - char __user *from, char *to,
87129 + char __user *from, unsigned char *to,
87130 int copy, int offset)
87131 {
87132 if (skb->ip_summed == CHECKSUM_NONE) {
87133 @@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87134 }
87135 }
87136
87137 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87138 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87139
87140 /**
87141 * sk_page_frag - return an appropriate page_frag
87142 diff --git a/include/net/tcp.h b/include/net/tcp.h
87143 index 590e01a..76498f3 100644
87144 --- a/include/net/tcp.h
87145 +++ b/include/net/tcp.h
87146 @@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
87147 void tcp_xmit_retransmit_queue(struct sock *);
87148 void tcp_simple_retransmit(struct sock *);
87149 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87150 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87151 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87152
87153 void tcp_send_probe0(struct sock *);
87154 void tcp_send_partial(struct sock *);
87155 @@ -696,8 +696,8 @@ struct tcp_skb_cb {
87156 struct inet6_skb_parm h6;
87157 #endif
87158 } header; /* For incoming frames */
87159 - __u32 seq; /* Starting sequence number */
87160 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87161 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
87162 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87163 __u32 when; /* used to compute rtt's */
87164 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
87165
87166 @@ -713,7 +713,7 @@ struct tcp_skb_cb {
87167
87168 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87169 /* 1 byte hole */
87170 - __u32 ack_seq; /* Sequence number ACK'd */
87171 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87172 };
87173
87174 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
87175 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87176 index 721e9c3b..3c81bbf 100644
87177 --- a/include/net/xfrm.h
87178 +++ b/include/net/xfrm.h
87179 @@ -285,7 +285,6 @@ struct xfrm_dst;
87180 struct xfrm_policy_afinfo {
87181 unsigned short family;
87182 struct dst_ops *dst_ops;
87183 - void (*garbage_collect)(struct net *net);
87184 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87185 const xfrm_address_t *saddr,
87186 const xfrm_address_t *daddr);
87187 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87188 struct net_device *dev,
87189 const struct flowi *fl);
87190 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87191 -};
87192 +} __do_const;
87193
87194 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87195 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87196 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87197 int (*transport_finish)(struct sk_buff *skb,
87198 int async);
87199 void (*local_error)(struct sk_buff *skb, u32 mtu);
87200 -};
87201 +} __do_const;
87202
87203 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87204 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87205 @@ -437,7 +436,7 @@ struct xfrm_mode {
87206 struct module *owner;
87207 unsigned int encap;
87208 int flags;
87209 -};
87210 +} __do_const;
87211
87212 /* Flags for xfrm_mode. */
87213 enum {
87214 @@ -534,7 +533,7 @@ struct xfrm_policy {
87215 struct timer_list timer;
87216
87217 struct flow_cache_object flo;
87218 - atomic_t genid;
87219 + atomic_unchecked_t genid;
87220 u32 priority;
87221 u32 index;
87222 struct xfrm_mark mark;
87223 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87224 }
87225
87226 void xfrm_garbage_collect(struct net *net);
87227 +void xfrm_garbage_collect_deferred(struct net *net);
87228
87229 #else
87230
87231 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87232 static inline void xfrm_garbage_collect(struct net *net)
87233 {
87234 }
87235 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87236 +{
87237 +}
87238 #endif
87239
87240 static __inline__
87241 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87242 index 1017e0b..227aa4d 100644
87243 --- a/include/rdma/iw_cm.h
87244 +++ b/include/rdma/iw_cm.h
87245 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87246 int backlog);
87247
87248 int (*destroy_listen)(struct iw_cm_id *cm_id);
87249 -};
87250 +} __no_const;
87251
87252 /**
87253 * iw_create_cm_id - Create an IW CM identifier.
87254 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87255 index 52beadf..598734c 100644
87256 --- a/include/scsi/libfc.h
87257 +++ b/include/scsi/libfc.h
87258 @@ -771,6 +771,7 @@ struct libfc_function_template {
87259 */
87260 void (*disc_stop_final) (struct fc_lport *);
87261 };
87262 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87263
87264 /**
87265 * struct fc_disc - Discovery context
87266 @@ -875,7 +876,7 @@ struct fc_lport {
87267 struct fc_vport *vport;
87268
87269 /* Operational Information */
87270 - struct libfc_function_template tt;
87271 + libfc_function_template_no_const tt;
87272 u8 link_up;
87273 u8 qfull;
87274 enum fc_lport_state state;
87275 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87276 index 1a0d184..4fb841f 100644
87277 --- a/include/scsi/scsi_device.h
87278 +++ b/include/scsi/scsi_device.h
87279 @@ -185,9 +185,9 @@ struct scsi_device {
87280 unsigned int max_device_blocked; /* what device_blocked counts down from */
87281 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87282
87283 - atomic_t iorequest_cnt;
87284 - atomic_t iodone_cnt;
87285 - atomic_t ioerr_cnt;
87286 + atomic_unchecked_t iorequest_cnt;
87287 + atomic_unchecked_t iodone_cnt;
87288 + atomic_unchecked_t ioerr_cnt;
87289
87290 struct device sdev_gendev,
87291 sdev_dev;
87292 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87293 index 007a0bc..7188db8 100644
87294 --- a/include/scsi/scsi_transport_fc.h
87295 +++ b/include/scsi/scsi_transport_fc.h
87296 @@ -756,7 +756,8 @@ struct fc_function_template {
87297 unsigned long show_host_system_hostname:1;
87298
87299 unsigned long disable_target_scan:1;
87300 -};
87301 +} __do_const;
87302 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87303
87304
87305 /**
87306 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87307 index ae6c3b8..fd748ac 100644
87308 --- a/include/sound/compress_driver.h
87309 +++ b/include/sound/compress_driver.h
87310 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87311 struct snd_compr_caps *caps);
87312 int (*get_codec_caps) (struct snd_compr_stream *stream,
87313 struct snd_compr_codec_caps *codec);
87314 -};
87315 +} __no_const;
87316
87317 /**
87318 * struct snd_compr: Compressed device
87319 diff --git a/include/sound/soc.h b/include/sound/soc.h
87320 index c83a334..27c8038 100644
87321 --- a/include/sound/soc.h
87322 +++ b/include/sound/soc.h
87323 @@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87324 /* probe ordering - for components with runtime dependencies */
87325 int probe_order;
87326 int remove_order;
87327 -};
87328 +} __do_const;
87329
87330 /* SoC platform interface */
87331 struct snd_soc_platform_driver {
87332 @@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87333 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87334 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87335 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87336 -};
87337 +} __do_const;
87338
87339 struct snd_soc_dai_link_component {
87340 const char *name;
87341 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87342 index 9ec9864..e2ee1ee 100644
87343 --- a/include/target/target_core_base.h
87344 +++ b/include/target/target_core_base.h
87345 @@ -761,7 +761,7 @@ struct se_device {
87346 atomic_long_t write_bytes;
87347 /* Active commands on this virtual SE device */
87348 atomic_t simple_cmds;
87349 - atomic_t dev_ordered_id;
87350 + atomic_unchecked_t dev_ordered_id;
87351 atomic_t dev_ordered_sync;
87352 atomic_t dev_qf_count;
87353 int export_count;
87354 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87355 new file mode 100644
87356 index 0000000..fb634b7
87357 --- /dev/null
87358 +++ b/include/trace/events/fs.h
87359 @@ -0,0 +1,53 @@
87360 +#undef TRACE_SYSTEM
87361 +#define TRACE_SYSTEM fs
87362 +
87363 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87364 +#define _TRACE_FS_H
87365 +
87366 +#include <linux/fs.h>
87367 +#include <linux/tracepoint.h>
87368 +
87369 +TRACE_EVENT(do_sys_open,
87370 +
87371 + TP_PROTO(const char *filename, int flags, int mode),
87372 +
87373 + TP_ARGS(filename, flags, mode),
87374 +
87375 + TP_STRUCT__entry(
87376 + __string( filename, filename )
87377 + __field( int, flags )
87378 + __field( int, mode )
87379 + ),
87380 +
87381 + TP_fast_assign(
87382 + __assign_str(filename, filename);
87383 + __entry->flags = flags;
87384 + __entry->mode = mode;
87385 + ),
87386 +
87387 + TP_printk("\"%s\" %x %o",
87388 + __get_str(filename), __entry->flags, __entry->mode)
87389 +);
87390 +
87391 +TRACE_EVENT(open_exec,
87392 +
87393 + TP_PROTO(const char *filename),
87394 +
87395 + TP_ARGS(filename),
87396 +
87397 + TP_STRUCT__entry(
87398 + __string( filename, filename )
87399 + ),
87400 +
87401 + TP_fast_assign(
87402 + __assign_str(filename, filename);
87403 + ),
87404 +
87405 + TP_printk("\"%s\"",
87406 + __get_str(filename))
87407 +);
87408 +
87409 +#endif /* _TRACE_FS_H */
87410 +
87411 +/* This part must be outside protection */
87412 +#include <trace/define_trace.h>
87413 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87414 index 3608beb..df39d8a 100644
87415 --- a/include/trace/events/irq.h
87416 +++ b/include/trace/events/irq.h
87417 @@ -36,7 +36,7 @@ struct softirq_action;
87418 */
87419 TRACE_EVENT(irq_handler_entry,
87420
87421 - TP_PROTO(int irq, struct irqaction *action),
87422 + TP_PROTO(int irq, const struct irqaction *action),
87423
87424 TP_ARGS(irq, action),
87425
87426 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87427 */
87428 TRACE_EVENT(irq_handler_exit,
87429
87430 - TP_PROTO(int irq, struct irqaction *action, int ret),
87431 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87432
87433 TP_ARGS(irq, action, ret),
87434
87435 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87436 index 7caf44c..23c6f27 100644
87437 --- a/include/uapi/linux/a.out.h
87438 +++ b/include/uapi/linux/a.out.h
87439 @@ -39,6 +39,14 @@ enum machine_type {
87440 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87441 };
87442
87443 +/* Constants for the N_FLAGS field */
87444 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87445 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87446 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87447 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87448 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87449 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87450 +
87451 #if !defined (N_MAGIC)
87452 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87453 #endif
87454 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87455 index 22b6ad3..aeba37e 100644
87456 --- a/include/uapi/linux/bcache.h
87457 +++ b/include/uapi/linux/bcache.h
87458 @@ -5,6 +5,7 @@
87459 * Bcache on disk data structures
87460 */
87461
87462 +#include <linux/compiler.h>
87463 #include <asm/types.h>
87464
87465 #define BITMASK(name, type, field, offset, size) \
87466 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87467 /* Btree keys - all units are in sectors */
87468
87469 struct bkey {
87470 - __u64 high;
87471 - __u64 low;
87472 + __u64 high __intentional_overflow(-1);
87473 + __u64 low __intentional_overflow(-1);
87474 __u64 ptr[];
87475 };
87476
87477 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87478 index d876736..ccce5c0 100644
87479 --- a/include/uapi/linux/byteorder/little_endian.h
87480 +++ b/include/uapi/linux/byteorder/little_endian.h
87481 @@ -42,51 +42,51 @@
87482
87483 static inline __le64 __cpu_to_le64p(const __u64 *p)
87484 {
87485 - return (__force __le64)*p;
87486 + return (__force const __le64)*p;
87487 }
87488 -static inline __u64 __le64_to_cpup(const __le64 *p)
87489 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87490 {
87491 - return (__force __u64)*p;
87492 + return (__force const __u64)*p;
87493 }
87494 static inline __le32 __cpu_to_le32p(const __u32 *p)
87495 {
87496 - return (__force __le32)*p;
87497 + return (__force const __le32)*p;
87498 }
87499 static inline __u32 __le32_to_cpup(const __le32 *p)
87500 {
87501 - return (__force __u32)*p;
87502 + return (__force const __u32)*p;
87503 }
87504 static inline __le16 __cpu_to_le16p(const __u16 *p)
87505 {
87506 - return (__force __le16)*p;
87507 + return (__force const __le16)*p;
87508 }
87509 static inline __u16 __le16_to_cpup(const __le16 *p)
87510 {
87511 - return (__force __u16)*p;
87512 + return (__force const __u16)*p;
87513 }
87514 static inline __be64 __cpu_to_be64p(const __u64 *p)
87515 {
87516 - return (__force __be64)__swab64p(p);
87517 + return (__force const __be64)__swab64p(p);
87518 }
87519 static inline __u64 __be64_to_cpup(const __be64 *p)
87520 {
87521 - return __swab64p((__u64 *)p);
87522 + return __swab64p((const __u64 *)p);
87523 }
87524 static inline __be32 __cpu_to_be32p(const __u32 *p)
87525 {
87526 - return (__force __be32)__swab32p(p);
87527 + return (__force const __be32)__swab32p(p);
87528 }
87529 -static inline __u32 __be32_to_cpup(const __be32 *p)
87530 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87531 {
87532 - return __swab32p((__u32 *)p);
87533 + return __swab32p((const __u32 *)p);
87534 }
87535 static inline __be16 __cpu_to_be16p(const __u16 *p)
87536 {
87537 - return (__force __be16)__swab16p(p);
87538 + return (__force const __be16)__swab16p(p);
87539 }
87540 static inline __u16 __be16_to_cpup(const __be16 *p)
87541 {
87542 - return __swab16p((__u16 *)p);
87543 + return __swab16p((const __u16 *)p);
87544 }
87545 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87546 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87547 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87548 index ef6103b..d4e65dd 100644
87549 --- a/include/uapi/linux/elf.h
87550 +++ b/include/uapi/linux/elf.h
87551 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87552 #define PT_GNU_EH_FRAME 0x6474e550
87553
87554 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87555 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87556 +
87557 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87558 +
87559 +/* Constants for the e_flags field */
87560 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87561 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87562 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87563 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87564 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87565 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87566
87567 /*
87568 * Extended Numbering
87569 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87570 #define DT_DEBUG 21
87571 #define DT_TEXTREL 22
87572 #define DT_JMPREL 23
87573 +#define DT_FLAGS 30
87574 + #define DF_TEXTREL 0x00000004
87575 #define DT_ENCODING 32
87576 #define OLD_DT_LOOS 0x60000000
87577 #define DT_LOOS 0x6000000d
87578 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87579 #define PF_W 0x2
87580 #define PF_X 0x1
87581
87582 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87583 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87584 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87585 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87586 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87587 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87588 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87589 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87590 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87591 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87592 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87593 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87594 +
87595 typedef struct elf32_phdr{
87596 Elf32_Word p_type;
87597 Elf32_Off p_offset;
87598 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87599 #define EI_OSABI 7
87600 #define EI_PAD 8
87601
87602 +#define EI_PAX 14
87603 +
87604 #define ELFMAG0 0x7f /* EI_MAG */
87605 #define ELFMAG1 'E'
87606 #define ELFMAG2 'L'
87607 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87608 index aa169c4..6a2771d 100644
87609 --- a/include/uapi/linux/personality.h
87610 +++ b/include/uapi/linux/personality.h
87611 @@ -30,6 +30,7 @@ enum {
87612 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87613 ADDR_NO_RANDOMIZE | \
87614 ADDR_COMPAT_LAYOUT | \
87615 + ADDR_LIMIT_3GB | \
87616 MMAP_PAGE_ZERO)
87617
87618 /*
87619 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87620 index 7530e74..e714828 100644
87621 --- a/include/uapi/linux/screen_info.h
87622 +++ b/include/uapi/linux/screen_info.h
87623 @@ -43,7 +43,8 @@ struct screen_info {
87624 __u16 pages; /* 0x32 */
87625 __u16 vesa_attributes; /* 0x34 */
87626 __u32 capabilities; /* 0x36 */
87627 - __u8 _reserved[6]; /* 0x3a */
87628 + __u16 vesapm_size; /* 0x3a */
87629 + __u8 _reserved[4]; /* 0x3c */
87630 } __attribute__((packed));
87631
87632 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87633 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87634 index 0e011eb..82681b1 100644
87635 --- a/include/uapi/linux/swab.h
87636 +++ b/include/uapi/linux/swab.h
87637 @@ -43,7 +43,7 @@
87638 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87639 */
87640
87641 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87642 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87643 {
87644 #ifdef __HAVE_BUILTIN_BSWAP16__
87645 return __builtin_bswap16(val);
87646 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87647 #endif
87648 }
87649
87650 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87651 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87652 {
87653 #ifdef __HAVE_BUILTIN_BSWAP32__
87654 return __builtin_bswap32(val);
87655 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87656 #endif
87657 }
87658
87659 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87660 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87661 {
87662 #ifdef __HAVE_BUILTIN_BSWAP64__
87663 return __builtin_bswap64(val);
87664 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87665 index 43aaba1..1c30b48 100644
87666 --- a/include/uapi/linux/sysctl.h
87667 +++ b/include/uapi/linux/sysctl.h
87668 @@ -155,8 +155,6 @@ enum
87669 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87670 };
87671
87672 -
87673 -
87674 /* CTL_VM names: */
87675 enum
87676 {
87677 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87678 index 778a329..1416ffb 100644
87679 --- a/include/uapi/linux/videodev2.h
87680 +++ b/include/uapi/linux/videodev2.h
87681 @@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87682 union {
87683 __s32 value;
87684 __s64 value64;
87685 - char *string;
87686 + char __user *string;
87687 __u8 *p_u8;
87688 __u16 *p_u16;
87689 __u32 *p_u32;
87690 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87691 index 1590c49..5eab462 100644
87692 --- a/include/uapi/linux/xattr.h
87693 +++ b/include/uapi/linux/xattr.h
87694 @@ -73,5 +73,9 @@
87695 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87696 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87697
87698 +/* User namespace */
87699 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87700 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87701 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87702
87703 #endif /* _UAPI_LINUX_XATTR_H */
87704 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87705 index f9466fa..f4e2b81 100644
87706 --- a/include/video/udlfb.h
87707 +++ b/include/video/udlfb.h
87708 @@ -53,10 +53,10 @@ struct dlfb_data {
87709 u32 pseudo_palette[256];
87710 int blank_mode; /*one of FB_BLANK_ */
87711 /* blit-only rendering path metrics, exposed through sysfs */
87712 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87713 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87714 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87715 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87716 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87717 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87718 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87719 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87720 };
87721
87722 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87723 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87724 index 30f5362..8ed8ac9 100644
87725 --- a/include/video/uvesafb.h
87726 +++ b/include/video/uvesafb.h
87727 @@ -122,6 +122,7 @@ struct uvesafb_par {
87728 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87729 u8 pmi_setpal; /* PMI for palette changes */
87730 u16 *pmi_base; /* protected mode interface location */
87731 + u8 *pmi_code; /* protected mode code location */
87732 void *pmi_start;
87733 void *pmi_pal;
87734 u8 *vbe_state_orig; /*
87735 diff --git a/init/Kconfig b/init/Kconfig
87736 index 80a6907..baf7d53 100644
87737 --- a/init/Kconfig
87738 +++ b/init/Kconfig
87739 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87740
87741 config CHECKPOINT_RESTORE
87742 bool "Checkpoint/restore support" if EXPERT
87743 + depends on !GRKERNSEC
87744 default n
87745 help
87746 Enables additional kernel features in a sake of checkpoint/restore.
87747 @@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87748
87749 config COMPAT_BRK
87750 bool "Disable heap randomization"
87751 - default y
87752 + default n
87753 help
87754 Randomizing heap placement makes heap exploits harder, but it
87755 also breaks ancient binaries (including anything libc5 based).
87756 @@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87757 config STOP_MACHINE
87758 bool
87759 default y
87760 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87761 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87762 help
87763 Need stop_machine() primitive.
87764
87765 diff --git a/init/Makefile b/init/Makefile
87766 index 7bc47ee..6da2dc7 100644
87767 --- a/init/Makefile
87768 +++ b/init/Makefile
87769 @@ -2,6 +2,9 @@
87770 # Makefile for the linux kernel.
87771 #
87772
87773 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87774 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87775 +
87776 obj-y := main.o version.o mounts.o
87777 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87778 obj-y += noinitramfs.o
87779 diff --git a/init/do_mounts.c b/init/do_mounts.c
87780 index 82f2288..ea1430a 100644
87781 --- a/init/do_mounts.c
87782 +++ b/init/do_mounts.c
87783 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87784 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87785 {
87786 struct super_block *s;
87787 - int err = sys_mount(name, "/root", fs, flags, data);
87788 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87789 if (err)
87790 return err;
87791
87792 - sys_chdir("/root");
87793 + sys_chdir((const char __force_user *)"/root");
87794 s = current->fs->pwd.dentry->d_sb;
87795 ROOT_DEV = s->s_dev;
87796 printk(KERN_INFO
87797 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87798 va_start(args, fmt);
87799 vsprintf(buf, fmt, args);
87800 va_end(args);
87801 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87802 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87803 if (fd >= 0) {
87804 sys_ioctl(fd, FDEJECT, 0);
87805 sys_close(fd);
87806 }
87807 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87808 - fd = sys_open("/dev/console", O_RDWR, 0);
87809 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87810 if (fd >= 0) {
87811 sys_ioctl(fd, TCGETS, (long)&termios);
87812 termios.c_lflag &= ~ICANON;
87813 sys_ioctl(fd, TCSETSF, (long)&termios);
87814 - sys_read(fd, &c, 1);
87815 + sys_read(fd, (char __user *)&c, 1);
87816 termios.c_lflag |= ICANON;
87817 sys_ioctl(fd, TCSETSF, (long)&termios);
87818 sys_close(fd);
87819 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87820 mount_root();
87821 out:
87822 devtmpfs_mount("dev");
87823 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87824 - sys_chroot(".");
87825 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87826 + sys_chroot((const char __force_user *)".");
87827 }
87828
87829 static bool is_tmpfs;
87830 diff --git a/init/do_mounts.h b/init/do_mounts.h
87831 index f5b978a..69dbfe8 100644
87832 --- a/init/do_mounts.h
87833 +++ b/init/do_mounts.h
87834 @@ -15,15 +15,15 @@ extern int root_mountflags;
87835
87836 static inline int create_dev(char *name, dev_t dev)
87837 {
87838 - sys_unlink(name);
87839 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87840 + sys_unlink((char __force_user *)name);
87841 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87842 }
87843
87844 #if BITS_PER_LONG == 32
87845 static inline u32 bstat(char *name)
87846 {
87847 struct stat64 stat;
87848 - if (sys_stat64(name, &stat) != 0)
87849 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87850 return 0;
87851 if (!S_ISBLK(stat.st_mode))
87852 return 0;
87853 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87854 static inline u32 bstat(char *name)
87855 {
87856 struct stat stat;
87857 - if (sys_newstat(name, &stat) != 0)
87858 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87859 return 0;
87860 if (!S_ISBLK(stat.st_mode))
87861 return 0;
87862 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87863 index 3e0878e..8a9d7a0 100644
87864 --- a/init/do_mounts_initrd.c
87865 +++ b/init/do_mounts_initrd.c
87866 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87867 {
87868 sys_unshare(CLONE_FS | CLONE_FILES);
87869 /* stdin/stdout/stderr for /linuxrc */
87870 - sys_open("/dev/console", O_RDWR, 0);
87871 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87872 sys_dup(0);
87873 sys_dup(0);
87874 /* move initrd over / and chdir/chroot in initrd root */
87875 - sys_chdir("/root");
87876 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87877 - sys_chroot(".");
87878 + sys_chdir((const char __force_user *)"/root");
87879 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87880 + sys_chroot((const char __force_user *)".");
87881 sys_setsid();
87882 return 0;
87883 }
87884 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87885 create_dev("/dev/root.old", Root_RAM0);
87886 /* mount initrd on rootfs' /root */
87887 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87888 - sys_mkdir("/old", 0700);
87889 - sys_chdir("/old");
87890 + sys_mkdir((const char __force_user *)"/old", 0700);
87891 + sys_chdir((const char __force_user *)"/old");
87892
87893 /* try loading default modules from initrd */
87894 load_default_modules();
87895 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87896 current->flags &= ~PF_FREEZER_SKIP;
87897
87898 /* move initrd to rootfs' /old */
87899 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87900 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87901 /* switch root and cwd back to / of rootfs */
87902 - sys_chroot("..");
87903 + sys_chroot((const char __force_user *)"..");
87904
87905 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87906 - sys_chdir("/old");
87907 + sys_chdir((const char __force_user *)"/old");
87908 return;
87909 }
87910
87911 - sys_chdir("/");
87912 + sys_chdir((const char __force_user *)"/");
87913 ROOT_DEV = new_decode_dev(real_root_dev);
87914 mount_root();
87915
87916 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87917 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87918 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87919 if (!error)
87920 printk("okay\n");
87921 else {
87922 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87923 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87924 if (error == -ENOENT)
87925 printk("/initrd does not exist. Ignored.\n");
87926 else
87927 printk("failed\n");
87928 printk(KERN_NOTICE "Unmounting old root\n");
87929 - sys_umount("/old", MNT_DETACH);
87930 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87931 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87932 if (fd < 0) {
87933 error = fd;
87934 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87935 * mounted in the normal path.
87936 */
87937 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87938 - sys_unlink("/initrd.image");
87939 + sys_unlink((const char __force_user *)"/initrd.image");
87940 handle_initrd();
87941 return 1;
87942 }
87943 }
87944 - sys_unlink("/initrd.image");
87945 + sys_unlink((const char __force_user *)"/initrd.image");
87946 return 0;
87947 }
87948 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87949 index 8cb6db5..d729f50 100644
87950 --- a/init/do_mounts_md.c
87951 +++ b/init/do_mounts_md.c
87952 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87953 partitioned ? "_d" : "", minor,
87954 md_setup_args[ent].device_names);
87955
87956 - fd = sys_open(name, 0, 0);
87957 + fd = sys_open((char __force_user *)name, 0, 0);
87958 if (fd < 0) {
87959 printk(KERN_ERR "md: open failed - cannot start "
87960 "array %s\n", name);
87961 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87962 * array without it
87963 */
87964 sys_close(fd);
87965 - fd = sys_open(name, 0, 0);
87966 + fd = sys_open((char __force_user *)name, 0, 0);
87967 sys_ioctl(fd, BLKRRPART, 0);
87968 }
87969 sys_close(fd);
87970 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87971
87972 wait_for_device_probe();
87973
87974 - fd = sys_open("/dev/md0", 0, 0);
87975 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87976 if (fd >= 0) {
87977 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87978 sys_close(fd);
87979 diff --git a/init/init_task.c b/init/init_task.c
87980 index ba0a7f36..2bcf1d5 100644
87981 --- a/init/init_task.c
87982 +++ b/init/init_task.c
87983 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87984 * Initial thread structure. Alignment of this is handled by a special
87985 * linker map entry.
87986 */
87987 +#ifdef CONFIG_X86
87988 +union thread_union init_thread_union __init_task_data;
87989 +#else
87990 union thread_union init_thread_union __init_task_data =
87991 { INIT_THREAD_INFO(init_task) };
87992 +#endif
87993 diff --git a/init/initramfs.c b/init/initramfs.c
87994 index bece48c..e911bd8 100644
87995 --- a/init/initramfs.c
87996 +++ b/init/initramfs.c
87997 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87998
87999 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
88000 while (count) {
88001 - ssize_t rv = sys_write(fd, p, count);
88002 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
88003
88004 if (rv < 0) {
88005 if (rv == -EINTR || rv == -EAGAIN)
88006 @@ -107,7 +107,7 @@ static void __init free_hash(void)
88007 }
88008 }
88009
88010 -static long __init do_utime(char *filename, time_t mtime)
88011 +static long __init do_utime(char __force_user *filename, time_t mtime)
88012 {
88013 struct timespec t[2];
88014
88015 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
88016 struct dir_entry *de, *tmp;
88017 list_for_each_entry_safe(de, tmp, &dir_list, list) {
88018 list_del(&de->list);
88019 - do_utime(de->name, de->mtime);
88020 + do_utime((char __force_user *)de->name, de->mtime);
88021 kfree(de->name);
88022 kfree(de);
88023 }
88024 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
88025 if (nlink >= 2) {
88026 char *old = find_link(major, minor, ino, mode, collected);
88027 if (old)
88028 - return (sys_link(old, collected) < 0) ? -1 : 1;
88029 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
88030 }
88031 return 0;
88032 }
88033 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
88034 {
88035 struct stat st;
88036
88037 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
88038 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
88039 if (S_ISDIR(st.st_mode))
88040 - sys_rmdir(path);
88041 + sys_rmdir((char __force_user *)path);
88042 else
88043 - sys_unlink(path);
88044 + sys_unlink((char __force_user *)path);
88045 }
88046 }
88047
88048 @@ -338,7 +338,7 @@ static int __init do_name(void)
88049 int openflags = O_WRONLY|O_CREAT;
88050 if (ml != 1)
88051 openflags |= O_TRUNC;
88052 - wfd = sys_open(collected, openflags, mode);
88053 + wfd = sys_open((char __force_user *)collected, openflags, mode);
88054
88055 if (wfd >= 0) {
88056 sys_fchown(wfd, uid, gid);
88057 @@ -350,17 +350,17 @@ static int __init do_name(void)
88058 }
88059 }
88060 } else if (S_ISDIR(mode)) {
88061 - sys_mkdir(collected, mode);
88062 - sys_chown(collected, uid, gid);
88063 - sys_chmod(collected, mode);
88064 + sys_mkdir((char __force_user *)collected, mode);
88065 + sys_chown((char __force_user *)collected, uid, gid);
88066 + sys_chmod((char __force_user *)collected, mode);
88067 dir_add(collected, mtime);
88068 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
88069 S_ISFIFO(mode) || S_ISSOCK(mode)) {
88070 if (maybe_link() == 0) {
88071 - sys_mknod(collected, mode, rdev);
88072 - sys_chown(collected, uid, gid);
88073 - sys_chmod(collected, mode);
88074 - do_utime(collected, mtime);
88075 + sys_mknod((char __force_user *)collected, mode, rdev);
88076 + sys_chown((char __force_user *)collected, uid, gid);
88077 + sys_chmod((char __force_user *)collected, mode);
88078 + do_utime((char __force_user *)collected, mtime);
88079 }
88080 }
88081 return 0;
88082 @@ -372,7 +372,7 @@ static int __init do_copy(void)
88083 if (xwrite(wfd, victim, body_len) != body_len)
88084 error("write error");
88085 sys_close(wfd);
88086 - do_utime(vcollected, mtime);
88087 + do_utime((char __force_user *)vcollected, mtime);
88088 kfree(vcollected);
88089 eat(body_len);
88090 state = SkipIt;
88091 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
88092 {
88093 collected[N_ALIGN(name_len) + body_len] = '\0';
88094 clean_path(collected, 0);
88095 - sys_symlink(collected + N_ALIGN(name_len), collected);
88096 - sys_lchown(collected, uid, gid);
88097 - do_utime(collected, mtime);
88098 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88099 + sys_lchown((char __force_user *)collected, uid, gid);
88100 + do_utime((char __force_user *)collected, mtime);
88101 state = SkipIt;
88102 next_state = Reset;
88103 return 0;
88104 diff --git a/init/main.c b/init/main.c
88105 index bb1aed9..64f9745 100644
88106 --- a/init/main.c
88107 +++ b/init/main.c
88108 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88109 static inline void mark_rodata_ro(void) { }
88110 #endif
88111
88112 +extern void grsecurity_init(void);
88113 +
88114 /*
88115 * Debug helper: via this flag we know that we are in 'early bootup code'
88116 * where only the boot processor is running with IRQ disabled. This means
88117 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88118
88119 __setup("reset_devices", set_reset_devices);
88120
88121 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88122 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88123 +static int __init setup_grsec_proc_gid(char *str)
88124 +{
88125 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88126 + return 1;
88127 +}
88128 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88129 +#endif
88130 +
88131 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88132 +unsigned long pax_user_shadow_base __read_only;
88133 +EXPORT_SYMBOL(pax_user_shadow_base);
88134 +extern char pax_enter_kernel_user[];
88135 +extern char pax_exit_kernel_user[];
88136 +#endif
88137 +
88138 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88139 +static int __init setup_pax_nouderef(char *str)
88140 +{
88141 +#ifdef CONFIG_X86_32
88142 + unsigned int cpu;
88143 + struct desc_struct *gdt;
88144 +
88145 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88146 + gdt = get_cpu_gdt_table(cpu);
88147 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88148 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88149 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88150 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88151 + }
88152 + loadsegment(ds, __KERNEL_DS);
88153 + loadsegment(es, __KERNEL_DS);
88154 + loadsegment(ss, __KERNEL_DS);
88155 +#else
88156 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88157 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88158 + clone_pgd_mask = ~(pgdval_t)0UL;
88159 + pax_user_shadow_base = 0UL;
88160 + setup_clear_cpu_cap(X86_FEATURE_PCID);
88161 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88162 +#endif
88163 +
88164 + return 0;
88165 +}
88166 +early_param("pax_nouderef", setup_pax_nouderef);
88167 +
88168 +#ifdef CONFIG_X86_64
88169 +static int __init setup_pax_weakuderef(char *str)
88170 +{
88171 + if (clone_pgd_mask != ~(pgdval_t)0UL)
88172 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88173 + return 1;
88174 +}
88175 +__setup("pax_weakuderef", setup_pax_weakuderef);
88176 +#endif
88177 +#endif
88178 +
88179 +#ifdef CONFIG_PAX_SOFTMODE
88180 +int pax_softmode;
88181 +
88182 +static int __init setup_pax_softmode(char *str)
88183 +{
88184 + get_option(&str, &pax_softmode);
88185 + return 1;
88186 +}
88187 +__setup("pax_softmode=", setup_pax_softmode);
88188 +#endif
88189 +
88190 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88191 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88192 static const char *panic_later, *panic_param;
88193 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88194 struct blacklist_entry *entry;
88195 char *fn_name;
88196
88197 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88198 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88199 if (!fn_name)
88200 return false;
88201
88202 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88203 {
88204 int count = preempt_count();
88205 int ret;
88206 - char msgbuf[64];
88207 + const char *msg1 = "", *msg2 = "";
88208
88209 if (initcall_blacklisted(fn))
88210 return -EPERM;
88211 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88212 else
88213 ret = fn();
88214
88215 - msgbuf[0] = 0;
88216 -
88217 if (preempt_count() != count) {
88218 - sprintf(msgbuf, "preemption imbalance ");
88219 + msg1 = " preemption imbalance";
88220 preempt_count_set(count);
88221 }
88222 if (irqs_disabled()) {
88223 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88224 + msg2 = " disabled interrupts";
88225 local_irq_enable();
88226 }
88227 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88228 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88229
88230 + add_latent_entropy();
88231 return ret;
88232 }
88233
88234 @@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
88235 {
88236 argv_init[0] = init_filename;
88237 return do_execve(getname_kernel(init_filename),
88238 - (const char __user *const __user *)argv_init,
88239 - (const char __user *const __user *)envp_init);
88240 + (const char __user *const __force_user *)argv_init,
88241 + (const char __user *const __force_user *)envp_init);
88242 }
88243
88244 static int try_to_run_init_process(const char *init_filename)
88245 @@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
88246 return ret;
88247 }
88248
88249 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88250 +extern int gr_init_ran;
88251 +#endif
88252 +
88253 static noinline void __init kernel_init_freeable(void);
88254
88255 static int __ref kernel_init(void *unused)
88256 @@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
88257 ramdisk_execute_command, ret);
88258 }
88259
88260 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88261 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88262 + gr_init_ran = 1;
88263 +#endif
88264 +
88265 /*
88266 * We try each of these until one succeeds.
88267 *
88268 @@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
88269 do_basic_setup();
88270
88271 /* Open the /dev/console on the rootfs, this should never fail */
88272 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88273 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88274 pr_err("Warning: unable to open an initial console.\n");
88275
88276 (void) sys_dup(0);
88277 @@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88278 if (!ramdisk_execute_command)
88279 ramdisk_execute_command = "/init";
88280
88281 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88282 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88283 ramdisk_execute_command = NULL;
88284 prepare_namespace();
88285 }
88286
88287 + grsecurity_init();
88288 +
88289 /*
88290 * Ok, we have completed the initial bootup, and
88291 * we're essentially up and running. Get rid of the
88292 diff --git a/ipc/compat.c b/ipc/compat.c
88293 index b5ef4f7..ff31d87 100644
88294 --- a/ipc/compat.c
88295 +++ b/ipc/compat.c
88296 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88297 COMPAT_SHMLBA);
88298 if (err < 0)
88299 return err;
88300 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88301 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88302 }
88303 case SHMDT:
88304 return sys_shmdt(compat_ptr(ptr));
88305 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88306 index c3f0326..d4e0579 100644
88307 --- a/ipc/ipc_sysctl.c
88308 +++ b/ipc/ipc_sysctl.c
88309 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88310 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88311 void __user *buffer, size_t *lenp, loff_t *ppos)
88312 {
88313 - struct ctl_table ipc_table;
88314 + ctl_table_no_const ipc_table;
88315
88316 memcpy(&ipc_table, table, sizeof(ipc_table));
88317 ipc_table.data = get_ipc(table);
88318 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88319 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88320 void __user *buffer, size_t *lenp, loff_t *ppos)
88321 {
88322 - struct ctl_table ipc_table;
88323 + ctl_table_no_const ipc_table;
88324
88325 memcpy(&ipc_table, table, sizeof(ipc_table));
88326 ipc_table.data = get_ipc(table);
88327 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88328 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88329 void __user *buffer, size_t *lenp, loff_t *ppos)
88330 {
88331 - struct ctl_table ipc_table;
88332 + ctl_table_no_const ipc_table;
88333 size_t lenp_bef = *lenp;
88334 int rc;
88335
88336 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88337 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88338 void __user *buffer, size_t *lenp, loff_t *ppos)
88339 {
88340 - struct ctl_table ipc_table;
88341 + ctl_table_no_const ipc_table;
88342 memcpy(&ipc_table, table, sizeof(ipc_table));
88343 ipc_table.data = get_ipc(table);
88344
88345 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88346 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88347 void __user *buffer, size_t *lenp, loff_t *ppos)
88348 {
88349 - struct ctl_table ipc_table;
88350 + ctl_table_no_const ipc_table;
88351 size_t lenp_bef = *lenp;
88352 int oldval;
88353 int rc;
88354 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88355 index 68d4e95..1477ded 100644
88356 --- a/ipc/mq_sysctl.c
88357 +++ b/ipc/mq_sysctl.c
88358 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88359 static int proc_mq_dointvec(struct ctl_table *table, int write,
88360 void __user *buffer, size_t *lenp, loff_t *ppos)
88361 {
88362 - struct ctl_table mq_table;
88363 + ctl_table_no_const mq_table;
88364 memcpy(&mq_table, table, sizeof(mq_table));
88365 mq_table.data = get_mq(table);
88366
88367 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88368 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88369 void __user *buffer, size_t *lenp, loff_t *ppos)
88370 {
88371 - struct ctl_table mq_table;
88372 + ctl_table_no_const mq_table;
88373 memcpy(&mq_table, table, sizeof(mq_table));
88374 mq_table.data = get_mq(table);
88375
88376 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88377 index 4fcf39a..d3cc2ec 100644
88378 --- a/ipc/mqueue.c
88379 +++ b/ipc/mqueue.c
88380 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88381 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88382 info->attr.mq_msgsize);
88383
88384 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88385 spin_lock(&mq_lock);
88386 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88387 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88388 diff --git a/ipc/shm.c b/ipc/shm.c
88389 index 7fc9f9f..95e201f 100644
88390 --- a/ipc/shm.c
88391 +++ b/ipc/shm.c
88392 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88393 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88394 #endif
88395
88396 +#ifdef CONFIG_GRKERNSEC
88397 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88398 + const u64 shm_createtime, const kuid_t cuid,
88399 + const int shmid);
88400 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88401 + const u64 shm_createtime);
88402 +#endif
88403 +
88404 void shm_init_ns(struct ipc_namespace *ns)
88405 {
88406 ns->shm_ctlmax = SHMMAX;
88407 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88408 shp->shm_lprid = 0;
88409 shp->shm_atim = shp->shm_dtim = 0;
88410 shp->shm_ctim = get_seconds();
88411 +#ifdef CONFIG_GRKERNSEC
88412 + shp->shm_createtime = ktime_get_ns();
88413 +#endif
88414 shp->shm_segsz = size;
88415 shp->shm_nattch = 0;
88416 shp->shm_file = file;
88417 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88418 f_mode = FMODE_READ | FMODE_WRITE;
88419 }
88420 if (shmflg & SHM_EXEC) {
88421 +
88422 +#ifdef CONFIG_PAX_MPROTECT
88423 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88424 + goto out;
88425 +#endif
88426 +
88427 prot |= PROT_EXEC;
88428 acc_mode |= S_IXUGO;
88429 }
88430 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88431 if (err)
88432 goto out_unlock;
88433
88434 +#ifdef CONFIG_GRKERNSEC
88435 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88436 + shp->shm_perm.cuid, shmid) ||
88437 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88438 + err = -EACCES;
88439 + goto out_unlock;
88440 + }
88441 +#endif
88442 +
88443 ipc_lock_object(&shp->shm_perm);
88444
88445 /* check if shm_destroy() is tearing down shp */
88446 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88447 path = shp->shm_file->f_path;
88448 path_get(&path);
88449 shp->shm_nattch++;
88450 +#ifdef CONFIG_GRKERNSEC
88451 + shp->shm_lapid = current->pid;
88452 +#endif
88453 size = i_size_read(path.dentry->d_inode);
88454 ipc_unlock_object(&shp->shm_perm);
88455 rcu_read_unlock();
88456 diff --git a/ipc/util.c b/ipc/util.c
88457 index 27d74e6..8be0be2 100644
88458 --- a/ipc/util.c
88459 +++ b/ipc/util.c
88460 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88461 int (*show)(struct seq_file *, void *);
88462 };
88463
88464 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88465 +
88466 static void ipc_memory_notifier(struct work_struct *work)
88467 {
88468 ipcns_notify(IPCNS_MEMCHANGED);
88469 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88470 granted_mode >>= 6;
88471 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88472 granted_mode >>= 3;
88473 +
88474 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88475 + return -1;
88476 +
88477 /* is there some bit set in requested_mode but not in granted_mode? */
88478 if ((requested_mode & ~granted_mode & 0007) &&
88479 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88480 diff --git a/kernel/audit.c b/kernel/audit.c
88481 index ba2ff5a..c6c0deb 100644
88482 --- a/kernel/audit.c
88483 +++ b/kernel/audit.c
88484 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88485 3) suppressed due to audit_rate_limit
88486 4) suppressed due to audit_backlog_limit
88487 */
88488 -static atomic_t audit_lost = ATOMIC_INIT(0);
88489 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88490
88491 /* The netlink socket. */
88492 static struct sock *audit_sock;
88493 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88494 unsigned long now;
88495 int print;
88496
88497 - atomic_inc(&audit_lost);
88498 + atomic_inc_unchecked(&audit_lost);
88499
88500 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88501
88502 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88503 if (print) {
88504 if (printk_ratelimit())
88505 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88506 - atomic_read(&audit_lost),
88507 + atomic_read_unchecked(&audit_lost),
88508 audit_rate_limit,
88509 audit_backlog_limit);
88510 audit_panic(message);
88511 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88512 s.pid = audit_pid;
88513 s.rate_limit = audit_rate_limit;
88514 s.backlog_limit = audit_backlog_limit;
88515 - s.lost = atomic_read(&audit_lost);
88516 + s.lost = atomic_read_unchecked(&audit_lost);
88517 s.backlog = skb_queue_len(&audit_skb_queue);
88518 s.version = AUDIT_VERSION_LATEST;
88519 s.backlog_wait_time = audit_backlog_wait_time;
88520 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88521 index 21eae3c..66db239 100644
88522 --- a/kernel/auditsc.c
88523 +++ b/kernel/auditsc.c
88524 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88525 }
88526
88527 /* global counter which is incremented every time something logs in */
88528 -static atomic_t session_id = ATOMIC_INIT(0);
88529 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88530
88531 static int audit_set_loginuid_perm(kuid_t loginuid)
88532 {
88533 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88534
88535 /* are we setting or clearing? */
88536 if (uid_valid(loginuid))
88537 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88538 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88539
88540 task->sessionid = sessionid;
88541 task->loginuid = loginuid;
88542 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88543 index 7f0dbcb..b54bb2c 100644
88544 --- a/kernel/bpf/core.c
88545 +++ b/kernel/bpf/core.c
88546 @@ -22,6 +22,7 @@
88547 */
88548 #include <linux/filter.h>
88549 #include <linux/skbuff.h>
88550 +#include <linux/vmalloc.h>
88551 #include <asm/unaligned.h>
88552
88553 /* Registers */
88554 @@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88555 return NULL;
88556 }
88557
88558 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88559 +{
88560 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88561 + gfp_extra_flags;
88562 + struct bpf_work_struct *ws;
88563 + struct bpf_prog *fp;
88564 +
88565 + size = round_up(size, PAGE_SIZE);
88566 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88567 + if (fp == NULL)
88568 + return NULL;
88569 +
88570 + ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88571 + if (ws == NULL) {
88572 + vfree(fp);
88573 + return NULL;
88574 + }
88575 +
88576 + fp->pages = size / PAGE_SIZE;
88577 + fp->work = ws;
88578 +
88579 + return fp;
88580 +}
88581 +EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88582 +
88583 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88584 + gfp_t gfp_extra_flags)
88585 +{
88586 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88587 + gfp_extra_flags;
88588 + struct bpf_prog *fp;
88589 +
88590 + BUG_ON(fp_old == NULL);
88591 +
88592 + size = round_up(size, PAGE_SIZE);
88593 + if (size <= fp_old->pages * PAGE_SIZE)
88594 + return fp_old;
88595 +
88596 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88597 + if (fp != NULL) {
88598 + memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88599 + fp->pages = size / PAGE_SIZE;
88600 +
88601 + /* We keep fp->work from fp_old around in the new
88602 + * reallocated structure.
88603 + */
88604 + fp_old->work = NULL;
88605 + __bpf_prog_free(fp_old);
88606 + }
88607 +
88608 + return fp;
88609 +}
88610 +EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88611 +
88612 +void __bpf_prog_free(struct bpf_prog *fp)
88613 +{
88614 + kfree(fp->work);
88615 + vfree(fp);
88616 +}
88617 +EXPORT_SYMBOL_GPL(__bpf_prog_free);
88618 +
88619 /* Base function for offset calculation. Needs to go into .text section,
88620 * therefore keeping it non-static as well; will also be used by JITs
88621 * anyway later on, so do not let the compiler omit it.
88622 @@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88623
88624 /* Probe if internal BPF can be JITed */
88625 bpf_int_jit_compile(fp);
88626 + /* Lock whole bpf_prog as read-only */
88627 + bpf_prog_lock_ro(fp);
88628 }
88629 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88630
88631 -/* free internal BPF program */
88632 +static void bpf_prog_free_deferred(struct work_struct *work)
88633 +{
88634 + struct bpf_work_struct *ws;
88635 +
88636 + ws = container_of(work, struct bpf_work_struct, work);
88637 + bpf_jit_free(ws->prog);
88638 +}
88639 +
88640 +/* Free internal BPF program */
88641 void bpf_prog_free(struct bpf_prog *fp)
88642 {
88643 - bpf_jit_free(fp);
88644 + struct bpf_work_struct *ws = fp->work;
88645 +
88646 + INIT_WORK(&ws->work, bpf_prog_free_deferred);
88647 + ws->prog = fp;
88648 + schedule_work(&ws->work);
88649 }
88650 EXPORT_SYMBOL_GPL(bpf_prog_free);
88651 diff --git a/kernel/capability.c b/kernel/capability.c
88652 index 989f5bf..d317ca0 100644
88653 --- a/kernel/capability.c
88654 +++ b/kernel/capability.c
88655 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88656 * before modification is attempted and the application
88657 * fails.
88658 */
88659 + if (tocopy > ARRAY_SIZE(kdata))
88660 + return -EFAULT;
88661 +
88662 if (copy_to_user(dataptr, kdata, tocopy
88663 * sizeof(struct __user_cap_data_struct))) {
88664 return -EFAULT;
88665 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88666 int ret;
88667
88668 rcu_read_lock();
88669 - ret = security_capable(__task_cred(t), ns, cap);
88670 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88671 + gr_task_is_capable(t, __task_cred(t), cap);
88672 rcu_read_unlock();
88673
88674 - return (ret == 0);
88675 + return ret;
88676 }
88677
88678 /**
88679 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88680 int ret;
88681
88682 rcu_read_lock();
88683 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88684 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88685 rcu_read_unlock();
88686
88687 - return (ret == 0);
88688 + return ret;
88689 }
88690
88691 /**
88692 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88693 BUG();
88694 }
88695
88696 - if (security_capable(current_cred(), ns, cap) == 0) {
88697 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88698 current->flags |= PF_SUPERPRIV;
88699 return true;
88700 }
88701 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88702 }
88703 EXPORT_SYMBOL(ns_capable);
88704
88705 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88706 +{
88707 + if (unlikely(!cap_valid(cap))) {
88708 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88709 + BUG();
88710 + }
88711 +
88712 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88713 + current->flags |= PF_SUPERPRIV;
88714 + return true;
88715 + }
88716 + return false;
88717 +}
88718 +EXPORT_SYMBOL(ns_capable_nolog);
88719 +
88720 /**
88721 * file_ns_capable - Determine if the file's opener had a capability in effect
88722 * @file: The file we want to check
88723 @@ -427,6 +446,12 @@ bool capable(int cap)
88724 }
88725 EXPORT_SYMBOL(capable);
88726
88727 +bool capable_nolog(int cap)
88728 +{
88729 + return ns_capable_nolog(&init_user_ns, cap);
88730 +}
88731 +EXPORT_SYMBOL(capable_nolog);
88732 +
88733 /**
88734 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88735 * @inode: The inode in question
88736 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88737 kgid_has_mapping(ns, inode->i_gid);
88738 }
88739 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88740 +
88741 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88742 +{
88743 + struct user_namespace *ns = current_user_ns();
88744 +
88745 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88746 + kgid_has_mapping(ns, inode->i_gid);
88747 +}
88748 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88749 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88750 index 3a73f99..4f29fea 100644
88751 --- a/kernel/cgroup.c
88752 +++ b/kernel/cgroup.c
88753 @@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88754 release_list);
88755 list_del_init(&cgrp->release_list);
88756 raw_spin_unlock(&release_list_lock);
88757 +
88758 + /*
88759 + * don't bother calling call_usermodehelper if we haven't
88760 + * configured a binary to execute
88761 + */
88762 + if (cgrp->root->release_agent_path[0] == '\0')
88763 + goto continue_free;
88764 +
88765 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88766 if (!pathbuf)
88767 goto continue_free;
88768 @@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88769 struct task_struct *task;
88770 int count = 0;
88771
88772 - seq_printf(seq, "css_set %p\n", cset);
88773 + seq_printf(seq, "css_set %pK\n", cset);
88774
88775 list_for_each_entry(task, &cset->tasks, cg_list) {
88776 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88777 diff --git a/kernel/compat.c b/kernel/compat.c
88778 index ebb3c36..1df606e 100644
88779 --- a/kernel/compat.c
88780 +++ b/kernel/compat.c
88781 @@ -13,6 +13,7 @@
88782
88783 #include <linux/linkage.h>
88784 #include <linux/compat.h>
88785 +#include <linux/module.h>
88786 #include <linux/errno.h>
88787 #include <linux/time.h>
88788 #include <linux/signal.h>
88789 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88790 mm_segment_t oldfs;
88791 long ret;
88792
88793 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88794 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88795 oldfs = get_fs();
88796 set_fs(KERNEL_DS);
88797 ret = hrtimer_nanosleep_restart(restart);
88798 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88799 oldfs = get_fs();
88800 set_fs(KERNEL_DS);
88801 ret = hrtimer_nanosleep(&tu,
88802 - rmtp ? (struct timespec __user *)&rmt : NULL,
88803 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88804 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88805 set_fs(oldfs);
88806
88807 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88808 mm_segment_t old_fs = get_fs();
88809
88810 set_fs(KERNEL_DS);
88811 - ret = sys_sigpending((old_sigset_t __user *) &s);
88812 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88813 set_fs(old_fs);
88814 if (ret == 0)
88815 ret = put_user(s, set);
88816 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88817 mm_segment_t old_fs = get_fs();
88818
88819 set_fs(KERNEL_DS);
88820 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88821 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88822 set_fs(old_fs);
88823
88824 if (!ret) {
88825 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88826 set_fs (KERNEL_DS);
88827 ret = sys_wait4(pid,
88828 (stat_addr ?
88829 - (unsigned int __user *) &status : NULL),
88830 - options, (struct rusage __user *) &r);
88831 + (unsigned int __force_user *) &status : NULL),
88832 + options, (struct rusage __force_user *) &r);
88833 set_fs (old_fs);
88834
88835 if (ret > 0) {
88836 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88837 memset(&info, 0, sizeof(info));
88838
88839 set_fs(KERNEL_DS);
88840 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88841 - uru ? (struct rusage __user *)&ru : NULL);
88842 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88843 + uru ? (struct rusage __force_user *)&ru : NULL);
88844 set_fs(old_fs);
88845
88846 if ((ret < 0) || (info.si_signo == 0))
88847 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88848 oldfs = get_fs();
88849 set_fs(KERNEL_DS);
88850 err = sys_timer_settime(timer_id, flags,
88851 - (struct itimerspec __user *) &newts,
88852 - (struct itimerspec __user *) &oldts);
88853 + (struct itimerspec __force_user *) &newts,
88854 + (struct itimerspec __force_user *) &oldts);
88855 set_fs(oldfs);
88856 if (!err && old && put_compat_itimerspec(old, &oldts))
88857 return -EFAULT;
88858 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88859 oldfs = get_fs();
88860 set_fs(KERNEL_DS);
88861 err = sys_timer_gettime(timer_id,
88862 - (struct itimerspec __user *) &ts);
88863 + (struct itimerspec __force_user *) &ts);
88864 set_fs(oldfs);
88865 if (!err && put_compat_itimerspec(setting, &ts))
88866 return -EFAULT;
88867 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88868 oldfs = get_fs();
88869 set_fs(KERNEL_DS);
88870 err = sys_clock_settime(which_clock,
88871 - (struct timespec __user *) &ts);
88872 + (struct timespec __force_user *) &ts);
88873 set_fs(oldfs);
88874 return err;
88875 }
88876 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88877 oldfs = get_fs();
88878 set_fs(KERNEL_DS);
88879 err = sys_clock_gettime(which_clock,
88880 - (struct timespec __user *) &ts);
88881 + (struct timespec __force_user *) &ts);
88882 set_fs(oldfs);
88883 if (!err && compat_put_timespec(&ts, tp))
88884 return -EFAULT;
88885 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88886
88887 oldfs = get_fs();
88888 set_fs(KERNEL_DS);
88889 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88890 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88891 set_fs(oldfs);
88892
88893 err = compat_put_timex(utp, &txc);
88894 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88895 oldfs = get_fs();
88896 set_fs(KERNEL_DS);
88897 err = sys_clock_getres(which_clock,
88898 - (struct timespec __user *) &ts);
88899 + (struct timespec __force_user *) &ts);
88900 set_fs(oldfs);
88901 if (!err && tp && compat_put_timespec(&ts, tp))
88902 return -EFAULT;
88903 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88904 struct timespec tu;
88905 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88906
88907 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88908 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88909 oldfs = get_fs();
88910 set_fs(KERNEL_DS);
88911 err = clock_nanosleep_restart(restart);
88912 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88913 oldfs = get_fs();
88914 set_fs(KERNEL_DS);
88915 err = sys_clock_nanosleep(which_clock, flags,
88916 - (struct timespec __user *) &in,
88917 - (struct timespec __user *) &out);
88918 + (struct timespec __force_user *) &in,
88919 + (struct timespec __force_user *) &out);
88920 set_fs(oldfs);
88921
88922 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88923 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88924 mm_segment_t old_fs = get_fs();
88925
88926 set_fs(KERNEL_DS);
88927 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88928 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88929 set_fs(old_fs);
88930 if (compat_put_timespec(&t, interval))
88931 return -EFAULT;
88932 diff --git a/kernel/configs.c b/kernel/configs.c
88933 index c18b1f1..b9a0132 100644
88934 --- a/kernel/configs.c
88935 +++ b/kernel/configs.c
88936 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88937 struct proc_dir_entry *entry;
88938
88939 /* create the current config file */
88940 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88941 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88942 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88943 + &ikconfig_file_ops);
88944 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88945 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88946 + &ikconfig_file_ops);
88947 +#endif
88948 +#else
88949 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88950 &ikconfig_file_ops);
88951 +#endif
88952 +
88953 if (!entry)
88954 return -ENOMEM;
88955
88956 diff --git a/kernel/cred.c b/kernel/cred.c
88957 index e0573a4..26c0fd3 100644
88958 --- a/kernel/cred.c
88959 +++ b/kernel/cred.c
88960 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88961 validate_creds(cred);
88962 alter_cred_subscribers(cred, -1);
88963 put_cred(cred);
88964 +
88965 +#ifdef CONFIG_GRKERNSEC_SETXID
88966 + cred = (struct cred *) tsk->delayed_cred;
88967 + if (cred != NULL) {
88968 + tsk->delayed_cred = NULL;
88969 + validate_creds(cred);
88970 + alter_cred_subscribers(cred, -1);
88971 + put_cred(cred);
88972 + }
88973 +#endif
88974 }
88975
88976 /**
88977 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88978 * Always returns 0 thus allowing this function to be tail-called at the end
88979 * of, say, sys_setgid().
88980 */
88981 -int commit_creds(struct cred *new)
88982 +static int __commit_creds(struct cred *new)
88983 {
88984 struct task_struct *task = current;
88985 const struct cred *old = task->real_cred;
88986 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88987
88988 get_cred(new); /* we will require a ref for the subj creds too */
88989
88990 + gr_set_role_label(task, new->uid, new->gid);
88991 +
88992 /* dumpability changes */
88993 if (!uid_eq(old->euid, new->euid) ||
88994 !gid_eq(old->egid, new->egid) ||
88995 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88996 put_cred(old);
88997 return 0;
88998 }
88999 +#ifdef CONFIG_GRKERNSEC_SETXID
89000 +extern int set_user(struct cred *new);
89001 +
89002 +void gr_delayed_cred_worker(void)
89003 +{
89004 + const struct cred *new = current->delayed_cred;
89005 + struct cred *ncred;
89006 +
89007 + current->delayed_cred = NULL;
89008 +
89009 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
89010 + // from doing get_cred on it when queueing this
89011 + put_cred(new);
89012 + return;
89013 + } else if (new == NULL)
89014 + return;
89015 +
89016 + ncred = prepare_creds();
89017 + if (!ncred)
89018 + goto die;
89019 + // uids
89020 + ncred->uid = new->uid;
89021 + ncred->euid = new->euid;
89022 + ncred->suid = new->suid;
89023 + ncred->fsuid = new->fsuid;
89024 + // gids
89025 + ncred->gid = new->gid;
89026 + ncred->egid = new->egid;
89027 + ncred->sgid = new->sgid;
89028 + ncred->fsgid = new->fsgid;
89029 + // groups
89030 + set_groups(ncred, new->group_info);
89031 + // caps
89032 + ncred->securebits = new->securebits;
89033 + ncred->cap_inheritable = new->cap_inheritable;
89034 + ncred->cap_permitted = new->cap_permitted;
89035 + ncred->cap_effective = new->cap_effective;
89036 + ncred->cap_bset = new->cap_bset;
89037 +
89038 + if (set_user(ncred)) {
89039 + abort_creds(ncred);
89040 + goto die;
89041 + }
89042 +
89043 + // from doing get_cred on it when queueing this
89044 + put_cred(new);
89045 +
89046 + __commit_creds(ncred);
89047 + return;
89048 +die:
89049 + // from doing get_cred on it when queueing this
89050 + put_cred(new);
89051 + do_group_exit(SIGKILL);
89052 +}
89053 +#endif
89054 +
89055 +int commit_creds(struct cred *new)
89056 +{
89057 +#ifdef CONFIG_GRKERNSEC_SETXID
89058 + int ret;
89059 + int schedule_it = 0;
89060 + struct task_struct *t;
89061 + unsigned oldsecurebits = current_cred()->securebits;
89062 +
89063 + /* we won't get called with tasklist_lock held for writing
89064 + and interrupts disabled as the cred struct in that case is
89065 + init_cred
89066 + */
89067 + if (grsec_enable_setxid && !current_is_single_threaded() &&
89068 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
89069 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
89070 + schedule_it = 1;
89071 + }
89072 + ret = __commit_creds(new);
89073 + if (schedule_it) {
89074 + rcu_read_lock();
89075 + read_lock(&tasklist_lock);
89076 + for (t = next_thread(current); t != current;
89077 + t = next_thread(t)) {
89078 + /* we'll check if the thread has uid 0 in
89079 + * the delayed worker routine
89080 + */
89081 + if (task_securebits(t) == oldsecurebits &&
89082 + t->delayed_cred == NULL) {
89083 + t->delayed_cred = get_cred(new);
89084 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
89085 + set_tsk_need_resched(t);
89086 + }
89087 + }
89088 + read_unlock(&tasklist_lock);
89089 + rcu_read_unlock();
89090 + }
89091 +
89092 + return ret;
89093 +#else
89094 + return __commit_creds(new);
89095 +#endif
89096 +}
89097 +
89098 EXPORT_SYMBOL(commit_creds);
89099
89100 /**
89101 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
89102 index 1adf62b..7736e06 100644
89103 --- a/kernel/debug/debug_core.c
89104 +++ b/kernel/debug/debug_core.c
89105 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
89106 */
89107 static atomic_t masters_in_kgdb;
89108 static atomic_t slaves_in_kgdb;
89109 -static atomic_t kgdb_break_tasklet_var;
89110 +static atomic_unchecked_t kgdb_break_tasklet_var;
89111 atomic_t kgdb_setting_breakpoint;
89112
89113 struct task_struct *kgdb_usethread;
89114 @@ -134,7 +134,7 @@ int kgdb_single_step;
89115 static pid_t kgdb_sstep_pid;
89116
89117 /* to keep track of the CPU which is doing the single stepping*/
89118 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89119 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89120
89121 /*
89122 * If you are debugging a problem where roundup (the collection of
89123 @@ -549,7 +549,7 @@ return_normal:
89124 * kernel will only try for the value of sstep_tries before
89125 * giving up and continuing on.
89126 */
89127 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
89128 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
89129 (kgdb_info[cpu].task &&
89130 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
89131 atomic_set(&kgdb_active, -1);
89132 @@ -647,8 +647,8 @@ cpu_master_loop:
89133 }
89134
89135 kgdb_restore:
89136 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
89137 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
89138 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
89139 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
89140 if (kgdb_info[sstep_cpu].task)
89141 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
89142 else
89143 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
89144 static void kgdb_tasklet_bpt(unsigned long ing)
89145 {
89146 kgdb_breakpoint();
89147 - atomic_set(&kgdb_break_tasklet_var, 0);
89148 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89149 }
89150
89151 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89152
89153 void kgdb_schedule_breakpoint(void)
89154 {
89155 - if (atomic_read(&kgdb_break_tasklet_var) ||
89156 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89157 atomic_read(&kgdb_active) != -1 ||
89158 atomic_read(&kgdb_setting_breakpoint))
89159 return;
89160 - atomic_inc(&kgdb_break_tasklet_var);
89161 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
89162 tasklet_schedule(&kgdb_tasklet_breakpoint);
89163 }
89164 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89165 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89166 index 379650b..30c5180 100644
89167 --- a/kernel/debug/kdb/kdb_main.c
89168 +++ b/kernel/debug/kdb/kdb_main.c
89169 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89170 continue;
89171
89172 kdb_printf("%-20s%8u 0x%p ", mod->name,
89173 - mod->core_size, (void *)mod);
89174 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
89175 #ifdef CONFIG_MODULE_UNLOAD
89176 kdb_printf("%4ld ", module_refcount(mod));
89177 #endif
89178 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89179 kdb_printf(" (Loading)");
89180 else
89181 kdb_printf(" (Live)");
89182 - kdb_printf(" 0x%p", mod->module_core);
89183 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89184
89185 #ifdef CONFIG_MODULE_UNLOAD
89186 {
89187 diff --git a/kernel/events/core.c b/kernel/events/core.c
89188 index 963bf13..a78dd3e 100644
89189 --- a/kernel/events/core.c
89190 +++ b/kernel/events/core.c
89191 @@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
89192 * 0 - disallow raw tracepoint access for unpriv
89193 * 1 - disallow cpu events for unpriv
89194 * 2 - disallow kernel profiling for unpriv
89195 + * 3 - disallow all unpriv perf event use
89196 */
89197 -int sysctl_perf_event_paranoid __read_mostly = 1;
89198 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89199 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89200 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89201 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89202 +#else
89203 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89204 +#endif
89205
89206 /* Minimum for 512 kiB + 1 user control page */
89207 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89208 @@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
89209
89210 tmp *= sysctl_perf_cpu_time_max_percent;
89211 do_div(tmp, 100);
89212 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89213 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89214 }
89215
89216 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89217 @@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89218 }
89219 }
89220
89221 -static atomic64_t perf_event_id;
89222 +static atomic64_unchecked_t perf_event_id;
89223
89224 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89225 enum event_type_t event_type);
89226 @@ -3034,7 +3041,7 @@ static void __perf_event_read(void *info)
89227
89228 static inline u64 perf_event_count(struct perf_event *event)
89229 {
89230 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89231 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89232 }
89233
89234 static u64 perf_event_read(struct perf_event *event)
89235 @@ -3410,9 +3417,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89236 mutex_lock(&event->child_mutex);
89237 total += perf_event_read(event);
89238 *enabled += event->total_time_enabled +
89239 - atomic64_read(&event->child_total_time_enabled);
89240 + atomic64_read_unchecked(&event->child_total_time_enabled);
89241 *running += event->total_time_running +
89242 - atomic64_read(&event->child_total_time_running);
89243 + atomic64_read_unchecked(&event->child_total_time_running);
89244
89245 list_for_each_entry(child, &event->child_list, child_list) {
89246 total += perf_event_read(child);
89247 @@ -3861,10 +3868,10 @@ void perf_event_update_userpage(struct perf_event *event)
89248 userpg->offset -= local64_read(&event->hw.prev_count);
89249
89250 userpg->time_enabled = enabled +
89251 - atomic64_read(&event->child_total_time_enabled);
89252 + atomic64_read_unchecked(&event->child_total_time_enabled);
89253
89254 userpg->time_running = running +
89255 - atomic64_read(&event->child_total_time_running);
89256 + atomic64_read_unchecked(&event->child_total_time_running);
89257
89258 arch_perf_update_userpage(userpg, now);
89259
89260 @@ -4428,7 +4435,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89261
89262 /* Data. */
89263 sp = perf_user_stack_pointer(regs);
89264 - rem = __output_copy_user(handle, (void *) sp, dump_size);
89265 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89266 dyn_size = dump_size - rem;
89267
89268 perf_output_skip(handle, rem);
89269 @@ -4519,11 +4526,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89270 values[n++] = perf_event_count(event);
89271 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89272 values[n++] = enabled +
89273 - atomic64_read(&event->child_total_time_enabled);
89274 + atomic64_read_unchecked(&event->child_total_time_enabled);
89275 }
89276 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89277 values[n++] = running +
89278 - atomic64_read(&event->child_total_time_running);
89279 + atomic64_read_unchecked(&event->child_total_time_running);
89280 }
89281 if (read_format & PERF_FORMAT_ID)
89282 values[n++] = primary_event_id(event);
89283 @@ -6838,7 +6845,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89284 event->parent = parent_event;
89285
89286 event->ns = get_pid_ns(task_active_pid_ns(current));
89287 - event->id = atomic64_inc_return(&perf_event_id);
89288 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89289
89290 event->state = PERF_EVENT_STATE_INACTIVE;
89291
89292 @@ -7117,6 +7124,11 @@ SYSCALL_DEFINE5(perf_event_open,
89293 if (flags & ~PERF_FLAG_ALL)
89294 return -EINVAL;
89295
89296 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89297 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89298 + return -EACCES;
89299 +#endif
89300 +
89301 err = perf_copy_attr(attr_uptr, &attr);
89302 if (err)
89303 return err;
89304 @@ -7469,10 +7481,10 @@ static void sync_child_event(struct perf_event *child_event,
89305 /*
89306 * Add back the child's count to the parent's count:
89307 */
89308 - atomic64_add(child_val, &parent_event->child_count);
89309 - atomic64_add(child_event->total_time_enabled,
89310 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89311 + atomic64_add_unchecked(child_event->total_time_enabled,
89312 &parent_event->child_total_time_enabled);
89313 - atomic64_add(child_event->total_time_running,
89314 + atomic64_add_unchecked(child_event->total_time_running,
89315 &parent_event->child_total_time_running);
89316
89317 /*
89318 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89319 index 569b2187..19940d9 100644
89320 --- a/kernel/events/internal.h
89321 +++ b/kernel/events/internal.h
89322 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89323 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89324 }
89325
89326 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89327 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89328 static inline unsigned long \
89329 func_name(struct perf_output_handle *handle, \
89330 - const void *buf, unsigned long len) \
89331 + const void user *buf, unsigned long len) \
89332 { \
89333 unsigned long size, written; \
89334 \
89335 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89336 return 0;
89337 }
89338
89339 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89340 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89341
89342 static inline unsigned long
89343 memcpy_skip(void *dst, const void *src, unsigned long n)
89344 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89345 return 0;
89346 }
89347
89348 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89349 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89350
89351 #ifndef arch_perf_out_copy_user
89352 #define arch_perf_out_copy_user arch_perf_out_copy_user
89353 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89354 }
89355 #endif
89356
89357 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89358 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89359
89360 /* Callchain handling */
89361 extern struct perf_callchain_entry *
89362 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89363 index 1d0af8a..9913530 100644
89364 --- a/kernel/events/uprobes.c
89365 +++ b/kernel/events/uprobes.c
89366 @@ -1671,7 +1671,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89367 {
89368 struct page *page;
89369 uprobe_opcode_t opcode;
89370 - int result;
89371 + long result;
89372
89373 pagefault_disable();
89374 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89375 diff --git a/kernel/exit.c b/kernel/exit.c
89376 index 32c58f7..9eb6907 100644
89377 --- a/kernel/exit.c
89378 +++ b/kernel/exit.c
89379 @@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89380 struct task_struct *leader;
89381 int zap_leader;
89382 repeat:
89383 +#ifdef CONFIG_NET
89384 + gr_del_task_from_ip_table(p);
89385 +#endif
89386 +
89387 /* don't need to get the RCU readlock here - the process is dead and
89388 * can't be modifying its own credentials. But shut RCU-lockdep up */
89389 rcu_read_lock();
89390 @@ -668,6 +672,8 @@ void do_exit(long code)
89391 struct task_struct *tsk = current;
89392 int group_dead;
89393
89394 + set_fs(USER_DS);
89395 +
89396 profile_task_exit(tsk);
89397
89398 WARN_ON(blk_needs_flush_plug(tsk));
89399 @@ -684,7 +690,6 @@ void do_exit(long code)
89400 * mm_release()->clear_child_tid() from writing to a user-controlled
89401 * kernel address.
89402 */
89403 - set_fs(USER_DS);
89404
89405 ptrace_event(PTRACE_EVENT_EXIT, code);
89406
89407 @@ -742,6 +747,9 @@ void do_exit(long code)
89408 tsk->exit_code = code;
89409 taskstats_exit(tsk, group_dead);
89410
89411 + gr_acl_handle_psacct(tsk, code);
89412 + gr_acl_handle_exit();
89413 +
89414 exit_mm(tsk);
89415
89416 if (group_dead)
89417 @@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89418 * Take down every thread in the group. This is called by fatal signals
89419 * as well as by sys_exit_group (below).
89420 */
89421 -void
89422 +__noreturn void
89423 do_group_exit(int exit_code)
89424 {
89425 struct signal_struct *sig = current->signal;
89426 diff --git a/kernel/fork.c b/kernel/fork.c
89427 index a91e47d..71c9064 100644
89428 --- a/kernel/fork.c
89429 +++ b/kernel/fork.c
89430 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89431 # endif
89432 #endif
89433
89434 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89435 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89436 + int node, void **lowmem_stack)
89437 +{
89438 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89439 + void *ret = NULL;
89440 + unsigned int i;
89441 +
89442 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89443 + if (*lowmem_stack == NULL)
89444 + goto out;
89445 +
89446 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89447 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89448 +
89449 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89450 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89451 + if (ret == NULL) {
89452 + free_thread_info(*lowmem_stack);
89453 + *lowmem_stack = NULL;
89454 + }
89455 +
89456 +out:
89457 + return ret;
89458 +}
89459 +
89460 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89461 +{
89462 + unmap_process_stacks(tsk);
89463 +}
89464 +#else
89465 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89466 + int node, void **lowmem_stack)
89467 +{
89468 + return alloc_thread_info_node(tsk, node);
89469 +}
89470 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89471 +{
89472 + free_thread_info(ti);
89473 +}
89474 +#endif
89475 +
89476 /* SLAB cache for signal_struct structures (tsk->signal) */
89477 static struct kmem_cache *signal_cachep;
89478
89479 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89480 /* SLAB cache for mm_struct structures (tsk->mm) */
89481 static struct kmem_cache *mm_cachep;
89482
89483 -static void account_kernel_stack(struct thread_info *ti, int account)
89484 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89485 {
89486 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89487 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89488 +#else
89489 struct zone *zone = page_zone(virt_to_page(ti));
89490 +#endif
89491
89492 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89493 }
89494
89495 void free_task(struct task_struct *tsk)
89496 {
89497 - account_kernel_stack(tsk->stack, -1);
89498 + account_kernel_stack(tsk, tsk->stack, -1);
89499 arch_release_thread_info(tsk->stack);
89500 - free_thread_info(tsk->stack);
89501 + gr_free_thread_info(tsk, tsk->stack);
89502 rt_mutex_debug_task_free(tsk);
89503 ftrace_graph_exit_task(tsk);
89504 put_seccomp_filter(tsk);
89505 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89506 struct task_struct *tsk;
89507 struct thread_info *ti;
89508 unsigned long *stackend;
89509 + void *lowmem_stack;
89510 int node = tsk_fork_get_node(orig);
89511 int err;
89512
89513 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89514 if (!tsk)
89515 return NULL;
89516
89517 - ti = alloc_thread_info_node(tsk, node);
89518 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89519 if (!ti)
89520 goto free_tsk;
89521
89522 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89523 goto free_ti;
89524
89525 tsk->stack = ti;
89526 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89527 + tsk->lowmem_stack = lowmem_stack;
89528 +#endif
89529 #ifdef CONFIG_SECCOMP
89530 /*
89531 * We must handle setting up seccomp filters once we're under
89532 @@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89533 *stackend = STACK_END_MAGIC; /* for overflow detection */
89534
89535 #ifdef CONFIG_CC_STACKPROTECTOR
89536 - tsk->stack_canary = get_random_int();
89537 + tsk->stack_canary = pax_get_random_long();
89538 #endif
89539
89540 /*
89541 @@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89542 tsk->splice_pipe = NULL;
89543 tsk->task_frag.page = NULL;
89544
89545 - account_kernel_stack(ti, 1);
89546 + account_kernel_stack(tsk, ti, 1);
89547
89548 return tsk;
89549
89550 free_ti:
89551 - free_thread_info(ti);
89552 + gr_free_thread_info(tsk, ti);
89553 free_tsk:
89554 free_task_struct(tsk);
89555 return NULL;
89556 }
89557
89558 #ifdef CONFIG_MMU
89559 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89560 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89561 +{
89562 + struct vm_area_struct *tmp;
89563 + unsigned long charge;
89564 + struct file *file;
89565 + int retval;
89566 +
89567 + charge = 0;
89568 + if (mpnt->vm_flags & VM_ACCOUNT) {
89569 + unsigned long len = vma_pages(mpnt);
89570 +
89571 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89572 + goto fail_nomem;
89573 + charge = len;
89574 + }
89575 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89576 + if (!tmp)
89577 + goto fail_nomem;
89578 + *tmp = *mpnt;
89579 + tmp->vm_mm = mm;
89580 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89581 + retval = vma_dup_policy(mpnt, tmp);
89582 + if (retval)
89583 + goto fail_nomem_policy;
89584 + if (anon_vma_fork(tmp, mpnt))
89585 + goto fail_nomem_anon_vma_fork;
89586 + tmp->vm_flags &= ~VM_LOCKED;
89587 + tmp->vm_next = tmp->vm_prev = NULL;
89588 + tmp->vm_mirror = NULL;
89589 + file = tmp->vm_file;
89590 + if (file) {
89591 + struct inode *inode = file_inode(file);
89592 + struct address_space *mapping = file->f_mapping;
89593 +
89594 + get_file(file);
89595 + if (tmp->vm_flags & VM_DENYWRITE)
89596 + atomic_dec(&inode->i_writecount);
89597 + mutex_lock(&mapping->i_mmap_mutex);
89598 + if (tmp->vm_flags & VM_SHARED)
89599 + atomic_inc(&mapping->i_mmap_writable);
89600 + flush_dcache_mmap_lock(mapping);
89601 + /* insert tmp into the share list, just after mpnt */
89602 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89603 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89604 + else
89605 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89606 + flush_dcache_mmap_unlock(mapping);
89607 + mutex_unlock(&mapping->i_mmap_mutex);
89608 + }
89609 +
89610 + /*
89611 + * Clear hugetlb-related page reserves for children. This only
89612 + * affects MAP_PRIVATE mappings. Faults generated by the child
89613 + * are not guaranteed to succeed, even if read-only
89614 + */
89615 + if (is_vm_hugetlb_page(tmp))
89616 + reset_vma_resv_huge_pages(tmp);
89617 +
89618 + return tmp;
89619 +
89620 +fail_nomem_anon_vma_fork:
89621 + mpol_put(vma_policy(tmp));
89622 +fail_nomem_policy:
89623 + kmem_cache_free(vm_area_cachep, tmp);
89624 +fail_nomem:
89625 + vm_unacct_memory(charge);
89626 + return NULL;
89627 +}
89628 +
89629 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89630 {
89631 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89632 struct rb_node **rb_link, *rb_parent;
89633 int retval;
89634 - unsigned long charge;
89635
89636 uprobe_start_dup_mmap();
89637 down_write(&oldmm->mmap_sem);
89638 @@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89639
89640 prev = NULL;
89641 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89642 - struct file *file;
89643 -
89644 if (mpnt->vm_flags & VM_DONTCOPY) {
89645 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89646 -vma_pages(mpnt));
89647 continue;
89648 }
89649 - charge = 0;
89650 - if (mpnt->vm_flags & VM_ACCOUNT) {
89651 - unsigned long len = vma_pages(mpnt);
89652 -
89653 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89654 - goto fail_nomem;
89655 - charge = len;
89656 - }
89657 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89658 - if (!tmp)
89659 - goto fail_nomem;
89660 - *tmp = *mpnt;
89661 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89662 - retval = vma_dup_policy(mpnt, tmp);
89663 - if (retval)
89664 - goto fail_nomem_policy;
89665 - tmp->vm_mm = mm;
89666 - if (anon_vma_fork(tmp, mpnt))
89667 - goto fail_nomem_anon_vma_fork;
89668 - tmp->vm_flags &= ~VM_LOCKED;
89669 - tmp->vm_next = tmp->vm_prev = NULL;
89670 - file = tmp->vm_file;
89671 - if (file) {
89672 - struct inode *inode = file_inode(file);
89673 - struct address_space *mapping = file->f_mapping;
89674 -
89675 - get_file(file);
89676 - if (tmp->vm_flags & VM_DENYWRITE)
89677 - atomic_dec(&inode->i_writecount);
89678 - mutex_lock(&mapping->i_mmap_mutex);
89679 - if (tmp->vm_flags & VM_SHARED)
89680 - atomic_inc(&mapping->i_mmap_writable);
89681 - flush_dcache_mmap_lock(mapping);
89682 - /* insert tmp into the share list, just after mpnt */
89683 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89684 - vma_nonlinear_insert(tmp,
89685 - &mapping->i_mmap_nonlinear);
89686 - else
89687 - vma_interval_tree_insert_after(tmp, mpnt,
89688 - &mapping->i_mmap);
89689 - flush_dcache_mmap_unlock(mapping);
89690 - mutex_unlock(&mapping->i_mmap_mutex);
89691 + tmp = dup_vma(mm, oldmm, mpnt);
89692 + if (!tmp) {
89693 + retval = -ENOMEM;
89694 + goto out;
89695 }
89696
89697 /*
89698 @@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89699 if (retval)
89700 goto out;
89701 }
89702 +
89703 +#ifdef CONFIG_PAX_SEGMEXEC
89704 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89705 + struct vm_area_struct *mpnt_m;
89706 +
89707 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89708 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89709 +
89710 + if (!mpnt->vm_mirror)
89711 + continue;
89712 +
89713 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89714 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89715 + mpnt->vm_mirror = mpnt_m;
89716 + } else {
89717 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89718 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89719 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89720 + mpnt->vm_mirror->vm_mirror = mpnt;
89721 + }
89722 + }
89723 + BUG_ON(mpnt_m);
89724 + }
89725 +#endif
89726 +
89727 /* a new mm has just been created */
89728 arch_dup_mmap(oldmm, mm);
89729 retval = 0;
89730 @@ -480,14 +583,6 @@ out:
89731 up_write(&oldmm->mmap_sem);
89732 uprobe_end_dup_mmap();
89733 return retval;
89734 -fail_nomem_anon_vma_fork:
89735 - mpol_put(vma_policy(tmp));
89736 -fail_nomem_policy:
89737 - kmem_cache_free(vm_area_cachep, tmp);
89738 -fail_nomem:
89739 - retval = -ENOMEM;
89740 - vm_unacct_memory(charge);
89741 - goto out;
89742 }
89743
89744 static inline int mm_alloc_pgd(struct mm_struct *mm)
89745 @@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89746 return ERR_PTR(err);
89747
89748 mm = get_task_mm(task);
89749 - if (mm && mm != current->mm &&
89750 - !ptrace_may_access(task, mode)) {
89751 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89752 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89753 mmput(mm);
89754 mm = ERR_PTR(-EACCES);
89755 }
89756 @@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89757 spin_unlock(&fs->lock);
89758 return -EAGAIN;
89759 }
89760 - fs->users++;
89761 + atomic_inc(&fs->users);
89762 spin_unlock(&fs->lock);
89763 return 0;
89764 }
89765 tsk->fs = copy_fs_struct(fs);
89766 if (!tsk->fs)
89767 return -ENOMEM;
89768 + /* Carry through gr_chroot_dentry and is_chrooted instead
89769 + of recomputing it here. Already copied when the task struct
89770 + is duplicated. This allows pivot_root to not be treated as
89771 + a chroot
89772 + */
89773 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89774 +
89775 return 0;
89776 }
89777
89778 @@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89779 * parts of the process environment (as per the clone
89780 * flags). The actual kick-off is left to the caller.
89781 */
89782 -static struct task_struct *copy_process(unsigned long clone_flags,
89783 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89784 unsigned long stack_start,
89785 unsigned long stack_size,
89786 int __user *child_tidptr,
89787 @@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89788 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89789 #endif
89790 retval = -EAGAIN;
89791 +
89792 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89793 +
89794 if (atomic_read(&p->real_cred->user->processes) >=
89795 task_rlimit(p, RLIMIT_NPROC)) {
89796 if (p->real_cred->user != INIT_USER &&
89797 @@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89798 goto bad_fork_free_pid;
89799 }
89800
89801 + /* synchronizes with gr_set_acls()
89802 + we need to call this past the point of no return for fork()
89803 + */
89804 + gr_copy_label(p);
89805 +
89806 if (likely(p->pid)) {
89807 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89808
89809 @@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89810 bad_fork_free:
89811 free_task(p);
89812 fork_out:
89813 + gr_log_forkfail(retval);
89814 +
89815 return ERR_PTR(retval);
89816 }
89817
89818 @@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89819
89820 p = copy_process(clone_flags, stack_start, stack_size,
89821 child_tidptr, NULL, trace);
89822 + add_latent_entropy();
89823 /*
89824 * Do this prior waking up the new thread - the thread pointer
89825 * might get invalid after that point, if the thread exits quickly.
89826 @@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89827 if (clone_flags & CLONE_PARENT_SETTID)
89828 put_user(nr, parent_tidptr);
89829
89830 + gr_handle_brute_check();
89831 +
89832 if (clone_flags & CLONE_VFORK) {
89833 p->vfork_done = &vfork;
89834 init_completion(&vfork);
89835 @@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89836 mm_cachep = kmem_cache_create("mm_struct",
89837 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89838 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89839 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89840 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89841 mmap_init();
89842 nsproxy_cache_init();
89843 }
89844 @@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89845 return 0;
89846
89847 /* don't need lock here; in the worst case we'll do useless copy */
89848 - if (fs->users == 1)
89849 + if (atomic_read(&fs->users) == 1)
89850 return 0;
89851
89852 *new_fsp = copy_fs_struct(fs);
89853 @@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89854 fs = current->fs;
89855 spin_lock(&fs->lock);
89856 current->fs = new_fs;
89857 - if (--fs->users)
89858 + gr_set_chroot_entries(current, &current->fs->root);
89859 + if (atomic_dec_return(&fs->users))
89860 new_fs = NULL;
89861 else
89862 new_fs = fs;
89863 diff --git a/kernel/futex.c b/kernel/futex.c
89864 index 815d7af..3d0743b 100644
89865 --- a/kernel/futex.c
89866 +++ b/kernel/futex.c
89867 @@ -202,7 +202,7 @@ struct futex_pi_state {
89868 atomic_t refcount;
89869
89870 union futex_key key;
89871 -};
89872 +} __randomize_layout;
89873
89874 /**
89875 * struct futex_q - The hashed futex queue entry, one per waiting task
89876 @@ -236,7 +236,7 @@ struct futex_q {
89877 struct rt_mutex_waiter *rt_waiter;
89878 union futex_key *requeue_pi_key;
89879 u32 bitset;
89880 -};
89881 +} __randomize_layout;
89882
89883 static const struct futex_q futex_q_init = {
89884 /* list gets initialized in queue_me()*/
89885 @@ -343,6 +343,8 @@ static void get_futex_key_refs(union futex_key *key)
89886 case FUT_OFF_MMSHARED:
89887 futex_get_mm(key); /* implies MB (B) */
89888 break;
89889 + default:
89890 + smp_mb(); /* explicit MB (B) */
89891 }
89892 }
89893
89894 @@ -394,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89895 struct page *page, *page_head;
89896 int err, ro = 0;
89897
89898 +#ifdef CONFIG_PAX_SEGMEXEC
89899 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89900 + return -EFAULT;
89901 +#endif
89902 +
89903 /*
89904 * The futex address must be "naturally" aligned.
89905 */
89906 @@ -593,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89907
89908 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89909 {
89910 - int ret;
89911 + unsigned long ret;
89912
89913 pagefault_disable();
89914 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89915 @@ -2998,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
89916 {
89917 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89918 u32 curval;
89919 + mm_segment_t oldfs;
89920
89921 /*
89922 * This will fail and we want it. Some arch implementations do
89923 @@ -3009,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
89924 * implementation, the non-functional ones will return
89925 * -ENOSYS.
89926 */
89927 + oldfs = get_fs();
89928 + set_fs(USER_DS);
89929 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89930 futex_cmpxchg_enabled = 1;
89931 + set_fs(oldfs);
89932 #endif
89933 }
89934
89935 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89936 index 55c8c93..9ba7ad6 100644
89937 --- a/kernel/futex_compat.c
89938 +++ b/kernel/futex_compat.c
89939 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89940 return 0;
89941 }
89942
89943 -static void __user *futex_uaddr(struct robust_list __user *entry,
89944 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89945 compat_long_t futex_offset)
89946 {
89947 compat_uptr_t base = ptr_to_compat(entry);
89948 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89949 index b358a80..fc25240 100644
89950 --- a/kernel/gcov/base.c
89951 +++ b/kernel/gcov/base.c
89952 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89953 }
89954
89955 #ifdef CONFIG_MODULES
89956 -static inline int within(void *addr, void *start, unsigned long size)
89957 -{
89958 - return ((addr >= start) && (addr < start + size));
89959 -}
89960 -
89961 /* Update list and generate events when modules are unloaded. */
89962 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89963 void *data)
89964 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89965
89966 /* Remove entries located in module from linked list. */
89967 while ((info = gcov_info_next(info))) {
89968 - if (within(info, mod->module_core, mod->core_size)) {
89969 + if (within_module_core_rw((unsigned long)info, mod)) {
89970 gcov_info_unlink(prev, info);
89971 if (gcov_events_enabled)
89972 gcov_event(GCOV_REMOVE, info);
89973 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89974 index 9019f15..9a3c42e 100644
89975 --- a/kernel/jump_label.c
89976 +++ b/kernel/jump_label.c
89977 @@ -14,6 +14,7 @@
89978 #include <linux/err.h>
89979 #include <linux/static_key.h>
89980 #include <linux/jump_label_ratelimit.h>
89981 +#include <linux/mm.h>
89982
89983 #ifdef HAVE_JUMP_LABEL
89984
89985 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89986
89987 size = (((unsigned long)stop - (unsigned long)start)
89988 / sizeof(struct jump_entry));
89989 + pax_open_kernel();
89990 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89991 + pax_close_kernel();
89992 }
89993
89994 static void jump_label_update(struct static_key *key, int enable);
89995 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89996 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89997 struct jump_entry *iter;
89998
89999 + pax_open_kernel();
90000 for (iter = iter_start; iter < iter_stop; iter++) {
90001 if (within_module_init(iter->code, mod))
90002 iter->code = 0;
90003 }
90004 + pax_close_kernel();
90005 }
90006
90007 static int
90008 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
90009 index ae51670..c1a9796 100644
90010 --- a/kernel/kallsyms.c
90011 +++ b/kernel/kallsyms.c
90012 @@ -11,6 +11,9 @@
90013 * Changed the compression method from stem compression to "table lookup"
90014 * compression (see scripts/kallsyms.c for a more complete description)
90015 */
90016 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90017 +#define __INCLUDED_BY_HIDESYM 1
90018 +#endif
90019 #include <linux/kallsyms.h>
90020 #include <linux/module.h>
90021 #include <linux/init.h>
90022 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
90023
90024 static inline int is_kernel_inittext(unsigned long addr)
90025 {
90026 + if (system_state != SYSTEM_BOOTING)
90027 + return 0;
90028 +
90029 if (addr >= (unsigned long)_sinittext
90030 && addr <= (unsigned long)_einittext)
90031 return 1;
90032 return 0;
90033 }
90034
90035 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90036 +#ifdef CONFIG_MODULES
90037 +static inline int is_module_text(unsigned long addr)
90038 +{
90039 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
90040 + return 1;
90041 +
90042 + addr = ktla_ktva(addr);
90043 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
90044 +}
90045 +#else
90046 +static inline int is_module_text(unsigned long addr)
90047 +{
90048 + return 0;
90049 +}
90050 +#endif
90051 +#endif
90052 +
90053 static inline int is_kernel_text(unsigned long addr)
90054 {
90055 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
90056 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
90057
90058 static inline int is_kernel(unsigned long addr)
90059 {
90060 +
90061 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90062 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
90063 + return 1;
90064 +
90065 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
90066 +#else
90067 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
90068 +#endif
90069 +
90070 return 1;
90071 return in_gate_area_no_mm(addr);
90072 }
90073
90074 static int is_ksym_addr(unsigned long addr)
90075 {
90076 +
90077 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90078 + if (is_module_text(addr))
90079 + return 0;
90080 +#endif
90081 +
90082 if (all_var)
90083 return is_kernel(addr);
90084
90085 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
90086
90087 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
90088 {
90089 - iter->name[0] = '\0';
90090 iter->nameoff = get_symbol_offset(new_pos);
90091 iter->pos = new_pos;
90092 }
90093 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
90094 {
90095 struct kallsym_iter *iter = m->private;
90096
90097 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90098 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
90099 + return 0;
90100 +#endif
90101 +
90102 /* Some debugging symbols have no name. Ignore them. */
90103 if (!iter->name[0])
90104 return 0;
90105 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
90106 */
90107 type = iter->exported ? toupper(iter->type) :
90108 tolower(iter->type);
90109 +
90110 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
90111 type, iter->name, iter->module_name);
90112 } else
90113 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
90114 struct kallsym_iter *iter;
90115 int ret;
90116
90117 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
90118 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
90119 if (!iter)
90120 return -ENOMEM;
90121 reset_iter(iter, 0);
90122 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
90123 index 0aa69ea..a7fcafb 100644
90124 --- a/kernel/kcmp.c
90125 +++ b/kernel/kcmp.c
90126 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
90127 struct task_struct *task1, *task2;
90128 int ret;
90129
90130 +#ifdef CONFIG_GRKERNSEC
90131 + return -ENOSYS;
90132 +#endif
90133 +
90134 rcu_read_lock();
90135
90136 /*
90137 diff --git a/kernel/kexec.c b/kernel/kexec.c
90138 index 2bee072..8979af8 100644
90139 --- a/kernel/kexec.c
90140 +++ b/kernel/kexec.c
90141 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90142 compat_ulong_t, flags)
90143 {
90144 struct compat_kexec_segment in;
90145 - struct kexec_segment out, __user *ksegments;
90146 + struct kexec_segment out;
90147 + struct kexec_segment __user *ksegments;
90148 unsigned long i, result;
90149
90150 /* Don't allow clients that don't understand the native
90151 diff --git a/kernel/kmod.c b/kernel/kmod.c
90152 index 8637e04..8b1d0d8 100644
90153 --- a/kernel/kmod.c
90154 +++ b/kernel/kmod.c
90155 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90156 kfree(info->argv);
90157 }
90158
90159 -static int call_modprobe(char *module_name, int wait)
90160 +static int call_modprobe(char *module_name, char *module_param, int wait)
90161 {
90162 struct subprocess_info *info;
90163 static char *envp[] = {
90164 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90165 NULL
90166 };
90167
90168 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90169 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90170 if (!argv)
90171 goto out;
90172
90173 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90174 argv[1] = "-q";
90175 argv[2] = "--";
90176 argv[3] = module_name; /* check free_modprobe_argv() */
90177 - argv[4] = NULL;
90178 + argv[4] = module_param;
90179 + argv[5] = NULL;
90180
90181 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90182 NULL, free_modprobe_argv, NULL);
90183 @@ -129,9 +130,8 @@ out:
90184 * If module auto-loading support is disabled then this function
90185 * becomes a no-operation.
90186 */
90187 -int __request_module(bool wait, const char *fmt, ...)
90188 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90189 {
90190 - va_list args;
90191 char module_name[MODULE_NAME_LEN];
90192 unsigned int max_modprobes;
90193 int ret;
90194 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90195 if (!modprobe_path[0])
90196 return 0;
90197
90198 - va_start(args, fmt);
90199 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90200 - va_end(args);
90201 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90202 if (ret >= MODULE_NAME_LEN)
90203 return -ENAMETOOLONG;
90204
90205 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90206 if (ret)
90207 return ret;
90208
90209 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90210 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90211 + /* hack to workaround consolekit/udisks stupidity */
90212 + read_lock(&tasklist_lock);
90213 + if (!strcmp(current->comm, "mount") &&
90214 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90215 + read_unlock(&tasklist_lock);
90216 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90217 + return -EPERM;
90218 + }
90219 + read_unlock(&tasklist_lock);
90220 + }
90221 +#endif
90222 +
90223 /* If modprobe needs a service that is in a module, we get a recursive
90224 * loop. Limit the number of running kmod threads to max_threads/2 or
90225 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90226 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
90227
90228 trace_module_request(module_name, wait, _RET_IP_);
90229
90230 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90231 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90232
90233 atomic_dec(&kmod_concurrent);
90234 return ret;
90235 }
90236 +
90237 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90238 +{
90239 + va_list args;
90240 + int ret;
90241 +
90242 + va_start(args, fmt);
90243 + ret = ____request_module(wait, module_param, fmt, args);
90244 + va_end(args);
90245 +
90246 + return ret;
90247 +}
90248 +
90249 +int __request_module(bool wait, const char *fmt, ...)
90250 +{
90251 + va_list args;
90252 + int ret;
90253 +
90254 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90255 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90256 + char module_param[MODULE_NAME_LEN];
90257 +
90258 + memset(module_param, 0, sizeof(module_param));
90259 +
90260 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90261 +
90262 + va_start(args, fmt);
90263 + ret = ____request_module(wait, module_param, fmt, args);
90264 + va_end(args);
90265 +
90266 + return ret;
90267 + }
90268 +#endif
90269 +
90270 + va_start(args, fmt);
90271 + ret = ____request_module(wait, NULL, fmt, args);
90272 + va_end(args);
90273 +
90274 + return ret;
90275 +}
90276 +
90277 EXPORT_SYMBOL(__request_module);
90278 #endif /* CONFIG_MODULES */
90279
90280 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
90281 */
90282 set_user_nice(current, 0);
90283
90284 +#ifdef CONFIG_GRKERNSEC
90285 + /* this is race-free as far as userland is concerned as we copied
90286 + out the path to be used prior to this point and are now operating
90287 + on that copy
90288 + */
90289 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90290 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90291 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90292 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90293 + retval = -EPERM;
90294 + goto fail;
90295 + }
90296 +#endif
90297 +
90298 retval = -ENOMEM;
90299 new = prepare_kernel_cred(current);
90300 if (!new)
90301 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90302 commit_creds(new);
90303
90304 retval = do_execve(getname_kernel(sub_info->path),
90305 - (const char __user *const __user *)sub_info->argv,
90306 - (const char __user *const __user *)sub_info->envp);
90307 + (const char __user *const __force_user *)sub_info->argv,
90308 + (const char __user *const __force_user *)sub_info->envp);
90309 if (!retval)
90310 return 0;
90311
90312 @@ -260,6 +327,10 @@ static int call_helper(void *data)
90313
90314 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90315 {
90316 +#ifdef CONFIG_GRKERNSEC
90317 + kfree(info->path);
90318 + info->path = info->origpath;
90319 +#endif
90320 if (info->cleanup)
90321 (*info->cleanup)(info);
90322 kfree(info);
90323 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90324 *
90325 * Thus the __user pointer cast is valid here.
90326 */
90327 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90328 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90329
90330 /*
90331 * If ret is 0, either ____call_usermodehelper failed and the
90332 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90333 goto out;
90334
90335 INIT_WORK(&sub_info->work, __call_usermodehelper);
90336 +#ifdef CONFIG_GRKERNSEC
90337 + sub_info->origpath = path;
90338 + sub_info->path = kstrdup(path, gfp_mask);
90339 +#else
90340 sub_info->path = path;
90341 +#endif
90342 sub_info->argv = argv;
90343 sub_info->envp = envp;
90344
90345 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90346 static int proc_cap_handler(struct ctl_table *table, int write,
90347 void __user *buffer, size_t *lenp, loff_t *ppos)
90348 {
90349 - struct ctl_table t;
90350 + ctl_table_no_const t;
90351 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90352 kernel_cap_t new_cap;
90353 int err, i;
90354 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90355 index 3995f54..e247879 100644
90356 --- a/kernel/kprobes.c
90357 +++ b/kernel/kprobes.c
90358 @@ -31,6 +31,9 @@
90359 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90360 * <prasanna@in.ibm.com> added function-return probes.
90361 */
90362 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90363 +#define __INCLUDED_BY_HIDESYM 1
90364 +#endif
90365 #include <linux/kprobes.h>
90366 #include <linux/hash.h>
90367 #include <linux/init.h>
90368 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90369
90370 static void *alloc_insn_page(void)
90371 {
90372 - return module_alloc(PAGE_SIZE);
90373 + return module_alloc_exec(PAGE_SIZE);
90374 }
90375
90376 static void free_insn_page(void *page)
90377 {
90378 - module_free(NULL, page);
90379 + module_free_exec(NULL, page);
90380 }
90381
90382 struct kprobe_insn_cache kprobe_insn_slots = {
90383 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90384 kprobe_type = "k";
90385
90386 if (sym)
90387 - seq_printf(pi, "%p %s %s+0x%x %s ",
90388 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90389 p->addr, kprobe_type, sym, offset,
90390 (modname ? modname : " "));
90391 else
90392 - seq_printf(pi, "%p %s %p ",
90393 + seq_printf(pi, "%pK %s %pK ",
90394 p->addr, kprobe_type, p->addr);
90395
90396 if (!pp)
90397 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90398 index 6683cce..daf8999 100644
90399 --- a/kernel/ksysfs.c
90400 +++ b/kernel/ksysfs.c
90401 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90402 {
90403 if (count+1 > UEVENT_HELPER_PATH_LEN)
90404 return -ENOENT;
90405 + if (!capable(CAP_SYS_ADMIN))
90406 + return -EPERM;
90407 memcpy(uevent_helper, buf, count);
90408 uevent_helper[count] = '\0';
90409 if (count && uevent_helper[count-1] == '\n')
90410 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90411 return count;
90412 }
90413
90414 -static struct bin_attribute notes_attr = {
90415 +static bin_attribute_no_const notes_attr __read_only = {
90416 .attr = {
90417 .name = "notes",
90418 .mode = S_IRUGO,
90419 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90420 index 88d0d44..e9ce0ee 100644
90421 --- a/kernel/locking/lockdep.c
90422 +++ b/kernel/locking/lockdep.c
90423 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90424 end = (unsigned long) &_end,
90425 addr = (unsigned long) obj;
90426
90427 +#ifdef CONFIG_PAX_KERNEXEC
90428 + start = ktla_ktva(start);
90429 +#endif
90430 +
90431 /*
90432 * static variable?
90433 */
90434 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90435 if (!static_obj(lock->key)) {
90436 debug_locks_off();
90437 printk("INFO: trying to register non-static key.\n");
90438 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90439 printk("the code is fine but needs lockdep annotation.\n");
90440 printk("turning off the locking correctness validator.\n");
90441 dump_stack();
90442 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90443 if (!class)
90444 return 0;
90445 }
90446 - atomic_inc((atomic_t *)&class->ops);
90447 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90448 if (very_verbose(class)) {
90449 printk("\nacquire class [%p] %s", class->key, class->name);
90450 if (class->name_version > 1)
90451 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90452 index ef43ac4..2720dfa 100644
90453 --- a/kernel/locking/lockdep_proc.c
90454 +++ b/kernel/locking/lockdep_proc.c
90455 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90456 return 0;
90457 }
90458
90459 - seq_printf(m, "%p", class->key);
90460 + seq_printf(m, "%pK", class->key);
90461 #ifdef CONFIG_DEBUG_LOCKDEP
90462 seq_printf(m, " OPS:%8ld", class->ops);
90463 #endif
90464 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90465
90466 list_for_each_entry(entry, &class->locks_after, entry) {
90467 if (entry->distance == 1) {
90468 - seq_printf(m, " -> [%p] ", entry->class->key);
90469 + seq_printf(m, " -> [%pK] ", entry->class->key);
90470 print_name(m, entry->class);
90471 seq_puts(m, "\n");
90472 }
90473 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90474 if (!class->key)
90475 continue;
90476
90477 - seq_printf(m, "[%p] ", class->key);
90478 + seq_printf(m, "[%pK] ", class->key);
90479 print_name(m, class);
90480 seq_puts(m, "\n");
90481 }
90482 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90483 if (!i)
90484 seq_line(m, '-', 40-namelen, namelen);
90485
90486 - snprintf(ip, sizeof(ip), "[<%p>]",
90487 + snprintf(ip, sizeof(ip), "[<%pK>]",
90488 (void *)class->contention_point[i]);
90489 seq_printf(m, "%40s %14lu %29s %pS\n",
90490 name, stats->contention_point[i],
90491 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90492 if (!i)
90493 seq_line(m, '-', 40-namelen, namelen);
90494
90495 - snprintf(ip, sizeof(ip), "[<%p>]",
90496 + snprintf(ip, sizeof(ip), "[<%pK>]",
90497 (void *)class->contending_point[i]);
90498 seq_printf(m, "%40s %14lu %29s %pS\n",
90499 name, stats->contending_point[i],
90500 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90501 index 9887a90..0cd2b1d 100644
90502 --- a/kernel/locking/mcs_spinlock.c
90503 +++ b/kernel/locking/mcs_spinlock.c
90504 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90505
90506 prev = decode_cpu(old);
90507 node->prev = prev;
90508 - ACCESS_ONCE(prev->next) = node;
90509 + ACCESS_ONCE_RW(prev->next) = node;
90510
90511 /*
90512 * Normally @prev is untouchable after the above store; because at that
90513 @@ -172,8 +172,8 @@ unqueue:
90514 * it will wait in Step-A.
90515 */
90516
90517 - ACCESS_ONCE(next->prev) = prev;
90518 - ACCESS_ONCE(prev->next) = next;
90519 + ACCESS_ONCE_RW(next->prev) = prev;
90520 + ACCESS_ONCE_RW(prev->next) = next;
90521
90522 return false;
90523 }
90524 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90525 node = this_cpu_ptr(&osq_node);
90526 next = xchg(&node->next, NULL);
90527 if (next) {
90528 - ACCESS_ONCE(next->locked) = 1;
90529 + ACCESS_ONCE_RW(next->locked) = 1;
90530 return;
90531 }
90532
90533 next = osq_wait_next(lock, node, NULL);
90534 if (next)
90535 - ACCESS_ONCE(next->locked) = 1;
90536 + ACCESS_ONCE_RW(next->locked) = 1;
90537 }
90538
90539 #endif
90540 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90541 index 23e89c5..8558eac 100644
90542 --- a/kernel/locking/mcs_spinlock.h
90543 +++ b/kernel/locking/mcs_spinlock.h
90544 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90545 */
90546 return;
90547 }
90548 - ACCESS_ONCE(prev->next) = node;
90549 + ACCESS_ONCE_RW(prev->next) = node;
90550
90551 /* Wait until the lock holder passes the lock down. */
90552 arch_mcs_spin_lock_contended(&node->locked);
90553 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90554 index 5cf6731..ce3bc5a 100644
90555 --- a/kernel/locking/mutex-debug.c
90556 +++ b/kernel/locking/mutex-debug.c
90557 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90558 }
90559
90560 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90561 - struct thread_info *ti)
90562 + struct task_struct *task)
90563 {
90564 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90565
90566 /* Mark the current thread as blocked on the lock: */
90567 - ti->task->blocked_on = waiter;
90568 + task->blocked_on = waiter;
90569 }
90570
90571 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90572 - struct thread_info *ti)
90573 + struct task_struct *task)
90574 {
90575 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90576 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90577 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90578 - ti->task->blocked_on = NULL;
90579 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90580 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90581 + task->blocked_on = NULL;
90582
90583 list_del_init(&waiter->list);
90584 waiter->task = NULL;
90585 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90586 index 0799fd3..d06ae3b 100644
90587 --- a/kernel/locking/mutex-debug.h
90588 +++ b/kernel/locking/mutex-debug.h
90589 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90590 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90591 extern void debug_mutex_add_waiter(struct mutex *lock,
90592 struct mutex_waiter *waiter,
90593 - struct thread_info *ti);
90594 + struct task_struct *task);
90595 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90596 - struct thread_info *ti);
90597 + struct task_struct *task);
90598 extern void debug_mutex_unlock(struct mutex *lock);
90599 extern void debug_mutex_init(struct mutex *lock, const char *name,
90600 struct lock_class_key *key);
90601 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90602 index ae712b2..d0d4a41 100644
90603 --- a/kernel/locking/mutex.c
90604 +++ b/kernel/locking/mutex.c
90605 @@ -486,7 +486,7 @@ slowpath:
90606 goto skip_wait;
90607
90608 debug_mutex_lock_common(lock, &waiter);
90609 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90610 + debug_mutex_add_waiter(lock, &waiter, task);
90611
90612 /* add waiting tasks to the end of the waitqueue (FIFO): */
90613 list_add_tail(&waiter.list, &lock->wait_list);
90614 @@ -531,7 +531,7 @@ slowpath:
90615 schedule_preempt_disabled();
90616 spin_lock_mutex(&lock->wait_lock, flags);
90617 }
90618 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90619 + mutex_remove_waiter(lock, &waiter, task);
90620 /* set it to 0 if there are no waiters left: */
90621 if (likely(list_empty(&lock->wait_list)))
90622 atomic_set(&lock->count, 0);
90623 @@ -568,7 +568,7 @@ skip_wait:
90624 return 0;
90625
90626 err:
90627 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90628 + mutex_remove_waiter(lock, &waiter, task);
90629 spin_unlock_mutex(&lock->wait_lock, flags);
90630 debug_mutex_free_waiter(&waiter);
90631 mutex_release(&lock->dep_map, 1, ip);
90632 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90633 index 1d96dd0..994ff19 100644
90634 --- a/kernel/locking/rtmutex-tester.c
90635 +++ b/kernel/locking/rtmutex-tester.c
90636 @@ -22,7 +22,7 @@
90637 #define MAX_RT_TEST_MUTEXES 8
90638
90639 static spinlock_t rttest_lock;
90640 -static atomic_t rttest_event;
90641 +static atomic_unchecked_t rttest_event;
90642
90643 struct test_thread_data {
90644 int opcode;
90645 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90646
90647 case RTTEST_LOCKCONT:
90648 td->mutexes[td->opdata] = 1;
90649 - td->event = atomic_add_return(1, &rttest_event);
90650 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90651 return 0;
90652
90653 case RTTEST_RESET:
90654 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90655 return 0;
90656
90657 case RTTEST_RESETEVENT:
90658 - atomic_set(&rttest_event, 0);
90659 + atomic_set_unchecked(&rttest_event, 0);
90660 return 0;
90661
90662 default:
90663 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90664 return ret;
90665
90666 td->mutexes[id] = 1;
90667 - td->event = atomic_add_return(1, &rttest_event);
90668 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90669 rt_mutex_lock(&mutexes[id]);
90670 - td->event = atomic_add_return(1, &rttest_event);
90671 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90672 td->mutexes[id] = 4;
90673 return 0;
90674
90675 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90676 return ret;
90677
90678 td->mutexes[id] = 1;
90679 - td->event = atomic_add_return(1, &rttest_event);
90680 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90681 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90682 - td->event = atomic_add_return(1, &rttest_event);
90683 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90684 td->mutexes[id] = ret ? 0 : 4;
90685 return ret ? -EINTR : 0;
90686
90687 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90688 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90689 return ret;
90690
90691 - td->event = atomic_add_return(1, &rttest_event);
90692 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90693 rt_mutex_unlock(&mutexes[id]);
90694 - td->event = atomic_add_return(1, &rttest_event);
90695 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90696 td->mutexes[id] = 0;
90697 return 0;
90698
90699 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90700 break;
90701
90702 td->mutexes[dat] = 2;
90703 - td->event = atomic_add_return(1, &rttest_event);
90704 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90705 break;
90706
90707 default:
90708 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90709 return;
90710
90711 td->mutexes[dat] = 3;
90712 - td->event = atomic_add_return(1, &rttest_event);
90713 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90714 break;
90715
90716 case RTTEST_LOCKNOWAIT:
90717 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90718 return;
90719
90720 td->mutexes[dat] = 1;
90721 - td->event = atomic_add_return(1, &rttest_event);
90722 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90723 return;
90724
90725 default:
90726 diff --git a/kernel/module.c b/kernel/module.c
90727 index 03214bd2..6242887 100644
90728 --- a/kernel/module.c
90729 +++ b/kernel/module.c
90730 @@ -60,6 +60,7 @@
90731 #include <linux/jump_label.h>
90732 #include <linux/pfn.h>
90733 #include <linux/bsearch.h>
90734 +#include <linux/grsecurity.h>
90735 #include <uapi/linux/module.h>
90736 #include "module-internal.h"
90737
90738 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90739
90740 /* Bounds of module allocation, for speeding __module_address.
90741 * Protected by module_mutex. */
90742 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90743 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90744 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90745
90746 int register_module_notifier(struct notifier_block * nb)
90747 {
90748 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90749 return true;
90750
90751 list_for_each_entry_rcu(mod, &modules, list) {
90752 - struct symsearch arr[] = {
90753 + struct symsearch modarr[] = {
90754 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90755 NOT_GPL_ONLY, false },
90756 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90757 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90758 if (mod->state == MODULE_STATE_UNFORMED)
90759 continue;
90760
90761 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90762 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90763 return true;
90764 }
90765 return false;
90766 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90767 if (!pcpusec->sh_size)
90768 return 0;
90769
90770 - if (align > PAGE_SIZE) {
90771 + if (align-1 >= PAGE_SIZE) {
90772 pr_warn("%s: per-cpu alignment %li > %li\n",
90773 mod->name, align, PAGE_SIZE);
90774 align = PAGE_SIZE;
90775 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90776 static ssize_t show_coresize(struct module_attribute *mattr,
90777 struct module_kobject *mk, char *buffer)
90778 {
90779 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90780 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90781 }
90782
90783 static struct module_attribute modinfo_coresize =
90784 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90785 static ssize_t show_initsize(struct module_attribute *mattr,
90786 struct module_kobject *mk, char *buffer)
90787 {
90788 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90789 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90790 }
90791
90792 static struct module_attribute modinfo_initsize =
90793 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90794 goto bad_version;
90795 }
90796
90797 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90798 + /*
90799 + * avoid potentially printing jibberish on attempted load
90800 + * of a module randomized with a different seed
90801 + */
90802 + pr_warn("no symbol version for %s\n", symname);
90803 +#else
90804 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90805 +#endif
90806 return 0;
90807
90808 bad_version:
90809 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90810 + /*
90811 + * avoid potentially printing jibberish on attempted load
90812 + * of a module randomized with a different seed
90813 + */
90814 + printk("attempted module disagrees about version of symbol %s\n",
90815 + symname);
90816 +#else
90817 printk("%s: disagrees about version of symbol %s\n",
90818 mod->name, symname);
90819 +#endif
90820 return 0;
90821 }
90822
90823 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90824 */
90825 #ifdef CONFIG_SYSFS
90826
90827 -#ifdef CONFIG_KALLSYMS
90828 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90829 static inline bool sect_empty(const Elf_Shdr *sect)
90830 {
90831 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90832 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90833 {
90834 unsigned int notes, loaded, i;
90835 struct module_notes_attrs *notes_attrs;
90836 - struct bin_attribute *nattr;
90837 + bin_attribute_no_const *nattr;
90838
90839 /* failed to create section attributes, so can't create notes */
90840 if (!mod->sect_attrs)
90841 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90842 static int module_add_modinfo_attrs(struct module *mod)
90843 {
90844 struct module_attribute *attr;
90845 - struct module_attribute *temp_attr;
90846 + module_attribute_no_const *temp_attr;
90847 int error = 0;
90848 int i;
90849
90850 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90851
90852 static void unset_module_core_ro_nx(struct module *mod)
90853 {
90854 - set_page_attributes(mod->module_core + mod->core_text_size,
90855 - mod->module_core + mod->core_size,
90856 + set_page_attributes(mod->module_core_rw,
90857 + mod->module_core_rw + mod->core_size_rw,
90858 set_memory_x);
90859 - set_page_attributes(mod->module_core,
90860 - mod->module_core + mod->core_ro_size,
90861 + set_page_attributes(mod->module_core_rx,
90862 + mod->module_core_rx + mod->core_size_rx,
90863 set_memory_rw);
90864 }
90865
90866 static void unset_module_init_ro_nx(struct module *mod)
90867 {
90868 - set_page_attributes(mod->module_init + mod->init_text_size,
90869 - mod->module_init + mod->init_size,
90870 + set_page_attributes(mod->module_init_rw,
90871 + mod->module_init_rw + mod->init_size_rw,
90872 set_memory_x);
90873 - set_page_attributes(mod->module_init,
90874 - mod->module_init + mod->init_ro_size,
90875 + set_page_attributes(mod->module_init_rx,
90876 + mod->module_init_rx + mod->init_size_rx,
90877 set_memory_rw);
90878 }
90879
90880 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90881 list_for_each_entry_rcu(mod, &modules, list) {
90882 if (mod->state == MODULE_STATE_UNFORMED)
90883 continue;
90884 - if ((mod->module_core) && (mod->core_text_size)) {
90885 - set_page_attributes(mod->module_core,
90886 - mod->module_core + mod->core_text_size,
90887 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90888 + set_page_attributes(mod->module_core_rx,
90889 + mod->module_core_rx + mod->core_size_rx,
90890 set_memory_rw);
90891 }
90892 - if ((mod->module_init) && (mod->init_text_size)) {
90893 - set_page_attributes(mod->module_init,
90894 - mod->module_init + mod->init_text_size,
90895 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90896 + set_page_attributes(mod->module_init_rx,
90897 + mod->module_init_rx + mod->init_size_rx,
90898 set_memory_rw);
90899 }
90900 }
90901 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90902 list_for_each_entry_rcu(mod, &modules, list) {
90903 if (mod->state == MODULE_STATE_UNFORMED)
90904 continue;
90905 - if ((mod->module_core) && (mod->core_text_size)) {
90906 - set_page_attributes(mod->module_core,
90907 - mod->module_core + mod->core_text_size,
90908 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90909 + set_page_attributes(mod->module_core_rx,
90910 + mod->module_core_rx + mod->core_size_rx,
90911 set_memory_ro);
90912 }
90913 - if ((mod->module_init) && (mod->init_text_size)) {
90914 - set_page_attributes(mod->module_init,
90915 - mod->module_init + mod->init_text_size,
90916 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90917 + set_page_attributes(mod->module_init_rx,
90918 + mod->module_init_rx + mod->init_size_rx,
90919 set_memory_ro);
90920 }
90921 }
90922 @@ -1842,7 +1861,9 @@ static void free_module(struct module *mod)
90923
90924 /* We leave it in list to prevent duplicate loads, but make sure
90925 * that noone uses it while it's being deconstructed. */
90926 + mutex_lock(&module_mutex);
90927 mod->state = MODULE_STATE_UNFORMED;
90928 + mutex_unlock(&module_mutex);
90929
90930 /* Remove dynamic debug info */
90931 ddebug_remove_module(mod->name);
90932 @@ -1863,16 +1884,19 @@ static void free_module(struct module *mod)
90933
90934 /* This may be NULL, but that's OK */
90935 unset_module_init_ro_nx(mod);
90936 - module_free(mod, mod->module_init);
90937 + module_free(mod, mod->module_init_rw);
90938 + module_free_exec(mod, mod->module_init_rx);
90939 kfree(mod->args);
90940 percpu_modfree(mod);
90941
90942 /* Free lock-classes: */
90943 - lockdep_free_key_range(mod->module_core, mod->core_size);
90944 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90945 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90946
90947 /* Finally, free the core (containing the module structure) */
90948 unset_module_core_ro_nx(mod);
90949 - module_free(mod, mod->module_core);
90950 + module_free_exec(mod, mod->module_core_rx);
90951 + module_free(mod, mod->module_core_rw);
90952
90953 #ifdef CONFIG_MPU
90954 update_protections(current->mm);
90955 @@ -1941,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90956 int ret = 0;
90957 const struct kernel_symbol *ksym;
90958
90959 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90960 + int is_fs_load = 0;
90961 + int register_filesystem_found = 0;
90962 + char *p;
90963 +
90964 + p = strstr(mod->args, "grsec_modharden_fs");
90965 + if (p) {
90966 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90967 + /* copy \0 as well */
90968 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90969 + is_fs_load = 1;
90970 + }
90971 +#endif
90972 +
90973 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90974 const char *name = info->strtab + sym[i].st_name;
90975
90976 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90977 + /* it's a real shame this will never get ripped and copied
90978 + upstream! ;(
90979 + */
90980 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90981 + register_filesystem_found = 1;
90982 +#endif
90983 +
90984 switch (sym[i].st_shndx) {
90985 case SHN_COMMON:
90986 /* Ignore common symbols */
90987 @@ -1968,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90988 ksym = resolve_symbol_wait(mod, info, name);
90989 /* Ok if resolved. */
90990 if (ksym && !IS_ERR(ksym)) {
90991 + pax_open_kernel();
90992 sym[i].st_value = ksym->value;
90993 + pax_close_kernel();
90994 break;
90995 }
90996
90997 @@ -1987,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90998 secbase = (unsigned long)mod_percpu(mod);
90999 else
91000 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
91001 + pax_open_kernel();
91002 sym[i].st_value += secbase;
91003 + pax_close_kernel();
91004 break;
91005 }
91006 }
91007
91008 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91009 + if (is_fs_load && !register_filesystem_found) {
91010 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
91011 + ret = -EPERM;
91012 + }
91013 +#endif
91014 +
91015 return ret;
91016 }
91017
91018 @@ -2075,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
91019 || s->sh_entsize != ~0UL
91020 || strstarts(sname, ".init"))
91021 continue;
91022 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
91023 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91024 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
91025 + else
91026 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
91027 pr_debug("\t%s\n", sname);
91028 }
91029 - switch (m) {
91030 - case 0: /* executable */
91031 - mod->core_size = debug_align(mod->core_size);
91032 - mod->core_text_size = mod->core_size;
91033 - break;
91034 - case 1: /* RO: text and ro-data */
91035 - mod->core_size = debug_align(mod->core_size);
91036 - mod->core_ro_size = mod->core_size;
91037 - break;
91038 - case 3: /* whole core */
91039 - mod->core_size = debug_align(mod->core_size);
91040 - break;
91041 - }
91042 }
91043
91044 pr_debug("Init section allocation order:\n");
91045 @@ -2104,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
91046 || s->sh_entsize != ~0UL
91047 || !strstarts(sname, ".init"))
91048 continue;
91049 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
91050 - | INIT_OFFSET_MASK);
91051 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91052 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
91053 + else
91054 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
91055 + s->sh_entsize |= INIT_OFFSET_MASK;
91056 pr_debug("\t%s\n", sname);
91057 }
91058 - switch (m) {
91059 - case 0: /* executable */
91060 - mod->init_size = debug_align(mod->init_size);
91061 - mod->init_text_size = mod->init_size;
91062 - break;
91063 - case 1: /* RO: text and ro-data */
91064 - mod->init_size = debug_align(mod->init_size);
91065 - mod->init_ro_size = mod->init_size;
91066 - break;
91067 - case 3: /* whole init */
91068 - mod->init_size = debug_align(mod->init_size);
91069 - break;
91070 - }
91071 }
91072 }
91073
91074 @@ -2293,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91075
91076 /* Put symbol section at end of init part of module. */
91077 symsect->sh_flags |= SHF_ALLOC;
91078 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
91079 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
91080 info->index.sym) | INIT_OFFSET_MASK;
91081 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
91082
91083 @@ -2310,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91084 }
91085
91086 /* Append room for core symbols at end of core part. */
91087 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
91088 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
91089 - mod->core_size += strtab_size;
91090 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
91091 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
91092 + mod->core_size_rx += strtab_size;
91093
91094 /* Put string table section at end of init part of module. */
91095 strsect->sh_flags |= SHF_ALLOC;
91096 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
91097 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
91098 info->index.str) | INIT_OFFSET_MASK;
91099 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
91100 }
91101 @@ -2334,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91102 /* Make sure we get permanent strtab: don't use info->strtab. */
91103 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
91104
91105 + pax_open_kernel();
91106 +
91107 /* Set types up while we still have access to sections. */
91108 for (i = 0; i < mod->num_symtab; i++)
91109 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
91110
91111 - mod->core_symtab = dst = mod->module_core + info->symoffs;
91112 - mod->core_strtab = s = mod->module_core + info->stroffs;
91113 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
91114 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
91115 src = mod->symtab;
91116 for (ndst = i = 0; i < mod->num_symtab; i++) {
91117 if (i == 0 ||
91118 @@ -2351,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91119 }
91120 }
91121 mod->core_num_syms = ndst;
91122 +
91123 + pax_close_kernel();
91124 }
91125 #else
91126 static inline void layout_symtab(struct module *mod, struct load_info *info)
91127 @@ -2384,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
91128 return vmalloc_exec(size);
91129 }
91130
91131 -static void *module_alloc_update_bounds(unsigned long size)
91132 +static void *module_alloc_update_bounds_rw(unsigned long size)
91133 {
91134 void *ret = module_alloc(size);
91135
91136 if (ret) {
91137 mutex_lock(&module_mutex);
91138 /* Update module bounds. */
91139 - if ((unsigned long)ret < module_addr_min)
91140 - module_addr_min = (unsigned long)ret;
91141 - if ((unsigned long)ret + size > module_addr_max)
91142 - module_addr_max = (unsigned long)ret + size;
91143 + if ((unsigned long)ret < module_addr_min_rw)
91144 + module_addr_min_rw = (unsigned long)ret;
91145 + if ((unsigned long)ret + size > module_addr_max_rw)
91146 + module_addr_max_rw = (unsigned long)ret + size;
91147 + mutex_unlock(&module_mutex);
91148 + }
91149 + return ret;
91150 +}
91151 +
91152 +static void *module_alloc_update_bounds_rx(unsigned long size)
91153 +{
91154 + void *ret = module_alloc_exec(size);
91155 +
91156 + if (ret) {
91157 + mutex_lock(&module_mutex);
91158 + /* Update module bounds. */
91159 + if ((unsigned long)ret < module_addr_min_rx)
91160 + module_addr_min_rx = (unsigned long)ret;
91161 + if ((unsigned long)ret + size > module_addr_max_rx)
91162 + module_addr_max_rx = (unsigned long)ret + size;
91163 mutex_unlock(&module_mutex);
91164 }
91165 return ret;
91166 @@ -2648,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91167 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91168
91169 if (info->index.sym == 0) {
91170 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91171 + /*
91172 + * avoid potentially printing jibberish on attempted load
91173 + * of a module randomized with a different seed
91174 + */
91175 + pr_warn("module has no symbols (stripped?)\n");
91176 +#else
91177 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91178 +#endif
91179 return ERR_PTR(-ENOEXEC);
91180 }
91181
91182 @@ -2664,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91183 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91184 {
91185 const char *modmagic = get_modinfo(info, "vermagic");
91186 + const char *license = get_modinfo(info, "license");
91187 int err;
91188
91189 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91190 + if (!license || !license_is_gpl_compatible(license))
91191 + return -ENOEXEC;
91192 +#endif
91193 +
91194 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91195 modmagic = NULL;
91196
91197 @@ -2690,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91198 }
91199
91200 /* Set up license info based on the info section */
91201 - set_license(mod, get_modinfo(info, "license"));
91202 + set_license(mod, license);
91203
91204 return 0;
91205 }
91206 @@ -2784,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91207 void *ptr;
91208
91209 /* Do the allocs. */
91210 - ptr = module_alloc_update_bounds(mod->core_size);
91211 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91212 /*
91213 * The pointer to this block is stored in the module structure
91214 * which is inside the block. Just mark it as not being a
91215 @@ -2794,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91216 if (!ptr)
91217 return -ENOMEM;
91218
91219 - memset(ptr, 0, mod->core_size);
91220 - mod->module_core = ptr;
91221 + memset(ptr, 0, mod->core_size_rw);
91222 + mod->module_core_rw = ptr;
91223
91224 - if (mod->init_size) {
91225 - ptr = module_alloc_update_bounds(mod->init_size);
91226 + if (mod->init_size_rw) {
91227 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91228 /*
91229 * The pointer to this block is stored in the module structure
91230 * which is inside the block. This block doesn't need to be
91231 @@ -2807,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91232 */
91233 kmemleak_ignore(ptr);
91234 if (!ptr) {
91235 - module_free(mod, mod->module_core);
91236 + module_free(mod, mod->module_core_rw);
91237 return -ENOMEM;
91238 }
91239 - memset(ptr, 0, mod->init_size);
91240 - mod->module_init = ptr;
91241 + memset(ptr, 0, mod->init_size_rw);
91242 + mod->module_init_rw = ptr;
91243 } else
91244 - mod->module_init = NULL;
91245 + mod->module_init_rw = NULL;
91246 +
91247 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91248 + kmemleak_not_leak(ptr);
91249 + if (!ptr) {
91250 + if (mod->module_init_rw)
91251 + module_free(mod, mod->module_init_rw);
91252 + module_free(mod, mod->module_core_rw);
91253 + return -ENOMEM;
91254 + }
91255 +
91256 + pax_open_kernel();
91257 + memset(ptr, 0, mod->core_size_rx);
91258 + pax_close_kernel();
91259 + mod->module_core_rx = ptr;
91260 +
91261 + if (mod->init_size_rx) {
91262 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91263 + kmemleak_ignore(ptr);
91264 + if (!ptr && mod->init_size_rx) {
91265 + module_free_exec(mod, mod->module_core_rx);
91266 + if (mod->module_init_rw)
91267 + module_free(mod, mod->module_init_rw);
91268 + module_free(mod, mod->module_core_rw);
91269 + return -ENOMEM;
91270 + }
91271 +
91272 + pax_open_kernel();
91273 + memset(ptr, 0, mod->init_size_rx);
91274 + pax_close_kernel();
91275 + mod->module_init_rx = ptr;
91276 + } else
91277 + mod->module_init_rx = NULL;
91278
91279 /* Transfer each section which specifies SHF_ALLOC */
91280 pr_debug("final section addresses:\n");
91281 @@ -2824,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91282 if (!(shdr->sh_flags & SHF_ALLOC))
91283 continue;
91284
91285 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
91286 - dest = mod->module_init
91287 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91288 - else
91289 - dest = mod->module_core + shdr->sh_entsize;
91290 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91291 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91292 + dest = mod->module_init_rw
91293 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91294 + else
91295 + dest = mod->module_init_rx
91296 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91297 + } else {
91298 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91299 + dest = mod->module_core_rw + shdr->sh_entsize;
91300 + else
91301 + dest = mod->module_core_rx + shdr->sh_entsize;
91302 + }
91303 +
91304 + if (shdr->sh_type != SHT_NOBITS) {
91305 +
91306 +#ifdef CONFIG_PAX_KERNEXEC
91307 +#ifdef CONFIG_X86_64
91308 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91309 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91310 +#endif
91311 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91312 + pax_open_kernel();
91313 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91314 + pax_close_kernel();
91315 + } else
91316 +#endif
91317
91318 - if (shdr->sh_type != SHT_NOBITS)
91319 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91320 + }
91321 /* Update sh_addr to point to copy in image. */
91322 - shdr->sh_addr = (unsigned long)dest;
91323 +
91324 +#ifdef CONFIG_PAX_KERNEXEC
91325 + if (shdr->sh_flags & SHF_EXECINSTR)
91326 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91327 + else
91328 +#endif
91329 +
91330 + shdr->sh_addr = (unsigned long)dest;
91331 pr_debug("\t0x%lx %s\n",
91332 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91333 }
91334 @@ -2890,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91335 * Do it before processing of module parameters, so the module
91336 * can provide parameter accessor functions of its own.
91337 */
91338 - if (mod->module_init)
91339 - flush_icache_range((unsigned long)mod->module_init,
91340 - (unsigned long)mod->module_init
91341 - + mod->init_size);
91342 - flush_icache_range((unsigned long)mod->module_core,
91343 - (unsigned long)mod->module_core + mod->core_size);
91344 + if (mod->module_init_rx)
91345 + flush_icache_range((unsigned long)mod->module_init_rx,
91346 + (unsigned long)mod->module_init_rx
91347 + + mod->init_size_rx);
91348 + flush_icache_range((unsigned long)mod->module_core_rx,
91349 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91350
91351 set_fs(old_fs);
91352 }
91353 @@ -2952,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91354 static void module_deallocate(struct module *mod, struct load_info *info)
91355 {
91356 percpu_modfree(mod);
91357 - module_free(mod, mod->module_init);
91358 - module_free(mod, mod->module_core);
91359 + module_free_exec(mod, mod->module_init_rx);
91360 + module_free_exec(mod, mod->module_core_rx);
91361 + module_free(mod, mod->module_init_rw);
91362 + module_free(mod, mod->module_core_rw);
91363 }
91364
91365 int __weak module_finalize(const Elf_Ehdr *hdr,
91366 @@ -2966,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91367 static int post_relocation(struct module *mod, const struct load_info *info)
91368 {
91369 /* Sort exception table now relocations are done. */
91370 + pax_open_kernel();
91371 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91372 + pax_close_kernel();
91373
91374 /* Copy relocated percpu area over. */
91375 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91376 @@ -3075,11 +3211,12 @@ static int do_init_module(struct module *mod)
91377 mod->strtab = mod->core_strtab;
91378 #endif
91379 unset_module_init_ro_nx(mod);
91380 - module_free(mod, mod->module_init);
91381 - mod->module_init = NULL;
91382 - mod->init_size = 0;
91383 - mod->init_ro_size = 0;
91384 - mod->init_text_size = 0;
91385 + module_free(mod, mod->module_init_rw);
91386 + module_free_exec(mod, mod->module_init_rx);
91387 + mod->module_init_rw = NULL;
91388 + mod->module_init_rx = NULL;
91389 + mod->init_size_rw = 0;
91390 + mod->init_size_rx = 0;
91391 mutex_unlock(&module_mutex);
91392 wake_up_all(&module_wq);
91393
91394 @@ -3147,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91395 module_bug_finalize(info->hdr, info->sechdrs, mod);
91396
91397 /* Set RO and NX regions for core */
91398 - set_section_ro_nx(mod->module_core,
91399 - mod->core_text_size,
91400 - mod->core_ro_size,
91401 - mod->core_size);
91402 + set_section_ro_nx(mod->module_core_rx,
91403 + mod->core_size_rx,
91404 + mod->core_size_rx,
91405 + mod->core_size_rx);
91406
91407 /* Set RO and NX regions for init */
91408 - set_section_ro_nx(mod->module_init,
91409 - mod->init_text_size,
91410 - mod->init_ro_size,
91411 - mod->init_size);
91412 + set_section_ro_nx(mod->module_init_rx,
91413 + mod->init_size_rx,
91414 + mod->init_size_rx,
91415 + mod->init_size_rx);
91416
91417 /* Mark state as coming so strong_try_module_get() ignores us,
91418 * but kallsyms etc. can see us. */
91419 @@ -3240,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91420 if (err)
91421 goto free_unload;
91422
91423 + /* Now copy in args */
91424 + mod->args = strndup_user(uargs, ~0UL >> 1);
91425 + if (IS_ERR(mod->args)) {
91426 + err = PTR_ERR(mod->args);
91427 + goto free_unload;
91428 + }
91429 +
91430 /* Set up MODINFO_ATTR fields */
91431 setup_modinfo(mod, info);
91432
91433 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91434 + {
91435 + char *p, *p2;
91436 +
91437 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91438 + 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);
91439 + err = -EPERM;
91440 + goto free_modinfo;
91441 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91442 + p += sizeof("grsec_modharden_normal") - 1;
91443 + p2 = strstr(p, "_");
91444 + if (p2) {
91445 + *p2 = '\0';
91446 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91447 + *p2 = '_';
91448 + }
91449 + err = -EPERM;
91450 + goto free_modinfo;
91451 + }
91452 + }
91453 +#endif
91454 +
91455 /* Fix up syms, so that st_value is a pointer to location. */
91456 err = simplify_symbols(mod, info);
91457 if (err < 0)
91458 @@ -3258,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91459
91460 flush_module_icache(mod);
91461
91462 - /* Now copy in args */
91463 - mod->args = strndup_user(uargs, ~0UL >> 1);
91464 - if (IS_ERR(mod->args)) {
91465 - err = PTR_ERR(mod->args);
91466 - goto free_arch_cleanup;
91467 - }
91468 -
91469 dynamic_debug_setup(info->debug, info->num_debug);
91470
91471 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91472 @@ -3312,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91473 ddebug_cleanup:
91474 dynamic_debug_remove(info->debug);
91475 synchronize_sched();
91476 - kfree(mod->args);
91477 - free_arch_cleanup:
91478 module_arch_cleanup(mod);
91479 free_modinfo:
91480 free_modinfo(mod);
91481 + kfree(mod->args);
91482 free_unload:
91483 module_unload_free(mod);
91484 unlink_mod:
91485 @@ -3401,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91486 unsigned long nextval;
91487
91488 /* At worse, next value is at end of module */
91489 - if (within_module_init(addr, mod))
91490 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91491 + if (within_module_init_rx(addr, mod))
91492 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91493 + else if (within_module_init_rw(addr, mod))
91494 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91495 + else if (within_module_core_rx(addr, mod))
91496 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91497 + else if (within_module_core_rw(addr, mod))
91498 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91499 else
91500 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91501 + return NULL;
91502
91503 /* Scan for closest preceding symbol, and next symbol. (ELF
91504 starts real symbols at 1). */
91505 @@ -3652,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91506 return 0;
91507
91508 seq_printf(m, "%s %u",
91509 - mod->name, mod->init_size + mod->core_size);
91510 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91511 print_unload_info(m, mod);
91512
91513 /* Informative for users. */
91514 @@ -3661,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91515 mod->state == MODULE_STATE_COMING ? "Loading":
91516 "Live");
91517 /* Used by oprofile and other similar tools. */
91518 - seq_printf(m, " 0x%pK", mod->module_core);
91519 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91520
91521 /* Taints info */
91522 if (mod->taints)
91523 @@ -3697,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91524
91525 static int __init proc_modules_init(void)
91526 {
91527 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91528 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91529 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91530 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91531 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91532 +#else
91533 proc_create("modules", 0, NULL, &proc_modules_operations);
91534 +#endif
91535 +#else
91536 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91537 +#endif
91538 return 0;
91539 }
91540 module_init(proc_modules_init);
91541 @@ -3758,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91542 {
91543 struct module *mod;
91544
91545 - if (addr < module_addr_min || addr > module_addr_max)
91546 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91547 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91548 return NULL;
91549
91550 list_for_each_entry_rcu(mod, &modules, list) {
91551 @@ -3799,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91552 */
91553 struct module *__module_text_address(unsigned long addr)
91554 {
91555 - struct module *mod = __module_address(addr);
91556 + struct module *mod;
91557 +
91558 +#ifdef CONFIG_X86_32
91559 + addr = ktla_ktva(addr);
91560 +#endif
91561 +
91562 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91563 + return NULL;
91564 +
91565 + mod = __module_address(addr);
91566 +
91567 if (mod) {
91568 /* Make sure it's within the text section. */
91569 - if (!within(addr, mod->module_init, mod->init_text_size)
91570 - && !within(addr, mod->module_core, mod->core_text_size))
91571 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91572 mod = NULL;
91573 }
91574 return mod;
91575 diff --git a/kernel/notifier.c b/kernel/notifier.c
91576 index 4803da6..1c5eea6 100644
91577 --- a/kernel/notifier.c
91578 +++ b/kernel/notifier.c
91579 @@ -5,6 +5,7 @@
91580 #include <linux/rcupdate.h>
91581 #include <linux/vmalloc.h>
91582 #include <linux/reboot.h>
91583 +#include <linux/mm.h>
91584
91585 /*
91586 * Notifier list for kernel code which wants to be called
91587 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91588 while ((*nl) != NULL) {
91589 if (n->priority > (*nl)->priority)
91590 break;
91591 - nl = &((*nl)->next);
91592 + nl = (struct notifier_block **)&((*nl)->next);
91593 }
91594 - n->next = *nl;
91595 + pax_open_kernel();
91596 + *(const void **)&n->next = *nl;
91597 rcu_assign_pointer(*nl, n);
91598 + pax_close_kernel();
91599 return 0;
91600 }
91601
91602 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91603 return 0;
91604 if (n->priority > (*nl)->priority)
91605 break;
91606 - nl = &((*nl)->next);
91607 + nl = (struct notifier_block **)&((*nl)->next);
91608 }
91609 - n->next = *nl;
91610 + pax_open_kernel();
91611 + *(const void **)&n->next = *nl;
91612 rcu_assign_pointer(*nl, n);
91613 + pax_close_kernel();
91614 return 0;
91615 }
91616
91617 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91618 {
91619 while ((*nl) != NULL) {
91620 if ((*nl) == n) {
91621 + pax_open_kernel();
91622 rcu_assign_pointer(*nl, n->next);
91623 + pax_close_kernel();
91624 return 0;
91625 }
91626 - nl = &((*nl)->next);
91627 + nl = (struct notifier_block **)&((*nl)->next);
91628 }
91629 return -ENOENT;
91630 }
91631 diff --git a/kernel/padata.c b/kernel/padata.c
91632 index 161402f..598814c 100644
91633 --- a/kernel/padata.c
91634 +++ b/kernel/padata.c
91635 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91636 * seq_nr mod. number of cpus in use.
91637 */
91638
91639 - seq_nr = atomic_inc_return(&pd->seq_nr);
91640 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91641 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91642
91643 return padata_index_to_cpu(pd, cpu_index);
91644 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91645 padata_init_pqueues(pd);
91646 padata_init_squeues(pd);
91647 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91648 - atomic_set(&pd->seq_nr, -1);
91649 + atomic_set_unchecked(&pd->seq_nr, -1);
91650 atomic_set(&pd->reorder_objects, 0);
91651 atomic_set(&pd->refcnt, 0);
91652 pd->pinst = pinst;
91653 diff --git a/kernel/panic.c b/kernel/panic.c
91654 index d09dc5c..9abbdff 100644
91655 --- a/kernel/panic.c
91656 +++ b/kernel/panic.c
91657 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91658 /*
91659 * Stop ourself in panic -- architecture code may override this
91660 */
91661 -void __weak panic_smp_self_stop(void)
91662 +void __weak __noreturn panic_smp_self_stop(void)
91663 {
91664 while (1)
91665 cpu_relax();
91666 @@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91667 disable_trace_on_warning();
91668
91669 pr_warn("------------[ cut here ]------------\n");
91670 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91671 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91672 raw_smp_processor_id(), current->pid, file, line, caller);
91673
91674 if (args)
91675 @@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91676 */
91677 __visible void __stack_chk_fail(void)
91678 {
91679 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91680 + dump_stack();
91681 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91682 __builtin_return_address(0));
91683 }
91684 EXPORT_SYMBOL(__stack_chk_fail);
91685 diff --git a/kernel/pid.c b/kernel/pid.c
91686 index 9b9a266..c20ef80 100644
91687 --- a/kernel/pid.c
91688 +++ b/kernel/pid.c
91689 @@ -33,6 +33,7 @@
91690 #include <linux/rculist.h>
91691 #include <linux/bootmem.h>
91692 #include <linux/hash.h>
91693 +#include <linux/security.h>
91694 #include <linux/pid_namespace.h>
91695 #include <linux/init_task.h>
91696 #include <linux/syscalls.h>
91697 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91698
91699 int pid_max = PID_MAX_DEFAULT;
91700
91701 -#define RESERVED_PIDS 300
91702 +#define RESERVED_PIDS 500
91703
91704 int pid_max_min = RESERVED_PIDS + 1;
91705 int pid_max_max = PID_MAX_LIMIT;
91706 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91707 */
91708 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91709 {
91710 + struct task_struct *task;
91711 +
91712 rcu_lockdep_assert(rcu_read_lock_held(),
91713 "find_task_by_pid_ns() needs rcu_read_lock()"
91714 " protection");
91715 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91716 +
91717 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91718 +
91719 + if (gr_pid_is_chrooted(task))
91720 + return NULL;
91721 +
91722 + return task;
91723 }
91724
91725 struct task_struct *find_task_by_vpid(pid_t vnr)
91726 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91727 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91728 }
91729
91730 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91731 +{
91732 + rcu_lockdep_assert(rcu_read_lock_held(),
91733 + "find_task_by_pid_ns() needs rcu_read_lock()"
91734 + " protection");
91735 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91736 +}
91737 +
91738 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91739 {
91740 struct pid *pid;
91741 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91742 index db95d8e..a0ca23f 100644
91743 --- a/kernel/pid_namespace.c
91744 +++ b/kernel/pid_namespace.c
91745 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91746 void __user *buffer, size_t *lenp, loff_t *ppos)
91747 {
91748 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91749 - struct ctl_table tmp = *table;
91750 + ctl_table_no_const tmp = *table;
91751
91752 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91753 return -EPERM;
91754 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91755 index e4e4121..71faf14 100644
91756 --- a/kernel/power/Kconfig
91757 +++ b/kernel/power/Kconfig
91758 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91759 config HIBERNATION
91760 bool "Hibernation (aka 'suspend to disk')"
91761 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91762 + depends on !GRKERNSEC_KMEM
91763 + depends on !PAX_MEMORY_SANITIZE
91764 select HIBERNATE_CALLBACKS
91765 select LZO_COMPRESS
91766 select LZO_DECOMPRESS
91767 diff --git a/kernel/power/process.c b/kernel/power/process.c
91768 index 4ee194e..925778f 100644
91769 --- a/kernel/power/process.c
91770 +++ b/kernel/power/process.c
91771 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91772 unsigned int elapsed_msecs;
91773 bool wakeup = false;
91774 int sleep_usecs = USEC_PER_MSEC;
91775 + bool timedout = false;
91776
91777 do_gettimeofday(&start);
91778
91779 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91780
91781 while (true) {
91782 todo = 0;
91783 + if (time_after(jiffies, end_time))
91784 + timedout = true;
91785 read_lock(&tasklist_lock);
91786 do_each_thread(g, p) {
91787 if (p == current || !freeze_task(p))
91788 continue;
91789
91790 - if (!freezer_should_skip(p))
91791 + if (!freezer_should_skip(p)) {
91792 todo++;
91793 + if (timedout) {
91794 + printk(KERN_ERR "Task refusing to freeze:\n");
91795 + sched_show_task(p);
91796 + }
91797 + }
91798 } while_each_thread(g, p);
91799 read_unlock(&tasklist_lock);
91800
91801 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91802 todo += wq_busy;
91803 }
91804
91805 - if (!todo || time_after(jiffies, end_time))
91806 + if (!todo || timedout)
91807 break;
91808
91809 if (pm_wakeup_pending()) {
91810 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91811 index 1ce7706..3b07c49 100644
91812 --- a/kernel/printk/printk.c
91813 +++ b/kernel/printk/printk.c
91814 @@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91815 if (from_file && type != SYSLOG_ACTION_OPEN)
91816 return 0;
91817
91818 +#ifdef CONFIG_GRKERNSEC_DMESG
91819 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91820 + return -EPERM;
91821 +#endif
91822 +
91823 if (syslog_action_restricted(type)) {
91824 if (capable(CAP_SYSLOG))
91825 return 0;
91826 diff --git a/kernel/profile.c b/kernel/profile.c
91827 index 54bf5ba..df6e0a2 100644
91828 --- a/kernel/profile.c
91829 +++ b/kernel/profile.c
91830 @@ -37,7 +37,7 @@ struct profile_hit {
91831 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91832 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91833
91834 -static atomic_t *prof_buffer;
91835 +static atomic_unchecked_t *prof_buffer;
91836 static unsigned long prof_len, prof_shift;
91837
91838 int prof_on __read_mostly;
91839 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91840 hits[i].pc = 0;
91841 continue;
91842 }
91843 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91844 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91845 hits[i].hits = hits[i].pc = 0;
91846 }
91847 }
91848 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91849 * Add the current hit(s) and flush the write-queue out
91850 * to the global buffer:
91851 */
91852 - atomic_add(nr_hits, &prof_buffer[pc]);
91853 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91854 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91855 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91856 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91857 hits[i].pc = hits[i].hits = 0;
91858 }
91859 out:
91860 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91861 {
91862 unsigned long pc;
91863 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91864 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91865 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91866 }
91867 #endif /* !CONFIG_SMP */
91868
91869 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91870 return -EFAULT;
91871 buf++; p++; count--; read++;
91872 }
91873 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91874 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91875 if (copy_to_user(buf, (void *)pnt, count))
91876 return -EFAULT;
91877 read += count;
91878 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91879 }
91880 #endif
91881 profile_discard_flip_buffers();
91882 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91883 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91884 return count;
91885 }
91886
91887 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91888 index 54e7522..5b82dd6 100644
91889 --- a/kernel/ptrace.c
91890 +++ b/kernel/ptrace.c
91891 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91892 if (seize)
91893 flags |= PT_SEIZED;
91894 rcu_read_lock();
91895 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91896 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91897 flags |= PT_PTRACE_CAP;
91898 rcu_read_unlock();
91899 task->ptrace = flags;
91900 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91901 break;
91902 return -EIO;
91903 }
91904 - if (copy_to_user(dst, buf, retval))
91905 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91906 return -EFAULT;
91907 copied += retval;
91908 src += retval;
91909 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91910 bool seized = child->ptrace & PT_SEIZED;
91911 int ret = -EIO;
91912 siginfo_t siginfo, *si;
91913 - void __user *datavp = (void __user *) data;
91914 + void __user *datavp = (__force void __user *) data;
91915 unsigned long __user *datalp = datavp;
91916 unsigned long flags;
91917
91918 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91919 goto out;
91920 }
91921
91922 + if (gr_handle_ptrace(child, request)) {
91923 + ret = -EPERM;
91924 + goto out_put_task_struct;
91925 + }
91926 +
91927 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91928 ret = ptrace_attach(child, request, addr, data);
91929 /*
91930 * Some architectures need to do book-keeping after
91931 * a ptrace attach.
91932 */
91933 - if (!ret)
91934 + if (!ret) {
91935 arch_ptrace_attach(child);
91936 + gr_audit_ptrace(child);
91937 + }
91938 goto out_put_task_struct;
91939 }
91940
91941 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91942 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91943 if (copied != sizeof(tmp))
91944 return -EIO;
91945 - return put_user(tmp, (unsigned long __user *)data);
91946 + return put_user(tmp, (__force unsigned long __user *)data);
91947 }
91948
91949 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91950 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91951 }
91952
91953 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91954 - compat_long_t, addr, compat_long_t, data)
91955 + compat_ulong_t, addr, compat_ulong_t, data)
91956 {
91957 struct task_struct *child;
91958 long ret;
91959 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91960 goto out;
91961 }
91962
91963 + if (gr_handle_ptrace(child, request)) {
91964 + ret = -EPERM;
91965 + goto out_put_task_struct;
91966 + }
91967 +
91968 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91969 ret = ptrace_attach(child, request, addr, data);
91970 /*
91971 * Some architectures need to do book-keeping after
91972 * a ptrace attach.
91973 */
91974 - if (!ret)
91975 + if (!ret) {
91976 arch_ptrace_attach(child);
91977 + gr_audit_ptrace(child);
91978 + }
91979 goto out_put_task_struct;
91980 }
91981
91982 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91983 index 948a769..5ca842b 100644
91984 --- a/kernel/rcu/rcutorture.c
91985 +++ b/kernel/rcu/rcutorture.c
91986 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91987 rcu_torture_count) = { 0 };
91988 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91989 rcu_torture_batch) = { 0 };
91990 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91991 -static atomic_t n_rcu_torture_alloc;
91992 -static atomic_t n_rcu_torture_alloc_fail;
91993 -static atomic_t n_rcu_torture_free;
91994 -static atomic_t n_rcu_torture_mberror;
91995 -static atomic_t n_rcu_torture_error;
91996 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91997 +static atomic_unchecked_t n_rcu_torture_alloc;
91998 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91999 +static atomic_unchecked_t n_rcu_torture_free;
92000 +static atomic_unchecked_t n_rcu_torture_mberror;
92001 +static atomic_unchecked_t n_rcu_torture_error;
92002 static long n_rcu_torture_barrier_error;
92003 static long n_rcu_torture_boost_ktrerror;
92004 static long n_rcu_torture_boost_rterror;
92005 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
92006
92007 spin_lock_bh(&rcu_torture_lock);
92008 if (list_empty(&rcu_torture_freelist)) {
92009 - atomic_inc(&n_rcu_torture_alloc_fail);
92010 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
92011 spin_unlock_bh(&rcu_torture_lock);
92012 return NULL;
92013 }
92014 - atomic_inc(&n_rcu_torture_alloc);
92015 + atomic_inc_unchecked(&n_rcu_torture_alloc);
92016 p = rcu_torture_freelist.next;
92017 list_del_init(p);
92018 spin_unlock_bh(&rcu_torture_lock);
92019 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
92020 static void
92021 rcu_torture_free(struct rcu_torture *p)
92022 {
92023 - atomic_inc(&n_rcu_torture_free);
92024 + atomic_inc_unchecked(&n_rcu_torture_free);
92025 spin_lock_bh(&rcu_torture_lock);
92026 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
92027 spin_unlock_bh(&rcu_torture_lock);
92028 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
92029 i = rp->rtort_pipe_count;
92030 if (i > RCU_TORTURE_PIPE_LEN)
92031 i = RCU_TORTURE_PIPE_LEN;
92032 - atomic_inc(&rcu_torture_wcount[i]);
92033 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92034 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
92035 rp->rtort_mbtest = 0;
92036 return true;
92037 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
92038 i = old_rp->rtort_pipe_count;
92039 if (i > RCU_TORTURE_PIPE_LEN)
92040 i = RCU_TORTURE_PIPE_LEN;
92041 - atomic_inc(&rcu_torture_wcount[i]);
92042 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92043 old_rp->rtort_pipe_count++;
92044 switch (synctype[torture_random(&rand) % nsynctypes]) {
92045 case RTWS_DEF_FREE:
92046 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
92047 return;
92048 }
92049 if (p->rtort_mbtest == 0)
92050 - atomic_inc(&n_rcu_torture_mberror);
92051 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92052 spin_lock(&rand_lock);
92053 cur_ops->read_delay(&rand);
92054 n_rcu_torture_timers++;
92055 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
92056 continue;
92057 }
92058 if (p->rtort_mbtest == 0)
92059 - atomic_inc(&n_rcu_torture_mberror);
92060 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92061 cur_ops->read_delay(&rand);
92062 preempt_disable();
92063 pipe_count = p->rtort_pipe_count;
92064 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
92065 }
92066 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
92067 page += sprintf(page,
92068 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92069 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92070 rcu_torture_current,
92071 rcu_torture_current_version,
92072 list_empty(&rcu_torture_freelist),
92073 - atomic_read(&n_rcu_torture_alloc),
92074 - atomic_read(&n_rcu_torture_alloc_fail),
92075 - atomic_read(&n_rcu_torture_free));
92076 + atomic_read_unchecked(&n_rcu_torture_alloc),
92077 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
92078 + atomic_read_unchecked(&n_rcu_torture_free));
92079 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
92080 - atomic_read(&n_rcu_torture_mberror),
92081 + atomic_read_unchecked(&n_rcu_torture_mberror),
92082 n_rcu_torture_boost_ktrerror,
92083 n_rcu_torture_boost_rterror);
92084 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
92085 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
92086 n_barrier_attempts,
92087 n_rcu_torture_barrier_error);
92088 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
92089 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
92090 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
92091 n_rcu_torture_barrier_error != 0 ||
92092 n_rcu_torture_boost_ktrerror != 0 ||
92093 n_rcu_torture_boost_rterror != 0 ||
92094 n_rcu_torture_boost_failure != 0 ||
92095 i > 1) {
92096 page += sprintf(page, "!!! ");
92097 - atomic_inc(&n_rcu_torture_error);
92098 + atomic_inc_unchecked(&n_rcu_torture_error);
92099 WARN_ON_ONCE(1);
92100 }
92101 page += sprintf(page, "Reader Pipe: ");
92102 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
92103 page += sprintf(page, "Free-Block Circulation: ");
92104 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92105 page += sprintf(page, " %d",
92106 - atomic_read(&rcu_torture_wcount[i]));
92107 + atomic_read_unchecked(&rcu_torture_wcount[i]));
92108 }
92109 page += sprintf(page, "\n");
92110 if (cur_ops->stats)
92111 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
92112
92113 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
92114
92115 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92116 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92117 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
92118 else if (torture_onoff_failures())
92119 rcu_torture_print_module_parms(cur_ops,
92120 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
92121
92122 rcu_torture_current = NULL;
92123 rcu_torture_current_version = 0;
92124 - atomic_set(&n_rcu_torture_alloc, 0);
92125 - atomic_set(&n_rcu_torture_alloc_fail, 0);
92126 - atomic_set(&n_rcu_torture_free, 0);
92127 - atomic_set(&n_rcu_torture_mberror, 0);
92128 - atomic_set(&n_rcu_torture_error, 0);
92129 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
92130 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
92131 + atomic_set_unchecked(&n_rcu_torture_free, 0);
92132 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
92133 + atomic_set_unchecked(&n_rcu_torture_error, 0);
92134 n_rcu_torture_barrier_error = 0;
92135 n_rcu_torture_boost_ktrerror = 0;
92136 n_rcu_torture_boost_rterror = 0;
92137 n_rcu_torture_boost_failure = 0;
92138 n_rcu_torture_boosts = 0;
92139 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
92140 - atomic_set(&rcu_torture_wcount[i], 0);
92141 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92142 for_each_possible_cpu(cpu) {
92143 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92144 per_cpu(rcu_torture_count, cpu)[i] = 0;
92145 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92146 index d9efcc1..ea543e9 100644
92147 --- a/kernel/rcu/tiny.c
92148 +++ b/kernel/rcu/tiny.c
92149 @@ -42,7 +42,7 @@
92150 /* Forward declarations for tiny_plugin.h. */
92151 struct rcu_ctrlblk;
92152 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92153 -static void rcu_process_callbacks(struct softirq_action *unused);
92154 +static void rcu_process_callbacks(void);
92155 static void __call_rcu(struct rcu_head *head,
92156 void (*func)(struct rcu_head *rcu),
92157 struct rcu_ctrlblk *rcp);
92158 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92159 false));
92160 }
92161
92162 -static void rcu_process_callbacks(struct softirq_action *unused)
92163 +static __latent_entropy void rcu_process_callbacks(void)
92164 {
92165 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92166 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92167 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92168 index 858c565..7efd915 100644
92169 --- a/kernel/rcu/tiny_plugin.h
92170 +++ b/kernel/rcu/tiny_plugin.h
92171 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92172 dump_stack();
92173 }
92174 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92175 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92176 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92177 3 * rcu_jiffies_till_stall_check() + 3;
92178 else if (ULONG_CMP_GE(j, js))
92179 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92180 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92181 }
92182
92183 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92184 {
92185 rcp->ticks_this_gp = 0;
92186 rcp->gp_start = jiffies;
92187 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92188 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92189 }
92190
92191 static void check_cpu_stalls(void)
92192 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92193 index 1b70cb6..ea62b0a 100644
92194 --- a/kernel/rcu/tree.c
92195 +++ b/kernel/rcu/tree.c
92196 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
92197 */
92198 rdtp = this_cpu_ptr(&rcu_dynticks);
92199 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92200 - atomic_add(2, &rdtp->dynticks); /* QS. */
92201 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92202 smp_mb__after_atomic(); /* Later stuff after QS. */
92203 break;
92204 }
92205 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92206 rcu_prepare_for_idle(smp_processor_id());
92207 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92208 smp_mb__before_atomic(); /* See above. */
92209 - atomic_inc(&rdtp->dynticks);
92210 + atomic_inc_unchecked(&rdtp->dynticks);
92211 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92212 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92213 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92214
92215 /*
92216 * It is illegal to enter an extended quiescent state while
92217 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92218 int user)
92219 {
92220 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92221 - atomic_inc(&rdtp->dynticks);
92222 + atomic_inc_unchecked(&rdtp->dynticks);
92223 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92224 smp_mb__after_atomic(); /* See above. */
92225 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92226 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92227 rcu_cleanup_after_idle(smp_processor_id());
92228 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92229 if (!user && !is_idle_task(current)) {
92230 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
92231 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92232
92233 if (rdtp->dynticks_nmi_nesting == 0 &&
92234 - (atomic_read(&rdtp->dynticks) & 0x1))
92235 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92236 return;
92237 rdtp->dynticks_nmi_nesting++;
92238 smp_mb__before_atomic(); /* Force delay from prior write. */
92239 - atomic_inc(&rdtp->dynticks);
92240 + atomic_inc_unchecked(&rdtp->dynticks);
92241 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92242 smp_mb__after_atomic(); /* See above. */
92243 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92244 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92245 }
92246
92247 /**
92248 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
92249 return;
92250 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92251 smp_mb__before_atomic(); /* See above. */
92252 - atomic_inc(&rdtp->dynticks);
92253 + atomic_inc_unchecked(&rdtp->dynticks);
92254 smp_mb__after_atomic(); /* Force delay to next write. */
92255 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92256 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92257 }
92258
92259 /**
92260 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
92261 */
92262 bool notrace __rcu_is_watching(void)
92263 {
92264 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92265 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92266 }
92267
92268 /**
92269 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92270 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92271 bool *isidle, unsigned long *maxj)
92272 {
92273 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92274 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92275 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92276 if ((rdp->dynticks_snap & 0x1) == 0) {
92277 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92278 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92279 int *rcrmp;
92280 unsigned int snap;
92281
92282 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92283 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92284 snap = (unsigned int)rdp->dynticks_snap;
92285
92286 /*
92287 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92288 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92289 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92290 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92291 - ACCESS_ONCE(rdp->cond_resched_completed) =
92292 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92293 ACCESS_ONCE(rdp->mynode->completed);
92294 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92295 - ACCESS_ONCE(*rcrmp) =
92296 + ACCESS_ONCE_RW(*rcrmp) =
92297 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92298 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92299 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92300 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92301 rsp->gp_start = j;
92302 smp_wmb(); /* Record start time before stall time. */
92303 j1 = rcu_jiffies_till_stall_check();
92304 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92305 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92306 rsp->jiffies_resched = j + j1 / 2;
92307 }
92308
92309 @@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92310 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92311 return;
92312 }
92313 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92314 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92315 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92316
92317 /*
92318 @@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92319
92320 raw_spin_lock_irqsave(&rnp->lock, flags);
92321 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92322 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92323 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92324 3 * rcu_jiffies_till_stall_check() + 3;
92325 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92326
92327 @@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92328 struct rcu_state *rsp;
92329
92330 for_each_rcu_flavor(rsp)
92331 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92332 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92333 }
92334
92335 /*
92336 @@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92337 raw_spin_unlock_irq(&rnp->lock);
92338 return 0;
92339 }
92340 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92341 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92342
92343 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92344 /*
92345 @@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92346 rdp = this_cpu_ptr(rsp->rda);
92347 rcu_preempt_check_blocked_tasks(rnp);
92348 rnp->qsmask = rnp->qsmaskinit;
92349 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92350 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92351 WARN_ON_ONCE(rnp->completed != rsp->completed);
92352 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92353 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92354 if (rnp == rdp->mynode)
92355 (void)__note_gp_changes(rsp, rnp, rdp);
92356 rcu_preempt_boost_start_gp(rnp);
92357 @@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92358 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92359 raw_spin_lock_irq(&rnp->lock);
92360 smp_mb__after_unlock_lock();
92361 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92362 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92363 raw_spin_unlock_irq(&rnp->lock);
92364 }
92365 return fqs_state;
92366 @@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92367 rcu_for_each_node_breadth_first(rsp, rnp) {
92368 raw_spin_lock_irq(&rnp->lock);
92369 smp_mb__after_unlock_lock();
92370 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92371 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92372 rdp = this_cpu_ptr(rsp->rda);
92373 if (rnp == rdp->mynode)
92374 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92375 @@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92376 rcu_nocb_gp_set(rnp, nocb);
92377
92378 /* Declare grace period done. */
92379 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92380 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92381 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92382 rsp->fqs_state = RCU_GP_IDLE;
92383 rdp = this_cpu_ptr(rsp->rda);
92384 /* Advance CBs to reduce false positives below. */
92385 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92386 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92387 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92388 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92389 trace_rcu_grace_period(rsp->name,
92390 ACCESS_ONCE(rsp->gpnum),
92391 TPS("newreq"));
92392 @@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92393 */
92394 return false;
92395 }
92396 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92397 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92398 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92399 TPS("newreq"));
92400
92401 @@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92402 rsp->qlen += rdp->qlen;
92403 rdp->n_cbs_orphaned += rdp->qlen;
92404 rdp->qlen_lazy = 0;
92405 - ACCESS_ONCE(rdp->qlen) = 0;
92406 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92407 }
92408
92409 /*
92410 @@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92411 }
92412 smp_mb(); /* List handling before counting for rcu_barrier(). */
92413 rdp->qlen_lazy -= count_lazy;
92414 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92415 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92416 rdp->n_cbs_invoked += count;
92417
92418 /* Reinstate batch limit if we have worked down the excess. */
92419 @@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92420 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92421 return; /* Someone beat us to it. */
92422 }
92423 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92424 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92425 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92426 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
92427 }
92428 @@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92429 /*
92430 * Do RCU core processing for the current CPU.
92431 */
92432 -static void rcu_process_callbacks(struct softirq_action *unused)
92433 +static void rcu_process_callbacks(void)
92434 {
92435 struct rcu_state *rsp;
92436
92437 @@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92438 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92439 if (debug_rcu_head_queue(head)) {
92440 /* Probable double call_rcu(), so leak the callback. */
92441 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92442 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92443 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92444 return;
92445 }
92446 @@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92447 local_irq_restore(flags);
92448 return;
92449 }
92450 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92451 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92452 if (lazy)
92453 rdp->qlen_lazy++;
92454 else
92455 @@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92456 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92457 * course be required on a 64-bit system.
92458 */
92459 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92460 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92461 (ulong)atomic_long_read(&rsp->expedited_done) +
92462 ULONG_MAX / 8)) {
92463 synchronize_sched();
92464 - atomic_long_inc(&rsp->expedited_wrap);
92465 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92466 return;
92467 }
92468
92469 @@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92470 * Take a ticket. Note that atomic_inc_return() implies a
92471 * full memory barrier.
92472 */
92473 - snap = atomic_long_inc_return(&rsp->expedited_start);
92474 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92475 firstsnap = snap;
92476 get_online_cpus();
92477 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92478 @@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92479 synchronize_sched_expedited_cpu_stop,
92480 NULL) == -EAGAIN) {
92481 put_online_cpus();
92482 - atomic_long_inc(&rsp->expedited_tryfail);
92483 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92484
92485 /* Check to see if someone else did our work for us. */
92486 s = atomic_long_read(&rsp->expedited_done);
92487 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92488 /* ensure test happens before caller kfree */
92489 smp_mb__before_atomic(); /* ^^^ */
92490 - atomic_long_inc(&rsp->expedited_workdone1);
92491 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92492 return;
92493 }
92494
92495 @@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92496 udelay(trycount * num_online_cpus());
92497 } else {
92498 wait_rcu_gp(call_rcu_sched);
92499 - atomic_long_inc(&rsp->expedited_normal);
92500 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92501 return;
92502 }
92503
92504 @@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92505 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92506 /* ensure test happens before caller kfree */
92507 smp_mb__before_atomic(); /* ^^^ */
92508 - atomic_long_inc(&rsp->expedited_workdone2);
92509 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92510 return;
92511 }
92512
92513 @@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92514 * period works for us.
92515 */
92516 get_online_cpus();
92517 - snap = atomic_long_read(&rsp->expedited_start);
92518 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92519 smp_mb(); /* ensure read is before try_stop_cpus(). */
92520 }
92521 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92522 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92523
92524 /*
92525 * Everyone up to our most recent fetch is covered by our grace
92526 @@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92527 * than we did already did their update.
92528 */
92529 do {
92530 - atomic_long_inc(&rsp->expedited_done_tries);
92531 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92532 s = atomic_long_read(&rsp->expedited_done);
92533 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92534 /* ensure test happens before caller kfree */
92535 smp_mb__before_atomic(); /* ^^^ */
92536 - atomic_long_inc(&rsp->expedited_done_lost);
92537 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92538 break;
92539 }
92540 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92541 - atomic_long_inc(&rsp->expedited_done_exit);
92542 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92543
92544 put_online_cpus();
92545 }
92546 @@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92547 * ACCESS_ONCE() to prevent the compiler from speculating
92548 * the increment to precede the early-exit check.
92549 */
92550 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92551 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92552 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92553 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92554 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92555 @@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92556
92557 /* Increment ->n_barrier_done to prevent duplicate work. */
92558 smp_mb(); /* Keep increment after above mechanism. */
92559 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92560 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92561 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92562 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92563 smp_mb(); /* Keep increment before caller's subsequent code. */
92564 @@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92565 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92566 init_callback_list(rdp);
92567 rdp->qlen_lazy = 0;
92568 - ACCESS_ONCE(rdp->qlen) = 0;
92569 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92570 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92571 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92572 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92573 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92574 rdp->cpu = cpu;
92575 rdp->rsp = rsp;
92576 rcu_boot_init_nocb_percpu_data(rdp);
92577 @@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92578 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92579 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92580 rcu_sysidle_init_percpu_data(rdp->dynticks);
92581 - atomic_set(&rdp->dynticks->dynticks,
92582 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92583 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92584 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92585 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92586
92587 /* Add CPU to rcu_node bitmasks. */
92588 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92589 index 6a86eb7..022b506 100644
92590 --- a/kernel/rcu/tree.h
92591 +++ b/kernel/rcu/tree.h
92592 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92593 long long dynticks_nesting; /* Track irq/process nesting level. */
92594 /* Process level is worth LLONG_MAX/2. */
92595 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92596 - atomic_t dynticks; /* Even value for idle, else odd. */
92597 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92598 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92599 long long dynticks_idle_nesting;
92600 /* irq/process nesting level from idle. */
92601 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92602 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92603 /* "Idle" excludes userspace execution. */
92604 unsigned long dynticks_idle_jiffies;
92605 /* End of last non-NMI non-idle period. */
92606 @@ -461,17 +461,17 @@ struct rcu_state {
92607 /* _rcu_barrier(). */
92608 /* End of fields guarded by barrier_mutex. */
92609
92610 - atomic_long_t expedited_start; /* Starting ticket. */
92611 - atomic_long_t expedited_done; /* Done ticket. */
92612 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92613 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92614 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92615 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92616 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92617 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92618 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92619 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92620 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92621 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92622 + atomic_long_t expedited_done; /* Done ticket. */
92623 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92624 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92625 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92626 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92627 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92628 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92629 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92630 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92631 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92632
92633 unsigned long jiffies_force_qs; /* Time at which to invoke */
92634 /* force_quiescent_state(). */
92635 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92636 index a7997e2..9787c9e 100644
92637 --- a/kernel/rcu/tree_plugin.h
92638 +++ b/kernel/rcu/tree_plugin.h
92639 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92640 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92641 {
92642 return !rcu_preempted_readers_exp(rnp) &&
92643 - ACCESS_ONCE(rnp->expmask) == 0;
92644 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92645 }
92646
92647 /*
92648 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92649
92650 /* Clean up and exit. */
92651 smp_mb(); /* ensure expedited GP seen before counter increment. */
92652 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92653 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92654 unlock_mb_ret:
92655 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92656 mb_ret:
92657 @@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92658 free_cpumask_var(cm);
92659 }
92660
92661 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92662 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92663 .store = &rcu_cpu_kthread_task,
92664 .thread_should_run = rcu_cpu_kthread_should_run,
92665 .thread_fn = rcu_cpu_kthread,
92666 @@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92667 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92668 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92669 cpu, ticks_value, ticks_title,
92670 - atomic_read(&rdtp->dynticks) & 0xfff,
92671 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92672 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92673 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92674 fast_no_hz);
92675 @@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92676 return;
92677 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92678 /* Prior xchg orders against prior callback enqueue. */
92679 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92680 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92681 wake_up(&rdp_leader->nocb_wq);
92682 }
92683 }
92684 @@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92685
92686 /* Enqueue the callback on the nocb list and update counts. */
92687 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92688 - ACCESS_ONCE(*old_rhpp) = rhp;
92689 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92690 atomic_long_add(rhcount, &rdp->nocb_q_count);
92691 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92692
92693 @@ -2272,7 +2272,7 @@ wait_again:
92694 continue; /* No CBs here, try next follower. */
92695
92696 /* Move callbacks to wait-for-GP list, which is empty. */
92697 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92698 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92699 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92700 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92701 rdp->nocb_gp_count_lazy =
92702 @@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92703 list = ACCESS_ONCE(rdp->nocb_follower_head);
92704 BUG_ON(!list);
92705 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92706 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92707 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92708 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92709 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92710 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92711 @@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92712 list = next;
92713 }
92714 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92715 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
92716 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92717 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92718 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92719 rdp->n_nocbs_invoked += c;
92720 }
92721 return 0;
92722 @@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92723 {
92724 if (!rcu_nocb_need_deferred_wakeup(rdp))
92725 return;
92726 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92727 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92728 wake_nocb_leader(rdp, false);
92729 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92730 }
92731 @@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92732 t = kthread_run(rcu_nocb_kthread, rdp,
92733 "rcuo%c/%d", rsp->abbr, cpu);
92734 BUG_ON(IS_ERR(t));
92735 - ACCESS_ONCE(rdp->nocb_kthread) = t;
92736 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92737 }
92738 }
92739
92740 @@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92741
92742 /* Record start of fully idle period. */
92743 j = jiffies;
92744 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92745 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92746 smp_mb__before_atomic();
92747 - atomic_inc(&rdtp->dynticks_idle);
92748 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92749 smp_mb__after_atomic();
92750 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92751 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92752 }
92753
92754 /*
92755 @@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92756
92757 /* Record end of idle period. */
92758 smp_mb__before_atomic();
92759 - atomic_inc(&rdtp->dynticks_idle);
92760 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92761 smp_mb__after_atomic();
92762 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92763 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92764
92765 /*
92766 * If we are the timekeeping CPU, we are permitted to be non-idle
92767 @@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92768 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92769
92770 /* Pick up current idle and NMI-nesting counter and check. */
92771 - cur = atomic_read(&rdtp->dynticks_idle);
92772 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92773 if (cur & 0x1) {
92774 *isidle = false; /* We are not idle! */
92775 return;
92776 @@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92777 case RCU_SYSIDLE_NOT:
92778
92779 /* First time all are idle, so note a short idle period. */
92780 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92781 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92782 break;
92783
92784 case RCU_SYSIDLE_SHORT:
92785 @@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92786 {
92787 smp_mb();
92788 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92789 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92790 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92791 }
92792
92793 /*
92794 @@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92795 smp_mb(); /* grace period precedes setting inuse. */
92796
92797 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92798 - ACCESS_ONCE(rshp->inuse) = 0;
92799 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92800 }
92801
92802 /*
92803 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92804 index 5cdc62e..cc52e88 100644
92805 --- a/kernel/rcu/tree_trace.c
92806 +++ b/kernel/rcu/tree_trace.c
92807 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92808 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92809 rdp->passed_quiesce, rdp->qs_pending);
92810 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92811 - atomic_read(&rdp->dynticks->dynticks),
92812 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92813 rdp->dynticks->dynticks_nesting,
92814 rdp->dynticks->dynticks_nmi_nesting,
92815 rdp->dynticks_fqs);
92816 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92817 struct rcu_state *rsp = (struct rcu_state *)m->private;
92818
92819 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",
92820 - atomic_long_read(&rsp->expedited_start),
92821 + atomic_long_read_unchecked(&rsp->expedited_start),
92822 atomic_long_read(&rsp->expedited_done),
92823 - atomic_long_read(&rsp->expedited_wrap),
92824 - atomic_long_read(&rsp->expedited_tryfail),
92825 - atomic_long_read(&rsp->expedited_workdone1),
92826 - atomic_long_read(&rsp->expedited_workdone2),
92827 - atomic_long_read(&rsp->expedited_normal),
92828 - atomic_long_read(&rsp->expedited_stoppedcpus),
92829 - atomic_long_read(&rsp->expedited_done_tries),
92830 - atomic_long_read(&rsp->expedited_done_lost),
92831 - atomic_long_read(&rsp->expedited_done_exit));
92832 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92833 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92834 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92835 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92836 + atomic_long_read_unchecked(&rsp->expedited_normal),
92837 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92838 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92839 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92840 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92841 return 0;
92842 }
92843
92844 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92845 index 4056d79..c11741a 100644
92846 --- a/kernel/rcu/update.c
92847 +++ b/kernel/rcu/update.c
92848 @@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92849 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92850 */
92851 if (till_stall_check < 3) {
92852 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92853 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92854 till_stall_check = 3;
92855 } else if (till_stall_check > 300) {
92856 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92857 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92858 till_stall_check = 300;
92859 }
92860 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92861 diff --git a/kernel/resource.c b/kernel/resource.c
92862 index 60c5a38..ed77193 100644
92863 --- a/kernel/resource.c
92864 +++ b/kernel/resource.c
92865 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92866
92867 static int __init ioresources_init(void)
92868 {
92869 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92870 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92871 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92872 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92873 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92874 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92875 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92876 +#endif
92877 +#else
92878 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92879 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92880 +#endif
92881 return 0;
92882 }
92883 __initcall(ioresources_init);
92884 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92885 index e73efba..c9bfbd4 100644
92886 --- a/kernel/sched/auto_group.c
92887 +++ b/kernel/sched/auto_group.c
92888 @@ -11,7 +11,7 @@
92889
92890 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92891 static struct autogroup autogroup_default;
92892 -static atomic_t autogroup_seq_nr;
92893 +static atomic_unchecked_t autogroup_seq_nr;
92894
92895 void __init autogroup_init(struct task_struct *init_task)
92896 {
92897 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92898
92899 kref_init(&ag->kref);
92900 init_rwsem(&ag->lock);
92901 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92902 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92903 ag->tg = tg;
92904 #ifdef CONFIG_RT_GROUP_SCHED
92905 /*
92906 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92907 index a63f4dc..349bbb0 100644
92908 --- a/kernel/sched/completion.c
92909 +++ b/kernel/sched/completion.c
92910 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92911 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92912 * or number of jiffies left till timeout) if completed.
92913 */
92914 -long __sched
92915 +long __sched __intentional_overflow(-1)
92916 wait_for_completion_interruptible_timeout(struct completion *x,
92917 unsigned long timeout)
92918 {
92919 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92920 *
92921 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92922 */
92923 -int __sched wait_for_completion_killable(struct completion *x)
92924 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92925 {
92926 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92927 if (t == -ERESTARTSYS)
92928 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92929 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92930 * or number of jiffies left till timeout) if completed.
92931 */
92932 -long __sched
92933 +long __sched __intentional_overflow(-1)
92934 wait_for_completion_killable_timeout(struct completion *x,
92935 unsigned long timeout)
92936 {
92937 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92938 index ec1a286..6b516b8 100644
92939 --- a/kernel/sched/core.c
92940 +++ b/kernel/sched/core.c
92941 @@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
92942 int sysctl_numa_balancing(struct ctl_table *table, int write,
92943 void __user *buffer, size_t *lenp, loff_t *ppos)
92944 {
92945 - struct ctl_table t;
92946 + ctl_table_no_const t;
92947 int err;
92948 int state = numabalancing_enabled;
92949
92950 @@ -2320,8 +2320,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92951 next->active_mm = oldmm;
92952 atomic_inc(&oldmm->mm_count);
92953 enter_lazy_tlb(oldmm, next);
92954 - } else
92955 + } else {
92956 switch_mm(oldmm, mm, next);
92957 + populate_stack();
92958 + }
92959
92960 if (!prev->mm) {
92961 prev->active_mm = NULL;
92962 @@ -3103,6 +3105,8 @@ int can_nice(const struct task_struct *p, const int nice)
92963 /* convert nice value [19,-20] to rlimit style value [1,40] */
92964 int nice_rlim = nice_to_rlimit(nice);
92965
92966 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92967 +
92968 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92969 capable(CAP_SYS_NICE));
92970 }
92971 @@ -3129,7 +3133,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92972 nice = task_nice(current) + increment;
92973
92974 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92975 - if (increment < 0 && !can_nice(current, nice))
92976 + if (increment < 0 && (!can_nice(current, nice) ||
92977 + gr_handle_chroot_nice()))
92978 return -EPERM;
92979
92980 retval = security_task_setnice(current, nice);
92981 @@ -3408,6 +3413,7 @@ recheck:
92982 if (policy != p->policy && !rlim_rtprio)
92983 return -EPERM;
92984
92985 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92986 /* can't increase priority */
92987 if (attr->sched_priority > p->rt_priority &&
92988 attr->sched_priority > rlim_rtprio)
92989 @@ -4797,6 +4803,7 @@ void idle_task_exit(void)
92990
92991 if (mm != &init_mm) {
92992 switch_mm(mm, &init_mm, current);
92993 + populate_stack();
92994 finish_arch_post_lock_switch();
92995 }
92996 mmdrop(mm);
92997 @@ -4892,7 +4899,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92998
92999 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
93000
93001 -static struct ctl_table sd_ctl_dir[] = {
93002 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
93003 {
93004 .procname = "sched_domain",
93005 .mode = 0555,
93006 @@ -4909,17 +4916,17 @@ static struct ctl_table sd_ctl_root[] = {
93007 {}
93008 };
93009
93010 -static struct ctl_table *sd_alloc_ctl_entry(int n)
93011 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
93012 {
93013 - struct ctl_table *entry =
93014 + ctl_table_no_const *entry =
93015 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
93016
93017 return entry;
93018 }
93019
93020 -static void sd_free_ctl_entry(struct ctl_table **tablep)
93021 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
93022 {
93023 - struct ctl_table *entry;
93024 + ctl_table_no_const *entry;
93025
93026 /*
93027 * In the intermediate directories, both the child directory and
93028 @@ -4927,22 +4934,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
93029 * will always be set. In the lowest directory the names are
93030 * static strings and all have proc handlers.
93031 */
93032 - for (entry = *tablep; entry->mode; entry++) {
93033 - if (entry->child)
93034 - sd_free_ctl_entry(&entry->child);
93035 + for (entry = tablep; entry->mode; entry++) {
93036 + if (entry->child) {
93037 + sd_free_ctl_entry(entry->child);
93038 + pax_open_kernel();
93039 + entry->child = NULL;
93040 + pax_close_kernel();
93041 + }
93042 if (entry->proc_handler == NULL)
93043 kfree(entry->procname);
93044 }
93045
93046 - kfree(*tablep);
93047 - *tablep = NULL;
93048 + kfree(tablep);
93049 }
93050
93051 static int min_load_idx = 0;
93052 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93053
93054 static void
93055 -set_table_entry(struct ctl_table *entry,
93056 +set_table_entry(ctl_table_no_const *entry,
93057 const char *procname, void *data, int maxlen,
93058 umode_t mode, proc_handler *proc_handler,
93059 bool load_idx)
93060 @@ -4962,7 +4972,7 @@ set_table_entry(struct ctl_table *entry,
93061 static struct ctl_table *
93062 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93063 {
93064 - struct ctl_table *table = sd_alloc_ctl_entry(14);
93065 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93066
93067 if (table == NULL)
93068 return NULL;
93069 @@ -5000,9 +5010,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
93070 return table;
93071 }
93072
93073 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
93074 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
93075 {
93076 - struct ctl_table *entry, *table;
93077 + ctl_table_no_const *entry, *table;
93078 struct sched_domain *sd;
93079 int domain_num = 0, i;
93080 char buf[32];
93081 @@ -5029,11 +5039,13 @@ static struct ctl_table_header *sd_sysctl_header;
93082 static void register_sched_domain_sysctl(void)
93083 {
93084 int i, cpu_num = num_possible_cpus();
93085 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
93086 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93087 char buf[32];
93088
93089 WARN_ON(sd_ctl_dir[0].child);
93090 + pax_open_kernel();
93091 sd_ctl_dir[0].child = entry;
93092 + pax_close_kernel();
93093
93094 if (entry == NULL)
93095 return;
93096 @@ -5056,8 +5068,12 @@ static void unregister_sched_domain_sysctl(void)
93097 if (sd_sysctl_header)
93098 unregister_sysctl_table(sd_sysctl_header);
93099 sd_sysctl_header = NULL;
93100 - if (sd_ctl_dir[0].child)
93101 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
93102 + if (sd_ctl_dir[0].child) {
93103 + sd_free_ctl_entry(sd_ctl_dir[0].child);
93104 + pax_open_kernel();
93105 + sd_ctl_dir[0].child = NULL;
93106 + pax_close_kernel();
93107 + }
93108 }
93109 #else
93110 static void register_sched_domain_sysctl(void)
93111 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93112 index bfa3c86..e58767c 100644
93113 --- a/kernel/sched/fair.c
93114 +++ b/kernel/sched/fair.c
93115 @@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93116
93117 static void reset_ptenuma_scan(struct task_struct *p)
93118 {
93119 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
93120 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93121 p->mm->numa_scan_offset = 0;
93122 }
93123
93124 @@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93125 * run_rebalance_domains is triggered when needed from the scheduler tick.
93126 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93127 */
93128 -static void run_rebalance_domains(struct softirq_action *h)
93129 +static __latent_entropy void run_rebalance_domains(void)
93130 {
93131 struct rq *this_rq = this_rq();
93132 enum cpu_idle_type idle = this_rq->idle_balance ?
93133 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93134 index 579712f..a338a9d 100644
93135 --- a/kernel/sched/sched.h
93136 +++ b/kernel/sched/sched.h
93137 @@ -1146,7 +1146,7 @@ struct sched_class {
93138 #ifdef CONFIG_FAIR_GROUP_SCHED
93139 void (*task_move_group) (struct task_struct *p, int on_rq);
93140 #endif
93141 -};
93142 +} __do_const;
93143
93144 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93145 {
93146 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93147 index 44eb005..84922be 100644
93148 --- a/kernel/seccomp.c
93149 +++ b/kernel/seccomp.c
93150 @@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93151 if (!filter)
93152 goto free_prog;
93153
93154 - filter->prog = kzalloc(bpf_prog_size(new_len),
93155 - GFP_KERNEL|__GFP_NOWARN);
93156 + filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
93157 if (!filter->prog)
93158 goto free_filter;
93159
93160 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
93161 if (ret)
93162 goto free_filter_prog;
93163 - kfree(fp);
93164
93165 + kfree(fp);
93166 atomic_set(&filter->usage, 1);
93167 filter->prog->len = new_len;
93168
93169 @@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93170 return filter;
93171
93172 free_filter_prog:
93173 - kfree(filter->prog);
93174 + __bpf_prog_free(filter->prog);
93175 free_filter:
93176 kfree(filter);
93177 free_prog:
93178 diff --git a/kernel/signal.c b/kernel/signal.c
93179 index 8f0876f..1153a5a 100644
93180 --- a/kernel/signal.c
93181 +++ b/kernel/signal.c
93182 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93183
93184 int print_fatal_signals __read_mostly;
93185
93186 -static void __user *sig_handler(struct task_struct *t, int sig)
93187 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
93188 {
93189 return t->sighand->action[sig - 1].sa.sa_handler;
93190 }
93191
93192 -static int sig_handler_ignored(void __user *handler, int sig)
93193 +static int sig_handler_ignored(__sighandler_t handler, int sig)
93194 {
93195 /* Is it explicitly or implicitly ignored? */
93196 return handler == SIG_IGN ||
93197 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93198
93199 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93200 {
93201 - void __user *handler;
93202 + __sighandler_t handler;
93203
93204 handler = sig_handler(t, sig);
93205
93206 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93207 atomic_inc(&user->sigpending);
93208 rcu_read_unlock();
93209
93210 + if (!override_rlimit)
93211 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93212 +
93213 if (override_rlimit ||
93214 atomic_read(&user->sigpending) <=
93215 task_rlimit(t, RLIMIT_SIGPENDING)) {
93216 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93217
93218 int unhandled_signal(struct task_struct *tsk, int sig)
93219 {
93220 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93221 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93222 if (is_global_init(tsk))
93223 return 1;
93224 if (handler != SIG_IGN && handler != SIG_DFL)
93225 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93226 }
93227 }
93228
93229 + /* allow glibc communication via tgkill to other threads in our
93230 + thread group */
93231 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93232 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93233 + && gr_handle_signal(t, sig))
93234 + return -EPERM;
93235 +
93236 return security_task_kill(t, info, sig, 0);
93237 }
93238
93239 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93240 return send_signal(sig, info, p, 1);
93241 }
93242
93243 -static int
93244 +int
93245 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93246 {
93247 return send_signal(sig, info, t, 0);
93248 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93249 unsigned long int flags;
93250 int ret, blocked, ignored;
93251 struct k_sigaction *action;
93252 + int is_unhandled = 0;
93253
93254 spin_lock_irqsave(&t->sighand->siglock, flags);
93255 action = &t->sighand->action[sig-1];
93256 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93257 }
93258 if (action->sa.sa_handler == SIG_DFL)
93259 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93260 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93261 + is_unhandled = 1;
93262 ret = specific_send_sig_info(sig, info, t);
93263 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93264
93265 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93266 + normal operation */
93267 + if (is_unhandled) {
93268 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93269 + gr_handle_crash(t, sig);
93270 + }
93271 +
93272 return ret;
93273 }
93274
93275 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93276 ret = check_kill_permission(sig, info, p);
93277 rcu_read_unlock();
93278
93279 - if (!ret && sig)
93280 + if (!ret && sig) {
93281 ret = do_send_sig_info(sig, info, p, true);
93282 + if (!ret)
93283 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93284 + }
93285
93286 return ret;
93287 }
93288 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93289 int error = -ESRCH;
93290
93291 rcu_read_lock();
93292 - p = find_task_by_vpid(pid);
93293 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93294 + /* allow glibc communication via tgkill to other threads in our
93295 + thread group */
93296 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93297 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93298 + p = find_task_by_vpid_unrestricted(pid);
93299 + else
93300 +#endif
93301 + p = find_task_by_vpid(pid);
93302 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93303 error = check_kill_permission(sig, info, p);
93304 /*
93305 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93306 }
93307 seg = get_fs();
93308 set_fs(KERNEL_DS);
93309 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93310 - (stack_t __force __user *) &uoss,
93311 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93312 + (stack_t __force_user *) &uoss,
93313 compat_user_stack_pointer());
93314 set_fs(seg);
93315 if (ret >= 0 && uoss_ptr) {
93316 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93317 index eb89e18..a4e6792 100644
93318 --- a/kernel/smpboot.c
93319 +++ b/kernel/smpboot.c
93320 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93321 }
93322 smpboot_unpark_thread(plug_thread, cpu);
93323 }
93324 - list_add(&plug_thread->list, &hotplug_threads);
93325 + pax_list_add(&plug_thread->list, &hotplug_threads);
93326 out:
93327 mutex_unlock(&smpboot_threads_lock);
93328 return ret;
93329 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93330 {
93331 get_online_cpus();
93332 mutex_lock(&smpboot_threads_lock);
93333 - list_del(&plug_thread->list);
93334 + pax_list_del(&plug_thread->list);
93335 smpboot_destroy_threads(plug_thread);
93336 mutex_unlock(&smpboot_threads_lock);
93337 put_online_cpus();
93338 diff --git a/kernel/softirq.c b/kernel/softirq.c
93339 index 5918d22..e95d1926 100644
93340 --- a/kernel/softirq.c
93341 +++ b/kernel/softirq.c
93342 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93343 EXPORT_SYMBOL(irq_stat);
93344 #endif
93345
93346 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93347 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93348
93349 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93350
93351 @@ -266,7 +266,7 @@ restart:
93352 kstat_incr_softirqs_this_cpu(vec_nr);
93353
93354 trace_softirq_entry(vec_nr);
93355 - h->action(h);
93356 + h->action();
93357 trace_softirq_exit(vec_nr);
93358 if (unlikely(prev_count != preempt_count())) {
93359 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93360 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93361 or_softirq_pending(1UL << nr);
93362 }
93363
93364 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93365 +void __init open_softirq(int nr, void (*action)(void))
93366 {
93367 softirq_vec[nr].action = action;
93368 }
93369 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93370 }
93371 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93372
93373 -static void tasklet_action(struct softirq_action *a)
93374 +static void tasklet_action(void)
93375 {
93376 struct tasklet_struct *list;
93377
93378 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93379 }
93380 }
93381
93382 -static void tasklet_hi_action(struct softirq_action *a)
93383 +static __latent_entropy void tasklet_hi_action(void)
93384 {
93385 struct tasklet_struct *list;
93386
93387 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93388 .notifier_call = cpu_callback
93389 };
93390
93391 -static struct smp_hotplug_thread softirq_threads = {
93392 +static struct smp_hotplug_thread softirq_threads __read_only = {
93393 .store = &ksoftirqd,
93394 .thread_should_run = ksoftirqd_should_run,
93395 .thread_fn = run_ksoftirqd,
93396 diff --git a/kernel/sys.c b/kernel/sys.c
93397 index ce81291..df2ca85 100644
93398 --- a/kernel/sys.c
93399 +++ b/kernel/sys.c
93400 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93401 error = -EACCES;
93402 goto out;
93403 }
93404 +
93405 + if (gr_handle_chroot_setpriority(p, niceval)) {
93406 + error = -EACCES;
93407 + goto out;
93408 + }
93409 +
93410 no_nice = security_task_setnice(p, niceval);
93411 if (no_nice) {
93412 error = no_nice;
93413 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93414 goto error;
93415 }
93416
93417 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93418 + goto error;
93419 +
93420 + if (!gid_eq(new->gid, old->gid)) {
93421 + /* make sure we generate a learn log for what will
93422 + end up being a role transition after a full-learning
93423 + policy is generated
93424 + CAP_SETGID is required to perform a transition
93425 + we may not log a CAP_SETGID check above, e.g.
93426 + in the case where new rgid = old egid
93427 + */
93428 + gr_learn_cap(current, new, CAP_SETGID);
93429 + }
93430 +
93431 if (rgid != (gid_t) -1 ||
93432 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93433 new->sgid = new->egid;
93434 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93435 old = current_cred();
93436
93437 retval = -EPERM;
93438 +
93439 + if (gr_check_group_change(kgid, kgid, kgid))
93440 + goto error;
93441 +
93442 if (ns_capable(old->user_ns, CAP_SETGID))
93443 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93444 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93445 @@ -403,7 +427,7 @@ error:
93446 /*
93447 * change the user struct in a credentials set to match the new UID
93448 */
93449 -static int set_user(struct cred *new)
93450 +int set_user(struct cred *new)
93451 {
93452 struct user_struct *new_user;
93453
93454 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93455 goto error;
93456 }
93457
93458 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93459 + goto error;
93460 +
93461 if (!uid_eq(new->uid, old->uid)) {
93462 + /* make sure we generate a learn log for what will
93463 + end up being a role transition after a full-learning
93464 + policy is generated
93465 + CAP_SETUID is required to perform a transition
93466 + we may not log a CAP_SETUID check above, e.g.
93467 + in the case where new ruid = old euid
93468 + */
93469 + gr_learn_cap(current, new, CAP_SETUID);
93470 retval = set_user(new);
93471 if (retval < 0)
93472 goto error;
93473 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93474 old = current_cred();
93475
93476 retval = -EPERM;
93477 +
93478 + if (gr_check_crash_uid(kuid))
93479 + goto error;
93480 + if (gr_check_user_change(kuid, kuid, kuid))
93481 + goto error;
93482 +
93483 if (ns_capable(old->user_ns, CAP_SETUID)) {
93484 new->suid = new->uid = kuid;
93485 if (!uid_eq(kuid, old->uid)) {
93486 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93487 goto error;
93488 }
93489
93490 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93491 + goto error;
93492 +
93493 if (ruid != (uid_t) -1) {
93494 new->uid = kruid;
93495 if (!uid_eq(kruid, old->uid)) {
93496 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93497 goto error;
93498 }
93499
93500 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93501 + goto error;
93502 +
93503 if (rgid != (gid_t) -1)
93504 new->gid = krgid;
93505 if (egid != (gid_t) -1)
93506 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93507 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93508 ns_capable(old->user_ns, CAP_SETUID)) {
93509 if (!uid_eq(kuid, old->fsuid)) {
93510 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93511 + goto error;
93512 +
93513 new->fsuid = kuid;
93514 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93515 goto change_okay;
93516 }
93517 }
93518
93519 +error:
93520 abort_creds(new);
93521 return old_fsuid;
93522
93523 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93524 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93525 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93526 ns_capable(old->user_ns, CAP_SETGID)) {
93527 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93528 + goto error;
93529 +
93530 if (!gid_eq(kgid, old->fsgid)) {
93531 new->fsgid = kgid;
93532 goto change_okay;
93533 }
93534 }
93535
93536 +error:
93537 abort_creds(new);
93538 return old_fsgid;
93539
93540 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93541 return -EFAULT;
93542
93543 down_read(&uts_sem);
93544 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93545 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93546 __OLD_UTS_LEN);
93547 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93548 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93549 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93550 __OLD_UTS_LEN);
93551 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93552 - error |= __copy_to_user(&name->release, &utsname()->release,
93553 + error |= __copy_to_user(name->release, &utsname()->release,
93554 __OLD_UTS_LEN);
93555 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93556 - error |= __copy_to_user(&name->version, &utsname()->version,
93557 + error |= __copy_to_user(name->version, &utsname()->version,
93558 __OLD_UTS_LEN);
93559 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93560 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93561 + error |= __copy_to_user(name->machine, &utsname()->machine,
93562 __OLD_UTS_LEN);
93563 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93564 up_read(&uts_sem);
93565 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93566 */
93567 new_rlim->rlim_cur = 1;
93568 }
93569 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93570 + is changed to a lower value. Since tasks can be created by the same
93571 + user in between this limit change and an execve by this task, force
93572 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93573 + */
93574 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93575 + tsk->flags |= PF_NPROC_EXCEEDED;
93576 }
93577 if (!retval) {
93578 if (old_rlim)
93579 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93580 index 75875a7..cd8e838 100644
93581 --- a/kernel/sysctl.c
93582 +++ b/kernel/sysctl.c
93583 @@ -94,7 +94,6 @@
93584
93585
93586 #if defined(CONFIG_SYSCTL)
93587 -
93588 /* External variables not in a header file. */
93589 extern int max_threads;
93590 extern int suid_dumpable;
93591 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93592
93593 /* Constants used for minimum and maximum */
93594 #ifdef CONFIG_LOCKUP_DETECTOR
93595 -static int sixty = 60;
93596 +static int sixty __read_only = 60;
93597 #endif
93598
93599 -static int __maybe_unused neg_one = -1;
93600 +static int __maybe_unused neg_one __read_only = -1;
93601
93602 -static int zero;
93603 -static int __maybe_unused one = 1;
93604 -static int __maybe_unused two = 2;
93605 -static int __maybe_unused four = 4;
93606 -static unsigned long one_ul = 1;
93607 -static int one_hundred = 100;
93608 +static int zero __read_only = 0;
93609 +static int __maybe_unused one __read_only = 1;
93610 +static int __maybe_unused two __read_only = 2;
93611 +static int __maybe_unused three __read_only = 3;
93612 +static int __maybe_unused four __read_only = 4;
93613 +static unsigned long one_ul __read_only = 1;
93614 +static int one_hundred __read_only = 100;
93615 #ifdef CONFIG_PRINTK
93616 -static int ten_thousand = 10000;
93617 +static int ten_thousand __read_only = 10000;
93618 #endif
93619
93620 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93621 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93622 void __user *buffer, size_t *lenp, loff_t *ppos);
93623 #endif
93624
93625 -#ifdef CONFIG_PRINTK
93626 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93627 void __user *buffer, size_t *lenp, loff_t *ppos);
93628 -#endif
93629
93630 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93631 void __user *buffer, size_t *lenp, loff_t *ppos);
93632 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93633
93634 #endif
93635
93636 +extern struct ctl_table grsecurity_table[];
93637 +
93638 static struct ctl_table kern_table[];
93639 static struct ctl_table vm_table[];
93640 static struct ctl_table fs_table[];
93641 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93642 int sysctl_legacy_va_layout;
93643 #endif
93644
93645 +#ifdef CONFIG_PAX_SOFTMODE
93646 +static struct ctl_table pax_table[] = {
93647 + {
93648 + .procname = "softmode",
93649 + .data = &pax_softmode,
93650 + .maxlen = sizeof(unsigned int),
93651 + .mode = 0600,
93652 + .proc_handler = &proc_dointvec,
93653 + },
93654 +
93655 + { }
93656 +};
93657 +#endif
93658 +
93659 /* The default sysctl tables: */
93660
93661 static struct ctl_table sysctl_base_table[] = {
93662 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93663 #endif
93664
93665 static struct ctl_table kern_table[] = {
93666 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93667 + {
93668 + .procname = "grsecurity",
93669 + .mode = 0500,
93670 + .child = grsecurity_table,
93671 + },
93672 +#endif
93673 +
93674 +#ifdef CONFIG_PAX_SOFTMODE
93675 + {
93676 + .procname = "pax",
93677 + .mode = 0500,
93678 + .child = pax_table,
93679 + },
93680 +#endif
93681 +
93682 {
93683 .procname = "sched_child_runs_first",
93684 .data = &sysctl_sched_child_runs_first,
93685 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93686 .data = &modprobe_path,
93687 .maxlen = KMOD_PATH_LEN,
93688 .mode = 0644,
93689 - .proc_handler = proc_dostring,
93690 + .proc_handler = proc_dostring_modpriv,
93691 },
93692 {
93693 .procname = "modules_disabled",
93694 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93695 .extra1 = &zero,
93696 .extra2 = &one,
93697 },
93698 +#endif
93699 {
93700 .procname = "kptr_restrict",
93701 .data = &kptr_restrict,
93702 .maxlen = sizeof(int),
93703 .mode = 0644,
93704 .proc_handler = proc_dointvec_minmax_sysadmin,
93705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93706 + .extra1 = &two,
93707 +#else
93708 .extra1 = &zero,
93709 +#endif
93710 .extra2 = &two,
93711 },
93712 -#endif
93713 {
93714 .procname = "ngroups_max",
93715 .data = &ngroups_max,
93716 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93717 */
93718 {
93719 .procname = "perf_event_paranoid",
93720 - .data = &sysctl_perf_event_paranoid,
93721 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93722 + .data = &sysctl_perf_event_legitimately_concerned,
93723 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93724 .mode = 0644,
93725 - .proc_handler = proc_dointvec,
93726 + /* go ahead, be a hero */
93727 + .proc_handler = proc_dointvec_minmax_sysadmin,
93728 + .extra1 = &neg_one,
93729 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93730 + .extra2 = &three,
93731 +#else
93732 + .extra2 = &two,
93733 +#endif
93734 },
93735 {
93736 .procname = "perf_event_mlock_kb",
93737 @@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93738 .proc_handler = proc_dointvec_minmax,
93739 .extra1 = &zero,
93740 },
93741 + {
93742 + .procname = "heap_stack_gap",
93743 + .data = &sysctl_heap_stack_gap,
93744 + .maxlen = sizeof(sysctl_heap_stack_gap),
93745 + .mode = 0644,
93746 + .proc_handler = proc_doulongvec_minmax,
93747 + },
93748 #else
93749 {
93750 .procname = "nr_trim_pages",
93751 @@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93752 (char __user *)buffer, lenp, ppos);
93753 }
93754
93755 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93756 + void __user *buffer, size_t *lenp, loff_t *ppos)
93757 +{
93758 + if (write && !capable(CAP_SYS_MODULE))
93759 + return -EPERM;
93760 +
93761 + return _proc_do_string(table->data, table->maxlen, write,
93762 + buffer, lenp, ppos);
93763 +}
93764 +
93765 static size_t proc_skip_spaces(char **buf)
93766 {
93767 size_t ret;
93768 @@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93769 len = strlen(tmp);
93770 if (len > *size)
93771 len = *size;
93772 + if (len > sizeof(tmp))
93773 + len = sizeof(tmp);
93774 if (copy_to_user(*buf, tmp, len))
93775 return -EFAULT;
93776 *size -= len;
93777 @@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93778 static int proc_taint(struct ctl_table *table, int write,
93779 void __user *buffer, size_t *lenp, loff_t *ppos)
93780 {
93781 - struct ctl_table t;
93782 + ctl_table_no_const t;
93783 unsigned long tmptaint = get_taint();
93784 int err;
93785
93786 @@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93787 return err;
93788 }
93789
93790 -#ifdef CONFIG_PRINTK
93791 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93792 void __user *buffer, size_t *lenp, loff_t *ppos)
93793 {
93794 @@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93795
93796 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93797 }
93798 -#endif
93799
93800 struct do_proc_dointvec_minmax_conv_param {
93801 int *min;
93802 @@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93803 return -ENOSYS;
93804 }
93805
93806 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93807 + void __user *buffer, size_t *lenp, loff_t *ppos)
93808 +{
93809 + return -ENOSYS;
93810 +}
93811 +
93812 int proc_dointvec(struct ctl_table *table, int write,
93813 void __user *buffer, size_t *lenp, loff_t *ppos)
93814 {
93815 @@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93816 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93817 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93818 EXPORT_SYMBOL(proc_dostring);
93819 +EXPORT_SYMBOL(proc_dostring_modpriv);
93820 EXPORT_SYMBOL(proc_doulongvec_minmax);
93821 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93822 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93823 index 13d2f7c..c93d0b0 100644
93824 --- a/kernel/taskstats.c
93825 +++ b/kernel/taskstats.c
93826 @@ -28,9 +28,12 @@
93827 #include <linux/fs.h>
93828 #include <linux/file.h>
93829 #include <linux/pid_namespace.h>
93830 +#include <linux/grsecurity.h>
93831 #include <net/genetlink.h>
93832 #include <linux/atomic.h>
93833
93834 +extern int gr_is_taskstats_denied(int pid);
93835 +
93836 /*
93837 * Maximum length of a cpumask that can be specified in
93838 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93839 @@ -576,6 +579,9 @@ err:
93840
93841 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93842 {
93843 + if (gr_is_taskstats_denied(current->pid))
93844 + return -EACCES;
93845 +
93846 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93847 return cmd_attr_register_cpumask(info);
93848 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93849 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93850 index a7077d3..dd48a49 100644
93851 --- a/kernel/time/alarmtimer.c
93852 +++ b/kernel/time/alarmtimer.c
93853 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93854 struct platform_device *pdev;
93855 int error = 0;
93856 int i;
93857 - struct k_clock alarm_clock = {
93858 + static struct k_clock alarm_clock = {
93859 .clock_getres = alarm_clock_getres,
93860 .clock_get = alarm_clock_get,
93861 .timer_create = alarm_timer_create,
93862 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93863 index 1c2fe7d..ce7483d 100644
93864 --- a/kernel/time/hrtimer.c
93865 +++ b/kernel/time/hrtimer.c
93866 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93867 local_irq_restore(flags);
93868 }
93869
93870 -static void run_hrtimer_softirq(struct softirq_action *h)
93871 +static __latent_entropy void run_hrtimer_softirq(void)
93872 {
93873 hrtimer_peek_ahead_timers();
93874 }
93875 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93876 index 3b89464..5e38379 100644
93877 --- a/kernel/time/posix-cpu-timers.c
93878 +++ b/kernel/time/posix-cpu-timers.c
93879 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93880
93881 static __init int init_posix_cpu_timers(void)
93882 {
93883 - struct k_clock process = {
93884 + static struct k_clock process = {
93885 .clock_getres = process_cpu_clock_getres,
93886 .clock_get = process_cpu_clock_get,
93887 .timer_create = process_cpu_timer_create,
93888 .nsleep = process_cpu_nsleep,
93889 .nsleep_restart = process_cpu_nsleep_restart,
93890 };
93891 - struct k_clock thread = {
93892 + static struct k_clock thread = {
93893 .clock_getres = thread_cpu_clock_getres,
93894 .clock_get = thread_cpu_clock_get,
93895 .timer_create = thread_cpu_timer_create,
93896 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93897 index 42b463a..a6b008f 100644
93898 --- a/kernel/time/posix-timers.c
93899 +++ b/kernel/time/posix-timers.c
93900 @@ -43,6 +43,7 @@
93901 #include <linux/hash.h>
93902 #include <linux/posix-clock.h>
93903 #include <linux/posix-timers.h>
93904 +#include <linux/grsecurity.h>
93905 #include <linux/syscalls.h>
93906 #include <linux/wait.h>
93907 #include <linux/workqueue.h>
93908 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93909 * which we beg off on and pass to do_sys_settimeofday().
93910 */
93911
93912 -static struct k_clock posix_clocks[MAX_CLOCKS];
93913 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93914
93915 /*
93916 * These ones are defined below.
93917 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93918 */
93919 static __init int init_posix_timers(void)
93920 {
93921 - struct k_clock clock_realtime = {
93922 + static struct k_clock clock_realtime = {
93923 .clock_getres = hrtimer_get_res,
93924 .clock_get = posix_clock_realtime_get,
93925 .clock_set = posix_clock_realtime_set,
93926 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93927 .timer_get = common_timer_get,
93928 .timer_del = common_timer_del,
93929 };
93930 - struct k_clock clock_monotonic = {
93931 + static struct k_clock clock_monotonic = {
93932 .clock_getres = hrtimer_get_res,
93933 .clock_get = posix_ktime_get_ts,
93934 .nsleep = common_nsleep,
93935 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93936 .timer_get = common_timer_get,
93937 .timer_del = common_timer_del,
93938 };
93939 - struct k_clock clock_monotonic_raw = {
93940 + static struct k_clock clock_monotonic_raw = {
93941 .clock_getres = hrtimer_get_res,
93942 .clock_get = posix_get_monotonic_raw,
93943 };
93944 - struct k_clock clock_realtime_coarse = {
93945 + static struct k_clock clock_realtime_coarse = {
93946 .clock_getres = posix_get_coarse_res,
93947 .clock_get = posix_get_realtime_coarse,
93948 };
93949 - struct k_clock clock_monotonic_coarse = {
93950 + static struct k_clock clock_monotonic_coarse = {
93951 .clock_getres = posix_get_coarse_res,
93952 .clock_get = posix_get_monotonic_coarse,
93953 };
93954 - struct k_clock clock_tai = {
93955 + static struct k_clock clock_tai = {
93956 .clock_getres = hrtimer_get_res,
93957 .clock_get = posix_get_tai,
93958 .nsleep = common_nsleep,
93959 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93960 .timer_get = common_timer_get,
93961 .timer_del = common_timer_del,
93962 };
93963 - struct k_clock clock_boottime = {
93964 + static struct k_clock clock_boottime = {
93965 .clock_getres = hrtimer_get_res,
93966 .clock_get = posix_get_boottime,
93967 .nsleep = common_nsleep,
93968 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93969 return;
93970 }
93971
93972 - posix_clocks[clock_id] = *new_clock;
93973 + posix_clocks[clock_id] = new_clock;
93974 }
93975 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93976
93977 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93978 return (id & CLOCKFD_MASK) == CLOCKFD ?
93979 &clock_posix_dynamic : &clock_posix_cpu;
93980
93981 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93982 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93983 return NULL;
93984 - return &posix_clocks[id];
93985 + return posix_clocks[id];
93986 }
93987
93988 static int common_timer_create(struct k_itimer *new_timer)
93989 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93990 struct k_clock *kc = clockid_to_kclock(which_clock);
93991 struct k_itimer *new_timer;
93992 int error, new_timer_id;
93993 - sigevent_t event;
93994 + sigevent_t event = { };
93995 int it_id_set = IT_ID_NOT_SET;
93996
93997 if (!kc)
93998 @@ -1013,6 +1014,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93999 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
94000 return -EFAULT;
94001
94002 + /* only the CLOCK_REALTIME clock can be set, all other clocks
94003 + have their clock_set fptr set to a nosettime dummy function
94004 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
94005 + call common_clock_set, which calls do_sys_settimeofday, which
94006 + we hook
94007 + */
94008 +
94009 return kc->clock_set(which_clock, &new_tp);
94010 }
94011
94012 diff --git a/kernel/time/time.c b/kernel/time/time.c
94013 index a9ae20f..d3fbde7 100644
94014 --- a/kernel/time/time.c
94015 +++ b/kernel/time/time.c
94016 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
94017 return error;
94018
94019 if (tz) {
94020 + /* we log in do_settimeofday called below, so don't log twice
94021 + */
94022 + if (!tv)
94023 + gr_log_timechange();
94024 +
94025 sys_tz = *tz;
94026 update_vsyscall_tz();
94027 if (firsttime) {
94028 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
94029 index ec1791f..6a086cd 100644
94030 --- a/kernel/time/timekeeping.c
94031 +++ b/kernel/time/timekeeping.c
94032 @@ -15,6 +15,7 @@
94033 #include <linux/init.h>
94034 #include <linux/mm.h>
94035 #include <linux/sched.h>
94036 +#include <linux/grsecurity.h>
94037 #include <linux/syscore_ops.h>
94038 #include <linux/clocksource.h>
94039 #include <linux/jiffies.h>
94040 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
94041 if (!timespec_valid_strict(tv))
94042 return -EINVAL;
94043
94044 + gr_log_timechange();
94045 +
94046 raw_spin_lock_irqsave(&timekeeper_lock, flags);
94047 write_seqcount_begin(&tk_core.seq);
94048
94049 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
94050 index 9bbb834..3caa8ed 100644
94051 --- a/kernel/time/timer.c
94052 +++ b/kernel/time/timer.c
94053 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
94054 /*
94055 * This function runs timers and the timer-tq in bottom half context.
94056 */
94057 -static void run_timer_softirq(struct softirq_action *h)
94058 +static __latent_entropy void run_timer_softirq(void)
94059 {
94060 struct tvec_base *base = __this_cpu_read(tvec_bases);
94061
94062 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
94063 *
94064 * In all cases the return value is guaranteed to be non-negative.
94065 */
94066 -signed long __sched schedule_timeout(signed long timeout)
94067 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
94068 {
94069 struct timer_list timer;
94070 unsigned long expire;
94071 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
94072 index 61ed862..3b52c65 100644
94073 --- a/kernel/time/timer_list.c
94074 +++ b/kernel/time/timer_list.c
94075 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
94076
94077 static void print_name_offset(struct seq_file *m, void *sym)
94078 {
94079 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94080 + SEQ_printf(m, "<%p>", NULL);
94081 +#else
94082 char symname[KSYM_NAME_LEN];
94083
94084 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
94085 SEQ_printf(m, "<%pK>", sym);
94086 else
94087 SEQ_printf(m, "%s", symname);
94088 +#endif
94089 }
94090
94091 static void
94092 @@ -119,7 +123,11 @@ next_one:
94093 static void
94094 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
94095 {
94096 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94097 + SEQ_printf(m, " .base: %p\n", NULL);
94098 +#else
94099 SEQ_printf(m, " .base: %pK\n", base);
94100 +#endif
94101 SEQ_printf(m, " .index: %d\n",
94102 base->index);
94103 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94104 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94105 {
94106 struct proc_dir_entry *pe;
94107
94108 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94109 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94110 +#else
94111 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94112 +#endif
94113 if (!pe)
94114 return -ENOMEM;
94115 return 0;
94116 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94117 index 1fb08f2..ca4bb1e 100644
94118 --- a/kernel/time/timer_stats.c
94119 +++ b/kernel/time/timer_stats.c
94120 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94121 static unsigned long nr_entries;
94122 static struct entry entries[MAX_ENTRIES];
94123
94124 -static atomic_t overflow_count;
94125 +static atomic_unchecked_t overflow_count;
94126
94127 /*
94128 * The entries are in a hash-table, for fast lookup:
94129 @@ -140,7 +140,7 @@ static void reset_entries(void)
94130 nr_entries = 0;
94131 memset(entries, 0, sizeof(entries));
94132 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94133 - atomic_set(&overflow_count, 0);
94134 + atomic_set_unchecked(&overflow_count, 0);
94135 }
94136
94137 static struct entry *alloc_entry(void)
94138 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94139 if (likely(entry))
94140 entry->count++;
94141 else
94142 - atomic_inc(&overflow_count);
94143 + atomic_inc_unchecked(&overflow_count);
94144
94145 out_unlock:
94146 raw_spin_unlock_irqrestore(lock, flags);
94147 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94148
94149 static void print_name_offset(struct seq_file *m, unsigned long addr)
94150 {
94151 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94152 + seq_printf(m, "<%p>", NULL);
94153 +#else
94154 char symname[KSYM_NAME_LEN];
94155
94156 if (lookup_symbol_name(addr, symname) < 0)
94157 - seq_printf(m, "<%p>", (void *)addr);
94158 + seq_printf(m, "<%pK>", (void *)addr);
94159 else
94160 seq_printf(m, "%s", symname);
94161 +#endif
94162 }
94163
94164 static int tstats_show(struct seq_file *m, void *v)
94165 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94166
94167 seq_puts(m, "Timer Stats Version: v0.3\n");
94168 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94169 - if (atomic_read(&overflow_count))
94170 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94171 + if (atomic_read_unchecked(&overflow_count))
94172 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94173 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94174
94175 for (i = 0; i < nr_entries; i++) {
94176 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94177 {
94178 struct proc_dir_entry *pe;
94179
94180 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94181 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94182 +#else
94183 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94184 +#endif
94185 if (!pe)
94186 return -ENOMEM;
94187 return 0;
94188 diff --git a/kernel/torture.c b/kernel/torture.c
94189 index d600af2..27a4e9d 100644
94190 --- a/kernel/torture.c
94191 +++ b/kernel/torture.c
94192 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94193 mutex_lock(&fullstop_mutex);
94194 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94195 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94196 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94197 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94198 } else {
94199 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94200 }
94201 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
94202 if (!torture_must_stop()) {
94203 if (stutter > 1) {
94204 schedule_timeout_interruptible(stutter - 1);
94205 - ACCESS_ONCE(stutter_pause_test) = 2;
94206 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
94207 }
94208 schedule_timeout_interruptible(1);
94209 - ACCESS_ONCE(stutter_pause_test) = 1;
94210 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
94211 }
94212 if (!torture_must_stop())
94213 schedule_timeout_interruptible(stutter);
94214 - ACCESS_ONCE(stutter_pause_test) = 0;
94215 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
94216 torture_shutdown_absorb("torture_stutter");
94217 } while (!torture_must_stop());
94218 torture_kthread_stopping("torture_stutter");
94219 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
94220 schedule_timeout_uninterruptible(10);
94221 return true;
94222 }
94223 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94224 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94225 mutex_unlock(&fullstop_mutex);
94226 torture_shutdown_cleanup();
94227 torture_shuffle_cleanup();
94228 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94229 index c1bd4ad..4b861dc 100644
94230 --- a/kernel/trace/blktrace.c
94231 +++ b/kernel/trace/blktrace.c
94232 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94233 struct blk_trace *bt = filp->private_data;
94234 char buf[16];
94235
94236 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94237 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94238
94239 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94240 }
94241 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94242 return 1;
94243
94244 bt = buf->chan->private_data;
94245 - atomic_inc(&bt->dropped);
94246 + atomic_inc_unchecked(&bt->dropped);
94247 return 0;
94248 }
94249
94250 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94251
94252 bt->dir = dir;
94253 bt->dev = dev;
94254 - atomic_set(&bt->dropped, 0);
94255 + atomic_set_unchecked(&bt->dropped, 0);
94256 INIT_LIST_HEAD(&bt->running_list);
94257
94258 ret = -EIO;
94259 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94260 index 5916a8e..5cd3b1f 100644
94261 --- a/kernel/trace/ftrace.c
94262 +++ b/kernel/trace/ftrace.c
94263 @@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94264 if (unlikely(ftrace_disabled))
94265 return 0;
94266
94267 + ret = ftrace_arch_code_modify_prepare();
94268 + FTRACE_WARN_ON(ret);
94269 + if (ret)
94270 + return 0;
94271 +
94272 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94273 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94274 if (ret) {
94275 ftrace_bug(ret, ip);
94276 - return 0;
94277 }
94278 - return 1;
94279 + return ret ? 0 : 1;
94280 }
94281
94282 /*
94283 @@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
94284 if (!count)
94285 return 0;
94286
94287 + pax_open_kernel();
94288 sort(start, count, sizeof(*start),
94289 ftrace_cmp_ips, ftrace_swap_ips);
94290 + pax_close_kernel();
94291
94292 start_pg = ftrace_allocate_pages(count);
94293 if (!start_pg)
94294 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94295 index 2d75c94..5ef6d32 100644
94296 --- a/kernel/trace/ring_buffer.c
94297 +++ b/kernel/trace/ring_buffer.c
94298 @@ -352,9 +352,9 @@ struct buffer_data_page {
94299 */
94300 struct buffer_page {
94301 struct list_head list; /* list of buffer pages */
94302 - local_t write; /* index for next write */
94303 + local_unchecked_t write; /* index for next write */
94304 unsigned read; /* index for next read */
94305 - local_t entries; /* entries on this page */
94306 + local_unchecked_t entries; /* entries on this page */
94307 unsigned long real_end; /* real end of data */
94308 struct buffer_data_page *page; /* Actual data page */
94309 };
94310 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94311 unsigned long last_overrun;
94312 local_t entries_bytes;
94313 local_t entries;
94314 - local_t overrun;
94315 - local_t commit_overrun;
94316 + local_unchecked_t overrun;
94317 + local_unchecked_t commit_overrun;
94318 local_t dropped_events;
94319 local_t committing;
94320 local_t commits;
94321 @@ -1005,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94322 *
94323 * We add a counter to the write field to denote this.
94324 */
94325 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94326 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94327 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94328 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94329
94330 /*
94331 * Just make sure we have seen our old_write and synchronize
94332 @@ -1034,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94333 * cmpxchg to only update if an interrupt did not already
94334 * do it for us. If the cmpxchg fails, we don't care.
94335 */
94336 - (void)local_cmpxchg(&next_page->write, old_write, val);
94337 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94338 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94339 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94340
94341 /*
94342 * No need to worry about races with clearing out the commit.
94343 @@ -1402,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94344
94345 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94346 {
94347 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94348 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94349 }
94350
94351 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94352 {
94353 - return local_read(&bpage->write) & RB_WRITE_MASK;
94354 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94355 }
94356
94357 static int
94358 @@ -1502,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94359 * bytes consumed in ring buffer from here.
94360 * Increment overrun to account for the lost events.
94361 */
94362 - local_add(page_entries, &cpu_buffer->overrun);
94363 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94364 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94365 }
94366
94367 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94368 * it is our responsibility to update
94369 * the counters.
94370 */
94371 - local_add(entries, &cpu_buffer->overrun);
94372 + local_add_unchecked(entries, &cpu_buffer->overrun);
94373 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94374
94375 /*
94376 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94377 if (tail == BUF_PAGE_SIZE)
94378 tail_page->real_end = 0;
94379
94380 - local_sub(length, &tail_page->write);
94381 + local_sub_unchecked(length, &tail_page->write);
94382 return;
94383 }
94384
94385 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94386 rb_event_set_padding(event);
94387
94388 /* Set the write back to the previous setting */
94389 - local_sub(length, &tail_page->write);
94390 + local_sub_unchecked(length, &tail_page->write);
94391 return;
94392 }
94393
94394 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94395
94396 /* Set write to end of buffer */
94397 length = (tail + length) - BUF_PAGE_SIZE;
94398 - local_sub(length, &tail_page->write);
94399 + local_sub_unchecked(length, &tail_page->write);
94400 }
94401
94402 /*
94403 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94404 * about it.
94405 */
94406 if (unlikely(next_page == commit_page)) {
94407 - local_inc(&cpu_buffer->commit_overrun);
94408 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94409 goto out_reset;
94410 }
94411
94412 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94413 cpu_buffer->tail_page) &&
94414 (cpu_buffer->commit_page ==
94415 cpu_buffer->reader_page))) {
94416 - local_inc(&cpu_buffer->commit_overrun);
94417 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94418 goto out_reset;
94419 }
94420 }
94421 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94422 length += RB_LEN_TIME_EXTEND;
94423
94424 tail_page = cpu_buffer->tail_page;
94425 - write = local_add_return(length, &tail_page->write);
94426 + write = local_add_return_unchecked(length, &tail_page->write);
94427
94428 /* set write to only the index of the write */
94429 write &= RB_WRITE_MASK;
94430 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94431 kmemcheck_annotate_bitfield(event, bitfield);
94432 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94433
94434 - local_inc(&tail_page->entries);
94435 + local_inc_unchecked(&tail_page->entries);
94436
94437 /*
94438 * If this is the first commit on the page, then update
94439 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94440
94441 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94442 unsigned long write_mask =
94443 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94444 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94445 unsigned long event_length = rb_event_length(event);
94446 /*
94447 * This is on the tail page. It is possible that
94448 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94449 */
94450 old_index += write_mask;
94451 new_index += write_mask;
94452 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94453 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94454 if (index == old_index) {
94455 /* update counters */
94456 local_sub(event_length, &cpu_buffer->entries_bytes);
94457 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94458
94459 /* Do the likely case first */
94460 if (likely(bpage->page == (void *)addr)) {
94461 - local_dec(&bpage->entries);
94462 + local_dec_unchecked(&bpage->entries);
94463 return;
94464 }
94465
94466 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94467 start = bpage;
94468 do {
94469 if (bpage->page == (void *)addr) {
94470 - local_dec(&bpage->entries);
94471 + local_dec_unchecked(&bpage->entries);
94472 return;
94473 }
94474 rb_inc_page(cpu_buffer, &bpage);
94475 @@ -3146,7 +3146,7 @@ static inline unsigned long
94476 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94477 {
94478 return local_read(&cpu_buffer->entries) -
94479 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94480 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94481 }
94482
94483 /**
94484 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94485 return 0;
94486
94487 cpu_buffer = buffer->buffers[cpu];
94488 - ret = local_read(&cpu_buffer->overrun);
94489 + ret = local_read_unchecked(&cpu_buffer->overrun);
94490
94491 return ret;
94492 }
94493 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94494 return 0;
94495
94496 cpu_buffer = buffer->buffers[cpu];
94497 - ret = local_read(&cpu_buffer->commit_overrun);
94498 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94499
94500 return ret;
94501 }
94502 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94503 /* if you care about this being correct, lock the buffer */
94504 for_each_buffer_cpu(buffer, cpu) {
94505 cpu_buffer = buffer->buffers[cpu];
94506 - overruns += local_read(&cpu_buffer->overrun);
94507 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94508 }
94509
94510 return overruns;
94511 @@ -3514,8 +3514,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94512 /*
94513 * Reset the reader page to size zero.
94514 */
94515 - local_set(&cpu_buffer->reader_page->write, 0);
94516 - local_set(&cpu_buffer->reader_page->entries, 0);
94517 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94518 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94519 local_set(&cpu_buffer->reader_page->page->commit, 0);
94520 cpu_buffer->reader_page->real_end = 0;
94521
94522 @@ -3549,7 +3549,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94523 * want to compare with the last_overrun.
94524 */
94525 smp_mb();
94526 - overwrite = local_read(&(cpu_buffer->overrun));
94527 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94528
94529 /*
94530 * Here's the tricky part.
94531 @@ -4121,8 +4121,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94532
94533 cpu_buffer->head_page
94534 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94535 - local_set(&cpu_buffer->head_page->write, 0);
94536 - local_set(&cpu_buffer->head_page->entries, 0);
94537 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94538 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94539 local_set(&cpu_buffer->head_page->page->commit, 0);
94540
94541 cpu_buffer->head_page->read = 0;
94542 @@ -4132,14 +4132,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94543
94544 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94545 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94546 - local_set(&cpu_buffer->reader_page->write, 0);
94547 - local_set(&cpu_buffer->reader_page->entries, 0);
94548 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94549 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94550 local_set(&cpu_buffer->reader_page->page->commit, 0);
94551 cpu_buffer->reader_page->read = 0;
94552
94553 local_set(&cpu_buffer->entries_bytes, 0);
94554 - local_set(&cpu_buffer->overrun, 0);
94555 - local_set(&cpu_buffer->commit_overrun, 0);
94556 + local_set_unchecked(&cpu_buffer->overrun, 0);
94557 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94558 local_set(&cpu_buffer->dropped_events, 0);
94559 local_set(&cpu_buffer->entries, 0);
94560 local_set(&cpu_buffer->committing, 0);
94561 @@ -4544,8 +4544,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94562 rb_init_page(bpage);
94563 bpage = reader->page;
94564 reader->page = *data_page;
94565 - local_set(&reader->write, 0);
94566 - local_set(&reader->entries, 0);
94567 + local_set_unchecked(&reader->write, 0);
94568 + local_set_unchecked(&reader->entries, 0);
94569 reader->read = 0;
94570 *data_page = bpage;
94571
94572 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94573 index 8a52839..dd6d7c8 100644
94574 --- a/kernel/trace/trace.c
94575 +++ b/kernel/trace/trace.c
94576 @@ -3487,7 +3487,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94577 return 0;
94578 }
94579
94580 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94581 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94582 {
94583 /* do nothing if flag is already set */
94584 if (!!(trace_flags & mask) == !!enabled)
94585 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94586 index 385391f..8d2250f 100644
94587 --- a/kernel/trace/trace.h
94588 +++ b/kernel/trace/trace.h
94589 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94590 void trace_printk_init_buffers(void);
94591 void trace_printk_start_comm(void);
94592 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94593 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94594 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94595
94596 /*
94597 * Normal trace_printk() and friends allocates special buffers
94598 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94599 index 57b67b1..66082a9 100644
94600 --- a/kernel/trace/trace_clock.c
94601 +++ b/kernel/trace/trace_clock.c
94602 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94603 return now;
94604 }
94605
94606 -static atomic64_t trace_counter;
94607 +static atomic64_unchecked_t trace_counter;
94608
94609 /*
94610 * trace_clock_counter(): simply an atomic counter.
94611 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94612 */
94613 u64 notrace trace_clock_counter(void)
94614 {
94615 - return atomic64_add_return(1, &trace_counter);
94616 + return atomic64_inc_return_unchecked(&trace_counter);
94617 }
94618 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94619 index ef06ce7..3ea161d 100644
94620 --- a/kernel/trace/trace_events.c
94621 +++ b/kernel/trace/trace_events.c
94622 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94623 return 0;
94624 }
94625
94626 -struct ftrace_module_file_ops;
94627 static void __add_event_to_tracers(struct ftrace_event_call *call);
94628
94629 /* Add an additional event_call dynamically */
94630 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94631 index 0abd9b8..6a663a2 100644
94632 --- a/kernel/trace/trace_mmiotrace.c
94633 +++ b/kernel/trace/trace_mmiotrace.c
94634 @@ -24,7 +24,7 @@ struct header_iter {
94635 static struct trace_array *mmio_trace_array;
94636 static bool overrun_detected;
94637 static unsigned long prev_overruns;
94638 -static atomic_t dropped_count;
94639 +static atomic_unchecked_t dropped_count;
94640
94641 static void mmio_reset_data(struct trace_array *tr)
94642 {
94643 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94644
94645 static unsigned long count_overruns(struct trace_iterator *iter)
94646 {
94647 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94648 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94649 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94650
94651 if (over > prev_overruns)
94652 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94653 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94654 sizeof(*entry), 0, pc);
94655 if (!event) {
94656 - atomic_inc(&dropped_count);
94657 + atomic_inc_unchecked(&dropped_count);
94658 return;
94659 }
94660 entry = ring_buffer_event_data(event);
94661 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94662 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94663 sizeof(*entry), 0, pc);
94664 if (!event) {
94665 - atomic_inc(&dropped_count);
94666 + atomic_inc_unchecked(&dropped_count);
94667 return;
94668 }
94669 entry = ring_buffer_event_data(event);
94670 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94671 index c6977d5..d243785 100644
94672 --- a/kernel/trace/trace_output.c
94673 +++ b/kernel/trace/trace_output.c
94674 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94675 goto out;
94676 }
94677
94678 + pax_open_kernel();
94679 if (event->funcs->trace == NULL)
94680 - event->funcs->trace = trace_nop_print;
94681 + *(void **)&event->funcs->trace = trace_nop_print;
94682 if (event->funcs->raw == NULL)
94683 - event->funcs->raw = trace_nop_print;
94684 + *(void **)&event->funcs->raw = trace_nop_print;
94685 if (event->funcs->hex == NULL)
94686 - event->funcs->hex = trace_nop_print;
94687 + *(void **)&event->funcs->hex = trace_nop_print;
94688 if (event->funcs->binary == NULL)
94689 - event->funcs->binary = trace_nop_print;
94690 + *(void **)&event->funcs->binary = trace_nop_print;
94691 + pax_close_kernel();
94692
94693 key = event->type & (EVENT_HASHSIZE - 1);
94694
94695 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94696 index 1f24ed9..10407ec 100644
94697 --- a/kernel/trace/trace_seq.c
94698 +++ b/kernel/trace/trace_seq.c
94699 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94700
94701 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94702 if (!IS_ERR(p)) {
94703 - p = mangle_path(s->buffer + s->len, p, "\n");
94704 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94705 if (p) {
94706 s->len = p - s->buffer;
94707 return 1;
94708 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94709 index 8a4e5cb..64f270d 100644
94710 --- a/kernel/trace/trace_stack.c
94711 +++ b/kernel/trace/trace_stack.c
94712 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94713 return;
94714
94715 /* we do not handle interrupt stacks yet */
94716 - if (!object_is_on_stack(stack))
94717 + if (!object_starts_on_stack(stack))
94718 return;
94719
94720 local_irq_save(flags);
94721 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94722 index aa312b0..395f343 100644
94723 --- a/kernel/user_namespace.c
94724 +++ b/kernel/user_namespace.c
94725 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94726 !kgid_has_mapping(parent_ns, group))
94727 return -EPERM;
94728
94729 +#ifdef CONFIG_GRKERNSEC
94730 + /*
94731 + * This doesn't really inspire confidence:
94732 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94733 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94734 + * Increases kernel attack surface in areas developers
94735 + * previously cared little about ("low importance due
94736 + * to requiring "root" capability")
94737 + * To be removed when this code receives *proper* review
94738 + */
94739 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94740 + !capable(CAP_SETGID))
94741 + return -EPERM;
94742 +#endif
94743 +
94744 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94745 if (!ns)
94746 return -ENOMEM;
94747 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94748 if (atomic_read(&current->mm->mm_users) > 1)
94749 return -EINVAL;
94750
94751 - if (current->fs->users != 1)
94752 + if (atomic_read(&current->fs->users) != 1)
94753 return -EINVAL;
94754
94755 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94756 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94757 index c8eac43..4b5f08f 100644
94758 --- a/kernel/utsname_sysctl.c
94759 +++ b/kernel/utsname_sysctl.c
94760 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94761 static int proc_do_uts_string(struct ctl_table *table, int write,
94762 void __user *buffer, size_t *lenp, loff_t *ppos)
94763 {
94764 - struct ctl_table uts_table;
94765 + ctl_table_no_const uts_table;
94766 int r;
94767 memcpy(&uts_table, table, sizeof(uts_table));
94768 uts_table.data = get_uts(table, write);
94769 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94770 index a8d6914..8fbdb13 100644
94771 --- a/kernel/watchdog.c
94772 +++ b/kernel/watchdog.c
94773 @@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94774 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94775 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94776
94777 -static struct smp_hotplug_thread watchdog_threads = {
94778 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94779 .store = &softlockup_watchdog,
94780 .thread_should_run = watchdog_should_run,
94781 .thread_fn = watchdog,
94782 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94783 index 5dbe22a..872413c 100644
94784 --- a/kernel/workqueue.c
94785 +++ b/kernel/workqueue.c
94786 @@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94787 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94788 worker_flags |= WORKER_REBOUND;
94789 worker_flags &= ~WORKER_UNBOUND;
94790 - ACCESS_ONCE(worker->flags) = worker_flags;
94791 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94792 }
94793
94794 spin_unlock_irq(&pool->lock);
94795 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94796 index a285900..5e3b26b 100644
94797 --- a/lib/Kconfig.debug
94798 +++ b/lib/Kconfig.debug
94799 @@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94800
94801 config DEBUG_WW_MUTEX_SLOWPATH
94802 bool "Wait/wound mutex debugging: Slowpath testing"
94803 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94804 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94805 select DEBUG_LOCK_ALLOC
94806 select DEBUG_SPINLOCK
94807 select DEBUG_MUTEXES
94808 @@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94809
94810 config DEBUG_LOCK_ALLOC
94811 bool "Lock debugging: detect incorrect freeing of live locks"
94812 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94813 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94814 select DEBUG_SPINLOCK
94815 select DEBUG_MUTEXES
94816 select LOCKDEP
94817 @@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94818
94819 config PROVE_LOCKING
94820 bool "Lock debugging: prove locking correctness"
94821 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94822 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94823 select LOCKDEP
94824 select DEBUG_SPINLOCK
94825 select DEBUG_MUTEXES
94826 @@ -964,7 +964,7 @@ config LOCKDEP
94827
94828 config LOCK_STAT
94829 bool "Lock usage statistics"
94830 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94831 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94832 select LOCKDEP
94833 select DEBUG_SPINLOCK
94834 select DEBUG_MUTEXES
94835 @@ -1437,6 +1437,7 @@ config LATENCYTOP
94836 depends on DEBUG_KERNEL
94837 depends on STACKTRACE_SUPPORT
94838 depends on PROC_FS
94839 + depends on !GRKERNSEC_HIDESYM
94840 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94841 select KALLSYMS
94842 select KALLSYMS_ALL
94843 @@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94844 config DEBUG_STRICT_USER_COPY_CHECKS
94845 bool "Strict user copy size checks"
94846 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94847 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94848 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94849 help
94850 Enabling this option turns a certain set of sanity checks for user
94851 copy operations into compile time failures.
94852 @@ -1581,7 +1582,7 @@ endmenu # runtime tests
94853
94854 config PROVIDE_OHCI1394_DMA_INIT
94855 bool "Remote debugging over FireWire early on boot"
94856 - depends on PCI && X86
94857 + depends on PCI && X86 && !GRKERNSEC
94858 help
94859 If you want to debug problems which hang or crash the kernel early
94860 on boot and the crashing machine has a FireWire port, you can use
94861 diff --git a/lib/Makefile b/lib/Makefile
94862 index d6b4bc4..a3724eb 100644
94863 --- a/lib/Makefile
94864 +++ b/lib/Makefile
94865 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94866 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94867 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94868 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94869 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94870 +obj-y += list_debug.o
94871 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94872
94873 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94874 diff --git a/lib/average.c b/lib/average.c
94875 index 114d1be..ab0350c 100644
94876 --- a/lib/average.c
94877 +++ b/lib/average.c
94878 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94879 {
94880 unsigned long internal = ACCESS_ONCE(avg->internal);
94881
94882 - ACCESS_ONCE(avg->internal) = internal ?
94883 + ACCESS_ONCE_RW(avg->internal) = internal ?
94884 (((internal << avg->weight) - internal) +
94885 (val << avg->factor)) >> avg->weight :
94886 (val << avg->factor);
94887 diff --git a/lib/bitmap.c b/lib/bitmap.c
94888 index 1e031f2..a53eb90 100644
94889 --- a/lib/bitmap.c
94890 +++ b/lib/bitmap.c
94891 @@ -429,7 +429,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94892 {
94893 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94894 u32 chunk;
94895 - const char __user __force *ubuf = (const char __user __force *)buf;
94896 + const char __user *ubuf = (const char __force_user *)buf;
94897
94898 bitmap_zero(maskp, nmaskbits);
94899
94900 @@ -514,7 +514,7 @@ int bitmap_parse_user(const char __user *ubuf,
94901 {
94902 if (!access_ok(VERIFY_READ, ubuf, ulen))
94903 return -EFAULT;
94904 - return __bitmap_parse((const char __force *)ubuf,
94905 + return __bitmap_parse((const char __force_kernel *)ubuf,
94906 ulen, 1, maskp, nmaskbits);
94907
94908 }
94909 @@ -605,7 +605,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94910 {
94911 unsigned a, b;
94912 int c, old_c, totaldigits;
94913 - const char __user __force *ubuf = (const char __user __force *)buf;
94914 + const char __user *ubuf = (const char __force_user *)buf;
94915 int exp_digit, in_range;
94916
94917 totaldigits = c = 0;
94918 @@ -700,7 +700,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94919 {
94920 if (!access_ok(VERIFY_READ, ubuf, ulen))
94921 return -EFAULT;
94922 - return __bitmap_parselist((const char __force *)ubuf,
94923 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94924 ulen, 1, maskp, nmaskbits);
94925 }
94926 EXPORT_SYMBOL(bitmap_parselist_user);
94927 diff --git a/lib/bug.c b/lib/bug.c
94928 index d1d7c78..b354235 100644
94929 --- a/lib/bug.c
94930 +++ b/lib/bug.c
94931 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94932 return BUG_TRAP_TYPE_NONE;
94933
94934 bug = find_bug(bugaddr);
94935 + if (!bug)
94936 + return BUG_TRAP_TYPE_NONE;
94937
94938 file = NULL;
94939 line = 0;
94940 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94941 index 547f7f9..a6d4ba0 100644
94942 --- a/lib/debugobjects.c
94943 +++ b/lib/debugobjects.c
94944 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94945 if (limit > 4)
94946 return;
94947
94948 - is_on_stack = object_is_on_stack(addr);
94949 + is_on_stack = object_starts_on_stack(addr);
94950 if (is_on_stack == onstack)
94951 return;
94952
94953 diff --git a/lib/div64.c b/lib/div64.c
94954 index 4382ad7..08aa558 100644
94955 --- a/lib/div64.c
94956 +++ b/lib/div64.c
94957 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94958 EXPORT_SYMBOL(__div64_32);
94959
94960 #ifndef div_s64_rem
94961 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94962 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94963 {
94964 u64 quotient;
94965
94966 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94967 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94968 */
94969 #ifndef div64_u64
94970 -u64 div64_u64(u64 dividend, u64 divisor)
94971 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94972 {
94973 u32 high = divisor >> 32;
94974 u64 quot;
94975 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94976 index 98f2d7e..899da5c 100644
94977 --- a/lib/dma-debug.c
94978 +++ b/lib/dma-debug.c
94979 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94980
94981 void dma_debug_add_bus(struct bus_type *bus)
94982 {
94983 - struct notifier_block *nb;
94984 + notifier_block_no_const *nb;
94985
94986 if (global_disable)
94987 return;
94988 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94989
94990 static void check_for_stack(struct device *dev, void *addr)
94991 {
94992 - if (object_is_on_stack(addr))
94993 + if (object_starts_on_stack(addr))
94994 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
94995 "stack [addr=%p]\n", addr);
94996 }
94997 diff --git a/lib/hash.c b/lib/hash.c
94998 index fea973f..386626f 100644
94999 --- a/lib/hash.c
95000 +++ b/lib/hash.c
95001 @@ -14,7 +14,7 @@
95002 #include <linux/hash.h>
95003 #include <linux/cache.h>
95004
95005 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
95006 +static struct fast_hash_ops arch_hash_ops __read_only = {
95007 .hash = jhash,
95008 .hash2 = jhash2,
95009 };
95010 diff --git a/lib/inflate.c b/lib/inflate.c
95011 index 013a761..c28f3fc 100644
95012 --- a/lib/inflate.c
95013 +++ b/lib/inflate.c
95014 @@ -269,7 +269,7 @@ static void free(void *where)
95015 malloc_ptr = free_mem_ptr;
95016 }
95017 #else
95018 -#define malloc(a) kmalloc(a, GFP_KERNEL)
95019 +#define malloc(a) kmalloc((a), GFP_KERNEL)
95020 #define free(a) kfree(a)
95021 #endif
95022
95023 diff --git a/lib/ioremap.c b/lib/ioremap.c
95024 index 0c9216c..863bd89 100644
95025 --- a/lib/ioremap.c
95026 +++ b/lib/ioremap.c
95027 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95028 unsigned long next;
95029
95030 phys_addr -= addr;
95031 - pmd = pmd_alloc(&init_mm, pud, addr);
95032 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95033 if (!pmd)
95034 return -ENOMEM;
95035 do {
95036 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95037 unsigned long next;
95038
95039 phys_addr -= addr;
95040 - pud = pud_alloc(&init_mm, pgd, addr);
95041 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95042 if (!pud)
95043 return -ENOMEM;
95044 do {
95045 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95046 index bd2bea9..6b3c95e 100644
95047 --- a/lib/is_single_threaded.c
95048 +++ b/lib/is_single_threaded.c
95049 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95050 struct task_struct *p, *t;
95051 bool ret;
95052
95053 + if (!mm)
95054 + return true;
95055 +
95056 if (atomic_read(&task->signal->live) != 1)
95057 return false;
95058
95059 diff --git a/lib/kobject.c b/lib/kobject.c
95060 index 58751bb..93a1853 100644
95061 --- a/lib/kobject.c
95062 +++ b/lib/kobject.c
95063 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95064
95065
95066 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95067 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95068 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95069
95070 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95071 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95072 {
95073 enum kobj_ns_type type = ops->type;
95074 int error;
95075 diff --git a/lib/list_debug.c b/lib/list_debug.c
95076 index c24c2f7..f0296f4 100644
95077 --- a/lib/list_debug.c
95078 +++ b/lib/list_debug.c
95079 @@ -11,7 +11,9 @@
95080 #include <linux/bug.h>
95081 #include <linux/kernel.h>
95082 #include <linux/rculist.h>
95083 +#include <linux/mm.h>
95084
95085 +#ifdef CONFIG_DEBUG_LIST
95086 /*
95087 * Insert a new entry between two known consecutive entries.
95088 *
95089 @@ -19,21 +21,40 @@
95090 * the prev/next entries already!
95091 */
95092
95093 +static bool __list_add_debug(struct list_head *new,
95094 + struct list_head *prev,
95095 + struct list_head *next)
95096 +{
95097 + if (unlikely(next->prev != prev)) {
95098 + printk(KERN_ERR "list_add corruption. next->prev should be "
95099 + "prev (%p), but was %p. (next=%p).\n",
95100 + prev, next->prev, next);
95101 + BUG();
95102 + return false;
95103 + }
95104 + if (unlikely(prev->next != next)) {
95105 + printk(KERN_ERR "list_add corruption. prev->next should be "
95106 + "next (%p), but was %p. (prev=%p).\n",
95107 + next, prev->next, prev);
95108 + BUG();
95109 + return false;
95110 + }
95111 + if (unlikely(new == prev || new == next)) {
95112 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95113 + new, prev, next);
95114 + BUG();
95115 + return false;
95116 + }
95117 + return true;
95118 +}
95119 +
95120 void __list_add(struct list_head *new,
95121 - struct list_head *prev,
95122 - struct list_head *next)
95123 + struct list_head *prev,
95124 + struct list_head *next)
95125 {
95126 - WARN(next->prev != prev,
95127 - "list_add corruption. next->prev should be "
95128 - "prev (%p), but was %p. (next=%p).\n",
95129 - prev, next->prev, next);
95130 - WARN(prev->next != next,
95131 - "list_add corruption. prev->next should be "
95132 - "next (%p), but was %p. (prev=%p).\n",
95133 - next, prev->next, prev);
95134 - WARN(new == prev || new == next,
95135 - "list_add double add: new=%p, prev=%p, next=%p.\n",
95136 - new, prev, next);
95137 + if (!__list_add_debug(new, prev, next))
95138 + return;
95139 +
95140 next->prev = new;
95141 new->next = next;
95142 new->prev = prev;
95143 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95144 }
95145 EXPORT_SYMBOL(__list_add);
95146
95147 -void __list_del_entry(struct list_head *entry)
95148 +static bool __list_del_entry_debug(struct list_head *entry)
95149 {
95150 struct list_head *prev, *next;
95151
95152 prev = entry->prev;
95153 next = entry->next;
95154
95155 - if (WARN(next == LIST_POISON1,
95156 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95157 - entry, LIST_POISON1) ||
95158 - WARN(prev == LIST_POISON2,
95159 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95160 - entry, LIST_POISON2) ||
95161 - WARN(prev->next != entry,
95162 - "list_del corruption. prev->next should be %p, "
95163 - "but was %p\n", entry, prev->next) ||
95164 - WARN(next->prev != entry,
95165 - "list_del corruption. next->prev should be %p, "
95166 - "but was %p\n", entry, next->prev))
95167 + if (unlikely(next == LIST_POISON1)) {
95168 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95169 + entry, LIST_POISON1);
95170 + BUG();
95171 + return false;
95172 + }
95173 + if (unlikely(prev == LIST_POISON2)) {
95174 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95175 + entry, LIST_POISON2);
95176 + BUG();
95177 + return false;
95178 + }
95179 + if (unlikely(entry->prev->next != entry)) {
95180 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95181 + "but was %p\n", entry, prev->next);
95182 + BUG();
95183 + return false;
95184 + }
95185 + if (unlikely(entry->next->prev != entry)) {
95186 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95187 + "but was %p\n", entry, next->prev);
95188 + BUG();
95189 + return false;
95190 + }
95191 + return true;
95192 +}
95193 +
95194 +void __list_del_entry(struct list_head *entry)
95195 +{
95196 + if (!__list_del_entry_debug(entry))
95197 return;
95198
95199 - __list_del(prev, next);
95200 + __list_del(entry->prev, entry->next);
95201 }
95202 EXPORT_SYMBOL(__list_del_entry);
95203
95204 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95205 void __list_add_rcu(struct list_head *new,
95206 struct list_head *prev, struct list_head *next)
95207 {
95208 - WARN(next->prev != prev,
95209 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95210 - prev, next->prev, next);
95211 - WARN(prev->next != next,
95212 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95213 - next, prev->next, prev);
95214 + if (!__list_add_debug(new, prev, next))
95215 + return;
95216 +
95217 new->next = next;
95218 new->prev = prev;
95219 rcu_assign_pointer(list_next_rcu(prev), new);
95220 next->prev = new;
95221 }
95222 EXPORT_SYMBOL(__list_add_rcu);
95223 +#endif
95224 +
95225 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95226 +{
95227 +#ifdef CONFIG_DEBUG_LIST
95228 + if (!__list_add_debug(new, prev, next))
95229 + return;
95230 +#endif
95231 +
95232 + pax_open_kernel();
95233 + next->prev = new;
95234 + new->next = next;
95235 + new->prev = prev;
95236 + prev->next = new;
95237 + pax_close_kernel();
95238 +}
95239 +EXPORT_SYMBOL(__pax_list_add);
95240 +
95241 +void pax_list_del(struct list_head *entry)
95242 +{
95243 +#ifdef CONFIG_DEBUG_LIST
95244 + if (!__list_del_entry_debug(entry))
95245 + return;
95246 +#endif
95247 +
95248 + pax_open_kernel();
95249 + __list_del(entry->prev, entry->next);
95250 + entry->next = LIST_POISON1;
95251 + entry->prev = LIST_POISON2;
95252 + pax_close_kernel();
95253 +}
95254 +EXPORT_SYMBOL(pax_list_del);
95255 +
95256 +void pax_list_del_init(struct list_head *entry)
95257 +{
95258 + pax_open_kernel();
95259 + __list_del(entry->prev, entry->next);
95260 + INIT_LIST_HEAD(entry);
95261 + pax_close_kernel();
95262 +}
95263 +EXPORT_SYMBOL(pax_list_del_init);
95264 +
95265 +void __pax_list_add_rcu(struct list_head *new,
95266 + struct list_head *prev, struct list_head *next)
95267 +{
95268 +#ifdef CONFIG_DEBUG_LIST
95269 + if (!__list_add_debug(new, prev, next))
95270 + return;
95271 +#endif
95272 +
95273 + pax_open_kernel();
95274 + new->next = next;
95275 + new->prev = prev;
95276 + rcu_assign_pointer(list_next_rcu(prev), new);
95277 + next->prev = new;
95278 + pax_close_kernel();
95279 +}
95280 +EXPORT_SYMBOL(__pax_list_add_rcu);
95281 +
95282 +void pax_list_del_rcu(struct list_head *entry)
95283 +{
95284 +#ifdef CONFIG_DEBUG_LIST
95285 + if (!__list_del_entry_debug(entry))
95286 + return;
95287 +#endif
95288 +
95289 + pax_open_kernel();
95290 + __list_del(entry->prev, entry->next);
95291 + entry->next = LIST_POISON1;
95292 + entry->prev = LIST_POISON2;
95293 + pax_close_kernel();
95294 +}
95295 +EXPORT_SYMBOL(pax_list_del_rcu);
95296 diff --git a/lib/lockref.c b/lib/lockref.c
95297 index d2233de..fa1a2f6 100644
95298 --- a/lib/lockref.c
95299 +++ b/lib/lockref.c
95300 @@ -48,13 +48,13 @@
95301 void lockref_get(struct lockref *lockref)
95302 {
95303 CMPXCHG_LOOP(
95304 - new.count++;
95305 + __lockref_inc(&new);
95306 ,
95307 return;
95308 );
95309
95310 spin_lock(&lockref->lock);
95311 - lockref->count++;
95312 + __lockref_inc(lockref);
95313 spin_unlock(&lockref->lock);
95314 }
95315 EXPORT_SYMBOL(lockref_get);
95316 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95317 int retval;
95318
95319 CMPXCHG_LOOP(
95320 - new.count++;
95321 + __lockref_inc(&new);
95322 if (!old.count)
95323 return 0;
95324 ,
95325 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95326 spin_lock(&lockref->lock);
95327 retval = 0;
95328 if (lockref->count) {
95329 - lockref->count++;
95330 + __lockref_inc(lockref);
95331 retval = 1;
95332 }
95333 spin_unlock(&lockref->lock);
95334 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95335 int lockref_get_or_lock(struct lockref *lockref)
95336 {
95337 CMPXCHG_LOOP(
95338 - new.count++;
95339 + __lockref_inc(&new);
95340 if (!old.count)
95341 break;
95342 ,
95343 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95344 spin_lock(&lockref->lock);
95345 if (!lockref->count)
95346 return 0;
95347 - lockref->count++;
95348 + __lockref_inc(lockref);
95349 spin_unlock(&lockref->lock);
95350 return 1;
95351 }
95352 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95353 int lockref_put_or_lock(struct lockref *lockref)
95354 {
95355 CMPXCHG_LOOP(
95356 - new.count--;
95357 + __lockref_dec(&new);
95358 if (old.count <= 1)
95359 break;
95360 ,
95361 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95362 spin_lock(&lockref->lock);
95363 if (lockref->count <= 1)
95364 return 0;
95365 - lockref->count--;
95366 + __lockref_dec(lockref);
95367 spin_unlock(&lockref->lock);
95368 return 1;
95369 }
95370 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95371 int retval;
95372
95373 CMPXCHG_LOOP(
95374 - new.count++;
95375 + __lockref_inc(&new);
95376 if ((int)old.count < 0)
95377 return 0;
95378 ,
95379 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95380 spin_lock(&lockref->lock);
95381 retval = 0;
95382 if ((int) lockref->count >= 0) {
95383 - lockref->count++;
95384 + __lockref_inc(lockref);
95385 retval = 1;
95386 }
95387 spin_unlock(&lockref->lock);
95388 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95389 index a89cf09..1a42c2d 100644
95390 --- a/lib/percpu-refcount.c
95391 +++ b/lib/percpu-refcount.c
95392 @@ -29,7 +29,7 @@
95393 * can't hit 0 before we've added up all the percpu refs.
95394 */
95395
95396 -#define PCPU_COUNT_BIAS (1U << 31)
95397 +#define PCPU_COUNT_BIAS (1U << 30)
95398
95399 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95400 {
95401 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95402 index 3291a8e..346a91e 100644
95403 --- a/lib/radix-tree.c
95404 +++ b/lib/radix-tree.c
95405 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95406 int nr;
95407 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95408 };
95409 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95410 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95411
95412 static inline void *ptr_to_indirect(void *ptr)
95413 {
95414 diff --git a/lib/random32.c b/lib/random32.c
95415 index c9b6bf3..4752c6d4 100644
95416 --- a/lib/random32.c
95417 +++ b/lib/random32.c
95418 @@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95419 }
95420 #endif
95421
95422 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95423 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95424
95425 /**
95426 * prandom_u32_state - seeded pseudo-random number generator.
95427 diff --git a/lib/rbtree.c b/lib/rbtree.c
95428 index c16c81a..4dcbda1 100644
95429 --- a/lib/rbtree.c
95430 +++ b/lib/rbtree.c
95431 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95432 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95433
95434 static const struct rb_augment_callbacks dummy_callbacks = {
95435 - dummy_propagate, dummy_copy, dummy_rotate
95436 + .propagate = dummy_propagate,
95437 + .copy = dummy_copy,
95438 + .rotate = dummy_rotate
95439 };
95440
95441 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95442 diff --git a/lib/show_mem.c b/lib/show_mem.c
95443 index 0922579..9d7adb9 100644
95444 --- a/lib/show_mem.c
95445 +++ b/lib/show_mem.c
95446 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95447 quicklist_total_size());
95448 #endif
95449 #ifdef CONFIG_MEMORY_FAILURE
95450 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95451 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95452 #endif
95453 }
95454 diff --git a/lib/string.c b/lib/string.c
95455 index f3c6ff5..70db57a 100644
95456 --- a/lib/string.c
95457 +++ b/lib/string.c
95458 @@ -604,6 +604,22 @@ void *memset(void *s, int c, size_t count)
95459 EXPORT_SYMBOL(memset);
95460 #endif
95461
95462 +/**
95463 + * memzero_explicit - Fill a region of memory (e.g. sensitive
95464 + * keying data) with 0s.
95465 + * @s: Pointer to the start of the area.
95466 + * @count: The size of the area.
95467 + *
95468 + * memzero_explicit() doesn't need an arch-specific version as
95469 + * it just invokes the one of memset() implicitly.
95470 + */
95471 +void memzero_explicit(void *s, size_t count)
95472 +{
95473 + memset(s, 0, count);
95474 + OPTIMIZER_HIDE_VAR(s);
95475 +}
95476 +EXPORT_SYMBOL(memzero_explicit);
95477 +
95478 #ifndef __HAVE_ARCH_MEMCPY
95479 /**
95480 * memcpy - Copy one area of memory to another
95481 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95482 index bb2b201..46abaf9 100644
95483 --- a/lib/strncpy_from_user.c
95484 +++ b/lib/strncpy_from_user.c
95485 @@ -21,7 +21,7 @@
95486 */
95487 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95488 {
95489 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95490 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95491 long res = 0;
95492
95493 /*
95494 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95495 index a28df52..3d55877 100644
95496 --- a/lib/strnlen_user.c
95497 +++ b/lib/strnlen_user.c
95498 @@ -26,7 +26,7 @@
95499 */
95500 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95501 {
95502 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95503 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95504 long align, res = 0;
95505 unsigned long c;
95506
95507 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95508 index 4abda07..b9d3765 100644
95509 --- a/lib/swiotlb.c
95510 +++ b/lib/swiotlb.c
95511 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95512
95513 void
95514 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95515 - dma_addr_t dev_addr)
95516 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95517 {
95518 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95519
95520 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95521 index 89e0345..3347efe 100644
95522 --- a/lib/test_bpf.c
95523 +++ b/lib/test_bpf.c
95524 @@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95525 break;
95526
95527 case INTERNAL:
95528 - fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95529 + fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95530 if (fp == NULL) {
95531 pr_cont("UNEXPECTED_FAIL no memory left\n");
95532 *err = -ENOMEM;
95533 diff --git a/lib/usercopy.c b/lib/usercopy.c
95534 index 4f5b1dd..7cab418 100644
95535 --- a/lib/usercopy.c
95536 +++ b/lib/usercopy.c
95537 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95538 WARN(1, "Buffer overflow detected!\n");
95539 }
95540 EXPORT_SYMBOL(copy_from_user_overflow);
95541 +
95542 +void copy_to_user_overflow(void)
95543 +{
95544 + WARN(1, "Buffer overflow detected!\n");
95545 +}
95546 +EXPORT_SYMBOL(copy_to_user_overflow);
95547 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95548 index 6fe2c84..2fe5ec6 100644
95549 --- a/lib/vsprintf.c
95550 +++ b/lib/vsprintf.c
95551 @@ -16,6 +16,9 @@
95552 * - scnprintf and vscnprintf
95553 */
95554
95555 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95556 +#define __INCLUDED_BY_HIDESYM 1
95557 +#endif
95558 #include <stdarg.h>
95559 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95560 #include <linux/types.h>
95561 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95562 #ifdef CONFIG_KALLSYMS
95563 if (*fmt == 'B')
95564 sprint_backtrace(sym, value);
95565 - else if (*fmt != 'f' && *fmt != 's')
95566 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95567 sprint_symbol(sym, value);
95568 else
95569 sprint_symbol_no_offset(sym, value);
95570 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95571 return number(buf, end, num, spec);
95572 }
95573
95574 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95575 +int kptr_restrict __read_mostly = 2;
95576 +#else
95577 int kptr_restrict __read_mostly;
95578 +#endif
95579
95580 /*
95581 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95582 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95583 *
95584 * - 'F' For symbolic function descriptor pointers with offset
95585 * - 'f' For simple symbolic function names without offset
95586 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95587 * - 'S' For symbolic direct pointers with offset
95588 * - 's' For symbolic direct pointers without offset
95589 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95590 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95591 * - 'B' For backtraced symbolic direct pointers with offset
95592 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95593 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95594
95595 if (!ptr && *fmt != 'K') {
95596 /*
95597 - * Print (null) with the same width as a pointer so it makes
95598 + * Print (nil) with the same width as a pointer so it makes
95599 * tabular output look nice.
95600 */
95601 if (spec.field_width == -1)
95602 spec.field_width = default_width;
95603 - return string(buf, end, "(null)", spec);
95604 + return string(buf, end, "(nil)", spec);
95605 }
95606
95607 switch (*fmt) {
95608 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95609 /* Fallthrough */
95610 case 'S':
95611 case 's':
95612 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95613 + break;
95614 +#else
95615 + return symbol_string(buf, end, ptr, spec, fmt);
95616 +#endif
95617 + case 'X':
95618 + ptr = dereference_function_descriptor(ptr);
95619 + case 'A':
95620 case 'B':
95621 return symbol_string(buf, end, ptr, spec, fmt);
95622 case 'R':
95623 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95624 va_end(va);
95625 return buf;
95626 }
95627 + case 'P':
95628 + break;
95629 case 'K':
95630 /*
95631 * %pK cannot be used in IRQ context because its test
95632 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95633 ((const struct file *)ptr)->f_path.dentry,
95634 spec, fmt);
95635 }
95636 +
95637 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95638 + /* 'P' = approved pointers to copy to userland,
95639 + as in the /proc/kallsyms case, as we make it display nothing
95640 + for non-root users, and the real contents for root users
95641 + 'X' = approved simple symbols
95642 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95643 + above
95644 + */
95645 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95646 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95647 + dump_stack();
95648 + ptr = NULL;
95649 + }
95650 +#endif
95651 +
95652 spec.flags |= SMALL;
95653 if (spec.field_width == -1) {
95654 spec.field_width = default_width;
95655 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95656 typeof(type) value; \
95657 if (sizeof(type) == 8) { \
95658 args = PTR_ALIGN(args, sizeof(u32)); \
95659 - *(u32 *)&value = *(u32 *)args; \
95660 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95661 + *(u32 *)&value = *(const u32 *)args; \
95662 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95663 } else { \
95664 args = PTR_ALIGN(args, sizeof(type)); \
95665 - value = *(typeof(type) *)args; \
95666 + value = *(const typeof(type) *)args; \
95667 } \
95668 args += sizeof(type); \
95669 value; \
95670 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95671 case FORMAT_TYPE_STR: {
95672 const char *str_arg = args;
95673 args += strlen(str_arg) + 1;
95674 - str = string(str, end, (char *)str_arg, spec);
95675 + str = string(str, end, str_arg, spec);
95676 break;
95677 }
95678
95679 diff --git a/localversion-grsec b/localversion-grsec
95680 new file mode 100644
95681 index 0000000..7cd6065
95682 --- /dev/null
95683 +++ b/localversion-grsec
95684 @@ -0,0 +1 @@
95685 +-grsec
95686 diff --git a/mm/Kconfig b/mm/Kconfig
95687 index 886db21..f514de2 100644
95688 --- a/mm/Kconfig
95689 +++ b/mm/Kconfig
95690 @@ -333,10 +333,11 @@ config KSM
95691 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95692
95693 config DEFAULT_MMAP_MIN_ADDR
95694 - int "Low address space to protect from user allocation"
95695 + int "Low address space to protect from user allocation"
95696 depends on MMU
95697 - default 4096
95698 - help
95699 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95700 + default 65536
95701 + help
95702 This is the portion of low virtual memory which should be protected
95703 from userspace allocation. Keeping a user from writing to low pages
95704 can help reduce the impact of kernel NULL pointer bugs.
95705 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
95706
95707 config HWPOISON_INJECT
95708 tristate "HWPoison pages injector"
95709 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95710 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95711 select PROC_PAGE_MONITOR
95712
95713 config NOMMU_INITIAL_TRIM_EXCESS
95714 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95715 index 1706cbb..f89dbca 100644
95716 --- a/mm/backing-dev.c
95717 +++ b/mm/backing-dev.c
95718 @@ -12,7 +12,7 @@
95719 #include <linux/device.h>
95720 #include <trace/events/writeback.h>
95721
95722 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95723 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95724
95725 struct backing_dev_info default_backing_dev_info = {
95726 .name = "default",
95727 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95728 return err;
95729
95730 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95731 - atomic_long_inc_return(&bdi_seq));
95732 + atomic_long_inc_return_unchecked(&bdi_seq));
95733 if (err) {
95734 bdi_destroy(bdi);
95735 return err;
95736 diff --git a/mm/filemap.c b/mm/filemap.c
95737 index 90effcd..539aa64 100644
95738 --- a/mm/filemap.c
95739 +++ b/mm/filemap.c
95740 @@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95741 struct address_space *mapping = file->f_mapping;
95742
95743 if (!mapping->a_ops->readpage)
95744 - return -ENOEXEC;
95745 + return -ENODEV;
95746 file_accessed(file);
95747 vma->vm_ops = &generic_file_vm_ops;
95748 return 0;
95749 @@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95750 *pos = i_size_read(inode);
95751
95752 if (limit != RLIM_INFINITY) {
95753 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95754 if (*pos >= limit) {
95755 send_sig(SIGXFSZ, current, 0);
95756 return -EFBIG;
95757 diff --git a/mm/fremap.c b/mm/fremap.c
95758 index 72b8fa3..c5b39f1 100644
95759 --- a/mm/fremap.c
95760 +++ b/mm/fremap.c
95761 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95762 retry:
95763 vma = find_vma(mm, start);
95764
95765 +#ifdef CONFIG_PAX_SEGMEXEC
95766 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95767 + goto out;
95768 +#endif
95769 +
95770 /*
95771 * Make sure the vma is shared, that it supports prefaulting,
95772 * and that the remapped range is valid and fully within
95773 diff --git a/mm/gup.c b/mm/gup.c
95774 index 91d044b..a58ecf6 100644
95775 --- a/mm/gup.c
95776 +++ b/mm/gup.c
95777 @@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95778 unsigned int fault_flags = 0;
95779 int ret;
95780
95781 - /* For mlock, just skip the stack guard page. */
95782 - if ((*flags & FOLL_MLOCK) &&
95783 - (stack_guard_page_start(vma, address) ||
95784 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95785 - return -ENOENT;
95786 if (*flags & FOLL_WRITE)
95787 fault_flags |= FAULT_FLAG_WRITE;
95788 if (nonblocking)
95789 @@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95790 if (!(gup_flags & FOLL_FORCE))
95791 gup_flags |= FOLL_NUMA;
95792
95793 - do {
95794 + while (nr_pages) {
95795 struct page *page;
95796 unsigned int foll_flags = gup_flags;
95797 unsigned int page_increm;
95798
95799 /* first iteration or cross vma bound */
95800 if (!vma || start >= vma->vm_end) {
95801 - vma = find_extend_vma(mm, start);
95802 + vma = find_vma(mm, start);
95803 if (!vma && in_gate_area(mm, start)) {
95804 int ret;
95805 ret = get_gate_page(mm, start & PAGE_MASK,
95806 @@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95807 goto next_page;
95808 }
95809
95810 - if (!vma || check_vma_flags(vma, gup_flags))
95811 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95812 return i ? : -EFAULT;
95813 if (is_vm_hugetlb_page(vma)) {
95814 i = follow_hugetlb_page(mm, vma, pages, vmas,
95815 @@ -510,7 +505,7 @@ next_page:
95816 i += page_increm;
95817 start += page_increm * PAGE_SIZE;
95818 nr_pages -= page_increm;
95819 - } while (nr_pages);
95820 + }
95821 return i;
95822 }
95823 EXPORT_SYMBOL(__get_user_pages);
95824 diff --git a/mm/highmem.c b/mm/highmem.c
95825 index 123bcd3..0de52ba 100644
95826 --- a/mm/highmem.c
95827 +++ b/mm/highmem.c
95828 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95829 * So no dangers, even with speculative execution.
95830 */
95831 page = pte_page(pkmap_page_table[i]);
95832 + pax_open_kernel();
95833 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95834 -
95835 + pax_close_kernel();
95836 set_page_address(page, NULL);
95837 need_flush = 1;
95838 }
95839 @@ -259,9 +260,11 @@ start:
95840 }
95841 }
95842 vaddr = PKMAP_ADDR(last_pkmap_nr);
95843 +
95844 + pax_open_kernel();
95845 set_pte_at(&init_mm, vaddr,
95846 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95847 -
95848 + pax_close_kernel();
95849 pkmap_count[last_pkmap_nr] = 1;
95850 set_page_address(page, (void *)vaddr);
95851
95852 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95853 index eeceeeb..a209d58 100644
95854 --- a/mm/hugetlb.c
95855 +++ b/mm/hugetlb.c
95856 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95857 struct ctl_table *table, int write,
95858 void __user *buffer, size_t *length, loff_t *ppos)
95859 {
95860 + ctl_table_no_const t;
95861 struct hstate *h = &default_hstate;
95862 unsigned long tmp = h->max_huge_pages;
95863 int ret;
95864 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95865 if (!hugepages_supported())
95866 return -ENOTSUPP;
95867
95868 - table->data = &tmp;
95869 - table->maxlen = sizeof(unsigned long);
95870 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95871 + t = *table;
95872 + t.data = &tmp;
95873 + t.maxlen = sizeof(unsigned long);
95874 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95875 if (ret)
95876 goto out;
95877
95878 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95879 struct hstate *h = &default_hstate;
95880 unsigned long tmp;
95881 int ret;
95882 + ctl_table_no_const hugetlb_table;
95883
95884 if (!hugepages_supported())
95885 return -ENOTSUPP;
95886 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95887 if (write && hstate_is_gigantic(h))
95888 return -EINVAL;
95889
95890 - table->data = &tmp;
95891 - table->maxlen = sizeof(unsigned long);
95892 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95893 + hugetlb_table = *table;
95894 + hugetlb_table.data = &tmp;
95895 + hugetlb_table.maxlen = sizeof(unsigned long);
95896 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95897 if (ret)
95898 goto out;
95899
95900 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95901 mutex_unlock(&mapping->i_mmap_mutex);
95902 }
95903
95904 +#ifdef CONFIG_PAX_SEGMEXEC
95905 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95906 +{
95907 + struct mm_struct *mm = vma->vm_mm;
95908 + struct vm_area_struct *vma_m;
95909 + unsigned long address_m;
95910 + pte_t *ptep_m;
95911 +
95912 + vma_m = pax_find_mirror_vma(vma);
95913 + if (!vma_m)
95914 + return;
95915 +
95916 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95917 + address_m = address + SEGMEXEC_TASK_SIZE;
95918 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95919 + get_page(page_m);
95920 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95921 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95922 +}
95923 +#endif
95924 +
95925 /*
95926 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95927 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95928 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95929 make_huge_pte(vma, new_page, 1));
95930 page_remove_rmap(old_page);
95931 hugepage_add_new_anon_rmap(new_page, vma, address);
95932 +
95933 +#ifdef CONFIG_PAX_SEGMEXEC
95934 + pax_mirror_huge_pte(vma, address, new_page);
95935 +#endif
95936 +
95937 /* Make the old page be freed below */
95938 new_page = old_page;
95939 }
95940 @@ -3063,6 +3093,10 @@ retry:
95941 && (vma->vm_flags & VM_SHARED)));
95942 set_huge_pte_at(mm, address, ptep, new_pte);
95943
95944 +#ifdef CONFIG_PAX_SEGMEXEC
95945 + pax_mirror_huge_pte(vma, address, page);
95946 +#endif
95947 +
95948 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95949 /* Optimization, do the COW without a second fault */
95950 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95951 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95952 struct hstate *h = hstate_vma(vma);
95953 struct address_space *mapping;
95954
95955 +#ifdef CONFIG_PAX_SEGMEXEC
95956 + struct vm_area_struct *vma_m;
95957 +#endif
95958 +
95959 address &= huge_page_mask(h);
95960
95961 ptep = huge_pte_offset(mm, address);
95962 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95963 VM_FAULT_SET_HINDEX(hstate_index(h));
95964 }
95965
95966 +#ifdef CONFIG_PAX_SEGMEXEC
95967 + vma_m = pax_find_mirror_vma(vma);
95968 + if (vma_m) {
95969 + unsigned long address_m;
95970 +
95971 + if (vma->vm_start > vma_m->vm_start) {
95972 + address_m = address;
95973 + address -= SEGMEXEC_TASK_SIZE;
95974 + vma = vma_m;
95975 + h = hstate_vma(vma);
95976 + } else
95977 + address_m = address + SEGMEXEC_TASK_SIZE;
95978 +
95979 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95980 + return VM_FAULT_OOM;
95981 + address_m &= HPAGE_MASK;
95982 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95983 + }
95984 +#endif
95985 +
95986 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95987 if (!ptep)
95988 return VM_FAULT_OOM;
95989 diff --git a/mm/internal.h b/mm/internal.h
95990 index a1b651b..f688570 100644
95991 --- a/mm/internal.h
95992 +++ b/mm/internal.h
95993 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
95994 * in mm/page_alloc.c
95995 */
95996 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95997 +extern void free_compound_page(struct page *page);
95998 extern void prep_compound_page(struct page *page, unsigned long order);
95999 #ifdef CONFIG_MEMORY_FAILURE
96000 extern bool is_free_buddy_page(struct page *page);
96001 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
96002
96003 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
96004 unsigned long, unsigned long,
96005 - unsigned long, unsigned long);
96006 + unsigned long, unsigned long) __intentional_overflow(-1);
96007
96008 extern void set_pageblock_order(void);
96009 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
96010 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
96011 index 9a09f20..6ef0515 100644
96012 --- a/mm/iov_iter.c
96013 +++ b/mm/iov_iter.c
96014 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
96015
96016 while (bytes) {
96017 char __user *buf = iov->iov_base + base;
96018 - int copy = min(bytes, iov->iov_len - base);
96019 + size_t copy = min(bytes, iov->iov_len - base);
96020
96021 base = 0;
96022 left = __copy_from_user_inatomic(vaddr, buf, copy);
96023 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
96024
96025 kaddr = kmap_atomic(page);
96026 if (likely(i->nr_segs == 1)) {
96027 - int left;
96028 + size_t left;
96029 char __user *buf = i->iov->iov_base + i->iov_offset;
96030 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
96031 copied = bytes - left;
96032 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
96033 * zero-length segments (without overruning the iovec).
96034 */
96035 while (bytes || unlikely(i->count && !iov->iov_len)) {
96036 - int copy;
96037 + size_t copy;
96038
96039 copy = min(bytes, iov->iov_len - base);
96040 BUG_ON(!i->count || i->count < copy);
96041 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
96042 index 3cda50c..032ba634 100644
96043 --- a/mm/kmemleak.c
96044 +++ b/mm/kmemleak.c
96045 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
96046
96047 for (i = 0; i < object->trace_len; i++) {
96048 void *ptr = (void *)object->trace[i];
96049 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
96050 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
96051 }
96052 }
96053
96054 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
96055 return -ENOMEM;
96056 }
96057
96058 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
96059 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
96060 &kmemleak_fops);
96061 if (!dentry)
96062 pr_warning("Failed to create the debugfs kmemleak file\n");
96063 diff --git a/mm/maccess.c b/mm/maccess.c
96064 index d53adf9..03a24bf 100644
96065 --- a/mm/maccess.c
96066 +++ b/mm/maccess.c
96067 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96068 set_fs(KERNEL_DS);
96069 pagefault_disable();
96070 ret = __copy_from_user_inatomic(dst,
96071 - (__force const void __user *)src, size);
96072 + (const void __force_user *)src, size);
96073 pagefault_enable();
96074 set_fs(old_fs);
96075
96076 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96077
96078 set_fs(KERNEL_DS);
96079 pagefault_disable();
96080 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96081 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96082 pagefault_enable();
96083 set_fs(old_fs);
96084
96085 diff --git a/mm/madvise.c b/mm/madvise.c
96086 index 0938b30..199abe8 100644
96087 --- a/mm/madvise.c
96088 +++ b/mm/madvise.c
96089 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96090 pgoff_t pgoff;
96091 unsigned long new_flags = vma->vm_flags;
96092
96093 +#ifdef CONFIG_PAX_SEGMEXEC
96094 + struct vm_area_struct *vma_m;
96095 +#endif
96096 +
96097 switch (behavior) {
96098 case MADV_NORMAL:
96099 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96100 @@ -126,6 +130,13 @@ success:
96101 /*
96102 * vm_flags is protected by the mmap_sem held in write mode.
96103 */
96104 +
96105 +#ifdef CONFIG_PAX_SEGMEXEC
96106 + vma_m = pax_find_mirror_vma(vma);
96107 + if (vma_m)
96108 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96109 +#endif
96110 +
96111 vma->vm_flags = new_flags;
96112
96113 out:
96114 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96115 struct vm_area_struct **prev,
96116 unsigned long start, unsigned long end)
96117 {
96118 +
96119 +#ifdef CONFIG_PAX_SEGMEXEC
96120 + struct vm_area_struct *vma_m;
96121 +#endif
96122 +
96123 *prev = vma;
96124 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96125 return -EINVAL;
96126 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96127 zap_page_range(vma, start, end - start, &details);
96128 } else
96129 zap_page_range(vma, start, end - start, NULL);
96130 +
96131 +#ifdef CONFIG_PAX_SEGMEXEC
96132 + vma_m = pax_find_mirror_vma(vma);
96133 + if (vma_m) {
96134 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96135 + struct zap_details details = {
96136 + .nonlinear_vma = vma_m,
96137 + .last_index = ULONG_MAX,
96138 + };
96139 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96140 + } else
96141 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96142 + }
96143 +#endif
96144 +
96145 return 0;
96146 }
96147
96148 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96149 if (end < start)
96150 return error;
96151
96152 +#ifdef CONFIG_PAX_SEGMEXEC
96153 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96154 + if (end > SEGMEXEC_TASK_SIZE)
96155 + return error;
96156 + } else
96157 +#endif
96158 +
96159 + if (end > TASK_SIZE)
96160 + return error;
96161 +
96162 error = 0;
96163 if (end == start)
96164 return error;
96165 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96166 index 44c6bd2..60369dc3 100644
96167 --- a/mm/memory-failure.c
96168 +++ b/mm/memory-failure.c
96169 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96170
96171 int sysctl_memory_failure_recovery __read_mostly = 1;
96172
96173 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96174 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96175
96176 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96177
96178 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96179 pfn, t->comm, t->pid);
96180 si.si_signo = SIGBUS;
96181 si.si_errno = 0;
96182 - si.si_addr = (void *)addr;
96183 + si.si_addr = (void __user *)addr;
96184 #ifdef __ARCH_SI_TRAPNO
96185 si.si_trapno = trapno;
96186 #endif
96187 @@ -791,7 +791,7 @@ static struct page_state {
96188 unsigned long res;
96189 char *msg;
96190 int (*action)(struct page *p, unsigned long pfn);
96191 -} error_states[] = {
96192 +} __do_const error_states[] = {
96193 { reserved, reserved, "reserved kernel", me_kernel },
96194 /*
96195 * free pages are specially detected outside this table:
96196 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96197 nr_pages = 1 << compound_order(hpage);
96198 else /* normal page or thp */
96199 nr_pages = 1;
96200 - atomic_long_add(nr_pages, &num_poisoned_pages);
96201 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96202
96203 /*
96204 * We need/can do nothing about count=0 pages.
96205 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96206 if (PageHWPoison(hpage)) {
96207 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96208 || (p != hpage && TestSetPageHWPoison(hpage))) {
96209 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96210 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96211 unlock_page(hpage);
96212 return 0;
96213 }
96214 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96215 */
96216 if (!PageHWPoison(p)) {
96217 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96218 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96219 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96220 put_page(hpage);
96221 res = 0;
96222 goto out;
96223 }
96224 if (hwpoison_filter(p)) {
96225 if (TestClearPageHWPoison(p))
96226 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96227 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96228 unlock_page(hpage);
96229 put_page(hpage);
96230 return 0;
96231 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96232 return 0;
96233 }
96234 if (TestClearPageHWPoison(p))
96235 - atomic_long_dec(&num_poisoned_pages);
96236 + atomic_long_dec_unchecked(&num_poisoned_pages);
96237 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96238 return 0;
96239 }
96240 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96241 */
96242 if (TestClearPageHWPoison(page)) {
96243 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96244 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96245 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96246 freeit = 1;
96247 if (PageHuge(page))
96248 clear_page_hwpoison_huge_page(page);
96249 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96250 if (PageHuge(page)) {
96251 set_page_hwpoison_huge_page(hpage);
96252 dequeue_hwpoisoned_huge_page(hpage);
96253 - atomic_long_add(1 << compound_order(hpage),
96254 + atomic_long_add_unchecked(1 << compound_order(hpage),
96255 &num_poisoned_pages);
96256 } else {
96257 SetPageHWPoison(page);
96258 - atomic_long_inc(&num_poisoned_pages);
96259 + atomic_long_inc_unchecked(&num_poisoned_pages);
96260 }
96261 }
96262 return ret;
96263 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96264 put_page(page);
96265 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96266 SetPageHWPoison(page);
96267 - atomic_long_inc(&num_poisoned_pages);
96268 + atomic_long_inc_unchecked(&num_poisoned_pages);
96269 return 0;
96270 }
96271
96272 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96273 if (!is_free_buddy_page(page))
96274 pr_info("soft offline: %#lx: page leaked\n",
96275 pfn);
96276 - atomic_long_inc(&num_poisoned_pages);
96277 + atomic_long_inc_unchecked(&num_poisoned_pages);
96278 }
96279 } else {
96280 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96281 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96282 if (PageHuge(page)) {
96283 set_page_hwpoison_huge_page(hpage);
96284 dequeue_hwpoisoned_huge_page(hpage);
96285 - atomic_long_add(1 << compound_order(hpage),
96286 + atomic_long_add_unchecked(1 << compound_order(hpage),
96287 &num_poisoned_pages);
96288 } else {
96289 SetPageHWPoison(page);
96290 - atomic_long_inc(&num_poisoned_pages);
96291 + atomic_long_inc_unchecked(&num_poisoned_pages);
96292 }
96293 }
96294 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96295 diff --git a/mm/memory.c b/mm/memory.c
96296 index e229970..68218aa 100644
96297 --- a/mm/memory.c
96298 +++ b/mm/memory.c
96299 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96300 free_pte_range(tlb, pmd, addr);
96301 } while (pmd++, addr = next, addr != end);
96302
96303 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96304 start &= PUD_MASK;
96305 if (start < floor)
96306 return;
96307 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96308 pmd = pmd_offset(pud, start);
96309 pud_clear(pud);
96310 pmd_free_tlb(tlb, pmd, start);
96311 +#endif
96312 +
96313 }
96314
96315 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96316 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96317 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96318 } while (pud++, addr = next, addr != end);
96319
96320 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96321 start &= PGDIR_MASK;
96322 if (start < floor)
96323 return;
96324 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96325 pud = pud_offset(pgd, start);
96326 pgd_clear(pgd);
96327 pud_free_tlb(tlb, pud, start);
96328 +#endif
96329 +
96330 }
96331
96332 /*
96333 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96334 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96335 */
96336 if (vma->vm_ops)
96337 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96338 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96339 vma->vm_ops->fault);
96340 if (vma->vm_file)
96341 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96342 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96343 vma->vm_file->f_op->mmap);
96344 dump_stack();
96345 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96346 @@ -1147,6 +1153,7 @@ again:
96347 print_bad_pte(vma, addr, ptent, page);
96348 if (unlikely(!__tlb_remove_page(tlb, page))) {
96349 force_flush = 1;
96350 + addr += PAGE_SIZE;
96351 break;
96352 }
96353 continue;
96354 @@ -1500,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96355 page_add_file_rmap(page);
96356 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96357
96358 +#ifdef CONFIG_PAX_SEGMEXEC
96359 + pax_mirror_file_pte(vma, addr, page, ptl);
96360 +#endif
96361 +
96362 retval = 0;
96363 pte_unmap_unlock(pte, ptl);
96364 return retval;
96365 @@ -1544,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96366 if (!page_count(page))
96367 return -EINVAL;
96368 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96369 +
96370 +#ifdef CONFIG_PAX_SEGMEXEC
96371 + struct vm_area_struct *vma_m;
96372 +#endif
96373 +
96374 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96375 BUG_ON(vma->vm_flags & VM_PFNMAP);
96376 vma->vm_flags |= VM_MIXEDMAP;
96377 +
96378 +#ifdef CONFIG_PAX_SEGMEXEC
96379 + vma_m = pax_find_mirror_vma(vma);
96380 + if (vma_m)
96381 + vma_m->vm_flags |= VM_MIXEDMAP;
96382 +#endif
96383 +
96384 }
96385 return insert_page(vma, addr, page, vma->vm_page_prot);
96386 }
96387 @@ -1629,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96388 unsigned long pfn)
96389 {
96390 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96391 + BUG_ON(vma->vm_mirror);
96392
96393 if (addr < vma->vm_start || addr >= vma->vm_end)
96394 return -EFAULT;
96395 @@ -1876,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96396
96397 BUG_ON(pud_huge(*pud));
96398
96399 - pmd = pmd_alloc(mm, pud, addr);
96400 + pmd = (mm == &init_mm) ?
96401 + pmd_alloc_kernel(mm, pud, addr) :
96402 + pmd_alloc(mm, pud, addr);
96403 if (!pmd)
96404 return -ENOMEM;
96405 do {
96406 @@ -1896,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96407 unsigned long next;
96408 int err;
96409
96410 - pud = pud_alloc(mm, pgd, addr);
96411 + pud = (mm == &init_mm) ?
96412 + pud_alloc_kernel(mm, pgd, addr) :
96413 + pud_alloc(mm, pgd, addr);
96414 if (!pud)
96415 return -ENOMEM;
96416 do {
96417 @@ -2018,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96418 return ret;
96419 }
96420
96421 +#ifdef CONFIG_PAX_SEGMEXEC
96422 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96423 +{
96424 + struct mm_struct *mm = vma->vm_mm;
96425 + spinlock_t *ptl;
96426 + pte_t *pte, entry;
96427 +
96428 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96429 + entry = *pte;
96430 + if (!pte_present(entry)) {
96431 + if (!pte_none(entry)) {
96432 + BUG_ON(pte_file(entry));
96433 + free_swap_and_cache(pte_to_swp_entry(entry));
96434 + pte_clear_not_present_full(mm, address, pte, 0);
96435 + }
96436 + } else {
96437 + struct page *page;
96438 +
96439 + flush_cache_page(vma, address, pte_pfn(entry));
96440 + entry = ptep_clear_flush(vma, address, pte);
96441 + BUG_ON(pte_dirty(entry));
96442 + page = vm_normal_page(vma, address, entry);
96443 + if (page) {
96444 + update_hiwater_rss(mm);
96445 + if (PageAnon(page))
96446 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96447 + else
96448 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96449 + page_remove_rmap(page);
96450 + page_cache_release(page);
96451 + }
96452 + }
96453 + pte_unmap_unlock(pte, ptl);
96454 +}
96455 +
96456 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96457 + *
96458 + * the ptl of the lower mapped page is held on entry and is not released on exit
96459 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96460 + */
96461 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96462 +{
96463 + struct mm_struct *mm = vma->vm_mm;
96464 + unsigned long address_m;
96465 + spinlock_t *ptl_m;
96466 + struct vm_area_struct *vma_m;
96467 + pmd_t *pmd_m;
96468 + pte_t *pte_m, entry_m;
96469 +
96470 + BUG_ON(!page_m || !PageAnon(page_m));
96471 +
96472 + vma_m = pax_find_mirror_vma(vma);
96473 + if (!vma_m)
96474 + return;
96475 +
96476 + BUG_ON(!PageLocked(page_m));
96477 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96478 + address_m = address + SEGMEXEC_TASK_SIZE;
96479 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96480 + pte_m = pte_offset_map(pmd_m, address_m);
96481 + ptl_m = pte_lockptr(mm, pmd_m);
96482 + if (ptl != ptl_m) {
96483 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96484 + if (!pte_none(*pte_m))
96485 + goto out;
96486 + }
96487 +
96488 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96489 + page_cache_get(page_m);
96490 + page_add_anon_rmap(page_m, vma_m, address_m);
96491 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96492 + set_pte_at(mm, address_m, pte_m, entry_m);
96493 + update_mmu_cache(vma_m, address_m, pte_m);
96494 +out:
96495 + if (ptl != ptl_m)
96496 + spin_unlock(ptl_m);
96497 + pte_unmap(pte_m);
96498 + unlock_page(page_m);
96499 +}
96500 +
96501 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96502 +{
96503 + struct mm_struct *mm = vma->vm_mm;
96504 + unsigned long address_m;
96505 + spinlock_t *ptl_m;
96506 + struct vm_area_struct *vma_m;
96507 + pmd_t *pmd_m;
96508 + pte_t *pte_m, entry_m;
96509 +
96510 + BUG_ON(!page_m || PageAnon(page_m));
96511 +
96512 + vma_m = pax_find_mirror_vma(vma);
96513 + if (!vma_m)
96514 + return;
96515 +
96516 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96517 + address_m = address + SEGMEXEC_TASK_SIZE;
96518 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96519 + pte_m = pte_offset_map(pmd_m, address_m);
96520 + ptl_m = pte_lockptr(mm, pmd_m);
96521 + if (ptl != ptl_m) {
96522 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96523 + if (!pte_none(*pte_m))
96524 + goto out;
96525 + }
96526 +
96527 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96528 + page_cache_get(page_m);
96529 + page_add_file_rmap(page_m);
96530 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96531 + set_pte_at(mm, address_m, pte_m, entry_m);
96532 + update_mmu_cache(vma_m, address_m, pte_m);
96533 +out:
96534 + if (ptl != ptl_m)
96535 + spin_unlock(ptl_m);
96536 + pte_unmap(pte_m);
96537 +}
96538 +
96539 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96540 +{
96541 + struct mm_struct *mm = vma->vm_mm;
96542 + unsigned long address_m;
96543 + spinlock_t *ptl_m;
96544 + struct vm_area_struct *vma_m;
96545 + pmd_t *pmd_m;
96546 + pte_t *pte_m, entry_m;
96547 +
96548 + vma_m = pax_find_mirror_vma(vma);
96549 + if (!vma_m)
96550 + return;
96551 +
96552 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96553 + address_m = address + SEGMEXEC_TASK_SIZE;
96554 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96555 + pte_m = pte_offset_map(pmd_m, address_m);
96556 + ptl_m = pte_lockptr(mm, pmd_m);
96557 + if (ptl != ptl_m) {
96558 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96559 + if (!pte_none(*pte_m))
96560 + goto out;
96561 + }
96562 +
96563 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96564 + set_pte_at(mm, address_m, pte_m, entry_m);
96565 +out:
96566 + if (ptl != ptl_m)
96567 + spin_unlock(ptl_m);
96568 + pte_unmap(pte_m);
96569 +}
96570 +
96571 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96572 +{
96573 + struct page *page_m;
96574 + pte_t entry;
96575 +
96576 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96577 + goto out;
96578 +
96579 + entry = *pte;
96580 + page_m = vm_normal_page(vma, address, entry);
96581 + if (!page_m)
96582 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96583 + else if (PageAnon(page_m)) {
96584 + if (pax_find_mirror_vma(vma)) {
96585 + pte_unmap_unlock(pte, ptl);
96586 + lock_page(page_m);
96587 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96588 + if (pte_same(entry, *pte))
96589 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96590 + else
96591 + unlock_page(page_m);
96592 + }
96593 + } else
96594 + pax_mirror_file_pte(vma, address, page_m, ptl);
96595 +
96596 +out:
96597 + pte_unmap_unlock(pte, ptl);
96598 +}
96599 +#endif
96600 +
96601 /*
96602 * This routine handles present pages, when users try to write
96603 * to a shared page. It is done by copying the page to a new address
96604 @@ -2216,6 +2424,12 @@ gotten:
96605 */
96606 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96607 if (likely(pte_same(*page_table, orig_pte))) {
96608 +
96609 +#ifdef CONFIG_PAX_SEGMEXEC
96610 + if (pax_find_mirror_vma(vma))
96611 + BUG_ON(!trylock_page(new_page));
96612 +#endif
96613 +
96614 if (old_page) {
96615 if (!PageAnon(old_page)) {
96616 dec_mm_counter_fast(mm, MM_FILEPAGES);
96617 @@ -2269,6 +2483,10 @@ gotten:
96618 page_remove_rmap(old_page);
96619 }
96620
96621 +#ifdef CONFIG_PAX_SEGMEXEC
96622 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96623 +#endif
96624 +
96625 /* Free the old page.. */
96626 new_page = old_page;
96627 ret |= VM_FAULT_WRITE;
96628 @@ -2543,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96629 swap_free(entry);
96630 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96631 try_to_free_swap(page);
96632 +
96633 +#ifdef CONFIG_PAX_SEGMEXEC
96634 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96635 +#endif
96636 +
96637 unlock_page(page);
96638 if (page != swapcache) {
96639 /*
96640 @@ -2566,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96641
96642 /* No need to invalidate - it was non-present before */
96643 update_mmu_cache(vma, address, page_table);
96644 +
96645 +#ifdef CONFIG_PAX_SEGMEXEC
96646 + pax_mirror_anon_pte(vma, address, page, ptl);
96647 +#endif
96648 +
96649 unlock:
96650 pte_unmap_unlock(page_table, ptl);
96651 out:
96652 @@ -2585,40 +2813,6 @@ out_release:
96653 }
96654
96655 /*
96656 - * This is like a special single-page "expand_{down|up}wards()",
96657 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96658 - * doesn't hit another vma.
96659 - */
96660 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96661 -{
96662 - address &= PAGE_MASK;
96663 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96664 - struct vm_area_struct *prev = vma->vm_prev;
96665 -
96666 - /*
96667 - * Is there a mapping abutting this one below?
96668 - *
96669 - * That's only ok if it's the same stack mapping
96670 - * that has gotten split..
96671 - */
96672 - if (prev && prev->vm_end == address)
96673 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96674 -
96675 - expand_downwards(vma, address - PAGE_SIZE);
96676 - }
96677 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96678 - struct vm_area_struct *next = vma->vm_next;
96679 -
96680 - /* As VM_GROWSDOWN but s/below/above/ */
96681 - if (next && next->vm_start == address + PAGE_SIZE)
96682 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96683 -
96684 - expand_upwards(vma, address + PAGE_SIZE);
96685 - }
96686 - return 0;
96687 -}
96688 -
96689 -/*
96690 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96691 * but allow concurrent faults), and pte mapped but not yet locked.
96692 * We return with mmap_sem still held, but pte unmapped and unlocked.
96693 @@ -2628,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96694 unsigned int flags)
96695 {
96696 struct mem_cgroup *memcg;
96697 - struct page *page;
96698 + struct page *page = NULL;
96699 spinlock_t *ptl;
96700 pte_t entry;
96701
96702 - pte_unmap(page_table);
96703 -
96704 - /* Check if we need to add a guard page to the stack */
96705 - if (check_stack_guard_page(vma, address) < 0)
96706 - return VM_FAULT_SIGBUS;
96707 -
96708 - /* Use the zero-page for reads */
96709 if (!(flags & FAULT_FLAG_WRITE)) {
96710 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96711 vma->vm_page_prot));
96712 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96713 + ptl = pte_lockptr(mm, pmd);
96714 + spin_lock(ptl);
96715 if (!pte_none(*page_table))
96716 goto unlock;
96717 goto setpte;
96718 }
96719
96720 /* Allocate our own private page. */
96721 + pte_unmap(page_table);
96722 +
96723 if (unlikely(anon_vma_prepare(vma)))
96724 goto oom;
96725 page = alloc_zeroed_user_highpage_movable(vma, address);
96726 @@ -2672,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96727 if (!pte_none(*page_table))
96728 goto release;
96729
96730 +#ifdef CONFIG_PAX_SEGMEXEC
96731 + if (pax_find_mirror_vma(vma))
96732 + BUG_ON(!trylock_page(page));
96733 +#endif
96734 +
96735 inc_mm_counter_fast(mm, MM_ANONPAGES);
96736 page_add_new_anon_rmap(page, vma, address);
96737 mem_cgroup_commit_charge(page, memcg, false);
96738 @@ -2681,6 +2876,12 @@ setpte:
96739
96740 /* No need to invalidate - it was non-present before */
96741 update_mmu_cache(vma, address, page_table);
96742 +
96743 +#ifdef CONFIG_PAX_SEGMEXEC
96744 + if (page)
96745 + pax_mirror_anon_pte(vma, address, page, ptl);
96746 +#endif
96747 +
96748 unlock:
96749 pte_unmap_unlock(page_table, ptl);
96750 return 0;
96751 @@ -2911,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96752 return ret;
96753 }
96754 do_set_pte(vma, address, fault_page, pte, false, false);
96755 +
96756 +#ifdef CONFIG_PAX_SEGMEXEC
96757 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96758 +#endif
96759 +
96760 unlock_page(fault_page);
96761 unlock_out:
96762 pte_unmap_unlock(pte, ptl);
96763 @@ -2953,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96764 page_cache_release(fault_page);
96765 goto uncharge_out;
96766 }
96767 +
96768 +#ifdef CONFIG_PAX_SEGMEXEC
96769 + if (pax_find_mirror_vma(vma))
96770 + BUG_ON(!trylock_page(new_page));
96771 +#endif
96772 +
96773 do_set_pte(vma, address, new_page, pte, true, true);
96774 +
96775 +#ifdef CONFIG_PAX_SEGMEXEC
96776 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96777 +#endif
96778 +
96779 mem_cgroup_commit_charge(new_page, memcg, false);
96780 lru_cache_add_active_or_unevictable(new_page, vma);
96781 pte_unmap_unlock(pte, ptl);
96782 @@ -3003,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96783 return ret;
96784 }
96785 do_set_pte(vma, address, fault_page, pte, true, false);
96786 +
96787 +#ifdef CONFIG_PAX_SEGMEXEC
96788 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96789 +#endif
96790 +
96791 pte_unmap_unlock(pte, ptl);
96792
96793 if (set_page_dirty(fault_page))
96794 @@ -3244,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96795 if (flags & FAULT_FLAG_WRITE)
96796 flush_tlb_fix_spurious_fault(vma, address);
96797 }
96798 +
96799 +#ifdef CONFIG_PAX_SEGMEXEC
96800 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96801 + return 0;
96802 +#endif
96803 +
96804 unlock:
96805 pte_unmap_unlock(pte, ptl);
96806 return 0;
96807 @@ -3263,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96808 pmd_t *pmd;
96809 pte_t *pte;
96810
96811 +#ifdef CONFIG_PAX_SEGMEXEC
96812 + struct vm_area_struct *vma_m;
96813 +#endif
96814 +
96815 if (unlikely(is_vm_hugetlb_page(vma)))
96816 return hugetlb_fault(mm, vma, address, flags);
96817
96818 +#ifdef CONFIG_PAX_SEGMEXEC
96819 + vma_m = pax_find_mirror_vma(vma);
96820 + if (vma_m) {
96821 + unsigned long address_m;
96822 + pgd_t *pgd_m;
96823 + pud_t *pud_m;
96824 + pmd_t *pmd_m;
96825 +
96826 + if (vma->vm_start > vma_m->vm_start) {
96827 + address_m = address;
96828 + address -= SEGMEXEC_TASK_SIZE;
96829 + vma = vma_m;
96830 + } else
96831 + address_m = address + SEGMEXEC_TASK_SIZE;
96832 +
96833 + pgd_m = pgd_offset(mm, address_m);
96834 + pud_m = pud_alloc(mm, pgd_m, address_m);
96835 + if (!pud_m)
96836 + return VM_FAULT_OOM;
96837 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96838 + if (!pmd_m)
96839 + return VM_FAULT_OOM;
96840 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96841 + return VM_FAULT_OOM;
96842 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96843 + }
96844 +#endif
96845 +
96846 pgd = pgd_offset(mm, address);
96847 pud = pud_alloc(mm, pgd, address);
96848 if (!pud)
96849 @@ -3399,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96850 spin_unlock(&mm->page_table_lock);
96851 return 0;
96852 }
96853 +
96854 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96855 +{
96856 + pud_t *new = pud_alloc_one(mm, address);
96857 + if (!new)
96858 + return -ENOMEM;
96859 +
96860 + smp_wmb(); /* See comment in __pte_alloc */
96861 +
96862 + spin_lock(&mm->page_table_lock);
96863 + if (pgd_present(*pgd)) /* Another has populated it */
96864 + pud_free(mm, new);
96865 + else
96866 + pgd_populate_kernel(mm, pgd, new);
96867 + spin_unlock(&mm->page_table_lock);
96868 + return 0;
96869 +}
96870 #endif /* __PAGETABLE_PUD_FOLDED */
96871
96872 #ifndef __PAGETABLE_PMD_FOLDED
96873 @@ -3429,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96874 spin_unlock(&mm->page_table_lock);
96875 return 0;
96876 }
96877 +
96878 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96879 +{
96880 + pmd_t *new = pmd_alloc_one(mm, address);
96881 + if (!new)
96882 + return -ENOMEM;
96883 +
96884 + smp_wmb(); /* See comment in __pte_alloc */
96885 +
96886 + spin_lock(&mm->page_table_lock);
96887 +#ifndef __ARCH_HAS_4LEVEL_HACK
96888 + if (pud_present(*pud)) /* Another has populated it */
96889 + pmd_free(mm, new);
96890 + else
96891 + pud_populate_kernel(mm, pud, new);
96892 +#else
96893 + if (pgd_present(*pud)) /* Another has populated it */
96894 + pmd_free(mm, new);
96895 + else
96896 + pgd_populate_kernel(mm, pud, new);
96897 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96898 + spin_unlock(&mm->page_table_lock);
96899 + return 0;
96900 +}
96901 #endif /* __PAGETABLE_PMD_FOLDED */
96902
96903 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96904 @@ -3538,8 +3839,8 @@ out:
96905 return ret;
96906 }
96907
96908 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96909 - void *buf, int len, int write)
96910 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96911 + void *buf, size_t len, int write)
96912 {
96913 resource_size_t phys_addr;
96914 unsigned long prot = 0;
96915 @@ -3565,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96916 * Access another process' address space as given in mm. If non-NULL, use the
96917 * given task for page fault accounting.
96918 */
96919 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96920 - unsigned long addr, void *buf, int len, int write)
96921 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96922 + unsigned long addr, void *buf, size_t len, int write)
96923 {
96924 struct vm_area_struct *vma;
96925 void *old_buf = buf;
96926 @@ -3574,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96927 down_read(&mm->mmap_sem);
96928 /* ignore errors, just check how much was successfully transferred */
96929 while (len) {
96930 - int bytes, ret, offset;
96931 + ssize_t bytes, ret, offset;
96932 void *maddr;
96933 struct page *page = NULL;
96934
96935 @@ -3635,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96936 *
96937 * The caller must hold a reference on @mm.
96938 */
96939 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96940 - void *buf, int len, int write)
96941 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96942 + void *buf, size_t len, int write)
96943 {
96944 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96945 }
96946 @@ -3646,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96947 * Source/target buffer must be kernel space,
96948 * Do not walk the page table directly, use get_user_pages
96949 */
96950 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96951 - void *buf, int len, int write)
96952 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96953 + void *buf, size_t len, int write)
96954 {
96955 struct mm_struct *mm;
96956 - int ret;
96957 + ssize_t ret;
96958
96959 mm = get_task_mm(tsk);
96960 if (!mm)
96961 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96962 index 8f5330d..b41914b 100644
96963 --- a/mm/mempolicy.c
96964 +++ b/mm/mempolicy.c
96965 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96966 unsigned long vmstart;
96967 unsigned long vmend;
96968
96969 +#ifdef CONFIG_PAX_SEGMEXEC
96970 + struct vm_area_struct *vma_m;
96971 +#endif
96972 +
96973 vma = find_vma(mm, start);
96974 if (!vma || vma->vm_start > start)
96975 return -EFAULT;
96976 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96977 err = vma_replace_policy(vma, new_pol);
96978 if (err)
96979 goto out;
96980 +
96981 +#ifdef CONFIG_PAX_SEGMEXEC
96982 + vma_m = pax_find_mirror_vma(vma);
96983 + if (vma_m) {
96984 + err = vma_replace_policy(vma_m, new_pol);
96985 + if (err)
96986 + goto out;
96987 + }
96988 +#endif
96989 +
96990 }
96991
96992 out:
96993 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96994
96995 if (end < start)
96996 return -EINVAL;
96997 +
96998 +#ifdef CONFIG_PAX_SEGMEXEC
96999 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97000 + if (end > SEGMEXEC_TASK_SIZE)
97001 + return -EINVAL;
97002 + } else
97003 +#endif
97004 +
97005 + if (end > TASK_SIZE)
97006 + return -EINVAL;
97007 +
97008 if (end == start)
97009 return 0;
97010
97011 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97012 */
97013 tcred = __task_cred(task);
97014 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97015 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97016 - !capable(CAP_SYS_NICE)) {
97017 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97018 rcu_read_unlock();
97019 err = -EPERM;
97020 goto out_put;
97021 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97022 goto out;
97023 }
97024
97025 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97026 + if (mm != current->mm &&
97027 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
97028 + mmput(mm);
97029 + err = -EPERM;
97030 + goto out;
97031 + }
97032 +#endif
97033 +
97034 err = do_migrate_pages(mm, old, new,
97035 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
97036
97037 diff --git a/mm/migrate.c b/mm/migrate.c
97038 index 2740360..d20a37d 100644
97039 --- a/mm/migrate.c
97040 +++ b/mm/migrate.c
97041 @@ -1503,8 +1503,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
97042 */
97043 tcred = __task_cred(task);
97044 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97045 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97046 - !capable(CAP_SYS_NICE)) {
97047 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97048 rcu_read_unlock();
97049 err = -EPERM;
97050 goto out;
97051 diff --git a/mm/mlock.c b/mm/mlock.c
97052 index ce84cb0..6d5a9aa 100644
97053 --- a/mm/mlock.c
97054 +++ b/mm/mlock.c
97055 @@ -14,6 +14,7 @@
97056 #include <linux/pagevec.h>
97057 #include <linux/mempolicy.h>
97058 #include <linux/syscalls.h>
97059 +#include <linux/security.h>
97060 #include <linux/sched.h>
97061 #include <linux/export.h>
97062 #include <linux/rmap.h>
97063 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
97064 {
97065 unsigned long nstart, end, tmp;
97066 struct vm_area_struct * vma, * prev;
97067 - int error;
97068 + int error = 0;
97069
97070 VM_BUG_ON(start & ~PAGE_MASK);
97071 VM_BUG_ON(len != PAGE_ALIGN(len));
97072 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97073 return -EINVAL;
97074 if (end == start)
97075 return 0;
97076 + if (end > TASK_SIZE)
97077 + return -EINVAL;
97078 +
97079 vma = find_vma(current->mm, start);
97080 if (!vma || vma->vm_start > start)
97081 return -ENOMEM;
97082 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97083 for (nstart = start ; ; ) {
97084 vm_flags_t newflags;
97085
97086 +#ifdef CONFIG_PAX_SEGMEXEC
97087 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97088 + break;
97089 +#endif
97090 +
97091 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97092
97093 newflags = vma->vm_flags & ~VM_LOCKED;
97094 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97095 locked += current->mm->locked_vm;
97096
97097 /* check against resource limits */
97098 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97099 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97100 error = do_mlock(start, len, 1);
97101
97102 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97103 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97104 vm_flags_t newflags;
97105
97106 +#ifdef CONFIG_PAX_SEGMEXEC
97107 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97108 + break;
97109 +#endif
97110 +
97111 newflags = vma->vm_flags & ~VM_LOCKED;
97112 if (flags & MCL_CURRENT)
97113 newflags |= VM_LOCKED;
97114 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97115 lock_limit >>= PAGE_SHIFT;
97116
97117 ret = -ENOMEM;
97118 +
97119 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97120 +
97121 down_write(&current->mm->mmap_sem);
97122 -
97123 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97124 capable(CAP_IPC_LOCK))
97125 ret = do_mlockall(flags);
97126 diff --git a/mm/mmap.c b/mm/mmap.c
97127 index c0a3637..c760814 100644
97128 --- a/mm/mmap.c
97129 +++ b/mm/mmap.c
97130 @@ -41,6 +41,7 @@
97131 #include <linux/notifier.h>
97132 #include <linux/memory.h>
97133 #include <linux/printk.h>
97134 +#include <linux/random.h>
97135
97136 #include <asm/uaccess.h>
97137 #include <asm/cacheflush.h>
97138 @@ -57,6 +58,16 @@
97139 #define arch_rebalance_pgtables(addr, len) (addr)
97140 #endif
97141
97142 +static inline void verify_mm_writelocked(struct mm_struct *mm)
97143 +{
97144 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97145 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97146 + up_read(&mm->mmap_sem);
97147 + BUG();
97148 + }
97149 +#endif
97150 +}
97151 +
97152 static void unmap_region(struct mm_struct *mm,
97153 struct vm_area_struct *vma, struct vm_area_struct *prev,
97154 unsigned long start, unsigned long end);
97155 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97156 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97157 *
97158 */
97159 -pgprot_t protection_map[16] = {
97160 +pgprot_t protection_map[16] __read_only = {
97161 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97162 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97163 };
97164
97165 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
97166 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97167 {
97168 - return __pgprot(pgprot_val(protection_map[vm_flags &
97169 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97170 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97171 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97172 +
97173 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97174 + if (!(__supported_pte_mask & _PAGE_NX) &&
97175 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97176 + (vm_flags & (VM_READ | VM_WRITE)))
97177 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97178 +#endif
97179 +
97180 + return prot;
97181 }
97182 EXPORT_SYMBOL(vm_get_page_prot);
97183
97184 @@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97185 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97186 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97187 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97188 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97189 /*
97190 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97191 * other variables. It can be updated by several CPUs frequently.
97192 @@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97193 struct vm_area_struct *next = vma->vm_next;
97194
97195 might_sleep();
97196 + BUG_ON(vma->vm_mirror);
97197 if (vma->vm_ops && vma->vm_ops->close)
97198 vma->vm_ops->close(vma);
97199 if (vma->vm_file)
97200 @@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97201 * not page aligned -Ram Gupta
97202 */
97203 rlim = rlimit(RLIMIT_DATA);
97204 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97205 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97206 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97207 + rlim = 4096 * PAGE_SIZE;
97208 +#endif
97209 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
97210 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
97211 (mm->end_data - mm->start_data) > rlim)
97212 goto out;
97213 @@ -949,6 +977,12 @@ static int
97214 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97215 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97216 {
97217 +
97218 +#ifdef CONFIG_PAX_SEGMEXEC
97219 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97220 + return 0;
97221 +#endif
97222 +
97223 if (is_mergeable_vma(vma, file, vm_flags) &&
97224 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97225 if (vma->vm_pgoff == vm_pgoff)
97226 @@ -968,6 +1002,12 @@ static int
97227 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97228 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97229 {
97230 +
97231 +#ifdef CONFIG_PAX_SEGMEXEC
97232 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97233 + return 0;
97234 +#endif
97235 +
97236 if (is_mergeable_vma(vma, file, vm_flags) &&
97237 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97238 pgoff_t vm_pglen;
97239 @@ -1010,13 +1050,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97240 struct vm_area_struct *vma_merge(struct mm_struct *mm,
97241 struct vm_area_struct *prev, unsigned long addr,
97242 unsigned long end, unsigned long vm_flags,
97243 - struct anon_vma *anon_vma, struct file *file,
97244 + struct anon_vma *anon_vma, struct file *file,
97245 pgoff_t pgoff, struct mempolicy *policy)
97246 {
97247 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97248 struct vm_area_struct *area, *next;
97249 int err;
97250
97251 +#ifdef CONFIG_PAX_SEGMEXEC
97252 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97253 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97254 +
97255 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97256 +#endif
97257 +
97258 /*
97259 * We later require that vma->vm_flags == vm_flags,
97260 * so this tests vma->vm_flags & VM_SPECIAL, too.
97261 @@ -1032,6 +1079,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97262 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97263 next = next->vm_next;
97264
97265 +#ifdef CONFIG_PAX_SEGMEXEC
97266 + if (prev)
97267 + prev_m = pax_find_mirror_vma(prev);
97268 + if (area)
97269 + area_m = pax_find_mirror_vma(area);
97270 + if (next)
97271 + next_m = pax_find_mirror_vma(next);
97272 +#endif
97273 +
97274 /*
97275 * Can it merge with the predecessor?
97276 */
97277 @@ -1051,9 +1107,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97278 /* cases 1, 6 */
97279 err = vma_adjust(prev, prev->vm_start,
97280 next->vm_end, prev->vm_pgoff, NULL);
97281 - } else /* cases 2, 5, 7 */
97282 +
97283 +#ifdef CONFIG_PAX_SEGMEXEC
97284 + if (!err && prev_m)
97285 + err = vma_adjust(prev_m, prev_m->vm_start,
97286 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97287 +#endif
97288 +
97289 + } else { /* cases 2, 5, 7 */
97290 err = vma_adjust(prev, prev->vm_start,
97291 end, prev->vm_pgoff, NULL);
97292 +
97293 +#ifdef CONFIG_PAX_SEGMEXEC
97294 + if (!err && prev_m)
97295 + err = vma_adjust(prev_m, prev_m->vm_start,
97296 + end_m, prev_m->vm_pgoff, NULL);
97297 +#endif
97298 +
97299 + }
97300 if (err)
97301 return NULL;
97302 khugepaged_enter_vma_merge(prev);
97303 @@ -1067,12 +1138,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97304 mpol_equal(policy, vma_policy(next)) &&
97305 can_vma_merge_before(next, vm_flags,
97306 anon_vma, file, pgoff+pglen)) {
97307 - if (prev && addr < prev->vm_end) /* case 4 */
97308 + if (prev && addr < prev->vm_end) { /* case 4 */
97309 err = vma_adjust(prev, prev->vm_start,
97310 addr, prev->vm_pgoff, NULL);
97311 - else /* cases 3, 8 */
97312 +
97313 +#ifdef CONFIG_PAX_SEGMEXEC
97314 + if (!err && prev_m)
97315 + err = vma_adjust(prev_m, prev_m->vm_start,
97316 + addr_m, prev_m->vm_pgoff, NULL);
97317 +#endif
97318 +
97319 + } else { /* cases 3, 8 */
97320 err = vma_adjust(area, addr, next->vm_end,
97321 next->vm_pgoff - pglen, NULL);
97322 +
97323 +#ifdef CONFIG_PAX_SEGMEXEC
97324 + if (!err && area_m)
97325 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97326 + next_m->vm_pgoff - pglen, NULL);
97327 +#endif
97328 +
97329 + }
97330 if (err)
97331 return NULL;
97332 khugepaged_enter_vma_merge(area);
97333 @@ -1181,8 +1267,10 @@ none:
97334 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97335 struct file *file, long pages)
97336 {
97337 - const unsigned long stack_flags
97338 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97339 +
97340 +#ifdef CONFIG_PAX_RANDMMAP
97341 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97342 +#endif
97343
97344 mm->total_vm += pages;
97345
97346 @@ -1190,7 +1278,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97347 mm->shared_vm += pages;
97348 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97349 mm->exec_vm += pages;
97350 - } else if (flags & stack_flags)
97351 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97352 mm->stack_vm += pages;
97353 }
97354 #endif /* CONFIG_PROC_FS */
97355 @@ -1220,6 +1308,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97356 locked += mm->locked_vm;
97357 lock_limit = rlimit(RLIMIT_MEMLOCK);
97358 lock_limit >>= PAGE_SHIFT;
97359 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97360 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97361 return -EAGAIN;
97362 }
97363 @@ -1246,7 +1335,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97364 * (the exception is when the underlying filesystem is noexec
97365 * mounted, in which case we dont add PROT_EXEC.)
97366 */
97367 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97368 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97369 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97370 prot |= PROT_EXEC;
97371
97372 @@ -1272,7 +1361,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97373 /* Obtain the address to map to. we verify (or select) it and ensure
97374 * that it represents a valid section of the address space.
97375 */
97376 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97377 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97378 if (addr & ~PAGE_MASK)
97379 return addr;
97380
97381 @@ -1283,6 +1372,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97382 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97383 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97384
97385 +#ifdef CONFIG_PAX_MPROTECT
97386 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97387 +
97388 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97389 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97390 + mm->binfmt->handle_mmap)
97391 + mm->binfmt->handle_mmap(file);
97392 +#endif
97393 +
97394 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97395 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97396 + gr_log_rwxmmap(file);
97397 +
97398 +#ifdef CONFIG_PAX_EMUPLT
97399 + vm_flags &= ~VM_EXEC;
97400 +#else
97401 + return -EPERM;
97402 +#endif
97403 +
97404 + }
97405 +
97406 + if (!(vm_flags & VM_EXEC))
97407 + vm_flags &= ~VM_MAYEXEC;
97408 +#else
97409 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97410 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97411 +#endif
97412 + else
97413 + vm_flags &= ~VM_MAYWRITE;
97414 + }
97415 +#endif
97416 +
97417 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97418 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97419 + vm_flags &= ~VM_PAGEEXEC;
97420 +#endif
97421 +
97422 if (flags & MAP_LOCKED)
97423 if (!can_do_mlock())
97424 return -EPERM;
97425 @@ -1370,6 +1496,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97426 vm_flags |= VM_NORESERVE;
97427 }
97428
97429 + if (!gr_acl_handle_mmap(file, prot))
97430 + return -EACCES;
97431 +
97432 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97433 if (!IS_ERR_VALUE(addr) &&
97434 ((vm_flags & VM_LOCKED) ||
97435 @@ -1463,7 +1592,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97436 vm_flags_t vm_flags = vma->vm_flags;
97437
97438 /* If it was private or non-writable, the write bit is already clear */
97439 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97440 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97441 return 0;
97442
97443 /* The backer wishes to know when pages are first written to? */
97444 @@ -1509,7 +1638,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97445 struct rb_node **rb_link, *rb_parent;
97446 unsigned long charged = 0;
97447
97448 +#ifdef CONFIG_PAX_SEGMEXEC
97449 + struct vm_area_struct *vma_m = NULL;
97450 +#endif
97451 +
97452 + /*
97453 + * mm->mmap_sem is required to protect against another thread
97454 + * changing the mappings in case we sleep.
97455 + */
97456 + verify_mm_writelocked(mm);
97457 +
97458 /* Check against address space limit. */
97459 +
97460 +#ifdef CONFIG_PAX_RANDMMAP
97461 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97462 +#endif
97463 +
97464 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97465 unsigned long nr_pages;
97466
97467 @@ -1528,11 +1672,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97468
97469 /* Clear old maps */
97470 error = -ENOMEM;
97471 -munmap_back:
97472 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97473 if (do_munmap(mm, addr, len))
97474 return -ENOMEM;
97475 - goto munmap_back;
97476 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97477 }
97478
97479 /*
97480 @@ -1563,6 +1706,16 @@ munmap_back:
97481 goto unacct_error;
97482 }
97483
97484 +#ifdef CONFIG_PAX_SEGMEXEC
97485 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97486 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97487 + if (!vma_m) {
97488 + error = -ENOMEM;
97489 + goto free_vma;
97490 + }
97491 + }
97492 +#endif
97493 +
97494 vma->vm_mm = mm;
97495 vma->vm_start = addr;
97496 vma->vm_end = addr + len;
97497 @@ -1593,6 +1746,13 @@ munmap_back:
97498 if (error)
97499 goto unmap_and_free_vma;
97500
97501 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97502 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97503 + vma->vm_flags |= VM_PAGEEXEC;
97504 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97505 + }
97506 +#endif
97507 +
97508 /* Can addr have changed??
97509 *
97510 * Answer: Yes, several device drivers can do it in their
97511 @@ -1626,6 +1786,12 @@ munmap_back:
97512 }
97513
97514 vma_link(mm, vma, prev, rb_link, rb_parent);
97515 +
97516 +#ifdef CONFIG_PAX_SEGMEXEC
97517 + if (vma_m)
97518 + BUG_ON(pax_mirror_vma(vma_m, vma));
97519 +#endif
97520 +
97521 /* Once vma denies write, undo our temporary denial count */
97522 if (file) {
97523 if (vm_flags & VM_SHARED)
97524 @@ -1638,6 +1804,7 @@ out:
97525 perf_event_mmap(vma);
97526
97527 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97528 + track_exec_limit(mm, addr, addr + len, vm_flags);
97529 if (vm_flags & VM_LOCKED) {
97530 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97531 vma == get_gate_vma(current->mm)))
97532 @@ -1673,6 +1840,12 @@ allow_write_and_free_vma:
97533 if (vm_flags & VM_DENYWRITE)
97534 allow_write_access(file);
97535 free_vma:
97536 +
97537 +#ifdef CONFIG_PAX_SEGMEXEC
97538 + if (vma_m)
97539 + kmem_cache_free(vm_area_cachep, vma_m);
97540 +#endif
97541 +
97542 kmem_cache_free(vm_area_cachep, vma);
97543 unacct_error:
97544 if (charged)
97545 @@ -1680,7 +1853,63 @@ unacct_error:
97546 return error;
97547 }
97548
97549 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97550 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97551 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97552 +{
97553 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97554 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97555 +
97556 + return 0;
97557 +}
97558 +#endif
97559 +
97560 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97561 +{
97562 + if (!vma) {
97563 +#ifdef CONFIG_STACK_GROWSUP
97564 + if (addr > sysctl_heap_stack_gap)
97565 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97566 + else
97567 + vma = find_vma(current->mm, 0);
97568 + if (vma && (vma->vm_flags & VM_GROWSUP))
97569 + return false;
97570 +#endif
97571 + return true;
97572 + }
97573 +
97574 + if (addr + len > vma->vm_start)
97575 + return false;
97576 +
97577 + if (vma->vm_flags & VM_GROWSDOWN)
97578 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97579 +#ifdef CONFIG_STACK_GROWSUP
97580 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97581 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97582 +#endif
97583 + else if (offset)
97584 + return offset <= vma->vm_start - addr - len;
97585 +
97586 + return true;
97587 +}
97588 +
97589 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97590 +{
97591 + if (vma->vm_start < len)
97592 + return -ENOMEM;
97593 +
97594 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97595 + if (offset <= vma->vm_start - len)
97596 + return vma->vm_start - len - offset;
97597 + else
97598 + return -ENOMEM;
97599 + }
97600 +
97601 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97602 + return vma->vm_start - len - sysctl_heap_stack_gap;
97603 + return -ENOMEM;
97604 +}
97605 +
97606 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97607 {
97608 /*
97609 * We implement the search by looking for an rbtree node that
97610 @@ -1728,11 +1957,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97611 }
97612 }
97613
97614 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97615 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97616 check_current:
97617 /* Check if current node has a suitable gap */
97618 if (gap_start > high_limit)
97619 return -ENOMEM;
97620 +
97621 + if (gap_end - gap_start > info->threadstack_offset)
97622 + gap_start += info->threadstack_offset;
97623 + else
97624 + gap_start = gap_end;
97625 +
97626 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97627 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97628 + gap_start += sysctl_heap_stack_gap;
97629 + else
97630 + gap_start = gap_end;
97631 + }
97632 + if (vma->vm_flags & VM_GROWSDOWN) {
97633 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97634 + gap_end -= sysctl_heap_stack_gap;
97635 + else
97636 + gap_end = gap_start;
97637 + }
97638 if (gap_end >= low_limit && gap_end - gap_start >= length)
97639 goto found;
97640
97641 @@ -1782,7 +2029,7 @@ found:
97642 return gap_start;
97643 }
97644
97645 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97646 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97647 {
97648 struct mm_struct *mm = current->mm;
97649 struct vm_area_struct *vma;
97650 @@ -1836,6 +2083,24 @@ check_current:
97651 gap_end = vma->vm_start;
97652 if (gap_end < low_limit)
97653 return -ENOMEM;
97654 +
97655 + if (gap_end - gap_start > info->threadstack_offset)
97656 + gap_end -= info->threadstack_offset;
97657 + else
97658 + gap_end = gap_start;
97659 +
97660 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97661 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97662 + gap_start += sysctl_heap_stack_gap;
97663 + else
97664 + gap_start = gap_end;
97665 + }
97666 + if (vma->vm_flags & VM_GROWSDOWN) {
97667 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97668 + gap_end -= sysctl_heap_stack_gap;
97669 + else
97670 + gap_end = gap_start;
97671 + }
97672 if (gap_start <= high_limit && gap_end - gap_start >= length)
97673 goto found;
97674
97675 @@ -1899,6 +2164,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97676 struct mm_struct *mm = current->mm;
97677 struct vm_area_struct *vma;
97678 struct vm_unmapped_area_info info;
97679 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97680
97681 if (len > TASK_SIZE - mmap_min_addr)
97682 return -ENOMEM;
97683 @@ -1906,11 +2172,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97684 if (flags & MAP_FIXED)
97685 return addr;
97686
97687 +#ifdef CONFIG_PAX_RANDMMAP
97688 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97689 +#endif
97690 +
97691 if (addr) {
97692 addr = PAGE_ALIGN(addr);
97693 vma = find_vma(mm, addr);
97694 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97695 - (!vma || addr + len <= vma->vm_start))
97696 + check_heap_stack_gap(vma, addr, len, offset))
97697 return addr;
97698 }
97699
97700 @@ -1919,6 +2189,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97701 info.low_limit = mm->mmap_base;
97702 info.high_limit = TASK_SIZE;
97703 info.align_mask = 0;
97704 + info.threadstack_offset = offset;
97705 return vm_unmapped_area(&info);
97706 }
97707 #endif
97708 @@ -1937,6 +2208,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97709 struct mm_struct *mm = current->mm;
97710 unsigned long addr = addr0;
97711 struct vm_unmapped_area_info info;
97712 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97713
97714 /* requested length too big for entire address space */
97715 if (len > TASK_SIZE - mmap_min_addr)
97716 @@ -1945,12 +2217,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97717 if (flags & MAP_FIXED)
97718 return addr;
97719
97720 +#ifdef CONFIG_PAX_RANDMMAP
97721 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97722 +#endif
97723 +
97724 /* requesting a specific address */
97725 if (addr) {
97726 addr = PAGE_ALIGN(addr);
97727 vma = find_vma(mm, addr);
97728 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97729 - (!vma || addr + len <= vma->vm_start))
97730 + check_heap_stack_gap(vma, addr, len, offset))
97731 return addr;
97732 }
97733
97734 @@ -1959,6 +2235,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97735 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97736 info.high_limit = mm->mmap_base;
97737 info.align_mask = 0;
97738 + info.threadstack_offset = offset;
97739 addr = vm_unmapped_area(&info);
97740
97741 /*
97742 @@ -1971,6 +2248,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97743 VM_BUG_ON(addr != -ENOMEM);
97744 info.flags = 0;
97745 info.low_limit = TASK_UNMAPPED_BASE;
97746 +
97747 +#ifdef CONFIG_PAX_RANDMMAP
97748 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97749 + info.low_limit += mm->delta_mmap;
97750 +#endif
97751 +
97752 info.high_limit = TASK_SIZE;
97753 addr = vm_unmapped_area(&info);
97754 }
97755 @@ -2071,6 +2354,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97756 return vma;
97757 }
97758
97759 +#ifdef CONFIG_PAX_SEGMEXEC
97760 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97761 +{
97762 + struct vm_area_struct *vma_m;
97763 +
97764 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97765 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97766 + BUG_ON(vma->vm_mirror);
97767 + return NULL;
97768 + }
97769 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97770 + vma_m = vma->vm_mirror;
97771 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97772 + BUG_ON(vma->vm_file != vma_m->vm_file);
97773 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97774 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97775 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97776 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97777 + return vma_m;
97778 +}
97779 +#endif
97780 +
97781 /*
97782 * Verify that the stack growth is acceptable and
97783 * update accounting. This is shared with both the
97784 @@ -2087,6 +2392,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97785 return -ENOMEM;
97786
97787 /* Stack limit test */
97788 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
97789 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97790 return -ENOMEM;
97791
97792 @@ -2097,6 +2403,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97793 locked = mm->locked_vm + grow;
97794 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97795 limit >>= PAGE_SHIFT;
97796 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97797 if (locked > limit && !capable(CAP_IPC_LOCK))
97798 return -ENOMEM;
97799 }
97800 @@ -2126,37 +2433,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97801 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97802 * vma is the last one with address > vma->vm_end. Have to extend vma.
97803 */
97804 +#ifndef CONFIG_IA64
97805 +static
97806 +#endif
97807 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97808 {
97809 int error;
97810 + bool locknext;
97811
97812 if (!(vma->vm_flags & VM_GROWSUP))
97813 return -EFAULT;
97814
97815 + /* Also guard against wrapping around to address 0. */
97816 + if (address < PAGE_ALIGN(address+1))
97817 + address = PAGE_ALIGN(address+1);
97818 + else
97819 + return -ENOMEM;
97820 +
97821 /*
97822 * We must make sure the anon_vma is allocated
97823 * so that the anon_vma locking is not a noop.
97824 */
97825 if (unlikely(anon_vma_prepare(vma)))
97826 return -ENOMEM;
97827 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97828 + if (locknext && anon_vma_prepare(vma->vm_next))
97829 + return -ENOMEM;
97830 vma_lock_anon_vma(vma);
97831 + if (locknext)
97832 + vma_lock_anon_vma(vma->vm_next);
97833
97834 /*
97835 * vma->vm_start/vm_end cannot change under us because the caller
97836 * is required to hold the mmap_sem in read mode. We need the
97837 - * anon_vma lock to serialize against concurrent expand_stacks.
97838 - * Also guard against wrapping around to address 0.
97839 + * anon_vma locks to serialize against concurrent expand_stacks
97840 + * and expand_upwards.
97841 */
97842 - if (address < PAGE_ALIGN(address+4))
97843 - address = PAGE_ALIGN(address+4);
97844 - else {
97845 - vma_unlock_anon_vma(vma);
97846 - return -ENOMEM;
97847 - }
97848 error = 0;
97849
97850 /* Somebody else might have raced and expanded it already */
97851 - if (address > vma->vm_end) {
97852 + 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)
97853 + error = -ENOMEM;
97854 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97855 unsigned long size, grow;
97856
97857 size = address - vma->vm_start;
97858 @@ -2191,6 +2509,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97859 }
97860 }
97861 }
97862 + if (locknext)
97863 + vma_unlock_anon_vma(vma->vm_next);
97864 vma_unlock_anon_vma(vma);
97865 khugepaged_enter_vma_merge(vma);
97866 validate_mm(vma->vm_mm);
97867 @@ -2205,6 +2525,8 @@ int expand_downwards(struct vm_area_struct *vma,
97868 unsigned long address)
97869 {
97870 int error;
97871 + bool lockprev = false;
97872 + struct vm_area_struct *prev;
97873
97874 /*
97875 * We must make sure the anon_vma is allocated
97876 @@ -2218,6 +2540,15 @@ int expand_downwards(struct vm_area_struct *vma,
97877 if (error)
97878 return error;
97879
97880 + prev = vma->vm_prev;
97881 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97882 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97883 +#endif
97884 + if (lockprev && anon_vma_prepare(prev))
97885 + return -ENOMEM;
97886 + if (lockprev)
97887 + vma_lock_anon_vma(prev);
97888 +
97889 vma_lock_anon_vma(vma);
97890
97891 /*
97892 @@ -2227,9 +2558,17 @@ int expand_downwards(struct vm_area_struct *vma,
97893 */
97894
97895 /* Somebody else might have raced and expanded it already */
97896 - if (address < vma->vm_start) {
97897 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97898 + error = -ENOMEM;
97899 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97900 unsigned long size, grow;
97901
97902 +#ifdef CONFIG_PAX_SEGMEXEC
97903 + struct vm_area_struct *vma_m;
97904 +
97905 + vma_m = pax_find_mirror_vma(vma);
97906 +#endif
97907 +
97908 size = vma->vm_end - address;
97909 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97910
97911 @@ -2254,13 +2593,27 @@ int expand_downwards(struct vm_area_struct *vma,
97912 vma->vm_pgoff -= grow;
97913 anon_vma_interval_tree_post_update_vma(vma);
97914 vma_gap_update(vma);
97915 +
97916 +#ifdef CONFIG_PAX_SEGMEXEC
97917 + if (vma_m) {
97918 + anon_vma_interval_tree_pre_update_vma(vma_m);
97919 + vma_m->vm_start -= grow << PAGE_SHIFT;
97920 + vma_m->vm_pgoff -= grow;
97921 + anon_vma_interval_tree_post_update_vma(vma_m);
97922 + vma_gap_update(vma_m);
97923 + }
97924 +#endif
97925 +
97926 spin_unlock(&vma->vm_mm->page_table_lock);
97927
97928 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97929 perf_event_mmap(vma);
97930 }
97931 }
97932 }
97933 vma_unlock_anon_vma(vma);
97934 + if (lockprev)
97935 + vma_unlock_anon_vma(prev);
97936 khugepaged_enter_vma_merge(vma);
97937 validate_mm(vma->vm_mm);
97938 return error;
97939 @@ -2358,6 +2711,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97940 do {
97941 long nrpages = vma_pages(vma);
97942
97943 +#ifdef CONFIG_PAX_SEGMEXEC
97944 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97945 + vma = remove_vma(vma);
97946 + continue;
97947 + }
97948 +#endif
97949 +
97950 if (vma->vm_flags & VM_ACCOUNT)
97951 nr_accounted += nrpages;
97952 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97953 @@ -2402,6 +2762,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97954 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97955 vma->vm_prev = NULL;
97956 do {
97957 +
97958 +#ifdef CONFIG_PAX_SEGMEXEC
97959 + if (vma->vm_mirror) {
97960 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97961 + vma->vm_mirror->vm_mirror = NULL;
97962 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97963 + vma->vm_mirror = NULL;
97964 + }
97965 +#endif
97966 +
97967 vma_rb_erase(vma, &mm->mm_rb);
97968 mm->map_count--;
97969 tail_vma = vma;
97970 @@ -2429,14 +2799,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97971 struct vm_area_struct *new;
97972 int err = -ENOMEM;
97973
97974 +#ifdef CONFIG_PAX_SEGMEXEC
97975 + struct vm_area_struct *vma_m, *new_m = NULL;
97976 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97977 +#endif
97978 +
97979 if (is_vm_hugetlb_page(vma) && (addr &
97980 ~(huge_page_mask(hstate_vma(vma)))))
97981 return -EINVAL;
97982
97983 +#ifdef CONFIG_PAX_SEGMEXEC
97984 + vma_m = pax_find_mirror_vma(vma);
97985 +#endif
97986 +
97987 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97988 if (!new)
97989 goto out_err;
97990
97991 +#ifdef CONFIG_PAX_SEGMEXEC
97992 + if (vma_m) {
97993 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97994 + if (!new_m) {
97995 + kmem_cache_free(vm_area_cachep, new);
97996 + goto out_err;
97997 + }
97998 + }
97999 +#endif
98000 +
98001 /* most fields are the same, copy all, and then fixup */
98002 *new = *vma;
98003
98004 @@ -2449,6 +2838,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98005 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
98006 }
98007
98008 +#ifdef CONFIG_PAX_SEGMEXEC
98009 + if (vma_m) {
98010 + *new_m = *vma_m;
98011 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
98012 + new_m->vm_mirror = new;
98013 + new->vm_mirror = new_m;
98014 +
98015 + if (new_below)
98016 + new_m->vm_end = addr_m;
98017 + else {
98018 + new_m->vm_start = addr_m;
98019 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
98020 + }
98021 + }
98022 +#endif
98023 +
98024 err = vma_dup_policy(vma, new);
98025 if (err)
98026 goto out_free_vma;
98027 @@ -2468,6 +2873,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98028 else
98029 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
98030
98031 +#ifdef CONFIG_PAX_SEGMEXEC
98032 + if (!err && vma_m) {
98033 + struct mempolicy *pol = vma_policy(new);
98034 +
98035 + if (anon_vma_clone(new_m, vma_m))
98036 + goto out_free_mpol;
98037 +
98038 + mpol_get(pol);
98039 + set_vma_policy(new_m, pol);
98040 +
98041 + if (new_m->vm_file)
98042 + get_file(new_m->vm_file);
98043 +
98044 + if (new_m->vm_ops && new_m->vm_ops->open)
98045 + new_m->vm_ops->open(new_m);
98046 +
98047 + if (new_below)
98048 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
98049 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98050 + else
98051 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98052 +
98053 + if (err) {
98054 + if (new_m->vm_ops && new_m->vm_ops->close)
98055 + new_m->vm_ops->close(new_m);
98056 + if (new_m->vm_file)
98057 + fput(new_m->vm_file);
98058 + mpol_put(pol);
98059 + }
98060 + }
98061 +#endif
98062 +
98063 /* Success. */
98064 if (!err)
98065 return 0;
98066 @@ -2477,10 +2914,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98067 new->vm_ops->close(new);
98068 if (new->vm_file)
98069 fput(new->vm_file);
98070 - unlink_anon_vmas(new);
98071 out_free_mpol:
98072 mpol_put(vma_policy(new));
98073 out_free_vma:
98074 +
98075 +#ifdef CONFIG_PAX_SEGMEXEC
98076 + if (new_m) {
98077 + unlink_anon_vmas(new_m);
98078 + kmem_cache_free(vm_area_cachep, new_m);
98079 + }
98080 +#endif
98081 +
98082 + unlink_anon_vmas(new);
98083 kmem_cache_free(vm_area_cachep, new);
98084 out_err:
98085 return err;
98086 @@ -2493,6 +2938,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98087 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98088 unsigned long addr, int new_below)
98089 {
98090 +
98091 +#ifdef CONFIG_PAX_SEGMEXEC
98092 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98093 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98094 + if (mm->map_count >= sysctl_max_map_count-1)
98095 + return -ENOMEM;
98096 + } else
98097 +#endif
98098 +
98099 if (mm->map_count >= sysctl_max_map_count)
98100 return -ENOMEM;
98101
98102 @@ -2504,11 +2958,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98103 * work. This now handles partial unmappings.
98104 * Jeremy Fitzhardinge <jeremy@goop.org>
98105 */
98106 +#ifdef CONFIG_PAX_SEGMEXEC
98107 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98108 {
98109 + int ret = __do_munmap(mm, start, len);
98110 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98111 + return ret;
98112 +
98113 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98114 +}
98115 +
98116 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98117 +#else
98118 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98119 +#endif
98120 +{
98121 unsigned long end;
98122 struct vm_area_struct *vma, *prev, *last;
98123
98124 + /*
98125 + * mm->mmap_sem is required to protect against another thread
98126 + * changing the mappings in case we sleep.
98127 + */
98128 + verify_mm_writelocked(mm);
98129 +
98130 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98131 return -EINVAL;
98132
98133 @@ -2583,6 +3056,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98134 /* Fix up all other VM information */
98135 remove_vma_list(mm, vma);
98136
98137 + track_exec_limit(mm, start, end, 0UL);
98138 +
98139 return 0;
98140 }
98141
98142 @@ -2591,6 +3066,13 @@ int vm_munmap(unsigned long start, size_t len)
98143 int ret;
98144 struct mm_struct *mm = current->mm;
98145
98146 +
98147 +#ifdef CONFIG_PAX_SEGMEXEC
98148 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98149 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98150 + return -EINVAL;
98151 +#endif
98152 +
98153 down_write(&mm->mmap_sem);
98154 ret = do_munmap(mm, start, len);
98155 up_write(&mm->mmap_sem);
98156 @@ -2604,16 +3086,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98157 return vm_munmap(addr, len);
98158 }
98159
98160 -static inline void verify_mm_writelocked(struct mm_struct *mm)
98161 -{
98162 -#ifdef CONFIG_DEBUG_VM
98163 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98164 - WARN_ON(1);
98165 - up_read(&mm->mmap_sem);
98166 - }
98167 -#endif
98168 -}
98169 -
98170 /*
98171 * this is really a simplified "do_mmap". it only handles
98172 * anonymous maps. eventually we may be able to do some
98173 @@ -2627,6 +3099,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98174 struct rb_node ** rb_link, * rb_parent;
98175 pgoff_t pgoff = addr >> PAGE_SHIFT;
98176 int error;
98177 + unsigned long charged;
98178
98179 len = PAGE_ALIGN(len);
98180 if (!len)
98181 @@ -2634,10 +3107,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98182
98183 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98184
98185 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98186 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98187 + flags &= ~VM_EXEC;
98188 +
98189 +#ifdef CONFIG_PAX_MPROTECT
98190 + if (mm->pax_flags & MF_PAX_MPROTECT)
98191 + flags &= ~VM_MAYEXEC;
98192 +#endif
98193 +
98194 + }
98195 +#endif
98196 +
98197 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98198 if (error & ~PAGE_MASK)
98199 return error;
98200
98201 + charged = len >> PAGE_SHIFT;
98202 +
98203 error = mlock_future_check(mm, mm->def_flags, len);
98204 if (error)
98205 return error;
98206 @@ -2651,21 +3138,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98207 /*
98208 * Clear old maps. this also does some error checking for us
98209 */
98210 - munmap_back:
98211 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98212 if (do_munmap(mm, addr, len))
98213 return -ENOMEM;
98214 - goto munmap_back;
98215 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98216 }
98217
98218 /* Check against address space limits *after* clearing old maps... */
98219 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98220 + if (!may_expand_vm(mm, charged))
98221 return -ENOMEM;
98222
98223 if (mm->map_count > sysctl_max_map_count)
98224 return -ENOMEM;
98225
98226 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98227 + if (security_vm_enough_memory_mm(mm, charged))
98228 return -ENOMEM;
98229
98230 /* Can we just expand an old private anonymous mapping? */
98231 @@ -2679,7 +3165,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98232 */
98233 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98234 if (!vma) {
98235 - vm_unacct_memory(len >> PAGE_SHIFT);
98236 + vm_unacct_memory(charged);
98237 return -ENOMEM;
98238 }
98239
98240 @@ -2693,10 +3179,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98241 vma_link(mm, vma, prev, rb_link, rb_parent);
98242 out:
98243 perf_event_mmap(vma);
98244 - mm->total_vm += len >> PAGE_SHIFT;
98245 + mm->total_vm += charged;
98246 if (flags & VM_LOCKED)
98247 - mm->locked_vm += (len >> PAGE_SHIFT);
98248 + mm->locked_vm += charged;
98249 vma->vm_flags |= VM_SOFTDIRTY;
98250 + track_exec_limit(mm, addr, addr + len, flags);
98251 return addr;
98252 }
98253
98254 @@ -2758,6 +3245,7 @@ void exit_mmap(struct mm_struct *mm)
98255 while (vma) {
98256 if (vma->vm_flags & VM_ACCOUNT)
98257 nr_accounted += vma_pages(vma);
98258 + vma->vm_mirror = NULL;
98259 vma = remove_vma(vma);
98260 }
98261 vm_unacct_memory(nr_accounted);
98262 @@ -2775,6 +3263,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98263 struct vm_area_struct *prev;
98264 struct rb_node **rb_link, *rb_parent;
98265
98266 +#ifdef CONFIG_PAX_SEGMEXEC
98267 + struct vm_area_struct *vma_m = NULL;
98268 +#endif
98269 +
98270 + if (security_mmap_addr(vma->vm_start))
98271 + return -EPERM;
98272 +
98273 /*
98274 * The vm_pgoff of a purely anonymous vma should be irrelevant
98275 * until its first write fault, when page's anon_vma and index
98276 @@ -2798,7 +3293,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98277 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98278 return -ENOMEM;
98279
98280 +#ifdef CONFIG_PAX_SEGMEXEC
98281 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98282 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98283 + if (!vma_m)
98284 + return -ENOMEM;
98285 + }
98286 +#endif
98287 +
98288 vma_link(mm, vma, prev, rb_link, rb_parent);
98289 +
98290 +#ifdef CONFIG_PAX_SEGMEXEC
98291 + if (vma_m)
98292 + BUG_ON(pax_mirror_vma(vma_m, vma));
98293 +#endif
98294 +
98295 return 0;
98296 }
98297
98298 @@ -2817,6 +3326,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98299 struct rb_node **rb_link, *rb_parent;
98300 bool faulted_in_anon_vma = true;
98301
98302 + BUG_ON(vma->vm_mirror);
98303 +
98304 /*
98305 * If anonymous vma has not yet been faulted, update new pgoff
98306 * to match new location, to increase its chance of merging.
98307 @@ -2881,6 +3392,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98308 return NULL;
98309 }
98310
98311 +#ifdef CONFIG_PAX_SEGMEXEC
98312 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98313 +{
98314 + struct vm_area_struct *prev_m;
98315 + struct rb_node **rb_link_m, *rb_parent_m;
98316 + struct mempolicy *pol_m;
98317 +
98318 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98319 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98320 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98321 + *vma_m = *vma;
98322 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98323 + if (anon_vma_clone(vma_m, vma))
98324 + return -ENOMEM;
98325 + pol_m = vma_policy(vma_m);
98326 + mpol_get(pol_m);
98327 + set_vma_policy(vma_m, pol_m);
98328 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98329 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98330 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98331 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98332 + if (vma_m->vm_file)
98333 + get_file(vma_m->vm_file);
98334 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98335 + vma_m->vm_ops->open(vma_m);
98336 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98337 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98338 + vma_m->vm_mirror = vma;
98339 + vma->vm_mirror = vma_m;
98340 + return 0;
98341 +}
98342 +#endif
98343 +
98344 /*
98345 * Return true if the calling process may expand its vm space by the passed
98346 * number of pages
98347 @@ -2892,6 +3436,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98348
98349 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98350
98351 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98352 if (cur + npages > lim)
98353 return 0;
98354 return 1;
98355 @@ -2974,6 +3519,22 @@ static struct vm_area_struct *__install_special_mapping(
98356 vma->vm_start = addr;
98357 vma->vm_end = addr + len;
98358
98359 +#ifdef CONFIG_PAX_MPROTECT
98360 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98361 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98362 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98363 + return ERR_PTR(-EPERM);
98364 + if (!(vm_flags & VM_EXEC))
98365 + vm_flags &= ~VM_MAYEXEC;
98366 +#else
98367 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98368 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98369 +#endif
98370 + else
98371 + vm_flags &= ~VM_MAYWRITE;
98372 + }
98373 +#endif
98374 +
98375 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98376 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98377
98378 diff --git a/mm/mprotect.c b/mm/mprotect.c
98379 index c43d557..0b7ccd2 100644
98380 --- a/mm/mprotect.c
98381 +++ b/mm/mprotect.c
98382 @@ -24,10 +24,18 @@
98383 #include <linux/migrate.h>
98384 #include <linux/perf_event.h>
98385 #include <linux/ksm.h>
98386 +#include <linux/sched/sysctl.h>
98387 +
98388 +#ifdef CONFIG_PAX_MPROTECT
98389 +#include <linux/elf.h>
98390 +#include <linux/binfmts.h>
98391 +#endif
98392 +
98393 #include <asm/uaccess.h>
98394 #include <asm/pgtable.h>
98395 #include <asm/cacheflush.h>
98396 #include <asm/tlbflush.h>
98397 +#include <asm/mmu_context.h>
98398
98399 #ifndef pgprot_modify
98400 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
98401 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98402 return pages;
98403 }
98404
98405 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98406 +/* called while holding the mmap semaphor for writing except stack expansion */
98407 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98408 +{
98409 + unsigned long oldlimit, newlimit = 0UL;
98410 +
98411 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98412 + return;
98413 +
98414 + spin_lock(&mm->page_table_lock);
98415 + oldlimit = mm->context.user_cs_limit;
98416 + if ((prot & VM_EXEC) && oldlimit < end)
98417 + /* USER_CS limit moved up */
98418 + newlimit = end;
98419 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98420 + /* USER_CS limit moved down */
98421 + newlimit = start;
98422 +
98423 + if (newlimit) {
98424 + mm->context.user_cs_limit = newlimit;
98425 +
98426 +#ifdef CONFIG_SMP
98427 + wmb();
98428 + cpus_clear(mm->context.cpu_user_cs_mask);
98429 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98430 +#endif
98431 +
98432 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98433 + }
98434 + spin_unlock(&mm->page_table_lock);
98435 + if (newlimit == end) {
98436 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98437 +
98438 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98439 + if (is_vm_hugetlb_page(vma))
98440 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98441 + else
98442 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98443 + }
98444 +}
98445 +#endif
98446 +
98447 int
98448 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98449 unsigned long start, unsigned long end, unsigned long newflags)
98450 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98451 int error;
98452 int dirty_accountable = 0;
98453
98454 +#ifdef CONFIG_PAX_SEGMEXEC
98455 + struct vm_area_struct *vma_m = NULL;
98456 + unsigned long start_m, end_m;
98457 +
98458 + start_m = start + SEGMEXEC_TASK_SIZE;
98459 + end_m = end + SEGMEXEC_TASK_SIZE;
98460 +#endif
98461 +
98462 if (newflags == oldflags) {
98463 *pprev = vma;
98464 return 0;
98465 }
98466
98467 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98468 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98469 +
98470 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98471 + return -ENOMEM;
98472 +
98473 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98474 + return -ENOMEM;
98475 + }
98476 +
98477 /*
98478 * If we make a private mapping writable we increase our commit;
98479 * but (without finer accounting) cannot reduce our commit if we
98480 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98481 }
98482 }
98483
98484 +#ifdef CONFIG_PAX_SEGMEXEC
98485 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98486 + if (start != vma->vm_start) {
98487 + error = split_vma(mm, vma, start, 1);
98488 + if (error)
98489 + goto fail;
98490 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98491 + *pprev = (*pprev)->vm_next;
98492 + }
98493 +
98494 + if (end != vma->vm_end) {
98495 + error = split_vma(mm, vma, end, 0);
98496 + if (error)
98497 + goto fail;
98498 + }
98499 +
98500 + if (pax_find_mirror_vma(vma)) {
98501 + error = __do_munmap(mm, start_m, end_m - start_m);
98502 + if (error)
98503 + goto fail;
98504 + } else {
98505 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98506 + if (!vma_m) {
98507 + error = -ENOMEM;
98508 + goto fail;
98509 + }
98510 + vma->vm_flags = newflags;
98511 + error = pax_mirror_vma(vma_m, vma);
98512 + if (error) {
98513 + vma->vm_flags = oldflags;
98514 + goto fail;
98515 + }
98516 + }
98517 + }
98518 +#endif
98519 +
98520 /*
98521 * First try to merge with previous and/or next vma.
98522 */
98523 @@ -319,9 +423,21 @@ success:
98524 * vm_flags and vm_page_prot are protected by the mmap_sem
98525 * held in write mode.
98526 */
98527 +
98528 +#ifdef CONFIG_PAX_SEGMEXEC
98529 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98530 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98531 +#endif
98532 +
98533 vma->vm_flags = newflags;
98534 +
98535 +#ifdef CONFIG_PAX_MPROTECT
98536 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98537 + mm->binfmt->handle_mprotect(vma, newflags);
98538 +#endif
98539 +
98540 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98541 - vm_get_page_prot(newflags));
98542 + vm_get_page_prot(vma->vm_flags));
98543
98544 if (vma_wants_writenotify(vma)) {
98545 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98546 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98547 end = start + len;
98548 if (end <= start)
98549 return -ENOMEM;
98550 +
98551 +#ifdef CONFIG_PAX_SEGMEXEC
98552 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98553 + if (end > SEGMEXEC_TASK_SIZE)
98554 + return -EINVAL;
98555 + } else
98556 +#endif
98557 +
98558 + if (end > TASK_SIZE)
98559 + return -EINVAL;
98560 +
98561 if (!arch_validate_prot(prot))
98562 return -EINVAL;
98563
98564 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98565 /*
98566 * Does the application expect PROT_READ to imply PROT_EXEC:
98567 */
98568 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98569 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98570 prot |= PROT_EXEC;
98571
98572 vm_flags = calc_vm_prot_bits(prot);
98573 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98574 if (start > vma->vm_start)
98575 prev = vma;
98576
98577 +#ifdef CONFIG_PAX_MPROTECT
98578 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98579 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98580 +#endif
98581 +
98582 for (nstart = start ; ; ) {
98583 unsigned long newflags;
98584
98585 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98586
98587 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98588 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98589 + if (prot & (PROT_WRITE | PROT_EXEC))
98590 + gr_log_rwxmprotect(vma);
98591 +
98592 + error = -EACCES;
98593 + goto out;
98594 + }
98595 +
98596 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98597 error = -EACCES;
98598 goto out;
98599 }
98600 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98601 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98602 if (error)
98603 goto out;
98604 +
98605 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98606 +
98607 nstart = tmp;
98608
98609 if (nstart < prev->vm_end)
98610 diff --git a/mm/mremap.c b/mm/mremap.c
98611 index 05f1180..c3cde48 100644
98612 --- a/mm/mremap.c
98613 +++ b/mm/mremap.c
98614 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98615 continue;
98616 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98617 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98618 +
98619 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98620 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98621 + pte = pte_exprotect(pte);
98622 +#endif
98623 +
98624 pte = move_soft_dirty_pte(pte);
98625 set_pte_at(mm, new_addr, new_pte, pte);
98626 }
98627 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98628 if (is_vm_hugetlb_page(vma))
98629 goto Einval;
98630
98631 +#ifdef CONFIG_PAX_SEGMEXEC
98632 + if (pax_find_mirror_vma(vma))
98633 + goto Einval;
98634 +#endif
98635 +
98636 /* We can't remap across vm area boundaries */
98637 if (old_len > vma->vm_end - addr)
98638 goto Efault;
98639 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98640 unsigned long ret = -EINVAL;
98641 unsigned long charged = 0;
98642 unsigned long map_flags;
98643 + unsigned long pax_task_size = TASK_SIZE;
98644
98645 if (new_addr & ~PAGE_MASK)
98646 goto out;
98647
98648 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98649 +#ifdef CONFIG_PAX_SEGMEXEC
98650 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98651 + pax_task_size = SEGMEXEC_TASK_SIZE;
98652 +#endif
98653 +
98654 + pax_task_size -= PAGE_SIZE;
98655 +
98656 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98657 goto out;
98658
98659 /* Check if the location we're moving into overlaps the
98660 * old location at all, and fail if it does.
98661 */
98662 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98663 - goto out;
98664 -
98665 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98666 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98667 goto out;
98668
98669 ret = do_munmap(mm, new_addr, new_len);
98670 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98671 unsigned long ret = -EINVAL;
98672 unsigned long charged = 0;
98673 bool locked = false;
98674 + unsigned long pax_task_size = TASK_SIZE;
98675
98676 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98677 return ret;
98678 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98679 if (!new_len)
98680 return ret;
98681
98682 +#ifdef CONFIG_PAX_SEGMEXEC
98683 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98684 + pax_task_size = SEGMEXEC_TASK_SIZE;
98685 +#endif
98686 +
98687 + pax_task_size -= PAGE_SIZE;
98688 +
98689 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98690 + old_len > pax_task_size || addr > pax_task_size-old_len)
98691 + return ret;
98692 +
98693 down_write(&current->mm->mmap_sem);
98694
98695 if (flags & MREMAP_FIXED) {
98696 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98697 new_addr = addr;
98698 }
98699 ret = addr;
98700 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98701 goto out;
98702 }
98703 }
98704 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98705 goto out;
98706 }
98707
98708 + map_flags = vma->vm_flags;
98709 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98710 + if (!(ret & ~PAGE_MASK)) {
98711 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98712 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98713 + }
98714 }
98715 out:
98716 if (ret & ~PAGE_MASK)
98717 diff --git a/mm/nommu.c b/mm/nommu.c
98718 index a881d96..e5932cd 100644
98719 --- a/mm/nommu.c
98720 +++ b/mm/nommu.c
98721 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98722 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98723 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98724 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98725 -int heap_stack_gap = 0;
98726
98727 atomic_long_t mmap_pages_allocated;
98728
98729 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98730 EXPORT_SYMBOL(find_vma);
98731
98732 /*
98733 - * find a VMA
98734 - * - we don't extend stack VMAs under NOMMU conditions
98735 - */
98736 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98737 -{
98738 - return find_vma(mm, addr);
98739 -}
98740 -
98741 -/*
98742 * expand a stack to a given address
98743 * - not supported under NOMMU conditions
98744 */
98745 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98746
98747 /* most fields are the same, copy all, and then fixup */
98748 *new = *vma;
98749 + INIT_LIST_HEAD(&new->anon_vma_chain);
98750 *region = *vma->vm_region;
98751 new->vm_region = region;
98752
98753 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98754 }
98755 EXPORT_SYMBOL(generic_file_remap_pages);
98756
98757 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98758 - unsigned long addr, void *buf, int len, int write)
98759 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98760 + unsigned long addr, void *buf, size_t len, int write)
98761 {
98762 struct vm_area_struct *vma;
98763
98764 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98765 *
98766 * The caller must hold a reference on @mm.
98767 */
98768 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98769 - void *buf, int len, int write)
98770 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98771 + void *buf, size_t len, int write)
98772 {
98773 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98774 }
98775 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98776 * Access another process' address space.
98777 * - source/target buffer must be kernel space
98778 */
98779 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98780 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98781 {
98782 struct mm_struct *mm;
98783
98784 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98785 index 91d73ef..0e564d2 100644
98786 --- a/mm/page-writeback.c
98787 +++ b/mm/page-writeback.c
98788 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98789 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98790 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98791 */
98792 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98793 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98794 unsigned long thresh,
98795 unsigned long bg_thresh,
98796 unsigned long dirty,
98797 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98798 index eee9619..155d328 100644
98799 --- a/mm/page_alloc.c
98800 +++ b/mm/page_alloc.c
98801 @@ -61,6 +61,7 @@
98802 #include <linux/page-debug-flags.h>
98803 #include <linux/hugetlb.h>
98804 #include <linux/sched/rt.h>
98805 +#include <linux/random.h>
98806
98807 #include <asm/sections.h>
98808 #include <asm/tlbflush.h>
98809 @@ -357,7 +358,7 @@ out:
98810 * This usage means that zero-order pages may not be compound.
98811 */
98812
98813 -static void free_compound_page(struct page *page)
98814 +void free_compound_page(struct page *page)
98815 {
98816 __free_pages_ok(page, compound_order(page));
98817 }
98818 @@ -751,6 +752,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98819 int i;
98820 int bad = 0;
98821
98822 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98823 + unsigned long index = 1UL << order;
98824 +#endif
98825 +
98826 trace_mm_page_free(page, order);
98827 kmemcheck_free_shadow(page, order);
98828
98829 @@ -767,6 +772,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98830 debug_check_no_obj_freed(page_address(page),
98831 PAGE_SIZE << order);
98832 }
98833 +
98834 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98835 + for (; index; --index)
98836 + sanitize_highpage(page + index - 1);
98837 +#endif
98838 +
98839 arch_free_page(page, order);
98840 kernel_map_pages(page, 1 << order, 0);
98841
98842 @@ -790,6 +801,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98843 local_irq_restore(flags);
98844 }
98845
98846 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98847 +bool __meminitdata extra_latent_entropy;
98848 +
98849 +static int __init setup_pax_extra_latent_entropy(char *str)
98850 +{
98851 + extra_latent_entropy = true;
98852 + return 0;
98853 +}
98854 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98855 +
98856 +volatile u64 latent_entropy __latent_entropy;
98857 +EXPORT_SYMBOL(latent_entropy);
98858 +#endif
98859 +
98860 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98861 {
98862 unsigned int nr_pages = 1 << order;
98863 @@ -805,6 +830,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98864 __ClearPageReserved(p);
98865 set_page_count(p, 0);
98866
98867 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98868 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98869 + u64 hash = 0;
98870 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98871 + const u64 *data = lowmem_page_address(page);
98872 +
98873 + for (index = 0; index < end; index++)
98874 + hash ^= hash + data[index];
98875 + latent_entropy ^= hash;
98876 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98877 + }
98878 +#endif
98879 +
98880 page_zone(page)->managed_pages += nr_pages;
98881 set_page_refcounted(page);
98882 __free_pages(page, order);
98883 @@ -933,8 +971,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98884 arch_alloc_page(page, order);
98885 kernel_map_pages(page, 1 << order, 1);
98886
98887 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98888 if (gfp_flags & __GFP_ZERO)
98889 prep_zero_page(page, order, gfp_flags);
98890 +#endif
98891
98892 if (order && (gfp_flags & __GFP_COMP))
98893 prep_compound_page(page, order);
98894 @@ -1612,7 +1652,7 @@ again:
98895 }
98896
98897 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98898 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98899 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98900 !zone_is_fair_depleted(zone))
98901 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
98902
98903 @@ -1933,7 +1973,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98904 do {
98905 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98906 high_wmark_pages(zone) - low_wmark_pages(zone) -
98907 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98908 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98909 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
98910 } while (zone++ != preferred_zone);
98911 }
98912 @@ -5702,7 +5742,7 @@ static void __setup_per_zone_wmarks(void)
98913
98914 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98915 high_wmark_pages(zone) - low_wmark_pages(zone) -
98916 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98917 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98918
98919 setup_zone_migrate_reserve(zone);
98920 spin_unlock_irqrestore(&zone->lock, flags);
98921 diff --git a/mm/percpu.c b/mm/percpu.c
98922 index da997f9..19040e9 100644
98923 --- a/mm/percpu.c
98924 +++ b/mm/percpu.c
98925 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98926 static unsigned int pcpu_high_unit_cpu __read_mostly;
98927
98928 /* the address of the first chunk which starts with the kernel static area */
98929 -void *pcpu_base_addr __read_mostly;
98930 +void *pcpu_base_addr __read_only;
98931 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98932
98933 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98934 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98935 index 5077afc..846c9ef 100644
98936 --- a/mm/process_vm_access.c
98937 +++ b/mm/process_vm_access.c
98938 @@ -13,6 +13,7 @@
98939 #include <linux/uio.h>
98940 #include <linux/sched.h>
98941 #include <linux/highmem.h>
98942 +#include <linux/security.h>
98943 #include <linux/ptrace.h>
98944 #include <linux/slab.h>
98945 #include <linux/syscalls.h>
98946 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98947 ssize_t iov_len;
98948 size_t total_len = iov_iter_count(iter);
98949
98950 + return -ENOSYS; // PaX: until properly audited
98951 +
98952 /*
98953 * Work out how many pages of struct pages we're going to need
98954 * when eventually calling get_user_pages
98955 */
98956 for (i = 0; i < riovcnt; i++) {
98957 iov_len = rvec[i].iov_len;
98958 - if (iov_len > 0) {
98959 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98960 - + iov_len)
98961 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98962 - / PAGE_SIZE + 1;
98963 - nr_pages = max(nr_pages, nr_pages_iov);
98964 - }
98965 + if (iov_len <= 0)
98966 + continue;
98967 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98968 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98969 + nr_pages = max(nr_pages, nr_pages_iov);
98970 }
98971
98972 if (nr_pages == 0)
98973 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98974 goto free_proc_pages;
98975 }
98976
98977 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98978 + rc = -EPERM;
98979 + goto put_task_struct;
98980 + }
98981 +
98982 mm = mm_access(task, PTRACE_MODE_ATTACH);
98983 if (!mm || IS_ERR(mm)) {
98984 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98985 diff --git a/mm/rmap.c b/mm/rmap.c
98986 index 3e8491c..02abccc 100644
98987 --- a/mm/rmap.c
98988 +++ b/mm/rmap.c
98989 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98990 struct anon_vma *anon_vma = vma->anon_vma;
98991 struct anon_vma_chain *avc;
98992
98993 +#ifdef CONFIG_PAX_SEGMEXEC
98994 + struct anon_vma_chain *avc_m = NULL;
98995 +#endif
98996 +
98997 might_sleep();
98998 if (unlikely(!anon_vma)) {
98999 struct mm_struct *mm = vma->vm_mm;
99000 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99001 if (!avc)
99002 goto out_enomem;
99003
99004 +#ifdef CONFIG_PAX_SEGMEXEC
99005 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
99006 + if (!avc_m)
99007 + goto out_enomem_free_avc;
99008 +#endif
99009 +
99010 anon_vma = find_mergeable_anon_vma(vma);
99011 allocated = NULL;
99012 if (!anon_vma) {
99013 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99014 /* page_table_lock to protect against threads */
99015 spin_lock(&mm->page_table_lock);
99016 if (likely(!vma->anon_vma)) {
99017 +
99018 +#ifdef CONFIG_PAX_SEGMEXEC
99019 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
99020 +
99021 + if (vma_m) {
99022 + BUG_ON(vma_m->anon_vma);
99023 + vma_m->anon_vma = anon_vma;
99024 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
99025 + avc_m = NULL;
99026 + }
99027 +#endif
99028 +
99029 vma->anon_vma = anon_vma;
99030 anon_vma_chain_link(vma, avc, anon_vma);
99031 allocated = NULL;
99032 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99033
99034 if (unlikely(allocated))
99035 put_anon_vma(allocated);
99036 +
99037 +#ifdef CONFIG_PAX_SEGMEXEC
99038 + if (unlikely(avc_m))
99039 + anon_vma_chain_free(avc_m);
99040 +#endif
99041 +
99042 if (unlikely(avc))
99043 anon_vma_chain_free(avc);
99044 }
99045 return 0;
99046
99047 out_enomem_free_avc:
99048 +
99049 +#ifdef CONFIG_PAX_SEGMEXEC
99050 + if (avc_m)
99051 + anon_vma_chain_free(avc_m);
99052 +#endif
99053 +
99054 anon_vma_chain_free(avc);
99055 out_enomem:
99056 return -ENOMEM;
99057 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99058 * Attach the anon_vmas from src to dst.
99059 * Returns 0 on success, -ENOMEM on failure.
99060 */
99061 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99062 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99063 {
99064 struct anon_vma_chain *avc, *pavc;
99065 struct anon_vma *root = NULL;
99066 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99067 * the corresponding VMA in the parent process is attached to.
99068 * Returns 0 on success, non-zero on failure.
99069 */
99070 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99071 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99072 {
99073 struct anon_vma_chain *avc;
99074 struct anon_vma *anon_vma;
99075 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
99076 void __init anon_vma_init(void)
99077 {
99078 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99079 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99080 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99081 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99082 + anon_vma_ctor);
99083 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99084 + SLAB_PANIC|SLAB_NO_SANITIZE);
99085 }
99086
99087 /*
99088 diff --git a/mm/shmem.c b/mm/shmem.c
99089 index 469f90d..34a09ee 100644
99090 --- a/mm/shmem.c
99091 +++ b/mm/shmem.c
99092 @@ -33,7 +33,7 @@
99093 #include <linux/swap.h>
99094 #include <linux/aio.h>
99095
99096 -static struct vfsmount *shm_mnt;
99097 +struct vfsmount *shm_mnt;
99098
99099 #ifdef CONFIG_SHMEM
99100 /*
99101 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99102 #define BOGO_DIRENT_SIZE 20
99103
99104 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99105 -#define SHORT_SYMLINK_LEN 128
99106 +#define SHORT_SYMLINK_LEN 64
99107
99108 /*
99109 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99110 @@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99111 static int shmem_xattr_validate(const char *name)
99112 {
99113 struct { const char *prefix; size_t len; } arr[] = {
99114 +
99115 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99116 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99117 +#endif
99118 +
99119 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99120 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99121 };
99122 @@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99123 if (err)
99124 return err;
99125
99126 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99127 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99128 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99129 + return -EOPNOTSUPP;
99130 + if (size > 8)
99131 + return -EINVAL;
99132 + }
99133 +#endif
99134 +
99135 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99136 }
99137
99138 @@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99139 int err = -ENOMEM;
99140
99141 /* Round up to L1_CACHE_BYTES to resist false sharing */
99142 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99143 - L1_CACHE_BYTES), GFP_KERNEL);
99144 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99145 if (!sbinfo)
99146 return -ENOMEM;
99147
99148 diff --git a/mm/slab.c b/mm/slab.c
99149 index 7c52b38..dc55dcb 100644
99150 --- a/mm/slab.c
99151 +++ b/mm/slab.c
99152 @@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99153 if ((x)->max_freeable < i) \
99154 (x)->max_freeable = i; \
99155 } while (0)
99156 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99157 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99158 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99159 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99160 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99161 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99162 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99163 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99164 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99165 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99166 #else
99167 #define STATS_INC_ACTIVE(x) do { } while (0)
99168 #define STATS_DEC_ACTIVE(x) do { } while (0)
99169 @@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99170 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99171 #define STATS_INC_FREEHIT(x) do { } while (0)
99172 #define STATS_INC_FREEMISS(x) do { } while (0)
99173 +#define STATS_INC_SANITIZED(x) do { } while (0)
99174 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99175 #endif
99176
99177 #if DEBUG
99178 @@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99179 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99180 */
99181 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99182 - const struct page *page, void *obj)
99183 + const struct page *page, const void *obj)
99184 {
99185 u32 offset = (obj - page->s_mem);
99186 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99187 @@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
99188 */
99189
99190 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
99191 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
99192 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99193
99194 if (INDEX_AC != INDEX_NODE)
99195 kmalloc_caches[INDEX_NODE] =
99196 create_kmalloc_cache("kmalloc-node",
99197 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99198 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99199
99200 slab_early_init = 0;
99201
99202 @@ -3384,6 +3388,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99203 struct array_cache *ac = cpu_cache_get(cachep);
99204
99205 check_irq_off();
99206 +
99207 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99208 + if (pax_sanitize_slab) {
99209 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
99210 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99211 +
99212 + if (cachep->ctor)
99213 + cachep->ctor(objp);
99214 +
99215 + STATS_INC_SANITIZED(cachep);
99216 + } else
99217 + STATS_INC_NOT_SANITIZED(cachep);
99218 + }
99219 +#endif
99220 +
99221 kmemleak_free_recursive(objp, cachep->flags);
99222 objp = cache_free_debugcheck(cachep, objp, caller);
99223
99224 @@ -3607,6 +3626,7 @@ void kfree(const void *objp)
99225
99226 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99227 return;
99228 + VM_BUG_ON(!virt_addr_valid(objp));
99229 local_irq_save(flags);
99230 kfree_debugcheck(objp);
99231 c = virt_to_cache(objp);
99232 @@ -4056,14 +4076,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99233 }
99234 /* cpu stats */
99235 {
99236 - unsigned long allochit = atomic_read(&cachep->allochit);
99237 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99238 - unsigned long freehit = atomic_read(&cachep->freehit);
99239 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99240 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99241 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99242 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99243 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99244
99245 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99246 allochit, allocmiss, freehit, freemiss);
99247 }
99248 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99249 + {
99250 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99251 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99252 +
99253 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99254 + }
99255 +#endif
99256 #endif
99257 }
99258
99259 @@ -4281,13 +4309,69 @@ static const struct file_operations proc_slabstats_operations = {
99260 static int __init slab_proc_init(void)
99261 {
99262 #ifdef CONFIG_DEBUG_SLAB_LEAK
99263 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99264 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99265 #endif
99266 return 0;
99267 }
99268 module_init(slab_proc_init);
99269 #endif
99270
99271 +bool is_usercopy_object(const void *ptr)
99272 +{
99273 + struct page *page;
99274 + struct kmem_cache *cachep;
99275 +
99276 + if (ZERO_OR_NULL_PTR(ptr))
99277 + return false;
99278 +
99279 + if (!slab_is_available())
99280 + return false;
99281 +
99282 + if (!virt_addr_valid(ptr))
99283 + return false;
99284 +
99285 + page = virt_to_head_page(ptr);
99286 +
99287 + if (!PageSlab(page))
99288 + return false;
99289 +
99290 + cachep = page->slab_cache;
99291 + return cachep->flags & SLAB_USERCOPY;
99292 +}
99293 +
99294 +#ifdef CONFIG_PAX_USERCOPY
99295 +const char *check_heap_object(const void *ptr, unsigned long n)
99296 +{
99297 + struct page *page;
99298 + struct kmem_cache *cachep;
99299 + unsigned int objnr;
99300 + unsigned long offset;
99301 +
99302 + if (ZERO_OR_NULL_PTR(ptr))
99303 + return "<null>";
99304 +
99305 + if (!virt_addr_valid(ptr))
99306 + return NULL;
99307 +
99308 + page = virt_to_head_page(ptr);
99309 +
99310 + if (!PageSlab(page))
99311 + return NULL;
99312 +
99313 + cachep = page->slab_cache;
99314 + if (!(cachep->flags & SLAB_USERCOPY))
99315 + return cachep->name;
99316 +
99317 + objnr = obj_to_index(cachep, page, ptr);
99318 + BUG_ON(objnr >= cachep->num);
99319 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99320 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99321 + return NULL;
99322 +
99323 + return cachep->name;
99324 +}
99325 +#endif
99326 +
99327 /**
99328 * ksize - get the actual amount of memory allocated for a given object
99329 * @objp: Pointer to the object
99330 diff --git a/mm/slab.h b/mm/slab.h
99331 index 0e0fdd3..c61c735 100644
99332 --- a/mm/slab.h
99333 +++ b/mm/slab.h
99334 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
99335 /* The slab cache that manages slab cache information */
99336 extern struct kmem_cache *kmem_cache;
99337
99338 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99339 +#ifdef CONFIG_X86_64
99340 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99341 +#else
99342 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99343 +#endif
99344 +extern bool pax_sanitize_slab;
99345 +#endif
99346 +
99347 unsigned long calculate_alignment(unsigned long flags,
99348 unsigned long align, unsigned long size);
99349
99350 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99351
99352 /* Legal flag mask for kmem_cache_create(), for various configurations */
99353 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99354 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99355 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99356 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99357
99358 #if defined(CONFIG_DEBUG_SLAB)
99359 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99360 @@ -251,6 +261,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99361 return s;
99362
99363 page = virt_to_head_page(x);
99364 +
99365 + BUG_ON(!PageSlab(page));
99366 +
99367 cachep = page->slab_cache;
99368 if (slab_equal_or_root(cachep, s))
99369 return cachep;
99370 diff --git a/mm/slab_common.c b/mm/slab_common.c
99371 index d319502..9eb3eb5 100644
99372 --- a/mm/slab_common.c
99373 +++ b/mm/slab_common.c
99374 @@ -25,11 +25,22 @@
99375
99376 #include "slab.h"
99377
99378 -enum slab_state slab_state;
99379 +enum slab_state slab_state __read_only;
99380 LIST_HEAD(slab_caches);
99381 DEFINE_MUTEX(slab_mutex);
99382 struct kmem_cache *kmem_cache;
99383
99384 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99385 +bool pax_sanitize_slab __read_only = true;
99386 +static int __init pax_sanitize_slab_setup(char *str)
99387 +{
99388 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
99389 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
99390 + return 1;
99391 +}
99392 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
99393 +#endif
99394 +
99395 #ifdef CONFIG_DEBUG_VM
99396 static int kmem_cache_sanity_check(const char *name, size_t size)
99397 {
99398 @@ -160,7 +171,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99399 if (err)
99400 goto out_free_cache;
99401
99402 - s->refcount = 1;
99403 + atomic_set(&s->refcount, 1);
99404 list_add(&s->list, &slab_caches);
99405 out:
99406 if (err)
99407 @@ -341,8 +352,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99408
99409 mutex_lock(&slab_mutex);
99410
99411 - s->refcount--;
99412 - if (s->refcount)
99413 + if (!atomic_dec_and_test(&s->refcount))
99414 goto out_unlock;
99415
99416 if (memcg_cleanup_cache_params(s) != 0)
99417 @@ -362,7 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99418 rcu_barrier();
99419
99420 memcg_free_cache_params(s);
99421 -#ifdef SLAB_SUPPORTS_SYSFS
99422 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99423 sysfs_slab_remove(s);
99424 #else
99425 slab_kmem_cache_release(s);
99426 @@ -418,7 +428,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99427 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99428 name, size, err);
99429
99430 - s->refcount = -1; /* Exempt from merging for now */
99431 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99432 }
99433
99434 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99435 @@ -431,7 +441,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99436
99437 create_boot_cache(s, name, size, flags);
99438 list_add(&s->list, &slab_caches);
99439 - s->refcount = 1;
99440 + atomic_set(&s->refcount, 1);
99441 return s;
99442 }
99443
99444 @@ -443,6 +453,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99445 EXPORT_SYMBOL(kmalloc_dma_caches);
99446 #endif
99447
99448 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99449 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99450 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99451 +#endif
99452 +
99453 /*
99454 * Conversion table for small slabs sizes / 8 to the index in the
99455 * kmalloc array. This is necessary for slabs < 192 since we have non power
99456 @@ -507,6 +522,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99457 return kmalloc_dma_caches[index];
99458
99459 #endif
99460 +
99461 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99462 + if (unlikely((flags & GFP_USERCOPY)))
99463 + return kmalloc_usercopy_caches[index];
99464 +
99465 +#endif
99466 +
99467 return kmalloc_caches[index];
99468 }
99469
99470 @@ -563,7 +585,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99471 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99472 if (!kmalloc_caches[i]) {
99473 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99474 - 1 << i, flags);
99475 + 1 << i, SLAB_USERCOPY | flags);
99476 }
99477
99478 /*
99479 @@ -572,10 +594,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99480 * earlier power of two caches
99481 */
99482 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99483 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99484 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99485
99486 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99487 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99488 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99489 }
99490
99491 /* Kmalloc array is now usable */
99492 @@ -608,6 +630,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99493 }
99494 }
99495 #endif
99496 +
99497 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99498 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99499 + struct kmem_cache *s = kmalloc_caches[i];
99500 +
99501 + if (s) {
99502 + int size = kmalloc_size(i);
99503 + char *n = kasprintf(GFP_NOWAIT,
99504 + "usercopy-kmalloc-%d", size);
99505 +
99506 + BUG_ON(!n);
99507 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99508 + size, SLAB_USERCOPY | flags);
99509 + }
99510 + }
99511 +#endif
99512 +
99513 }
99514 #endif /* !CONFIG_SLOB */
99515
99516 @@ -666,6 +705,9 @@ void print_slabinfo_header(struct seq_file *m)
99517 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99518 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99519 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99520 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99521 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99522 +#endif
99523 #endif
99524 seq_putc(m, '\n');
99525 }
99526 diff --git a/mm/slob.c b/mm/slob.c
99527 index 21980e0..ed9a648 100644
99528 --- a/mm/slob.c
99529 +++ b/mm/slob.c
99530 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99531 /*
99532 * Return the size of a slob block.
99533 */
99534 -static slobidx_t slob_units(slob_t *s)
99535 +static slobidx_t slob_units(const slob_t *s)
99536 {
99537 if (s->units > 0)
99538 return s->units;
99539 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99540 /*
99541 * Return the next free slob block pointer after this one.
99542 */
99543 -static slob_t *slob_next(slob_t *s)
99544 +static slob_t *slob_next(const slob_t *s)
99545 {
99546 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99547 slobidx_t next;
99548 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99549 /*
99550 * Returns true if s is the last free block in its page.
99551 */
99552 -static int slob_last(slob_t *s)
99553 +static int slob_last(const slob_t *s)
99554 {
99555 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99556 }
99557
99558 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99559 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99560 {
99561 - void *page;
99562 + struct page *page;
99563
99564 #ifdef CONFIG_NUMA
99565 if (node != NUMA_NO_NODE)
99566 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99567 if (!page)
99568 return NULL;
99569
99570 - return page_address(page);
99571 + __SetPageSlab(page);
99572 + return page;
99573 }
99574
99575 -static void slob_free_pages(void *b, int order)
99576 +static void slob_free_pages(struct page *sp, int order)
99577 {
99578 if (current->reclaim_state)
99579 current->reclaim_state->reclaimed_slab += 1 << order;
99580 - free_pages((unsigned long)b, order);
99581 + __ClearPageSlab(sp);
99582 + page_mapcount_reset(sp);
99583 + sp->private = 0;
99584 + __free_pages(sp, order);
99585 }
99586
99587 /*
99588 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99589
99590 /* Not enough space: must allocate a new page */
99591 if (!b) {
99592 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99593 - if (!b)
99594 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99595 + if (!sp)
99596 return NULL;
99597 - sp = virt_to_page(b);
99598 - __SetPageSlab(sp);
99599 + b = page_address(sp);
99600
99601 spin_lock_irqsave(&slob_lock, flags);
99602 sp->units = SLOB_UNITS(PAGE_SIZE);
99603 sp->freelist = b;
99604 + sp->private = 0;
99605 INIT_LIST_HEAD(&sp->lru);
99606 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99607 set_slob_page_free(sp, slob_list);
99608 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99609 if (slob_page_free(sp))
99610 clear_slob_page_free(sp);
99611 spin_unlock_irqrestore(&slob_lock, flags);
99612 - __ClearPageSlab(sp);
99613 - page_mapcount_reset(sp);
99614 - slob_free_pages(b, 0);
99615 + slob_free_pages(sp, 0);
99616 return;
99617 }
99618
99619 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99620 + if (pax_sanitize_slab)
99621 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99622 +#endif
99623 +
99624 if (!slob_page_free(sp)) {
99625 /* This slob page is about to become partially free. Easy! */
99626 sp->units = units;
99627 @@ -424,11 +431,10 @@ out:
99628 */
99629
99630 static __always_inline void *
99631 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99632 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99633 {
99634 - unsigned int *m;
99635 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99636 - void *ret;
99637 + slob_t *m;
99638 + void *ret = NULL;
99639
99640 gfp &= gfp_allowed_mask;
99641
99642 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99643
99644 if (!m)
99645 return NULL;
99646 - *m = size;
99647 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99648 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99649 + m[0].units = size;
99650 + m[1].units = align;
99651 ret = (void *)m + align;
99652
99653 trace_kmalloc_node(caller, ret,
99654 size, size + align, gfp, node);
99655 } else {
99656 unsigned int order = get_order(size);
99657 + struct page *page;
99658
99659 if (likely(order))
99660 gfp |= __GFP_COMP;
99661 - ret = slob_new_pages(gfp, order, node);
99662 + page = slob_new_pages(gfp, order, node);
99663 + if (page) {
99664 + ret = page_address(page);
99665 + page->private = size;
99666 + }
99667
99668 trace_kmalloc_node(caller, ret,
99669 size, PAGE_SIZE << order, gfp, node);
99670 }
99671
99672 - kmemleak_alloc(ret, size, 1, gfp);
99673 + return ret;
99674 +}
99675 +
99676 +static __always_inline void *
99677 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99678 +{
99679 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99680 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99681 +
99682 + if (!ZERO_OR_NULL_PTR(ret))
99683 + kmemleak_alloc(ret, size, 1, gfp);
99684 return ret;
99685 }
99686
99687 @@ -493,34 +517,112 @@ void kfree(const void *block)
99688 return;
99689 kmemleak_free(block);
99690
99691 + VM_BUG_ON(!virt_addr_valid(block));
99692 sp = virt_to_page(block);
99693 - if (PageSlab(sp)) {
99694 + VM_BUG_ON(!PageSlab(sp));
99695 + if (!sp->private) {
99696 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99697 - unsigned int *m = (unsigned int *)(block - align);
99698 - slob_free(m, *m + align);
99699 - } else
99700 + slob_t *m = (slob_t *)(block - align);
99701 + slob_free(m, m[0].units + align);
99702 + } else {
99703 + __ClearPageSlab(sp);
99704 + page_mapcount_reset(sp);
99705 + sp->private = 0;
99706 __free_pages(sp, compound_order(sp));
99707 + }
99708 }
99709 EXPORT_SYMBOL(kfree);
99710
99711 +bool is_usercopy_object(const void *ptr)
99712 +{
99713 + if (!slab_is_available())
99714 + return false;
99715 +
99716 + // PAX: TODO
99717 +
99718 + return false;
99719 +}
99720 +
99721 +#ifdef CONFIG_PAX_USERCOPY
99722 +const char *check_heap_object(const void *ptr, unsigned long n)
99723 +{
99724 + struct page *page;
99725 + const slob_t *free;
99726 + const void *base;
99727 + unsigned long flags;
99728 +
99729 + if (ZERO_OR_NULL_PTR(ptr))
99730 + return "<null>";
99731 +
99732 + if (!virt_addr_valid(ptr))
99733 + return NULL;
99734 +
99735 + page = virt_to_head_page(ptr);
99736 + if (!PageSlab(page))
99737 + return NULL;
99738 +
99739 + if (page->private) {
99740 + base = page;
99741 + if (base <= ptr && n <= page->private - (ptr - base))
99742 + return NULL;
99743 + return "<slob>";
99744 + }
99745 +
99746 + /* some tricky double walking to find the chunk */
99747 + spin_lock_irqsave(&slob_lock, flags);
99748 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99749 + free = page->freelist;
99750 +
99751 + while (!slob_last(free) && (void *)free <= ptr) {
99752 + base = free + slob_units(free);
99753 + free = slob_next(free);
99754 + }
99755 +
99756 + while (base < (void *)free) {
99757 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99758 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99759 + int offset;
99760 +
99761 + if (ptr < base + align)
99762 + break;
99763 +
99764 + offset = ptr - base - align;
99765 + if (offset >= m) {
99766 + base += size;
99767 + continue;
99768 + }
99769 +
99770 + if (n > m - offset)
99771 + break;
99772 +
99773 + spin_unlock_irqrestore(&slob_lock, flags);
99774 + return NULL;
99775 + }
99776 +
99777 + spin_unlock_irqrestore(&slob_lock, flags);
99778 + return "<slob>";
99779 +}
99780 +#endif
99781 +
99782 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99783 size_t ksize(const void *block)
99784 {
99785 struct page *sp;
99786 int align;
99787 - unsigned int *m;
99788 + slob_t *m;
99789
99790 BUG_ON(!block);
99791 if (unlikely(block == ZERO_SIZE_PTR))
99792 return 0;
99793
99794 sp = virt_to_page(block);
99795 - if (unlikely(!PageSlab(sp)))
99796 - return PAGE_SIZE << compound_order(sp);
99797 + VM_BUG_ON(!PageSlab(sp));
99798 + if (sp->private)
99799 + return sp->private;
99800
99801 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99802 - m = (unsigned int *)(block - align);
99803 - return SLOB_UNITS(*m) * SLOB_UNIT;
99804 + m = (slob_t *)(block - align);
99805 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99806 }
99807 EXPORT_SYMBOL(ksize);
99808
99809 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99810
99811 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99812 {
99813 - void *b;
99814 + void *b = NULL;
99815
99816 flags &= gfp_allowed_mask;
99817
99818 lockdep_trace_alloc(flags);
99819
99820 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99821 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99822 +#else
99823 if (c->size < PAGE_SIZE) {
99824 b = slob_alloc(c->size, flags, c->align, node);
99825 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99826 SLOB_UNITS(c->size) * SLOB_UNIT,
99827 flags, node);
99828 } else {
99829 - b = slob_new_pages(flags, get_order(c->size), node);
99830 + struct page *sp;
99831 +
99832 + sp = slob_new_pages(flags, get_order(c->size), node);
99833 + if (sp) {
99834 + b = page_address(sp);
99835 + sp->private = c->size;
99836 + }
99837 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99838 PAGE_SIZE << get_order(c->size),
99839 flags, node);
99840 }
99841 +#endif
99842
99843 if (b && c->ctor)
99844 c->ctor(b);
99845 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
99846
99847 static void __kmem_cache_free(void *b, int size)
99848 {
99849 - if (size < PAGE_SIZE)
99850 + struct page *sp;
99851 +
99852 + sp = virt_to_page(b);
99853 + BUG_ON(!PageSlab(sp));
99854 + if (!sp->private)
99855 slob_free(b, size);
99856 else
99857 - slob_free_pages(b, get_order(size));
99858 + slob_free_pages(sp, get_order(size));
99859 }
99860
99861 static void kmem_rcu_free(struct rcu_head *head)
99862 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
99863
99864 void kmem_cache_free(struct kmem_cache *c, void *b)
99865 {
99866 + int size = c->size;
99867 +
99868 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99869 + if (size + c->align < PAGE_SIZE) {
99870 + size += c->align;
99871 + b -= c->align;
99872 + }
99873 +#endif
99874 +
99875 kmemleak_free_recursive(b, c->flags);
99876 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99877 struct slob_rcu *slob_rcu;
99878 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99879 - slob_rcu->size = c->size;
99880 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99881 + slob_rcu->size = size;
99882 call_rcu(&slob_rcu->head, kmem_rcu_free);
99883 } else {
99884 - __kmem_cache_free(b, c->size);
99885 + __kmem_cache_free(b, size);
99886 }
99887
99888 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99889 + trace_kfree(_RET_IP_, b);
99890 +#else
99891 trace_kmem_cache_free(_RET_IP_, b);
99892 +#endif
99893 +
99894 }
99895 EXPORT_SYMBOL(kmem_cache_free);
99896
99897 diff --git a/mm/slub.c b/mm/slub.c
99898 index 3e8afcc..68c99031 100644
99899 --- a/mm/slub.c
99900 +++ b/mm/slub.c
99901 @@ -207,7 +207,7 @@ struct track {
99902
99903 enum track_item { TRACK_ALLOC, TRACK_FREE };
99904
99905 -#ifdef CONFIG_SYSFS
99906 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99907 static int sysfs_slab_add(struct kmem_cache *);
99908 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99909 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99910 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
99911 if (!t->addr)
99912 return;
99913
99914 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99915 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99916 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99917 #ifdef CONFIG_STACKTRACE
99918 {
99919 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99920
99921 slab_free_hook(s, x);
99922
99923 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99924 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
99925 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99926 + if (s->ctor)
99927 + s->ctor(x);
99928 + }
99929 +#endif
99930 +
99931 redo:
99932 /*
99933 * Determine the currently cpus per cpu slab.
99934 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
99935 * Merge control. If this is set then no merging of slab caches will occur.
99936 * (Could be removed. This was introduced to pacify the merge skeptics.)
99937 */
99938 -static int slub_nomerge;
99939 +static int slub_nomerge = 1;
99940
99941 /*
99942 * Calculate the order of allocation given an slab object size.
99943 @@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99944 s->inuse = size;
99945
99946 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99947 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99948 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
99949 +#endif
99950 s->ctor)) {
99951 /*
99952 * Relocate free pointer after the object if it is not
99953 @@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99954 EXPORT_SYMBOL(__kmalloc_node);
99955 #endif
99956
99957 +bool is_usercopy_object(const void *ptr)
99958 +{
99959 + struct page *page;
99960 + struct kmem_cache *s;
99961 +
99962 + if (ZERO_OR_NULL_PTR(ptr))
99963 + return false;
99964 +
99965 + if (!slab_is_available())
99966 + return false;
99967 +
99968 + if (!virt_addr_valid(ptr))
99969 + return false;
99970 +
99971 + page = virt_to_head_page(ptr);
99972 +
99973 + if (!PageSlab(page))
99974 + return false;
99975 +
99976 + s = page->slab_cache;
99977 + return s->flags & SLAB_USERCOPY;
99978 +}
99979 +
99980 +#ifdef CONFIG_PAX_USERCOPY
99981 +const char *check_heap_object(const void *ptr, unsigned long n)
99982 +{
99983 + struct page *page;
99984 + struct kmem_cache *s;
99985 + unsigned long offset;
99986 +
99987 + if (ZERO_OR_NULL_PTR(ptr))
99988 + return "<null>";
99989 +
99990 + if (!virt_addr_valid(ptr))
99991 + return NULL;
99992 +
99993 + page = virt_to_head_page(ptr);
99994 +
99995 + if (!PageSlab(page))
99996 + return NULL;
99997 +
99998 + s = page->slab_cache;
99999 + if (!(s->flags & SLAB_USERCOPY))
100000 + return s->name;
100001 +
100002 + offset = (ptr - page_address(page)) % s->size;
100003 + if (offset <= s->object_size && n <= s->object_size - offset)
100004 + return NULL;
100005 +
100006 + return s->name;
100007 +}
100008 +#endif
100009 +
100010 size_t ksize(const void *object)
100011 {
100012 struct page *page;
100013 @@ -3341,6 +3405,7 @@ void kfree(const void *x)
100014 if (unlikely(ZERO_OR_NULL_PTR(x)))
100015 return;
100016
100017 + VM_BUG_ON(!virt_addr_valid(x));
100018 page = virt_to_head_page(x);
100019 if (unlikely(!PageSlab(page))) {
100020 BUG_ON(!PageCompound(page));
100021 @@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
100022 /*
100023 * We may have set a slab to be unmergeable during bootstrap.
100024 */
100025 - if (s->refcount < 0)
100026 + if (atomic_read(&s->refcount) < 0)
100027 return 1;
100028
100029 return 0;
100030 @@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100031 int i;
100032 struct kmem_cache *c;
100033
100034 - s->refcount++;
100035 + atomic_inc(&s->refcount);
100036
100037 /*
100038 * Adjust the object sizes so that we clear
100039 @@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100040 }
100041
100042 if (sysfs_slab_alias(s, name)) {
100043 - s->refcount--;
100044 + atomic_dec(&s->refcount);
100045 s = NULL;
100046 }
100047 }
100048 @@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100049 }
100050 #endif
100051
100052 -#ifdef CONFIG_SYSFS
100053 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100054 static int count_inuse(struct page *page)
100055 {
100056 return page->inuse;
100057 @@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100058 len += sprintf(buf + len, "%7ld ", l->count);
100059
100060 if (l->addr)
100061 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100062 + len += sprintf(buf + len, "%pS", NULL);
100063 +#else
100064 len += sprintf(buf + len, "%pS", (void *)l->addr);
100065 +#endif
100066 else
100067 len += sprintf(buf + len, "<not-available>");
100068
100069 @@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
100070 validate_slab_cache(kmalloc_caches[9]);
100071 }
100072 #else
100073 -#ifdef CONFIG_SYSFS
100074 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100075 static void resiliency_test(void) {};
100076 #endif
100077 #endif
100078
100079 -#ifdef CONFIG_SYSFS
100080 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100081 enum slab_stat_type {
100082 SL_ALL, /* All slabs */
100083 SL_PARTIAL, /* Only partially allocated slabs */
100084 @@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100085 {
100086 if (!s->ctor)
100087 return 0;
100088 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100089 + return sprintf(buf, "%pS\n", NULL);
100090 +#else
100091 return sprintf(buf, "%pS\n", s->ctor);
100092 +#endif
100093 }
100094 SLAB_ATTR_RO(ctor);
100095
100096 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100097 {
100098 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100099 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100100 }
100101 SLAB_ATTR_RO(aliases);
100102
100103 @@ -4554,6 +4627,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100104 SLAB_ATTR_RO(cache_dma);
100105 #endif
100106
100107 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100108 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100109 +{
100110 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100111 +}
100112 +SLAB_ATTR_RO(usercopy);
100113 +#endif
100114 +
100115 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100116 {
100117 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100118 @@ -4888,6 +4969,9 @@ static struct attribute *slab_attrs[] = {
100119 #ifdef CONFIG_ZONE_DMA
100120 &cache_dma_attr.attr,
100121 #endif
100122 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100123 + &usercopy_attr.attr,
100124 +#endif
100125 #ifdef CONFIG_NUMA
100126 &remote_node_defrag_ratio_attr.attr,
100127 #endif
100128 @@ -5132,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
100129 return name;
100130 }
100131
100132 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100133 static int sysfs_slab_add(struct kmem_cache *s)
100134 {
100135 int err;
100136 @@ -5205,6 +5290,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100137 kobject_del(&s->kobj);
100138 kobject_put(&s->kobj);
100139 }
100140 +#endif
100141
100142 /*
100143 * Need to buffer aliases during bootup until sysfs becomes
100144 @@ -5218,6 +5304,7 @@ struct saved_alias {
100145
100146 static struct saved_alias *alias_list;
100147
100148 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100149 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100150 {
100151 struct saved_alias *al;
100152 @@ -5240,6 +5327,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100153 alias_list = al;
100154 return 0;
100155 }
100156 +#endif
100157
100158 static int __init slab_sysfs_init(void)
100159 {
100160 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100161 index 4cba9c2..b4f9fcc 100644
100162 --- a/mm/sparse-vmemmap.c
100163 +++ b/mm/sparse-vmemmap.c
100164 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100165 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100166 if (!p)
100167 return NULL;
100168 - pud_populate(&init_mm, pud, p);
100169 + pud_populate_kernel(&init_mm, pud, p);
100170 }
100171 return pud;
100172 }
100173 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100174 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100175 if (!p)
100176 return NULL;
100177 - pgd_populate(&init_mm, pgd, p);
100178 + pgd_populate_kernel(&init_mm, pgd, p);
100179 }
100180 return pgd;
100181 }
100182 diff --git a/mm/sparse.c b/mm/sparse.c
100183 index d1b48b6..6e8590e 100644
100184 --- a/mm/sparse.c
100185 +++ b/mm/sparse.c
100186 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100187
100188 for (i = 0; i < PAGES_PER_SECTION; i++) {
100189 if (PageHWPoison(&memmap[i])) {
100190 - atomic_long_sub(1, &num_poisoned_pages);
100191 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100192 ClearPageHWPoison(&memmap[i]);
100193 }
100194 }
100195 diff --git a/mm/swap.c b/mm/swap.c
100196 index 6b2dc38..46b79ba 100644
100197 --- a/mm/swap.c
100198 +++ b/mm/swap.c
100199 @@ -31,6 +31,7 @@
100200 #include <linux/memcontrol.h>
100201 #include <linux/gfp.h>
100202 #include <linux/uio.h>
100203 +#include <linux/hugetlb.h>
100204
100205 #include "internal.h"
100206
100207 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100208
100209 __page_cache_release(page);
100210 dtor = get_compound_page_dtor(page);
100211 + if (!PageHuge(page))
100212 + BUG_ON(dtor != free_compound_page);
100213 (*dtor)(page);
100214 }
100215
100216 diff --git a/mm/swapfile.c b/mm/swapfile.c
100217 index 8798b2e..348f9dd 100644
100218 --- a/mm/swapfile.c
100219 +++ b/mm/swapfile.c
100220 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100221
100222 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100223 /* Activity counter to indicate that a swapon or swapoff has occurred */
100224 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100225 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100226
100227 static inline unsigned char swap_count(unsigned char ent)
100228 {
100229 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100230 spin_unlock(&swap_lock);
100231
100232 err = 0;
100233 - atomic_inc(&proc_poll_event);
100234 + atomic_inc_unchecked(&proc_poll_event);
100235 wake_up_interruptible(&proc_poll_wait);
100236
100237 out_dput:
100238 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100239
100240 poll_wait(file, &proc_poll_wait, wait);
100241
100242 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100243 - seq->poll_event = atomic_read(&proc_poll_event);
100244 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100245 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100246 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100247 }
100248
100249 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100250 return ret;
100251
100252 seq = file->private_data;
100253 - seq->poll_event = atomic_read(&proc_poll_event);
100254 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100255 return 0;
100256 }
100257
100258 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100259 (frontswap_map) ? "FS" : "");
100260
100261 mutex_unlock(&swapon_mutex);
100262 - atomic_inc(&proc_poll_event);
100263 + atomic_inc_unchecked(&proc_poll_event);
100264 wake_up_interruptible(&proc_poll_wait);
100265
100266 if (S_ISREG(inode->i_mode))
100267 diff --git a/mm/util.c b/mm/util.c
100268 index 093c973..b70a268 100644
100269 --- a/mm/util.c
100270 +++ b/mm/util.c
100271 @@ -202,6 +202,12 @@ done:
100272 void arch_pick_mmap_layout(struct mm_struct *mm)
100273 {
100274 mm->mmap_base = TASK_UNMAPPED_BASE;
100275 +
100276 +#ifdef CONFIG_PAX_RANDMMAP
100277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100278 + mm->mmap_base += mm->delta_mmap;
100279 +#endif
100280 +
100281 mm->get_unmapped_area = arch_get_unmapped_area;
100282 }
100283 #endif
100284 @@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100285 if (!mm->arg_end)
100286 goto out_mm; /* Shh! No looking before we're done */
100287
100288 + if (gr_acl_handle_procpidmem(task))
100289 + goto out_mm;
100290 +
100291 len = mm->arg_end - mm->arg_start;
100292
100293 if (len > buflen)
100294 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100295 index 2b0aa54..b451f74 100644
100296 --- a/mm/vmalloc.c
100297 +++ b/mm/vmalloc.c
100298 @@ -40,6 +40,21 @@ struct vfree_deferred {
100299 };
100300 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100301
100302 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100303 +struct stack_deferred_llist {
100304 + struct llist_head list;
100305 + void *stack;
100306 + void *lowmem_stack;
100307 +};
100308 +
100309 +struct stack_deferred {
100310 + struct stack_deferred_llist list;
100311 + struct work_struct wq;
100312 +};
100313 +
100314 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100315 +#endif
100316 +
100317 static void __vunmap(const void *, int);
100318
100319 static void free_work(struct work_struct *w)
100320 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100321 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100322 struct llist_node *llnode = llist_del_all(&p->list);
100323 while (llnode) {
100324 - void *p = llnode;
100325 + void *x = llnode;
100326 llnode = llist_next(llnode);
100327 - __vunmap(p, 1);
100328 + __vunmap(x, 1);
100329 }
100330 }
100331
100332 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100333 +static void unmap_work(struct work_struct *w)
100334 +{
100335 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100336 + struct llist_node *llnode = llist_del_all(&p->list.list);
100337 + while (llnode) {
100338 + struct stack_deferred_llist *x =
100339 + llist_entry((struct llist_head *)llnode,
100340 + struct stack_deferred_llist, list);
100341 + void *stack = ACCESS_ONCE(x->stack);
100342 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100343 + llnode = llist_next(llnode);
100344 + __vunmap(stack, 0);
100345 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100346 + }
100347 +}
100348 +#endif
100349 +
100350 /*** Page table manipulation functions ***/
100351
100352 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100353 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100354
100355 pte = pte_offset_kernel(pmd, addr);
100356 do {
100357 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100358 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100359 +
100360 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100361 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100362 + BUG_ON(!pte_exec(*pte));
100363 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100364 + continue;
100365 + }
100366 +#endif
100367 +
100368 + {
100369 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100370 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100371 + }
100372 } while (pte++, addr += PAGE_SIZE, addr != end);
100373 }
100374
100375 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100376 pte = pte_alloc_kernel(pmd, addr);
100377 if (!pte)
100378 return -ENOMEM;
100379 +
100380 + pax_open_kernel();
100381 do {
100382 struct page *page = pages[*nr];
100383
100384 - if (WARN_ON(!pte_none(*pte)))
100385 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100386 + if (pgprot_val(prot) & _PAGE_NX)
100387 +#endif
100388 +
100389 + if (!pte_none(*pte)) {
100390 + pax_close_kernel();
100391 + WARN_ON(1);
100392 return -EBUSY;
100393 - if (WARN_ON(!page))
100394 + }
100395 + if (!page) {
100396 + pax_close_kernel();
100397 + WARN_ON(1);
100398 return -ENOMEM;
100399 + }
100400 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100401 (*nr)++;
100402 } while (pte++, addr += PAGE_SIZE, addr != end);
100403 + pax_close_kernel();
100404 return 0;
100405 }
100406
100407 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100408 pmd_t *pmd;
100409 unsigned long next;
100410
100411 - pmd = pmd_alloc(&init_mm, pud, addr);
100412 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100413 if (!pmd)
100414 return -ENOMEM;
100415 do {
100416 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100417 pud_t *pud;
100418 unsigned long next;
100419
100420 - pud = pud_alloc(&init_mm, pgd, addr);
100421 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100422 if (!pud)
100423 return -ENOMEM;
100424 do {
100425 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100426 if (addr >= MODULES_VADDR && addr < MODULES_END)
100427 return 1;
100428 #endif
100429 +
100430 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100431 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100432 + return 1;
100433 +#endif
100434 +
100435 return is_vmalloc_addr(x);
100436 }
100437
100438 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100439
100440 if (!pgd_none(*pgd)) {
100441 pud_t *pud = pud_offset(pgd, addr);
100442 +#ifdef CONFIG_X86
100443 + if (!pud_large(*pud))
100444 +#endif
100445 if (!pud_none(*pud)) {
100446 pmd_t *pmd = pmd_offset(pud, addr);
100447 +#ifdef CONFIG_X86
100448 + if (!pmd_large(*pmd))
100449 +#endif
100450 if (!pmd_none(*pmd)) {
100451 pte_t *ptep, pte;
100452
100453 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100454 for_each_possible_cpu(i) {
100455 struct vmap_block_queue *vbq;
100456 struct vfree_deferred *p;
100457 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100458 + struct stack_deferred *p2;
100459 +#endif
100460
100461 vbq = &per_cpu(vmap_block_queue, i);
100462 spin_lock_init(&vbq->lock);
100463 INIT_LIST_HEAD(&vbq->free);
100464 +
100465 p = &per_cpu(vfree_deferred, i);
100466 init_llist_head(&p->list);
100467 INIT_WORK(&p->wq, free_work);
100468 +
100469 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100470 + p2 = &per_cpu(stack_deferred, i);
100471 + init_llist_head(&p2->list.list);
100472 + INIT_WORK(&p2->wq, unmap_work);
100473 +#endif
100474 }
100475
100476 /* Import existing vmlist entries. */
100477 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100478 struct vm_struct *area;
100479
100480 BUG_ON(in_interrupt());
100481 +
100482 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100483 + if (flags & VM_KERNEXEC) {
100484 + if (start != VMALLOC_START || end != VMALLOC_END)
100485 + return NULL;
100486 + start = (unsigned long)MODULES_EXEC_VADDR;
100487 + end = (unsigned long)MODULES_EXEC_END;
100488 + }
100489 +#endif
100490 +
100491 if (flags & VM_IOREMAP)
100492 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100493
100494 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100495 }
100496 EXPORT_SYMBOL(vunmap);
100497
100498 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100499 +void unmap_process_stacks(struct task_struct *task)
100500 +{
100501 + if (unlikely(in_interrupt())) {
100502 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100503 + struct stack_deferred_llist *list = task->stack;
100504 + list->stack = task->stack;
100505 + list->lowmem_stack = task->lowmem_stack;
100506 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100507 + schedule_work(&p->wq);
100508 + } else {
100509 + __vunmap(task->stack, 0);
100510 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100511 + }
100512 +}
100513 +#endif
100514 +
100515 /**
100516 * vmap - map an array of pages into virtually contiguous space
100517 * @pages: array of page pointers
100518 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100519 if (count > totalram_pages)
100520 return NULL;
100521
100522 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100523 + if (!(pgprot_val(prot) & _PAGE_NX))
100524 + flags |= VM_KERNEXEC;
100525 +#endif
100526 +
100527 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100528 __builtin_return_address(0));
100529 if (!area)
100530 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100531 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100532 goto fail;
100533
100534 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100535 + if (!(pgprot_val(prot) & _PAGE_NX))
100536 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100537 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100538 + else
100539 +#endif
100540 +
100541 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100542 start, end, node, gfp_mask, caller);
100543 if (!area)
100544 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100545 * For tight control over page level allocator and protection flags
100546 * use __vmalloc() instead.
100547 */
100548 -
100549 void *vmalloc_exec(unsigned long size)
100550 {
100551 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100552 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100553 NUMA_NO_NODE, __builtin_return_address(0));
100554 }
100555
100556 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100557 {
100558 struct vm_struct *area;
100559
100560 + BUG_ON(vma->vm_mirror);
100561 +
100562 size = PAGE_ALIGN(size);
100563
100564 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100565 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100566 v->addr, v->addr + v->size, v->size);
100567
100568 if (v->caller)
100569 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100570 + seq_printf(m, " %pK", v->caller);
100571 +#else
100572 seq_printf(m, " %pS", v->caller);
100573 +#endif
100574
100575 if (v->nr_pages)
100576 seq_printf(m, " pages=%d", v->nr_pages);
100577 diff --git a/mm/vmstat.c b/mm/vmstat.c
100578 index e9ab104..de275bd 100644
100579 --- a/mm/vmstat.c
100580 +++ b/mm/vmstat.c
100581 @@ -20,6 +20,7 @@
100582 #include <linux/writeback.h>
100583 #include <linux/compaction.h>
100584 #include <linux/mm_inline.h>
100585 +#include <linux/grsecurity.h>
100586
100587 #include "internal.h"
100588
100589 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100590 *
100591 * vm_stat contains the global counters
100592 */
100593 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100594 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100595 EXPORT_SYMBOL(vm_stat);
100596
100597 #ifdef CONFIG_SMP
100598 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100599
100600 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100601 if (diff[i])
100602 - atomic_long_add(diff[i], &vm_stat[i]);
100603 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100604 }
100605
100606 /*
100607 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100608 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100609 if (v) {
100610
100611 - atomic_long_add(v, &zone->vm_stat[i]);
100612 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100613 global_diff[i] += v;
100614 #ifdef CONFIG_NUMA
100615 /* 3 seconds idle till flush */
100616 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100617
100618 v = p->vm_stat_diff[i];
100619 p->vm_stat_diff[i] = 0;
100620 - atomic_long_add(v, &zone->vm_stat[i]);
100621 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100622 global_diff[i] += v;
100623 }
100624 }
100625 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100626 if (pset->vm_stat_diff[i]) {
100627 int v = pset->vm_stat_diff[i];
100628 pset->vm_stat_diff[i] = 0;
100629 - atomic_long_add(v, &zone->vm_stat[i]);
100630 - atomic_long_add(v, &vm_stat[i]);
100631 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100632 + atomic_long_add_unchecked(v, &vm_stat[i]);
100633 }
100634 }
100635 #endif
100636 @@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100637 stat_items_size += sizeof(struct vm_event_state);
100638 #endif
100639
100640 - v = kmalloc(stat_items_size, GFP_KERNEL);
100641 + v = kzalloc(stat_items_size, GFP_KERNEL);
100642 m->private = v;
100643 if (!v)
100644 return ERR_PTR(-ENOMEM);
100645 +
100646 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100647 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100648 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100649 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100650 + && !in_group_p(grsec_proc_gid)
100651 +#endif
100652 + )
100653 + return (unsigned long *)m->private + *pos;
100654 +#endif
100655 +#endif
100656 +
100657 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100658 v[i] = global_page_state(i);
100659 v += NR_VM_ZONE_STAT_ITEMS;
100660 @@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100661 cpu_notifier_register_done();
100662 #endif
100663 #ifdef CONFIG_PROC_FS
100664 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100665 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100666 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100667 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100668 + {
100669 + mode_t gr_mode = S_IRUGO;
100670 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100671 + gr_mode = S_IRUSR;
100672 +#endif
100673 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100674 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100675 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100676 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100677 + }
100678 #endif
100679 return 0;
100680 }
100681 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100682 index 64c6bed..b79a5de 100644
100683 --- a/net/8021q/vlan.c
100684 +++ b/net/8021q/vlan.c
100685 @@ -481,7 +481,7 @@ out:
100686 return NOTIFY_DONE;
100687 }
100688
100689 -static struct notifier_block vlan_notifier_block __read_mostly = {
100690 +static struct notifier_block vlan_notifier_block = {
100691 .notifier_call = vlan_device_event,
100692 };
100693
100694 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100695 err = -EPERM;
100696 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100697 break;
100698 - if ((args.u.name_type >= 0) &&
100699 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100700 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100701 struct vlan_net *vn;
100702
100703 vn = net_generic(net, vlan_net_id);
100704 diff --git a/net/9p/client.c b/net/9p/client.c
100705 index e86a9bea..e91f70e 100644
100706 --- a/net/9p/client.c
100707 +++ b/net/9p/client.c
100708 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100709 len - inline_len);
100710 } else {
100711 err = copy_from_user(ename + inline_len,
100712 - uidata, len - inline_len);
100713 + (char __force_user *)uidata, len - inline_len);
100714 if (err) {
100715 err = -EFAULT;
100716 goto out_err;
100717 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100718 kernel_buf = 1;
100719 indata = data;
100720 } else
100721 - indata = (__force char *)udata;
100722 + indata = (__force_kernel char *)udata;
100723 /*
100724 * response header len is 11
100725 * PDU Header(7) + IO Size (4)
100726 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100727 kernel_buf = 1;
100728 odata = data;
100729 } else
100730 - odata = (char *)udata;
100731 + odata = (char __force_kernel *)udata;
100732 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100733 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100734 fid->fid, offset, rsize);
100735 diff --git a/net/9p/mod.c b/net/9p/mod.c
100736 index 6ab36ae..6f1841b 100644
100737 --- a/net/9p/mod.c
100738 +++ b/net/9p/mod.c
100739 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100740 void v9fs_register_trans(struct p9_trans_module *m)
100741 {
100742 spin_lock(&v9fs_trans_lock);
100743 - list_add_tail(&m->list, &v9fs_trans_list);
100744 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100745 spin_unlock(&v9fs_trans_lock);
100746 }
100747 EXPORT_SYMBOL(v9fs_register_trans);
100748 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100749 void v9fs_unregister_trans(struct p9_trans_module *m)
100750 {
100751 spin_lock(&v9fs_trans_lock);
100752 - list_del_init(&m->list);
100753 + pax_list_del_init((struct list_head *)&m->list);
100754 spin_unlock(&v9fs_trans_lock);
100755 }
100756 EXPORT_SYMBOL(v9fs_unregister_trans);
100757 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100758 index 80d08f6..de63fd1 100644
100759 --- a/net/9p/trans_fd.c
100760 +++ b/net/9p/trans_fd.c
100761 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100762 oldfs = get_fs();
100763 set_fs(get_ds());
100764 /* The cast to a user pointer is valid due to the set_fs() */
100765 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100766 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100767 set_fs(oldfs);
100768
100769 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100770 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100771 index af46bc4..f9adfcd 100644
100772 --- a/net/appletalk/atalk_proc.c
100773 +++ b/net/appletalk/atalk_proc.c
100774 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100775 struct proc_dir_entry *p;
100776 int rc = -ENOMEM;
100777
100778 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100779 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100780 if (!atalk_proc_dir)
100781 goto out;
100782
100783 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100784 index 876fbe8..8bbea9f 100644
100785 --- a/net/atm/atm_misc.c
100786 +++ b/net/atm/atm_misc.c
100787 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100788 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100789 return 1;
100790 atm_return(vcc, truesize);
100791 - atomic_inc(&vcc->stats->rx_drop);
100792 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100793 return 0;
100794 }
100795 EXPORT_SYMBOL(atm_charge);
100796 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100797 }
100798 }
100799 atm_return(vcc, guess);
100800 - atomic_inc(&vcc->stats->rx_drop);
100801 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100802 return NULL;
100803 }
100804 EXPORT_SYMBOL(atm_alloc_charge);
100805 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100806
100807 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100808 {
100809 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100810 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100811 __SONET_ITEMS
100812 #undef __HANDLE_ITEM
100813 }
100814 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100815
100816 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100817 {
100818 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100819 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100820 __SONET_ITEMS
100821 #undef __HANDLE_ITEM
100822 }
100823 diff --git a/net/atm/lec.c b/net/atm/lec.c
100824 index 4b98f89..5a2f6cb 100644
100825 --- a/net/atm/lec.c
100826 +++ b/net/atm/lec.c
100827 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100828 }
100829
100830 static struct lane2_ops lane2_ops = {
100831 - lane2_resolve, /* resolve, spec 3.1.3 */
100832 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100833 - NULL /* associate indicator, spec 3.1.5 */
100834 + .resolve = lane2_resolve,
100835 + .associate_req = lane2_associate_req,
100836 + .associate_indicator = NULL
100837 };
100838
100839 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100840 diff --git a/net/atm/lec.h b/net/atm/lec.h
100841 index 4149db1..f2ab682 100644
100842 --- a/net/atm/lec.h
100843 +++ b/net/atm/lec.h
100844 @@ -48,7 +48,7 @@ struct lane2_ops {
100845 const u8 *tlvs, u32 sizeoftlvs);
100846 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100847 const u8 *tlvs, u32 sizeoftlvs);
100848 -};
100849 +} __no_const;
100850
100851 /*
100852 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100853 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100854 index d1b2d9a..d549f7f 100644
100855 --- a/net/atm/mpoa_caches.c
100856 +++ b/net/atm/mpoa_caches.c
100857 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100858
100859
100860 static struct in_cache_ops ingress_ops = {
100861 - in_cache_add_entry, /* add_entry */
100862 - in_cache_get, /* get */
100863 - in_cache_get_with_mask, /* get_with_mask */
100864 - in_cache_get_by_vcc, /* get_by_vcc */
100865 - in_cache_put, /* put */
100866 - in_cache_remove_entry, /* remove_entry */
100867 - cache_hit, /* cache_hit */
100868 - clear_count_and_expired, /* clear_count */
100869 - check_resolving_entries, /* check_resolving */
100870 - refresh_entries, /* refresh */
100871 - in_destroy_cache /* destroy_cache */
100872 + .add_entry = in_cache_add_entry,
100873 + .get = in_cache_get,
100874 + .get_with_mask = in_cache_get_with_mask,
100875 + .get_by_vcc = in_cache_get_by_vcc,
100876 + .put = in_cache_put,
100877 + .remove_entry = in_cache_remove_entry,
100878 + .cache_hit = cache_hit,
100879 + .clear_count = clear_count_and_expired,
100880 + .check_resolving = check_resolving_entries,
100881 + .refresh = refresh_entries,
100882 + .destroy_cache = in_destroy_cache
100883 };
100884
100885 static struct eg_cache_ops egress_ops = {
100886 - eg_cache_add_entry, /* add_entry */
100887 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100888 - eg_cache_get_by_tag, /* get_by_tag */
100889 - eg_cache_get_by_vcc, /* get_by_vcc */
100890 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100891 - eg_cache_put, /* put */
100892 - eg_cache_remove_entry, /* remove_entry */
100893 - update_eg_cache_entry, /* update */
100894 - clear_expired, /* clear_expired */
100895 - eg_destroy_cache /* destroy_cache */
100896 + .add_entry = eg_cache_add_entry,
100897 + .get_by_cache_id = eg_cache_get_by_cache_id,
100898 + .get_by_tag = eg_cache_get_by_tag,
100899 + .get_by_vcc = eg_cache_get_by_vcc,
100900 + .get_by_src_ip = eg_cache_get_by_src_ip,
100901 + .put = eg_cache_put,
100902 + .remove_entry = eg_cache_remove_entry,
100903 + .update = update_eg_cache_entry,
100904 + .clear_expired = clear_expired,
100905 + .destroy_cache = eg_destroy_cache
100906 };
100907
100908
100909 diff --git a/net/atm/proc.c b/net/atm/proc.c
100910 index bbb6461..cf04016 100644
100911 --- a/net/atm/proc.c
100912 +++ b/net/atm/proc.c
100913 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100914 const struct k_atm_aal_stats *stats)
100915 {
100916 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100917 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100918 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100919 - atomic_read(&stats->rx_drop));
100920 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100921 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100922 + atomic_read_unchecked(&stats->rx_drop));
100923 }
100924
100925 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100926 diff --git a/net/atm/resources.c b/net/atm/resources.c
100927 index 0447d5d..3cf4728 100644
100928 --- a/net/atm/resources.c
100929 +++ b/net/atm/resources.c
100930 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100931 static void copy_aal_stats(struct k_atm_aal_stats *from,
100932 struct atm_aal_stats *to)
100933 {
100934 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100935 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100936 __AAL_STAT_ITEMS
100937 #undef __HANDLE_ITEM
100938 }
100939 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100940 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100941 struct atm_aal_stats *to)
100942 {
100943 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100944 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100945 __AAL_STAT_ITEMS
100946 #undef __HANDLE_ITEM
100947 }
100948 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100949 index 919a5ce..cc6b444 100644
100950 --- a/net/ax25/sysctl_net_ax25.c
100951 +++ b/net/ax25/sysctl_net_ax25.c
100952 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100953 {
100954 char path[sizeof("net/ax25/") + IFNAMSIZ];
100955 int k;
100956 - struct ctl_table *table;
100957 + ctl_table_no_const *table;
100958
100959 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100960 if (!table)
100961 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100962 index 1e80539..676c37a 100644
100963 --- a/net/batman-adv/bat_iv_ogm.c
100964 +++ b/net/batman-adv/bat_iv_ogm.c
100965 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100966
100967 /* randomize initial seqno to avoid collision */
100968 get_random_bytes(&random_seqno, sizeof(random_seqno));
100969 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100970 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100971
100972 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100973 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100974 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100975 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100976
100977 /* change sequence number to network order */
100978 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100979 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100980 batadv_ogm_packet->seqno = htonl(seqno);
100981 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100982 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100983
100984 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100985
100986 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100987 return;
100988
100989 /* could be changed by schedule_own_packet() */
100990 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100991 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100992
100993 if (ogm_packet->flags & BATADV_DIRECTLINK)
100994 has_directlink_flag = true;
100995 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100996 index fc1835c..eead856 100644
100997 --- a/net/batman-adv/fragmentation.c
100998 +++ b/net/batman-adv/fragmentation.c
100999 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101000 frag_header.packet_type = BATADV_UNICAST_FRAG;
101001 frag_header.version = BATADV_COMPAT_VERSION;
101002 frag_header.ttl = BATADV_TTL;
101003 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101004 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101005 frag_header.reserved = 0;
101006 frag_header.no = 0;
101007 frag_header.total_size = htons(skb->len);
101008 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101009 index 5467955..30cc771 100644
101010 --- a/net/batman-adv/soft-interface.c
101011 +++ b/net/batman-adv/soft-interface.c
101012 @@ -296,7 +296,7 @@ send:
101013 primary_if->net_dev->dev_addr);
101014
101015 /* set broadcast sequence number */
101016 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101017 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101018 bcast_packet->seqno = htonl(seqno);
101019
101020 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101021 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101022 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101023
101024 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101025 - atomic_set(&bat_priv->bcast_seqno, 1);
101026 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101027 atomic_set(&bat_priv->tt.vn, 0);
101028 atomic_set(&bat_priv->tt.local_changes, 0);
101029 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101030 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101031
101032 /* randomize initial seqno to avoid collision */
101033 get_random_bytes(&random_seqno, sizeof(random_seqno));
101034 - atomic_set(&bat_priv->frag_seqno, random_seqno);
101035 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101036
101037 bat_priv->primary_if = NULL;
101038 bat_priv->num_ifaces = 0;
101039 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101040 index 8854c05..ee5d5497 100644
101041 --- a/net/batman-adv/types.h
101042 +++ b/net/batman-adv/types.h
101043 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101044 struct batadv_hard_iface_bat_iv {
101045 unsigned char *ogm_buff;
101046 int ogm_buff_len;
101047 - atomic_t ogm_seqno;
101048 + atomic_unchecked_t ogm_seqno;
101049 };
101050
101051 /**
101052 @@ -768,7 +768,7 @@ struct batadv_priv {
101053 atomic_t bonding;
101054 atomic_t fragmentation;
101055 atomic_t packet_size_max;
101056 - atomic_t frag_seqno;
101057 + atomic_unchecked_t frag_seqno;
101058 #ifdef CONFIG_BATMAN_ADV_BLA
101059 atomic_t bridge_loop_avoidance;
101060 #endif
101061 @@ -787,7 +787,7 @@ struct batadv_priv {
101062 #endif
101063 uint32_t isolation_mark;
101064 uint32_t isolation_mark_mask;
101065 - atomic_t bcast_seqno;
101066 + atomic_unchecked_t bcast_seqno;
101067 atomic_t bcast_queue_left;
101068 atomic_t batman_queue_left;
101069 char num_ifaces;
101070 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101071 index 115f149..f0ba286 100644
101072 --- a/net/bluetooth/hci_sock.c
101073 +++ b/net/bluetooth/hci_sock.c
101074 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101075 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101076 }
101077
101078 - len = min_t(unsigned int, len, sizeof(uf));
101079 + len = min((size_t)len, sizeof(uf));
101080 if (copy_from_user(&uf, optval, len)) {
101081 err = -EFAULT;
101082 break;
101083 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101084 index 46547b9..f5defc1 100644
101085 --- a/net/bluetooth/l2cap_core.c
101086 +++ b/net/bluetooth/l2cap_core.c
101087 @@ -3569,8 +3569,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101088 break;
101089
101090 case L2CAP_CONF_RFC:
101091 - if (olen == sizeof(rfc))
101092 - memcpy(&rfc, (void *)val, olen);
101093 + if (olen != sizeof(rfc))
101094 + break;
101095 +
101096 + memcpy(&rfc, (void *)val, olen);
101097
101098 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101099 rfc.mode != chan->mode)
101100 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101101 index 1884f72..b3b71f9 100644
101102 --- a/net/bluetooth/l2cap_sock.c
101103 +++ b/net/bluetooth/l2cap_sock.c
101104 @@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101105 struct sock *sk = sock->sk;
101106 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101107 struct l2cap_options opts;
101108 - int len, err = 0;
101109 + int err = 0;
101110 + size_t len = optlen;
101111 u32 opt;
101112
101113 BT_DBG("sk %p", sk);
101114 @@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101115 opts.max_tx = chan->max_tx;
101116 opts.txwin_size = chan->tx_win;
101117
101118 - len = min_t(unsigned int, sizeof(opts), optlen);
101119 + len = min(sizeof(opts), len);
101120 if (copy_from_user((char *) &opts, optval, len)) {
101121 err = -EFAULT;
101122 break;
101123 @@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101124 struct bt_security sec;
101125 struct bt_power pwr;
101126 struct l2cap_conn *conn;
101127 - int len, err = 0;
101128 + int err = 0;
101129 + size_t len = optlen;
101130 u32 opt;
101131
101132 BT_DBG("sk %p", sk);
101133 @@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101134
101135 sec.level = BT_SECURITY_LOW;
101136
101137 - len = min_t(unsigned int, sizeof(sec), optlen);
101138 + len = min(sizeof(sec), len);
101139 if (copy_from_user((char *) &sec, optval, len)) {
101140 err = -EFAULT;
101141 break;
101142 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101143
101144 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101145
101146 - len = min_t(unsigned int, sizeof(pwr), optlen);
101147 + len = min(sizeof(pwr), len);
101148 if (copy_from_user((char *) &pwr, optval, len)) {
101149 err = -EFAULT;
101150 break;
101151 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101152 index 8bbbb5e..6fc0950 100644
101153 --- a/net/bluetooth/rfcomm/sock.c
101154 +++ b/net/bluetooth/rfcomm/sock.c
101155 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101156 struct sock *sk = sock->sk;
101157 struct bt_security sec;
101158 int err = 0;
101159 - size_t len;
101160 + size_t len = optlen;
101161 u32 opt;
101162
101163 BT_DBG("sk %p", sk);
101164 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101165
101166 sec.level = BT_SECURITY_LOW;
101167
101168 - len = min_t(unsigned int, sizeof(sec), optlen);
101169 + len = min(sizeof(sec), len);
101170 if (copy_from_user((char *) &sec, optval, len)) {
101171 err = -EFAULT;
101172 break;
101173 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101174 index 8e385a0..a5bdd8e 100644
101175 --- a/net/bluetooth/rfcomm/tty.c
101176 +++ b/net/bluetooth/rfcomm/tty.c
101177 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101178 BT_DBG("tty %p id %d", tty, tty->index);
101179
101180 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101181 - dev->channel, dev->port.count);
101182 + dev->channel, atomic_read(&dev->port.count));
101183
101184 err = tty_port_open(&dev->port, tty, filp);
101185 if (err)
101186 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101187 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101188
101189 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101190 - dev->port.count);
101191 + atomic_read(&dev->port.count));
101192
101193 tty_port_close(&dev->port, tty, filp);
101194 }
101195 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101196 index 6d69631..b8fdc85 100644
101197 --- a/net/bridge/netfilter/ebtables.c
101198 +++ b/net/bridge/netfilter/ebtables.c
101199 @@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101200 tmp.valid_hooks = t->table->valid_hooks;
101201 }
101202 mutex_unlock(&ebt_mutex);
101203 - if (copy_to_user(user, &tmp, *len) != 0) {
101204 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101205 BUGPRINT("c2u Didn't work\n");
101206 ret = -EFAULT;
101207 break;
101208 @@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101209 goto out;
101210 tmp.valid_hooks = t->valid_hooks;
101211
101212 - if (copy_to_user(user, &tmp, *len) != 0) {
101213 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101214 ret = -EFAULT;
101215 break;
101216 }
101217 @@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101218 tmp.entries_size = t->table->entries_size;
101219 tmp.valid_hooks = t->table->valid_hooks;
101220
101221 - if (copy_to_user(user, &tmp, *len) != 0) {
101222 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101223 ret = -EFAULT;
101224 break;
101225 }
101226 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101227 index f5afda1..dcf770a 100644
101228 --- a/net/caif/cfctrl.c
101229 +++ b/net/caif/cfctrl.c
101230 @@ -10,6 +10,7 @@
101231 #include <linux/spinlock.h>
101232 #include <linux/slab.h>
101233 #include <linux/pkt_sched.h>
101234 +#include <linux/sched.h>
101235 #include <net/caif/caif_layer.h>
101236 #include <net/caif/cfpkt.h>
101237 #include <net/caif/cfctrl.h>
101238 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101239 memset(&dev_info, 0, sizeof(dev_info));
101240 dev_info.id = 0xff;
101241 cfsrvl_init(&this->serv, 0, &dev_info, false);
101242 - atomic_set(&this->req_seq_no, 1);
101243 - atomic_set(&this->rsp_seq_no, 1);
101244 + atomic_set_unchecked(&this->req_seq_no, 1);
101245 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101246 this->serv.layer.receive = cfctrl_recv;
101247 sprintf(this->serv.layer.name, "ctrl");
101248 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101249 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101250 struct cfctrl_request_info *req)
101251 {
101252 spin_lock_bh(&ctrl->info_list_lock);
101253 - atomic_inc(&ctrl->req_seq_no);
101254 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101255 + atomic_inc_unchecked(&ctrl->req_seq_no);
101256 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101257 list_add_tail(&req->list, &ctrl->list);
101258 spin_unlock_bh(&ctrl->info_list_lock);
101259 }
101260 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101261 if (p != first)
101262 pr_warn("Requests are not received in order\n");
101263
101264 - atomic_set(&ctrl->rsp_seq_no,
101265 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101266 p->sequence_no);
101267 list_del(&p->list);
101268 goto out;
101269 diff --git a/net/can/af_can.c b/net/can/af_can.c
101270 index ce82337..5d17b4d 100644
101271 --- a/net/can/af_can.c
101272 +++ b/net/can/af_can.c
101273 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101274 };
101275
101276 /* notifier block for netdevice event */
101277 -static struct notifier_block can_netdev_notifier __read_mostly = {
101278 +static struct notifier_block can_netdev_notifier = {
101279 .notifier_call = can_notifier,
101280 };
101281
101282 diff --git a/net/can/bcm.c b/net/can/bcm.c
101283 index dcb75c0..24b1b43 100644
101284 --- a/net/can/bcm.c
101285 +++ b/net/can/bcm.c
101286 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101287 }
101288
101289 /* create /proc/net/can-bcm directory */
101290 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101291 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101292 return 0;
101293 }
101294
101295 diff --git a/net/can/gw.c b/net/can/gw.c
101296 index 050a211..bb9fe33 100644
101297 --- a/net/can/gw.c
101298 +++ b/net/can/gw.c
101299 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101300 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101301
101302 static HLIST_HEAD(cgw_list);
101303 -static struct notifier_block notifier;
101304
101305 static struct kmem_cache *cgw_cache __read_mostly;
101306
101307 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101308 return err;
101309 }
101310
101311 +static struct notifier_block notifier = {
101312 + .notifier_call = cgw_notifier
101313 +};
101314 +
101315 static __init int cgw_module_init(void)
101316 {
101317 /* sanitize given module parameter */
101318 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101319 return -ENOMEM;
101320
101321 /* set notifier */
101322 - notifier.notifier_call = cgw_notifier;
101323 register_netdevice_notifier(&notifier);
101324
101325 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101326 diff --git a/net/can/proc.c b/net/can/proc.c
101327 index 1a19b98..df2b4ec 100644
101328 --- a/net/can/proc.c
101329 +++ b/net/can/proc.c
101330 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101331 void can_init_proc(void)
101332 {
101333 /* create /proc/net/can directory */
101334 - can_dir = proc_mkdir("can", init_net.proc_net);
101335 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101336
101337 if (!can_dir) {
101338 printk(KERN_INFO "can: failed to create /proc/net/can . "
101339 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101340 index b2f571d..b584643 100644
101341 --- a/net/ceph/messenger.c
101342 +++ b/net/ceph/messenger.c
101343 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101344 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101345
101346 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101347 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101348 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101349
101350 static struct page *zero_page; /* used in certain error cases */
101351
101352 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101353 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101354 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101355
101356 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101357 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101358 s = addr_str[i];
101359
101360 switch (ss->ss_family) {
101361 diff --git a/net/compat.c b/net/compat.c
101362 index bc8aeef..f9c070c 100644
101363 --- a/net/compat.c
101364 +++ b/net/compat.c
101365 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101366 return -EFAULT;
101367 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101368 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101369 - kmsg->msg_name = compat_ptr(tmp1);
101370 - kmsg->msg_iov = compat_ptr(tmp2);
101371 - kmsg->msg_control = compat_ptr(tmp3);
101372 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101373 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101374 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101375 return 0;
101376 }
101377
101378 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101379
101380 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101381 if (mode == VERIFY_READ) {
101382 - int err = move_addr_to_kernel(kern_msg->msg_name,
101383 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101384 kern_msg->msg_namelen,
101385 kern_address);
101386 if (err < 0)
101387 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101388 }
101389
101390 tot_len = iov_from_user_compat_to_kern(kern_iov,
101391 - (struct compat_iovec __user *)kern_msg->msg_iov,
101392 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101393 kern_msg->msg_iovlen);
101394 if (tot_len >= 0)
101395 kern_msg->msg_iov = kern_iov;
101396 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101397
101398 #define CMSG_COMPAT_FIRSTHDR(msg) \
101399 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101400 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101401 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101402 (struct compat_cmsghdr __user *)NULL)
101403
101404 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101405 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101406 (ucmlen) <= (unsigned long) \
101407 ((mhdr)->msg_controllen - \
101408 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101409 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101410
101411 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101412 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101413 {
101414 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101415 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101416 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101417 msg->msg_controllen)
101418 return NULL;
101419 return (struct compat_cmsghdr __user *)ptr;
101420 @@ -223,7 +223,7 @@ Efault:
101421
101422 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101423 {
101424 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101425 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101426 struct compat_cmsghdr cmhdr;
101427 struct compat_timeval ctv;
101428 struct compat_timespec cts[3];
101429 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101430
101431 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101432 {
101433 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101434 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101435 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101436 int fdnum = scm->fp->count;
101437 struct file **fp = scm->fp->fp;
101438 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101439 return -EFAULT;
101440 old_fs = get_fs();
101441 set_fs(KERNEL_DS);
101442 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101443 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101444 set_fs(old_fs);
101445
101446 return err;
101447 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101448 len = sizeof(ktime);
101449 old_fs = get_fs();
101450 set_fs(KERNEL_DS);
101451 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101452 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101453 set_fs(old_fs);
101454
101455 if (!err) {
101456 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101457 case MCAST_JOIN_GROUP:
101458 case MCAST_LEAVE_GROUP:
101459 {
101460 - struct compat_group_req __user *gr32 = (void *)optval;
101461 + struct compat_group_req __user *gr32 = (void __user *)optval;
101462 struct group_req __user *kgr =
101463 compat_alloc_user_space(sizeof(struct group_req));
101464 u32 interface;
101465 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101466 case MCAST_BLOCK_SOURCE:
101467 case MCAST_UNBLOCK_SOURCE:
101468 {
101469 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101470 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101471 struct group_source_req __user *kgsr = compat_alloc_user_space(
101472 sizeof(struct group_source_req));
101473 u32 interface;
101474 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101475 }
101476 case MCAST_MSFILTER:
101477 {
101478 - struct compat_group_filter __user *gf32 = (void *)optval;
101479 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101480 struct group_filter __user *kgf;
101481 u32 interface, fmode, numsrc;
101482
101483 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101484 char __user *optval, int __user *optlen,
101485 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101486 {
101487 - struct compat_group_filter __user *gf32 = (void *)optval;
101488 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101489 struct group_filter __user *kgf;
101490 int __user *koptlen;
101491 u32 interface, fmode, numsrc;
101492 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101493
101494 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101495 return -EINVAL;
101496 - if (copy_from_user(a, args, nas[call]))
101497 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101498 return -EFAULT;
101499 a0 = a[0];
101500 a1 = a[1];
101501 diff --git a/net/core/datagram.c b/net/core/datagram.c
101502 index fdbc9a8..cd6972c 100644
101503 --- a/net/core/datagram.c
101504 +++ b/net/core/datagram.c
101505 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101506 }
101507
101508 kfree_skb(skb);
101509 - atomic_inc(&sk->sk_drops);
101510 + atomic_inc_unchecked(&sk->sk_drops);
101511 sk_mem_reclaim_partial(sk);
101512
101513 return err;
101514 diff --git a/net/core/dev.c b/net/core/dev.c
101515 index cf8a95f..2837211 100644
101516 --- a/net/core/dev.c
101517 +++ b/net/core/dev.c
101518 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101519 {
101520 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101521 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101522 - atomic_long_inc(&dev->rx_dropped);
101523 + atomic_long_inc_unchecked(&dev->rx_dropped);
101524 kfree_skb(skb);
101525 return NET_RX_DROP;
101526 }
101527 }
101528
101529 if (unlikely(!is_skb_forwardable(dev, skb))) {
101530 - atomic_long_inc(&dev->rx_dropped);
101531 + atomic_long_inc_unchecked(&dev->rx_dropped);
101532 kfree_skb(skb);
101533 return NET_RX_DROP;
101534 }
101535 @@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101536
101537 struct dev_gso_cb {
101538 void (*destructor)(struct sk_buff *skb);
101539 -};
101540 +} __no_const;
101541
101542 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101543
101544 @@ -2952,7 +2952,7 @@ recursion_alert:
101545 rc = -ENETDOWN;
101546 rcu_read_unlock_bh();
101547
101548 - atomic_long_inc(&dev->tx_dropped);
101549 + atomic_long_inc_unchecked(&dev->tx_dropped);
101550 kfree_skb(skb);
101551 return rc;
101552 out:
101553 @@ -3296,7 +3296,7 @@ enqueue:
101554
101555 local_irq_restore(flags);
101556
101557 - atomic_long_inc(&skb->dev->rx_dropped);
101558 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101559 kfree_skb(skb);
101560 return NET_RX_DROP;
101561 }
101562 @@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101563 }
101564 EXPORT_SYMBOL(netif_rx_ni);
101565
101566 -static void net_tx_action(struct softirq_action *h)
101567 +static __latent_entropy void net_tx_action(void)
101568 {
101569 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101570
101571 @@ -3706,7 +3706,7 @@ ncls:
101572 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101573 } else {
101574 drop:
101575 - atomic_long_inc(&skb->dev->rx_dropped);
101576 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101577 kfree_skb(skb);
101578 /* Jamal, now you will not able to escape explaining
101579 * me how you were going to use this. :-)
101580 @@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101581 }
101582 EXPORT_SYMBOL(netif_napi_del);
101583
101584 -static void net_rx_action(struct softirq_action *h)
101585 +static __latent_entropy void net_rx_action(void)
101586 {
101587 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101588 unsigned long time_limit = jiffies + 2;
101589 @@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101590 } else {
101591 netdev_stats_to_stats64(storage, &dev->stats);
101592 }
101593 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101594 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101595 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101596 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101597 return storage;
101598 }
101599 EXPORT_SYMBOL(dev_get_stats);
101600 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101601 index cf999e0..c59a975 100644
101602 --- a/net/core/dev_ioctl.c
101603 +++ b/net/core/dev_ioctl.c
101604 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101605 if (no_module && capable(CAP_NET_ADMIN))
101606 no_module = request_module("netdev-%s", name);
101607 if (no_module && capable(CAP_SYS_MODULE)) {
101608 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101609 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101610 +#else
101611 if (!request_module("%s", name))
101612 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101613 name);
101614 +#endif
101615 }
101616 }
101617 EXPORT_SYMBOL(dev_load);
101618 diff --git a/net/core/filter.c b/net/core/filter.c
101619 index d814b8a..b5ab778 100644
101620 --- a/net/core/filter.c
101621 +++ b/net/core/filter.c
101622 @@ -559,7 +559,11 @@ do_pass:
101623
101624 /* Unkown instruction. */
101625 default:
101626 - goto err;
101627 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101628 + fp->code, fp->jt, fp->jf, fp->k);
101629 + kfree(addrs);
101630 + BUG();
101631 + return -EINVAL;
101632 }
101633
101634 insn++;
101635 @@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101636 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101637 int pc, ret = 0;
101638
101639 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101640 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101641
101642 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101643 if (!masks)
101644 @@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101645
101646 /* Expand fp for appending the new filter representation. */
101647 old_fp = fp;
101648 - fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101649 + fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101650 if (!fp) {
101651 /* The old_fp is still around in case we couldn't
101652 * allocate new memory, so uncharge on that one.
101653 @@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101654 if (fprog->filter == NULL)
101655 return -EINVAL;
101656
101657 - fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101658 + fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101659 if (!fp)
101660 return -ENOMEM;
101661
101662 - memcpy(fp->insns, fprog->filter, fsize);
101663 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101664
101665 fp->len = fprog->len;
101666 /* Since unattached filters are not copied back to user
101667 @@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101668 if (fprog->filter == NULL)
101669 return -EINVAL;
101670
101671 - prog = kmalloc(bpf_fsize, GFP_KERNEL);
101672 + prog = bpf_prog_alloc(bpf_fsize, 0);
101673 if (!prog)
101674 return -ENOMEM;
101675
101676 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
101677 - kfree(prog);
101678 + __bpf_prog_free(prog);
101679 return -EFAULT;
101680 }
101681
101682 @@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101683
101684 err = bpf_prog_store_orig_filter(prog, fprog);
101685 if (err) {
101686 - kfree(prog);
101687 + __bpf_prog_free(prog);
101688 return -ENOMEM;
101689 }
101690
101691 diff --git a/net/core/flow.c b/net/core/flow.c
101692 index a0348fd..6951c76 100644
101693 --- a/net/core/flow.c
101694 +++ b/net/core/flow.c
101695 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101696 static int flow_entry_valid(struct flow_cache_entry *fle,
101697 struct netns_xfrm *xfrm)
101698 {
101699 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101700 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101701 return 0;
101702 if (fle->object && !fle->object->ops->check(fle->object))
101703 return 0;
101704 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101705 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101706 fcp->hash_count++;
101707 }
101708 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101709 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101710 flo = fle->object;
101711 if (!flo)
101712 goto ret_object;
101713 @@ -263,7 +263,7 @@ nocache:
101714 }
101715 flo = resolver(net, key, family, dir, flo, ctx);
101716 if (fle) {
101717 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101718 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101719 if (!IS_ERR(flo))
101720 fle->object = flo;
101721 else
101722 diff --git a/net/core/iovec.c b/net/core/iovec.c
101723 index e1ec45a..e5c6f16 100644
101724 --- a/net/core/iovec.c
101725 +++ b/net/core/iovec.c
101726 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101727 if (m->msg_name && m->msg_namelen) {
101728 if (mode == VERIFY_READ) {
101729 void __user *namep;
101730 - namep = (void __user __force *) m->msg_name;
101731 + namep = (void __force_user *) m->msg_name;
101732 err = move_addr_to_kernel(namep, m->msg_namelen,
101733 address);
101734 if (err < 0)
101735 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101736 }
101737
101738 size = m->msg_iovlen * sizeof(struct iovec);
101739 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101740 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101741 return -EFAULT;
101742
101743 m->msg_iov = iov;
101744 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101745 index ef31fef..8be66d9 100644
101746 --- a/net/core/neighbour.c
101747 +++ b/net/core/neighbour.c
101748 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101749 void __user *buffer, size_t *lenp, loff_t *ppos)
101750 {
101751 int size, ret;
101752 - struct ctl_table tmp = *ctl;
101753 + ctl_table_no_const tmp = *ctl;
101754
101755 tmp.extra1 = &zero;
101756 tmp.extra2 = &unres_qlen_max;
101757 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101758 void __user *buffer,
101759 size_t *lenp, loff_t *ppos)
101760 {
101761 - struct ctl_table tmp = *ctl;
101762 + ctl_table_no_const tmp = *ctl;
101763 int ret;
101764
101765 tmp.extra1 = &zero;
101766 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101767 index 2bf8329..2eb1423 100644
101768 --- a/net/core/net-procfs.c
101769 +++ b/net/core/net-procfs.c
101770 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101771 struct rtnl_link_stats64 temp;
101772 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101773
101774 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101775 + if (gr_proc_is_restricted())
101776 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101777 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101778 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101779 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101780 + else
101781 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101782 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101783 dev->name, stats->rx_bytes, stats->rx_packets,
101784 stats->rx_errors,
101785 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101786 return 0;
101787 }
101788
101789 -static const struct seq_operations dev_seq_ops = {
101790 +const struct seq_operations dev_seq_ops = {
101791 .start = dev_seq_start,
101792 .next = dev_seq_next,
101793 .stop = dev_seq_stop,
101794 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101795
101796 static int softnet_seq_open(struct inode *inode, struct file *file)
101797 {
101798 - return seq_open(file, &softnet_seq_ops);
101799 + return seq_open_restrict(file, &softnet_seq_ops);
101800 }
101801
101802 static const struct file_operations softnet_seq_fops = {
101803 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101804 else
101805 seq_printf(seq, "%04x", ntohs(pt->type));
101806
101807 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101808 + seq_printf(seq, " %-8s %pf\n",
101809 + pt->dev ? pt->dev->name : "", NULL);
101810 +#else
101811 seq_printf(seq, " %-8s %pf\n",
101812 pt->dev ? pt->dev->name : "", pt->func);
101813 +#endif
101814 }
101815
101816 return 0;
101817 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101818 index 9dd0669..c52fb1b 100644
101819 --- a/net/core/net-sysfs.c
101820 +++ b/net/core/net-sysfs.c
101821 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101822 {
101823 struct net_device *netdev = to_net_dev(dev);
101824 return sprintf(buf, fmt_dec,
101825 - atomic_read(&netdev->carrier_changes));
101826 + atomic_read_unchecked(&netdev->carrier_changes));
101827 }
101828 static DEVICE_ATTR_RO(carrier_changes);
101829
101830 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101831 index 7c6b51a..e9dd57f 100644
101832 --- a/net/core/net_namespace.c
101833 +++ b/net/core/net_namespace.c
101834 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101835 int error;
101836 LIST_HEAD(net_exit_list);
101837
101838 - list_add_tail(&ops->list, list);
101839 + pax_list_add_tail((struct list_head *)&ops->list, list);
101840 if (ops->init || (ops->id && ops->size)) {
101841 for_each_net(net) {
101842 error = ops_init(ops, net);
101843 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101844
101845 out_undo:
101846 /* If I have an error cleanup all namespaces I initialized */
101847 - list_del(&ops->list);
101848 + pax_list_del((struct list_head *)&ops->list);
101849 ops_exit_list(ops, &net_exit_list);
101850 ops_free_list(ops, &net_exit_list);
101851 return error;
101852 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101853 struct net *net;
101854 LIST_HEAD(net_exit_list);
101855
101856 - list_del(&ops->list);
101857 + pax_list_del((struct list_head *)&ops->list);
101858 for_each_net(net)
101859 list_add_tail(&net->exit_list, &net_exit_list);
101860 ops_exit_list(ops, &net_exit_list);
101861 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101862 mutex_lock(&net_mutex);
101863 error = register_pernet_operations(&pernet_list, ops);
101864 if (!error && (first_device == &pernet_list))
101865 - first_device = &ops->list;
101866 + first_device = (struct list_head *)&ops->list;
101867 mutex_unlock(&net_mutex);
101868 return error;
101869 }
101870 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101871 index 907fb5e..8260f040b 100644
101872 --- a/net/core/netpoll.c
101873 +++ b/net/core/netpoll.c
101874 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101875 struct udphdr *udph;
101876 struct iphdr *iph;
101877 struct ethhdr *eth;
101878 - static atomic_t ip_ident;
101879 + static atomic_unchecked_t ip_ident;
101880 struct ipv6hdr *ip6h;
101881
101882 udp_len = len + sizeof(*udph);
101883 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101884 put_unaligned(0x45, (unsigned char *)iph);
101885 iph->tos = 0;
101886 put_unaligned(htons(ip_len), &(iph->tot_len));
101887 - iph->id = htons(atomic_inc_return(&ip_ident));
101888 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101889 iph->frag_off = 0;
101890 iph->ttl = 64;
101891 iph->protocol = IPPROTO_UDP;
101892 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101893 index 8b849dd..cd88bfc 100644
101894 --- a/net/core/pktgen.c
101895 +++ b/net/core/pktgen.c
101896 @@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
101897 pn->net = net;
101898 INIT_LIST_HEAD(&pn->pktgen_threads);
101899 pn->pktgen_exiting = false;
101900 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101901 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101902 if (!pn->proc_dir) {
101903 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101904 return -ENODEV;
101905 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101906 index f0493e3..0f43f7a 100644
101907 --- a/net/core/rtnetlink.c
101908 +++ b/net/core/rtnetlink.c
101909 @@ -58,7 +58,7 @@ struct rtnl_link {
101910 rtnl_doit_func doit;
101911 rtnl_dumpit_func dumpit;
101912 rtnl_calcit_func calcit;
101913 -};
101914 +} __no_const;
101915
101916 static DEFINE_MUTEX(rtnl_mutex);
101917
101918 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101919 * to use the ops for creating device. So do not
101920 * fill up dellink as well. That disables rtnl_dellink.
101921 */
101922 - if (ops->setup && !ops->dellink)
101923 - ops->dellink = unregister_netdevice_queue;
101924 + if (ops->setup && !ops->dellink) {
101925 + pax_open_kernel();
101926 + *(void **)&ops->dellink = unregister_netdevice_queue;
101927 + pax_close_kernel();
101928 + }
101929
101930 - list_add_tail(&ops->list, &link_ops);
101931 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101932 return 0;
101933 }
101934 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101935 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101936 for_each_net(net) {
101937 __rtnl_kill_links(net, ops);
101938 }
101939 - list_del(&ops->list);
101940 + pax_list_del((struct list_head *)&ops->list);
101941 }
101942 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101943
101944 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101945 (dev->ifalias &&
101946 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101947 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101948 - atomic_read(&dev->carrier_changes)))
101949 + atomic_read_unchecked(&dev->carrier_changes)))
101950 goto nla_put_failure;
101951
101952 if (1) {
101953 diff --git a/net/core/scm.c b/net/core/scm.c
101954 index b442e7e..6f5b5a2 100644
101955 --- a/net/core/scm.c
101956 +++ b/net/core/scm.c
101957 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101958 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101959 {
101960 struct cmsghdr __user *cm
101961 - = (__force struct cmsghdr __user *)msg->msg_control;
101962 + = (struct cmsghdr __force_user *)msg->msg_control;
101963 struct cmsghdr cmhdr;
101964 int cmlen = CMSG_LEN(len);
101965 int err;
101966 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101967 err = -EFAULT;
101968 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101969 goto out;
101970 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101971 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101972 goto out;
101973 cmlen = CMSG_SPACE(len);
101974 if (msg->msg_controllen < cmlen)
101975 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101976 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101977 {
101978 struct cmsghdr __user *cm
101979 - = (__force struct cmsghdr __user*)msg->msg_control;
101980 + = (struct cmsghdr __force_user *)msg->msg_control;
101981
101982 int fdmax = 0;
101983 int fdnum = scm->fp->count;
101984 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101985 if (fdnum < fdmax)
101986 fdmax = fdnum;
101987
101988 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101989 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101990 i++, cmfptr++)
101991 {
101992 struct socket *sock;
101993 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101994 index 8d28969..4d36260 100644
101995 --- a/net/core/skbuff.c
101996 +++ b/net/core/skbuff.c
101997 @@ -360,18 +360,29 @@ refill:
101998 goto end;
101999 }
102000 nc->frag.size = PAGE_SIZE << order;
102001 -recycle:
102002 - atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
102003 + /* Even if we own the page, we do not use atomic_set().
102004 + * This would break get_page_unless_zero() users.
102005 + */
102006 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
102007 + &nc->frag.page->_count);
102008 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102009 nc->frag.offset = 0;
102010 }
102011
102012 if (nc->frag.offset + fragsz > nc->frag.size) {
102013 - /* avoid unnecessary locked operations if possible */
102014 - if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
102015 - atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
102016 - goto recycle;
102017 - goto refill;
102018 + if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
102019 + if (!atomic_sub_and_test(nc->pagecnt_bias,
102020 + &nc->frag.page->_count))
102021 + goto refill;
102022 + /* OK, page count is 0, we can safely set it */
102023 + atomic_set(&nc->frag.page->_count,
102024 + NETDEV_PAGECNT_MAX_BIAS);
102025 + } else {
102026 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
102027 + &nc->frag.page->_count);
102028 + }
102029 + nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102030 + nc->frag.offset = 0;
102031 }
102032
102033 data = page_address(nc->frag.page) + nc->frag.offset;
102034 @@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
102035 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102036 int len, __wsum csum)
102037 {
102038 - const struct skb_checksum_ops ops = {
102039 + static const struct skb_checksum_ops ops = {
102040 .update = csum_partial_ext,
102041 .combine = csum_block_add_ext,
102042 };
102043 @@ -3237,13 +3248,15 @@ void __init skb_init(void)
102044 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102045 sizeof(struct sk_buff),
102046 0,
102047 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102048 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102049 + SLAB_NO_SANITIZE,
102050 NULL);
102051 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102052 (2*sizeof(struct sk_buff)) +
102053 sizeof(atomic_t),
102054 0,
102055 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102056 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102057 + SLAB_NO_SANITIZE,
102058 NULL);
102059 }
102060
102061 diff --git a/net/core/sock.c b/net/core/sock.c
102062 index 9c3f823..bd8c884 100644
102063 --- a/net/core/sock.c
102064 +++ b/net/core/sock.c
102065 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102066 struct sk_buff_head *list = &sk->sk_receive_queue;
102067
102068 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102069 - atomic_inc(&sk->sk_drops);
102070 + atomic_inc_unchecked(&sk->sk_drops);
102071 trace_sock_rcvqueue_full(sk, skb);
102072 return -ENOMEM;
102073 }
102074 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102075 return err;
102076
102077 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102078 - atomic_inc(&sk->sk_drops);
102079 + atomic_inc_unchecked(&sk->sk_drops);
102080 return -ENOBUFS;
102081 }
102082
102083 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102084 skb_dst_force(skb);
102085
102086 spin_lock_irqsave(&list->lock, flags);
102087 - skb->dropcount = atomic_read(&sk->sk_drops);
102088 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102089 __skb_queue_tail(list, skb);
102090 spin_unlock_irqrestore(&list->lock, flags);
102091
102092 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102093 skb->dev = NULL;
102094
102095 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102096 - atomic_inc(&sk->sk_drops);
102097 + atomic_inc_unchecked(&sk->sk_drops);
102098 goto discard_and_relse;
102099 }
102100 if (nested)
102101 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102102 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102103 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102104 bh_unlock_sock(sk);
102105 - atomic_inc(&sk->sk_drops);
102106 + atomic_inc_unchecked(&sk->sk_drops);
102107 goto discard_and_relse;
102108 }
102109
102110 @@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102111 struct timeval tm;
102112 } v;
102113
102114 - int lv = sizeof(int);
102115 - int len;
102116 + unsigned int lv = sizeof(int);
102117 + unsigned int len;
102118
102119 if (get_user(len, optlen))
102120 return -EFAULT;
102121 - if (len < 0)
102122 + if (len > INT_MAX)
102123 return -EINVAL;
102124
102125 memset(&v, 0, sizeof(v));
102126 @@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102127
102128 case SO_PEERNAME:
102129 {
102130 - char address[128];
102131 + char address[_K_SS_MAXSIZE];
102132
102133 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102134 return -ENOTCONN;
102135 - if (lv < len)
102136 + if (lv < len || sizeof address < len)
102137 return -EINVAL;
102138 if (copy_to_user(optval, address, len))
102139 return -EFAULT;
102140 @@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102141
102142 if (len > lv)
102143 len = lv;
102144 - if (copy_to_user(optval, &v, len))
102145 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102146 return -EFAULT;
102147 lenout:
102148 if (put_user(len, optlen))
102149 @@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102150 */
102151 void sock_kfree_s(struct sock *sk, void *mem, int size)
102152 {
102153 + if (WARN_ON_ONCE(!mem))
102154 + return;
102155 kfree(mem);
102156 atomic_sub(size, &sk->sk_omem_alloc);
102157 }
102158 @@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102159 */
102160 smp_wmb();
102161 atomic_set(&sk->sk_refcnt, 1);
102162 - atomic_set(&sk->sk_drops, 0);
102163 + atomic_set_unchecked(&sk->sk_drops, 0);
102164 }
102165 EXPORT_SYMBOL(sock_init_data);
102166
102167 @@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102168 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102169 int level, int type)
102170 {
102171 + struct sock_extended_err ee;
102172 struct sock_exterr_skb *serr;
102173 struct sk_buff *skb, *skb2;
102174 int copied, err;
102175 @@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102176 sock_recv_timestamp(msg, sk, skb);
102177
102178 serr = SKB_EXT_ERR(skb);
102179 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102180 + ee = serr->ee;
102181 + put_cmsg(msg, level, type, sizeof ee, &ee);
102182
102183 msg->msg_flags |= MSG_ERRQUEUE;
102184 err = copied;
102185 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102186 index ad704c7..ca48aff 100644
102187 --- a/net/core/sock_diag.c
102188 +++ b/net/core/sock_diag.c
102189 @@ -9,26 +9,33 @@
102190 #include <linux/inet_diag.h>
102191 #include <linux/sock_diag.h>
102192
102193 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102194 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102195 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102196 static DEFINE_MUTEX(sock_diag_table_mutex);
102197
102198 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102199 {
102200 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102201 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102202 cookie[1] != INET_DIAG_NOCOOKIE) &&
102203 ((u32)(unsigned long)sk != cookie[0] ||
102204 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102205 return -ESTALE;
102206 else
102207 +#endif
102208 return 0;
102209 }
102210 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102211
102212 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102213 {
102214 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102215 + cookie[0] = 0;
102216 + cookie[1] = 0;
102217 +#else
102218 cookie[0] = (u32)(unsigned long)sk;
102219 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102220 +#endif
102221 }
102222 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102223
102224 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102225 mutex_lock(&sock_diag_table_mutex);
102226 if (sock_diag_handlers[hndl->family])
102227 err = -EBUSY;
102228 - else
102229 + else {
102230 + pax_open_kernel();
102231 sock_diag_handlers[hndl->family] = hndl;
102232 + pax_close_kernel();
102233 + }
102234 mutex_unlock(&sock_diag_table_mutex);
102235
102236 return err;
102237 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102238
102239 mutex_lock(&sock_diag_table_mutex);
102240 BUG_ON(sock_diag_handlers[family] != hnld);
102241 + pax_open_kernel();
102242 sock_diag_handlers[family] = NULL;
102243 + pax_close_kernel();
102244 mutex_unlock(&sock_diag_table_mutex);
102245 }
102246 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102247 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102248 index cf9cd13..50683950 100644
102249 --- a/net/core/sysctl_net_core.c
102250 +++ b/net/core/sysctl_net_core.c
102251 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102252 {
102253 unsigned int orig_size, size;
102254 int ret, i;
102255 - struct ctl_table tmp = {
102256 + ctl_table_no_const tmp = {
102257 .data = &size,
102258 .maxlen = sizeof(size),
102259 .mode = table->mode
102260 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102261 void __user *buffer, size_t *lenp, loff_t *ppos)
102262 {
102263 char id[IFNAMSIZ];
102264 - struct ctl_table tbl = {
102265 + ctl_table_no_const tbl = {
102266 .data = id,
102267 .maxlen = IFNAMSIZ,
102268 };
102269 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102270 .mode = 0644,
102271 .proc_handler = proc_dointvec
102272 },
102273 -#ifdef CONFIG_BPF_JIT
102274 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102275 {
102276 .procname = "bpf_jit_enable",
102277 .data = &bpf_jit_enable,
102278 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102279
102280 static __net_init int sysctl_core_net_init(struct net *net)
102281 {
102282 - struct ctl_table *tbl;
102283 + ctl_table_no_const *tbl = NULL;
102284
102285 net->core.sysctl_somaxconn = SOMAXCONN;
102286
102287 - tbl = netns_core_table;
102288 if (!net_eq(net, &init_net)) {
102289 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102290 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102291 if (tbl == NULL)
102292 goto err_dup;
102293
102294 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102295 if (net->user_ns != &init_user_ns) {
102296 tbl[0].procname = NULL;
102297 }
102298 - }
102299 -
102300 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102301 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102302 + } else
102303 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102304 if (net->core.sysctl_hdr == NULL)
102305 goto err_reg;
102306
102307 return 0;
102308
102309 err_reg:
102310 - if (tbl != netns_core_table)
102311 - kfree(tbl);
102312 + kfree(tbl);
102313 err_dup:
102314 return -ENOMEM;
102315 }
102316 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102317 kfree(tbl);
102318 }
102319
102320 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102321 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102322 .init = sysctl_core_net_init,
102323 .exit = sysctl_core_net_exit,
102324 };
102325 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102326 index ae011b4..d2d18bf 100644
102327 --- a/net/decnet/af_decnet.c
102328 +++ b/net/decnet/af_decnet.c
102329 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
102330 .sysctl_rmem = sysctl_decnet_rmem,
102331 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102332 .obj_size = sizeof(struct dn_sock),
102333 + .slab_flags = SLAB_USERCOPY,
102334 };
102335
102336 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102337 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102338 index 3b726f3..1af6368 100644
102339 --- a/net/decnet/dn_dev.c
102340 +++ b/net/decnet/dn_dev.c
102341 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
102342 .extra1 = &min_t3,
102343 .extra2 = &max_t3
102344 },
102345 - {0}
102346 + { }
102347 },
102348 };
102349
102350 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102351 index 5325b54..a0d4d69 100644
102352 --- a/net/decnet/sysctl_net_decnet.c
102353 +++ b/net/decnet/sysctl_net_decnet.c
102354 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102355
102356 if (len > *lenp) len = *lenp;
102357
102358 - if (copy_to_user(buffer, addr, len))
102359 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102360 return -EFAULT;
102361
102362 *lenp = len;
102363 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102364
102365 if (len > *lenp) len = *lenp;
102366
102367 - if (copy_to_user(buffer, devname, len))
102368 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102369 return -EFAULT;
102370
102371 *lenp = len;
102372 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102373 index 32755cb..236d827 100644
102374 --- a/net/ieee802154/reassembly.c
102375 +++ b/net/ieee802154/reassembly.c
102376 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102377
102378 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102379 {
102380 - struct ctl_table *table;
102381 + ctl_table_no_const *table = NULL;
102382 struct ctl_table_header *hdr;
102383 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102384 net_ieee802154_lowpan(net);
102385
102386 - table = lowpan_frags_ns_ctl_table;
102387 if (!net_eq(net, &init_net)) {
102388 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102389 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102390 GFP_KERNEL);
102391 if (table == NULL)
102392 goto err_alloc;
102393 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102394 /* Don't export sysctls to unprivileged users */
102395 if (net->user_ns != &init_user_ns)
102396 table[0].procname = NULL;
102397 - }
102398 -
102399 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102400 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102401 + } else
102402 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102403 if (hdr == NULL)
102404 goto err_reg;
102405
102406 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102407 return 0;
102408
102409 err_reg:
102410 - if (!net_eq(net, &init_net))
102411 - kfree(table);
102412 + kfree(table);
102413 err_alloc:
102414 return -ENOMEM;
102415 }
102416 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102417 index 214882e..f958b50 100644
102418 --- a/net/ipv4/devinet.c
102419 +++ b/net/ipv4/devinet.c
102420 @@ -1548,7 +1548,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102421 idx = 0;
102422 head = &net->dev_index_head[h];
102423 rcu_read_lock();
102424 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102425 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102426 net->dev_base_seq;
102427 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102428 if (idx < s_idx)
102429 @@ -1866,7 +1866,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102430 idx = 0;
102431 head = &net->dev_index_head[h];
102432 rcu_read_lock();
102433 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102434 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102435 net->dev_base_seq;
102436 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102437 if (idx < s_idx)
102438 @@ -2101,7 +2101,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102439 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102440 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102441
102442 -static struct devinet_sysctl_table {
102443 +static const struct devinet_sysctl_table {
102444 struct ctl_table_header *sysctl_header;
102445 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102446 } devinet_sysctl = {
102447 @@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
102448 int err;
102449 struct ipv4_devconf *all, *dflt;
102450 #ifdef CONFIG_SYSCTL
102451 - struct ctl_table *tbl = ctl_forward_entry;
102452 + ctl_table_no_const *tbl = NULL;
102453 struct ctl_table_header *forw_hdr;
102454 #endif
102455
102456 @@ -2251,7 +2251,7 @@ static __net_init int devinet_init_net(struct net *net)
102457 goto err_alloc_dflt;
102458
102459 #ifdef CONFIG_SYSCTL
102460 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102461 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102462 if (tbl == NULL)
102463 goto err_alloc_ctl;
102464
102465 @@ -2271,7 +2271,10 @@ static __net_init int devinet_init_net(struct net *net)
102466 goto err_reg_dflt;
102467
102468 err = -ENOMEM;
102469 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102470 + if (!net_eq(net, &init_net))
102471 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102472 + else
102473 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102474 if (forw_hdr == NULL)
102475 goto err_reg_ctl;
102476 net->ipv4.forw_hdr = forw_hdr;
102477 @@ -2287,8 +2290,7 @@ err_reg_ctl:
102478 err_reg_dflt:
102479 __devinet_sysctl_unregister(all);
102480 err_reg_all:
102481 - if (tbl != ctl_forward_entry)
102482 - kfree(tbl);
102483 + kfree(tbl);
102484 err_alloc_ctl:
102485 #endif
102486 if (dflt != &ipv4_devconf_dflt)
102487 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102488 index 255aa99..45c78f8 100644
102489 --- a/net/ipv4/fib_frontend.c
102490 +++ b/net/ipv4/fib_frontend.c
102491 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102492 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102493 fib_sync_up(dev);
102494 #endif
102495 - atomic_inc(&net->ipv4.dev_addr_genid);
102496 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102497 rt_cache_flush(dev_net(dev));
102498 break;
102499 case NETDEV_DOWN:
102500 fib_del_ifaddr(ifa, NULL);
102501 - atomic_inc(&net->ipv4.dev_addr_genid);
102502 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102503 if (ifa->ifa_dev->ifa_list == NULL) {
102504 /* Last address was deleted from this interface.
102505 * Disable IP.
102506 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102507 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102508 fib_sync_up(dev);
102509 #endif
102510 - atomic_inc(&net->ipv4.dev_addr_genid);
102511 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102512 rt_cache_flush(net);
102513 break;
102514 case NETDEV_DOWN:
102515 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102516 index b10cd43a..22327f9 100644
102517 --- a/net/ipv4/fib_semantics.c
102518 +++ b/net/ipv4/fib_semantics.c
102519 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102520 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102521 nh->nh_gw,
102522 nh->nh_parent->fib_scope);
102523 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102524 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102525
102526 return nh->nh_saddr;
102527 }
102528 diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102529 index 6556263..db77807 100644
102530 --- a/net/ipv4/gre_offload.c
102531 +++ b/net/ipv4/gre_offload.c
102532 @@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102533 if (csum)
102534 skb->encap_hdr_csum = 1;
102535
102536 - if (unlikely(!pskb_may_pull(skb, ghl)))
102537 - goto out;
102538 -
102539 /* setup inner skb. */
102540 skb->protocol = greh->protocol;
102541 skb->encapsulation = 0;
102542
102543 + if (unlikely(!pskb_may_pull(skb, ghl)))
102544 + goto out;
102545 +
102546 __skb_pull(skb, ghl);
102547 skb_reset_mac_header(skb);
102548 skb_set_network_header(skb, skb_inner_network_offset(skb));
102549 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102550 index 43116e8..ba0916a8 100644
102551 --- a/net/ipv4/inet_hashtables.c
102552 +++ b/net/ipv4/inet_hashtables.c
102553 @@ -18,6 +18,7 @@
102554 #include <linux/sched.h>
102555 #include <linux/slab.h>
102556 #include <linux/wait.h>
102557 +#include <linux/security.h>
102558
102559 #include <net/inet_connection_sock.h>
102560 #include <net/inet_hashtables.h>
102561 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102562 return inet_ehashfn(net, laddr, lport, faddr, fport);
102563 }
102564
102565 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102566 +
102567 /*
102568 * Allocate and initialize a new local port bind bucket.
102569 * The bindhash mutex for snum's hash chain must be held here.
102570 @@ -554,6 +557,8 @@ ok:
102571 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102572 spin_unlock(&head->lock);
102573
102574 + gr_update_task_in_ip_table(inet_sk(sk));
102575 +
102576 if (tw) {
102577 inet_twsk_deschedule(tw, death_row);
102578 while (twrefcnt) {
102579 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102580 index bd5f592..e80e605 100644
102581 --- a/net/ipv4/inetpeer.c
102582 +++ b/net/ipv4/inetpeer.c
102583 @@ -482,7 +482,7 @@ relookup:
102584 if (p) {
102585 p->daddr = *daddr;
102586 atomic_set(&p->refcnt, 1);
102587 - atomic_set(&p->rid, 0);
102588 + atomic_set_unchecked(&p->rid, 0);
102589 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102590 p->rate_tokens = 0;
102591 /* 60*HZ is arbitrary, but chosen enough high so that the first
102592 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102593 index 15f0e2b..8cf8177 100644
102594 --- a/net/ipv4/ip_fragment.c
102595 +++ b/net/ipv4/ip_fragment.c
102596 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102597 return 0;
102598
102599 start = qp->rid;
102600 - end = atomic_inc_return(&peer->rid);
102601 + end = atomic_inc_return_unchecked(&peer->rid);
102602 qp->rid = end;
102603
102604 rc = qp->q.fragments && (end - start) > max;
102605 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102606
102607 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102608 {
102609 - struct ctl_table *table;
102610 + ctl_table_no_const *table = NULL;
102611 struct ctl_table_header *hdr;
102612
102613 - table = ip4_frags_ns_ctl_table;
102614 if (!net_eq(net, &init_net)) {
102615 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102616 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102617 if (table == NULL)
102618 goto err_alloc;
102619
102620 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102621 /* Don't export sysctls to unprivileged users */
102622 if (net->user_ns != &init_user_ns)
102623 table[0].procname = NULL;
102624 - }
102625 + hdr = register_net_sysctl(net, "net/ipv4", table);
102626 + } else
102627 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102628
102629 - hdr = register_net_sysctl(net, "net/ipv4", table);
102630 if (hdr == NULL)
102631 goto err_reg;
102632
102633 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102634 return 0;
102635
102636 err_reg:
102637 - if (!net_eq(net, &init_net))
102638 - kfree(table);
102639 + kfree(table);
102640 err_alloc:
102641 return -ENOMEM;
102642 }
102643 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102644 index 9b84254..c776611 100644
102645 --- a/net/ipv4/ip_gre.c
102646 +++ b/net/ipv4/ip_gre.c
102647 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102648 module_param(log_ecn_error, bool, 0644);
102649 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102650
102651 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102652 +static struct rtnl_link_ops ipgre_link_ops;
102653 static int ipgre_tunnel_init(struct net_device *dev);
102654
102655 static int ipgre_net_id __read_mostly;
102656 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102657 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
102658 };
102659
102660 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102661 +static struct rtnl_link_ops ipgre_link_ops = {
102662 .kind = "gre",
102663 .maxtype = IFLA_GRE_MAX,
102664 .policy = ipgre_policy,
102665 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102666 .fill_info = ipgre_fill_info,
102667 };
102668
102669 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102670 +static struct rtnl_link_ops ipgre_tap_ops = {
102671 .kind = "gretap",
102672 .maxtype = IFLA_GRE_MAX,
102673 .policy = ipgre_policy,
102674 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102675 index 3d4da2c..40f9c29 100644
102676 --- a/net/ipv4/ip_input.c
102677 +++ b/net/ipv4/ip_input.c
102678 @@ -147,6 +147,10 @@
102679 #include <linux/mroute.h>
102680 #include <linux/netlink.h>
102681
102682 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102683 +extern int grsec_enable_blackhole;
102684 +#endif
102685 +
102686 /*
102687 * Process Router Attention IP option (RFC 2113)
102688 */
102689 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102690 if (!raw) {
102691 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102692 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102693 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102694 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102695 +#endif
102696 icmp_send(skb, ICMP_DEST_UNREACH,
102697 ICMP_PROT_UNREACH, 0);
102698 }
102699 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102700 index 215af2b..73cbbe1 100644
102701 --- a/net/ipv4/ip_output.c
102702 +++ b/net/ipv4/ip_output.c
102703 @@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
102704 */
102705 features = netif_skb_features(skb);
102706 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
102707 - if (IS_ERR(segs)) {
102708 + if (IS_ERR_OR_NULL(segs)) {
102709 kfree_skb(skb);
102710 return -ENOMEM;
102711 }
102712 @@ -1533,6 +1533,7 @@ void ip_send_unicast_reply(struct net *net, struct sk_buff *skb, __be32 daddr,
102713 struct sk_buff *nskb;
102714 struct sock *sk;
102715 struct inet_sock *inet;
102716 + int err;
102717
102718 if (ip_options_echo(&replyopts.opt.opt, skb))
102719 return;
102720 @@ -1572,8 +1573,13 @@ void ip_send_unicast_reply(struct net *net, struct sk_buff *skb, __be32 daddr,
102721 sock_net_set(sk, net);
102722 __skb_queue_head_init(&sk->sk_write_queue);
102723 sk->sk_sndbuf = sysctl_wmem_default;
102724 - ip_append_data(sk, &fl4, ip_reply_glue_bits, arg->iov->iov_base, len, 0,
102725 - &ipc, &rt, MSG_DONTWAIT);
102726 + err = ip_append_data(sk, &fl4, ip_reply_glue_bits, arg->iov->iov_base,
102727 + len, 0, &ipc, &rt, MSG_DONTWAIT);
102728 + if (unlikely(err)) {
102729 + ip_flush_pending_frames(sk);
102730 + goto out;
102731 + }
102732 +
102733 nskb = skb_peek(&sk->sk_write_queue);
102734 if (nskb) {
102735 if (arg->csumoffset >= 0)
102736 @@ -1585,7 +1591,7 @@ void ip_send_unicast_reply(struct net *net, struct sk_buff *skb, __be32 daddr,
102737 skb_set_queue_mapping(nskb, skb_get_queue_mapping(skb));
102738 ip_push_pending_frames(sk, &fl4);
102739 }
102740 -
102741 +out:
102742 put_cpu_var(unicast_sock);
102743
102744 ip_rt_put(rt);
102745 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102746 index 5cb830c..81a7a56 100644
102747 --- a/net/ipv4/ip_sockglue.c
102748 +++ b/net/ipv4/ip_sockglue.c
102749 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102750 len = min_t(unsigned int, len, opt->optlen);
102751 if (put_user(len, optlen))
102752 return -EFAULT;
102753 - if (copy_to_user(optval, opt->__data, len))
102754 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102755 + copy_to_user(optval, opt->__data, len))
102756 return -EFAULT;
102757 return 0;
102758 }
102759 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102760 if (sk->sk_type != SOCK_STREAM)
102761 return -ENOPROTOOPT;
102762
102763 - msg.msg_control = (__force void *) optval;
102764 + msg.msg_control = (__force_kernel void *) optval;
102765 msg.msg_controllen = len;
102766 msg.msg_flags = flags;
102767
102768 diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
102769 index f4c987b..88c386c 100644
102770 --- a/net/ipv4/ip_tunnel_core.c
102771 +++ b/net/ipv4/ip_tunnel_core.c
102772 @@ -91,11 +91,12 @@ int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
102773 skb_pull_rcsum(skb, hdr_len);
102774
102775 if (inner_proto == htons(ETH_P_TEB)) {
102776 - struct ethhdr *eh = (struct ethhdr *)skb->data;
102777 + struct ethhdr *eh;
102778
102779 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
102780 return -ENOMEM;
102781
102782 + eh = (struct ethhdr *)skb->data;
102783 if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
102784 skb->protocol = eh->h_proto;
102785 else
102786 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102787 index e453cb7..3c8d952 100644
102788 --- a/net/ipv4/ip_vti.c
102789 +++ b/net/ipv4/ip_vti.c
102790 @@ -45,7 +45,7 @@
102791 #include <net/net_namespace.h>
102792 #include <net/netns/generic.h>
102793
102794 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102795 +static struct rtnl_link_ops vti_link_ops;
102796
102797 static int vti_net_id __read_mostly;
102798 static int vti_tunnel_init(struct net_device *dev);
102799 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102800 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102801 };
102802
102803 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102804 +static struct rtnl_link_ops vti_link_ops = {
102805 .kind = "vti",
102806 .maxtype = IFLA_VTI_MAX,
102807 .policy = vti_policy,
102808 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102809 index 5bbef4f..5bc4fb6 100644
102810 --- a/net/ipv4/ipconfig.c
102811 +++ b/net/ipv4/ipconfig.c
102812 @@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102813
102814 mm_segment_t oldfs = get_fs();
102815 set_fs(get_ds());
102816 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102817 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102818 set_fs(oldfs);
102819 return res;
102820 }
102821 @@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102822
102823 mm_segment_t oldfs = get_fs();
102824 set_fs(get_ds());
102825 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102826 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102827 set_fs(oldfs);
102828 return res;
102829 }
102830 @@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102831
102832 mm_segment_t oldfs = get_fs();
102833 set_fs(get_ds());
102834 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102835 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102836 set_fs(oldfs);
102837 return res;
102838 }
102839 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102840 index 62eaa00..29b2dc2 100644
102841 --- a/net/ipv4/ipip.c
102842 +++ b/net/ipv4/ipip.c
102843 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102844 static int ipip_net_id __read_mostly;
102845
102846 static int ipip_tunnel_init(struct net_device *dev);
102847 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102848 +static struct rtnl_link_ops ipip_link_ops;
102849
102850 static int ipip_err(struct sk_buff *skb, u32 info)
102851 {
102852 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102853 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
102854 };
102855
102856 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102857 +static struct rtnl_link_ops ipip_link_ops = {
102858 .kind = "ipip",
102859 .maxtype = IFLA_IPTUN_MAX,
102860 .policy = ipip_policy,
102861 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102862 index f95b6f9..2ee2097 100644
102863 --- a/net/ipv4/netfilter/arp_tables.c
102864 +++ b/net/ipv4/netfilter/arp_tables.c
102865 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102866 #endif
102867
102868 static int get_info(struct net *net, void __user *user,
102869 - const int *len, int compat)
102870 + int len, int compat)
102871 {
102872 char name[XT_TABLE_MAXNAMELEN];
102873 struct xt_table *t;
102874 int ret;
102875
102876 - if (*len != sizeof(struct arpt_getinfo)) {
102877 - duprintf("length %u != %Zu\n", *len,
102878 + if (len != sizeof(struct arpt_getinfo)) {
102879 + duprintf("length %u != %Zu\n", len,
102880 sizeof(struct arpt_getinfo));
102881 return -EINVAL;
102882 }
102883 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102884 info.size = private->size;
102885 strcpy(info.name, name);
102886
102887 - if (copy_to_user(user, &info, *len) != 0)
102888 + if (copy_to_user(user, &info, len) != 0)
102889 ret = -EFAULT;
102890 else
102891 ret = 0;
102892 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102893
102894 switch (cmd) {
102895 case ARPT_SO_GET_INFO:
102896 - ret = get_info(sock_net(sk), user, len, 1);
102897 + ret = get_info(sock_net(sk), user, *len, 1);
102898 break;
102899 case ARPT_SO_GET_ENTRIES:
102900 ret = compat_get_entries(sock_net(sk), user, len);
102901 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102902
102903 switch (cmd) {
102904 case ARPT_SO_GET_INFO:
102905 - ret = get_info(sock_net(sk), user, len, 0);
102906 + ret = get_info(sock_net(sk), user, *len, 0);
102907 break;
102908
102909 case ARPT_SO_GET_ENTRIES:
102910 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102911 index 99e810f..3711b81 100644
102912 --- a/net/ipv4/netfilter/ip_tables.c
102913 +++ b/net/ipv4/netfilter/ip_tables.c
102914 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102915 #endif
102916
102917 static int get_info(struct net *net, void __user *user,
102918 - const int *len, int compat)
102919 + int len, int compat)
102920 {
102921 char name[XT_TABLE_MAXNAMELEN];
102922 struct xt_table *t;
102923 int ret;
102924
102925 - if (*len != sizeof(struct ipt_getinfo)) {
102926 - duprintf("length %u != %zu\n", *len,
102927 + if (len != sizeof(struct ipt_getinfo)) {
102928 + duprintf("length %u != %zu\n", len,
102929 sizeof(struct ipt_getinfo));
102930 return -EINVAL;
102931 }
102932 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102933 info.size = private->size;
102934 strcpy(info.name, name);
102935
102936 - if (copy_to_user(user, &info, *len) != 0)
102937 + if (copy_to_user(user, &info, len) != 0)
102938 ret = -EFAULT;
102939 else
102940 ret = 0;
102941 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102942
102943 switch (cmd) {
102944 case IPT_SO_GET_INFO:
102945 - ret = get_info(sock_net(sk), user, len, 1);
102946 + ret = get_info(sock_net(sk), user, *len, 1);
102947 break;
102948 case IPT_SO_GET_ENTRIES:
102949 ret = compat_get_entries(sock_net(sk), user, len);
102950 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102951
102952 switch (cmd) {
102953 case IPT_SO_GET_INFO:
102954 - ret = get_info(sock_net(sk), user, len, 0);
102955 + ret = get_info(sock_net(sk), user, *len, 0);
102956 break;
102957
102958 case IPT_SO_GET_ENTRIES:
102959 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102960 index 2510c02..cfb34fa 100644
102961 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102962 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102963 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102964 spin_lock_init(&cn->lock);
102965
102966 #ifdef CONFIG_PROC_FS
102967 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102968 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102969 if (!cn->procdir) {
102970 pr_err("Unable to proc dir entry\n");
102971 return -ENOMEM;
102972 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102973 index a3c59a0..ec620a50 100644
102974 --- a/net/ipv4/ping.c
102975 +++ b/net/ipv4/ping.c
102976 @@ -59,7 +59,7 @@ struct ping_table {
102977 };
102978
102979 static struct ping_table ping_table;
102980 -struct pingv6_ops pingv6_ops;
102981 +struct pingv6_ops *pingv6_ops;
102982 EXPORT_SYMBOL_GPL(pingv6_ops);
102983
102984 static u16 ping_port_rover;
102985 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102986 return -ENODEV;
102987 }
102988 }
102989 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102990 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102991 scoped);
102992 rcu_read_unlock();
102993
102994 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102995 }
102996 #if IS_ENABLED(CONFIG_IPV6)
102997 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102998 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102999 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103000 #endif
103001 }
103002
103003 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103004 info, (u8 *)icmph);
103005 #if IS_ENABLED(CONFIG_IPV6)
103006 } else if (family == AF_INET6) {
103007 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103008 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103009 info, (u8 *)icmph);
103010 #endif
103011 }
103012 @@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103013 return ip_recv_error(sk, msg, len, addr_len);
103014 #if IS_ENABLED(CONFIG_IPV6)
103015 } else if (family == AF_INET6) {
103016 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
103017 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
103018 addr_len);
103019 #endif
103020 }
103021 @@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103022 }
103023
103024 if (inet6_sk(sk)->rxopt.all)
103025 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103026 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103027 if (skb->protocol == htons(ETH_P_IPV6) &&
103028 inet6_sk(sk)->rxopt.all)
103029 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103030 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103031 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103032 ip_cmsg_recv(msg, skb);
103033 #endif
103034 @@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103035 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103036 0, sock_i_ino(sp),
103037 atomic_read(&sp->sk_refcnt), sp,
103038 - atomic_read(&sp->sk_drops));
103039 + atomic_read_unchecked(&sp->sk_drops));
103040 }
103041
103042 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103043 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103044 index 739db31..74f0210 100644
103045 --- a/net/ipv4/raw.c
103046 +++ b/net/ipv4/raw.c
103047 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103048 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103049 {
103050 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103051 - atomic_inc(&sk->sk_drops);
103052 + atomic_inc_unchecked(&sk->sk_drops);
103053 kfree_skb(skb);
103054 return NET_RX_DROP;
103055 }
103056 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103057
103058 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103059 {
103060 + struct icmp_filter filter;
103061 +
103062 if (optlen > sizeof(struct icmp_filter))
103063 optlen = sizeof(struct icmp_filter);
103064 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103065 + if (copy_from_user(&filter, optval, optlen))
103066 return -EFAULT;
103067 + raw_sk(sk)->filter = filter;
103068 return 0;
103069 }
103070
103071 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103072 {
103073 int len, ret = -EFAULT;
103074 + struct icmp_filter filter;
103075
103076 if (get_user(len, optlen))
103077 goto out;
103078 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103079 if (len > sizeof(struct icmp_filter))
103080 len = sizeof(struct icmp_filter);
103081 ret = -EFAULT;
103082 - if (put_user(len, optlen) ||
103083 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103084 + filter = raw_sk(sk)->filter;
103085 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103086 goto out;
103087 ret = 0;
103088 out: return ret;
103089 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103090 0, 0L, 0,
103091 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103092 0, sock_i_ino(sp),
103093 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103094 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103095 }
103096
103097 static int raw_seq_show(struct seq_file *seq, void *v)
103098 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103099 index cbadb94..691f99e 100644
103100 --- a/net/ipv4/route.c
103101 +++ b/net/ipv4/route.c
103102 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103103
103104 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103105 {
103106 - return seq_open(file, &rt_cache_seq_ops);
103107 + return seq_open_restrict(file, &rt_cache_seq_ops);
103108 }
103109
103110 static const struct file_operations rt_cache_seq_fops = {
103111 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103112
103113 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103114 {
103115 - return seq_open(file, &rt_cpu_seq_ops);
103116 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103117 }
103118
103119 static const struct file_operations rt_cpu_seq_fops = {
103120 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103121
103122 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103123 {
103124 - return single_open(file, rt_acct_proc_show, NULL);
103125 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103126 }
103127
103128 static const struct file_operations rt_acct_proc_fops = {
103129 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103130
103131 #define IP_IDENTS_SZ 2048u
103132 struct ip_ident_bucket {
103133 - atomic_t id;
103134 + atomic_unchecked_t id;
103135 u32 stamp32;
103136 };
103137
103138 -static struct ip_ident_bucket *ip_idents __read_mostly;
103139 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103140
103141 /* In order to protect privacy, we add a perturbation to identifiers
103142 * if one generator is seldom used. This makes hard for an attacker
103143 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103144 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103145 delta = prandom_u32_max(now - old);
103146
103147 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103148 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103149 }
103150 EXPORT_SYMBOL(ip_idents_reserve);
103151
103152 @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103153 .maxlen = sizeof(int),
103154 .mode = 0200,
103155 .proc_handler = ipv4_sysctl_rtcache_flush,
103156 + .extra1 = &init_net,
103157 },
103158 { },
103159 };
103160
103161 static __net_init int sysctl_route_net_init(struct net *net)
103162 {
103163 - struct ctl_table *tbl;
103164 + ctl_table_no_const *tbl = NULL;
103165
103166 - tbl = ipv4_route_flush_table;
103167 if (!net_eq(net, &init_net)) {
103168 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103169 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103170 if (tbl == NULL)
103171 goto err_dup;
103172
103173 /* Don't export sysctls to unprivileged users */
103174 if (net->user_ns != &init_user_ns)
103175 tbl[0].procname = NULL;
103176 - }
103177 - tbl[0].extra1 = net;
103178 + tbl[0].extra1 = net;
103179 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103180 + } else
103181 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103182
103183 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103184 if (net->ipv4.route_hdr == NULL)
103185 goto err_reg;
103186 return 0;
103187
103188 err_reg:
103189 - if (tbl != ipv4_route_flush_table)
103190 - kfree(tbl);
103191 + kfree(tbl);
103192 err_dup:
103193 return -ENOMEM;
103194 }
103195 @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103196
103197 static __net_init int rt_genid_init(struct net *net)
103198 {
103199 - atomic_set(&net->ipv4.rt_genid, 0);
103200 - atomic_set(&net->fnhe_genid, 0);
103201 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103202 + atomic_set_unchecked(&net->fnhe_genid, 0);
103203 get_random_bytes(&net->ipv4.dev_addr_genid,
103204 sizeof(net->ipv4.dev_addr_genid));
103205 return 0;
103206 @@ -2717,11 +2717,7 @@ int __init ip_rt_init(void)
103207 {
103208 int rc = 0;
103209
103210 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103211 - if (!ip_idents)
103212 - panic("IP: failed to allocate ip_idents\n");
103213 -
103214 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103215 + prandom_bytes(ip_idents, sizeof(ip_idents));
103216
103217 #ifdef CONFIG_IP_ROUTE_CLASSID
103218 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103219 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103220 index 79a007c..5023029 100644
103221 --- a/net/ipv4/sysctl_net_ipv4.c
103222 +++ b/net/ipv4/sysctl_net_ipv4.c
103223 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103224 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103225 int ret;
103226 int range[2];
103227 - struct ctl_table tmp = {
103228 + ctl_table_no_const tmp = {
103229 .data = &range,
103230 .maxlen = sizeof(range),
103231 .mode = table->mode,
103232 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103233 int ret;
103234 gid_t urange[2];
103235 kgid_t low, high;
103236 - struct ctl_table tmp = {
103237 + ctl_table_no_const tmp = {
103238 .data = &urange,
103239 .maxlen = sizeof(urange),
103240 .mode = table->mode,
103241 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103242 void __user *buffer, size_t *lenp, loff_t *ppos)
103243 {
103244 char val[TCP_CA_NAME_MAX];
103245 - struct ctl_table tbl = {
103246 + ctl_table_no_const tbl = {
103247 .data = val,
103248 .maxlen = TCP_CA_NAME_MAX,
103249 };
103250 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103251 void __user *buffer, size_t *lenp,
103252 loff_t *ppos)
103253 {
103254 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103255 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103256 int ret;
103257
103258 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103259 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103260 void __user *buffer, size_t *lenp,
103261 loff_t *ppos)
103262 {
103263 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103264 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103265 int ret;
103266
103267 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103268 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103269 void __user *buffer, size_t *lenp,
103270 loff_t *ppos)
103271 {
103272 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103273 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103274 struct tcp_fastopen_context *ctxt;
103275 int ret;
103276 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103277 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
103278
103279 static __net_init int ipv4_sysctl_init_net(struct net *net)
103280 {
103281 - struct ctl_table *table;
103282 + ctl_table_no_const *table = NULL;
103283
103284 - table = ipv4_net_table;
103285 if (!net_eq(net, &init_net)) {
103286 int i;
103287
103288 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103289 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103290 if (table == NULL)
103291 goto err_alloc;
103292
103293 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103294 table[i].data += (void *)net - (void *)&init_net;
103295 }
103296
103297 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103298 + if (!net_eq(net, &init_net))
103299 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103300 + else
103301 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103302 if (net->ipv4.ipv4_hdr == NULL)
103303 goto err_reg;
103304
103305 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103306 index a906e02..f3b6a0f 100644
103307 --- a/net/ipv4/tcp_input.c
103308 +++ b/net/ipv4/tcp_input.c
103309 @@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103310 * without any lock. We want to make sure compiler wont store
103311 * intermediate values in this location.
103312 */
103313 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103314 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103315 sk->sk_max_pacing_rate);
103316 }
103317
103318 @@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103319 * simplifies code)
103320 */
103321 static void
103322 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103323 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103324 struct sk_buff *head, struct sk_buff *tail,
103325 u32 start, u32 end)
103326 {
103327 @@ -5546,6 +5546,7 @@ discard:
103328 tcp_paws_reject(&tp->rx_opt, 0))
103329 goto discard_and_undo;
103330
103331 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103332 if (th->syn) {
103333 /* We see SYN without ACK. It is attempt of
103334 * simultaneous connect with crossed SYNs.
103335 @@ -5596,6 +5597,7 @@ discard:
103336 goto discard;
103337 #endif
103338 }
103339 +#endif
103340 /* "fifth, if neither of the SYN or RST bits is set then
103341 * drop the segment and return."
103342 */
103343 @@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103344 goto discard;
103345
103346 if (th->syn) {
103347 - if (th->fin)
103348 + if (th->fin || th->urg || th->psh)
103349 goto discard;
103350 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103351 return 1;
103352 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103353 index cd17f00..1e1f252 100644
103354 --- a/net/ipv4/tcp_ipv4.c
103355 +++ b/net/ipv4/tcp_ipv4.c
103356 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
103357 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103358
103359
103360 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103361 +extern int grsec_enable_blackhole;
103362 +#endif
103363 +
103364 #ifdef CONFIG_TCP_MD5SIG
103365 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103366 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103367 @@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103368 return 0;
103369
103370 reset:
103371 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103372 + if (!grsec_enable_blackhole)
103373 +#endif
103374 tcp_v4_send_reset(rsk, skb);
103375 discard:
103376 kfree_skb(skb);
103377 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103378 TCP_SKB_CB(skb)->sacked = 0;
103379
103380 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103381 - if (!sk)
103382 + if (!sk) {
103383 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103384 + ret = 1;
103385 +#endif
103386 goto no_tcp_socket;
103387 -
103388 + }
103389 process:
103390 - if (sk->sk_state == TCP_TIME_WAIT)
103391 + if (sk->sk_state == TCP_TIME_WAIT) {
103392 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103393 + ret = 2;
103394 +#endif
103395 goto do_time_wait;
103396 + }
103397
103398 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103399 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103400 @@ -1704,6 +1718,10 @@ csum_error:
103401 bad_packet:
103402 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103403 } else {
103404 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103405 + if (!grsec_enable_blackhole || (ret == 1 &&
103406 + (skb->dev->flags & IFF_LOOPBACK)))
103407 +#endif
103408 tcp_v4_send_reset(NULL, skb);
103409 }
103410
103411 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103412 index 1649988..6251843 100644
103413 --- a/net/ipv4/tcp_minisocks.c
103414 +++ b/net/ipv4/tcp_minisocks.c
103415 @@ -27,6 +27,10 @@
103416 #include <net/inet_common.h>
103417 #include <net/xfrm.h>
103418
103419 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103420 +extern int grsec_enable_blackhole;
103421 +#endif
103422 +
103423 int sysctl_tcp_syncookies __read_mostly = 1;
103424 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103425
103426 @@ -740,7 +744,10 @@ embryonic_reset:
103427 * avoid becoming vulnerable to outside attack aiming at
103428 * resetting legit local connections.
103429 */
103430 - req->rsk_ops->send_reset(sk, skb);
103431 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103432 + if (!grsec_enable_blackhole)
103433 +#endif
103434 + req->rsk_ops->send_reset(sk, skb);
103435 } else if (fastopen) { /* received a valid RST pkt */
103436 reqsk_fastopen_remove(sk, req, true);
103437 tcp_reset(sk);
103438 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103439 index 3b66610..bfbe23a 100644
103440 --- a/net/ipv4/tcp_probe.c
103441 +++ b/net/ipv4/tcp_probe.c
103442 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103443 if (cnt + width >= len)
103444 break;
103445
103446 - if (copy_to_user(buf + cnt, tbuf, width))
103447 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103448 return -EFAULT;
103449 cnt += width;
103450 }
103451 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103452 index df90cd1..9ab2c9b 100644
103453 --- a/net/ipv4/tcp_timer.c
103454 +++ b/net/ipv4/tcp_timer.c
103455 @@ -22,6 +22,10 @@
103456 #include <linux/gfp.h>
103457 #include <net/tcp.h>
103458
103459 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103460 +extern int grsec_lastack_retries;
103461 +#endif
103462 +
103463 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103464 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103465 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103466 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103467 }
103468 }
103469
103470 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103471 + if ((sk->sk_state == TCP_LAST_ACK) &&
103472 + (grsec_lastack_retries > 0) &&
103473 + (grsec_lastack_retries < retry_until))
103474 + retry_until = grsec_lastack_retries;
103475 +#endif
103476 +
103477 if (retransmits_timed_out(sk, retry_until,
103478 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103479 /* Has it gone just too far? */
103480 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103481 index f57c0e4..cf24bd0 100644
103482 --- a/net/ipv4/udp.c
103483 +++ b/net/ipv4/udp.c
103484 @@ -87,6 +87,7 @@
103485 #include <linux/types.h>
103486 #include <linux/fcntl.h>
103487 #include <linux/module.h>
103488 +#include <linux/security.h>
103489 #include <linux/socket.h>
103490 #include <linux/sockios.h>
103491 #include <linux/igmp.h>
103492 @@ -113,6 +114,10 @@
103493 #include <net/busy_poll.h>
103494 #include "udp_impl.h"
103495
103496 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103497 +extern int grsec_enable_blackhole;
103498 +#endif
103499 +
103500 struct udp_table udp_table __read_mostly;
103501 EXPORT_SYMBOL(udp_table);
103502
103503 @@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103504 return true;
103505 }
103506
103507 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103508 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103509 +
103510 /*
103511 * This routine is called by the ICMP module when it gets some
103512 * sort of error condition. If err < 0 then the socket should
103513 @@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103514 dport = usin->sin_port;
103515 if (dport == 0)
103516 return -EINVAL;
103517 +
103518 + err = gr_search_udp_sendmsg(sk, usin);
103519 + if (err)
103520 + return err;
103521 } else {
103522 if (sk->sk_state != TCP_ESTABLISHED)
103523 return -EDESTADDRREQ;
103524 +
103525 + err = gr_search_udp_sendmsg(sk, NULL);
103526 + if (err)
103527 + return err;
103528 +
103529 daddr = inet->inet_daddr;
103530 dport = inet->inet_dport;
103531 /* Open fast path for connected socket.
103532 @@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103533 IS_UDPLITE(sk));
103534 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103535 IS_UDPLITE(sk));
103536 - atomic_inc(&sk->sk_drops);
103537 + atomic_inc_unchecked(&sk->sk_drops);
103538 __skb_unlink(skb, rcvq);
103539 __skb_queue_tail(&list_kill, skb);
103540 }
103541 @@ -1261,6 +1278,10 @@ try_again:
103542 if (!skb)
103543 goto out;
103544
103545 + err = gr_search_udp_recvmsg(sk, skb);
103546 + if (err)
103547 + goto out_free;
103548 +
103549 ulen = skb->len - sizeof(struct udphdr);
103550 copied = len;
103551 if (copied > ulen)
103552 @@ -1294,7 +1315,7 @@ try_again:
103553 if (unlikely(err)) {
103554 trace_kfree_skb(skb, udp_recvmsg);
103555 if (!peeked) {
103556 - atomic_inc(&sk->sk_drops);
103557 + atomic_inc_unchecked(&sk->sk_drops);
103558 UDP_INC_STATS_USER(sock_net(sk),
103559 UDP_MIB_INERRORS, is_udplite);
103560 }
103561 @@ -1591,7 +1612,7 @@ csum_error:
103562 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103563 drop:
103564 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103565 - atomic_inc(&sk->sk_drops);
103566 + atomic_inc_unchecked(&sk->sk_drops);
103567 kfree_skb(skb);
103568 return -1;
103569 }
103570 @@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103571 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103572
103573 if (!skb1) {
103574 - atomic_inc(&sk->sk_drops);
103575 + atomic_inc_unchecked(&sk->sk_drops);
103576 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103577 IS_UDPLITE(sk));
103578 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103579 @@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103580 goto csum_error;
103581
103582 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103583 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103584 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103585 +#endif
103586 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103587
103588 /*
103589 @@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103590 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103591 0, sock_i_ino(sp),
103592 atomic_read(&sp->sk_refcnt), sp,
103593 - atomic_read(&sp->sk_drops));
103594 + atomic_read_unchecked(&sp->sk_drops));
103595 }
103596
103597 int udp4_seq_show(struct seq_file *seq, void *v)
103598 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103599 index 6156f68..d6ab46d 100644
103600 --- a/net/ipv4/xfrm4_policy.c
103601 +++ b/net/ipv4/xfrm4_policy.c
103602 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103603 fl4->flowi4_tos = iph->tos;
103604 }
103605
103606 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103607 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103608 {
103609 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103610
103611 - xfrm4_policy_afinfo.garbage_collect(net);
103612 + xfrm_garbage_collect_deferred(net);
103613 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103614 }
103615
103616 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103617
103618 static int __net_init xfrm4_net_init(struct net *net)
103619 {
103620 - struct ctl_table *table;
103621 + ctl_table_no_const *table = NULL;
103622 struct ctl_table_header *hdr;
103623
103624 - table = xfrm4_policy_table;
103625 if (!net_eq(net, &init_net)) {
103626 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103627 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103628 if (!table)
103629 goto err_alloc;
103630
103631 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103632 - }
103633 -
103634 - hdr = register_net_sysctl(net, "net/ipv4", table);
103635 + hdr = register_net_sysctl(net, "net/ipv4", table);
103636 + } else
103637 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103638 if (!hdr)
103639 goto err_reg;
103640
103641 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103642 return 0;
103643
103644 err_reg:
103645 - if (!net_eq(net, &init_net))
103646 - kfree(table);
103647 + kfree(table);
103648 err_alloc:
103649 return -ENOMEM;
103650 }
103651 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103652 index 3e118df..27b16cf 100644
103653 --- a/net/ipv6/addrconf.c
103654 +++ b/net/ipv6/addrconf.c
103655 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103656 idx = 0;
103657 head = &net->dev_index_head[h];
103658 rcu_read_lock();
103659 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103660 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103661 net->dev_base_seq;
103662 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103663 if (idx < s_idx)
103664 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103665 p.iph.ihl = 5;
103666 p.iph.protocol = IPPROTO_IPV6;
103667 p.iph.ttl = 64;
103668 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103669 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103670
103671 if (ops->ndo_do_ioctl) {
103672 mm_segment_t oldfs = get_fs();
103673 @@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
103674 .release = seq_release_net,
103675 };
103676
103677 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103678 +extern void unregister_ipv6_seq_ops_addr(void);
103679 +
103680 static int __net_init if6_proc_net_init(struct net *net)
103681 {
103682 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103683 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103684 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103685 + unregister_ipv6_seq_ops_addr();
103686 return -ENOMEM;
103687 + }
103688 return 0;
103689 }
103690
103691 static void __net_exit if6_proc_net_exit(struct net *net)
103692 {
103693 remove_proc_entry("if_inet6", net->proc_net);
103694 + unregister_ipv6_seq_ops_addr();
103695 }
103696
103697 static struct pernet_operations if6_proc_net_ops = {
103698 @@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103699 s_ip_idx = ip_idx = cb->args[2];
103700
103701 rcu_read_lock();
103702 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103703 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103704 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103705 idx = 0;
103706 head = &net->dev_index_head[h];
103707 @@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103708 rt_genid_bump_ipv6(net);
103709 break;
103710 }
103711 - atomic_inc(&net->ipv6.dev_addr_genid);
103712 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103713 }
103714
103715 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103716 @@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103717 int *valp = ctl->data;
103718 int val = *valp;
103719 loff_t pos = *ppos;
103720 - struct ctl_table lctl;
103721 + ctl_table_no_const lctl;
103722 int ret;
103723
103724 /*
103725 @@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103726 int *valp = ctl->data;
103727 int val = *valp;
103728 loff_t pos = *ppos;
103729 - struct ctl_table lctl;
103730 + ctl_table_no_const lctl;
103731 int ret;
103732
103733 /*
103734 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103735 index 2daa3a1..341066c 100644
103736 --- a/net/ipv6/af_inet6.c
103737 +++ b/net/ipv6/af_inet6.c
103738 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103739 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103740 net->ipv6.sysctl.flowlabel_consistency = 1;
103741 net->ipv6.sysctl.auto_flowlabels = 0;
103742 - atomic_set(&net->ipv6.rt_genid, 0);
103743 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
103744
103745 err = ipv6_init_mibs(net);
103746 if (err)
103747 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103748 index 2753319..b7e625c 100644
103749 --- a/net/ipv6/datagram.c
103750 +++ b/net/ipv6/datagram.c
103751 @@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103752 0,
103753 sock_i_ino(sp),
103754 atomic_read(&sp->sk_refcnt), sp,
103755 - atomic_read(&sp->sk_drops));
103756 + atomic_read_unchecked(&sp->sk_drops));
103757 }
103758 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103759 index 06ba3e5..5c08d38 100644
103760 --- a/net/ipv6/icmp.c
103761 +++ b/net/ipv6/icmp.c
103762 @@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103763
103764 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103765 {
103766 - struct ctl_table *table;
103767 + ctl_table_no_const *table;
103768
103769 table = kmemdup(ipv6_icmp_table_template,
103770 sizeof(ipv6_icmp_table_template),
103771 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103772 index 97299d7..c8e6894 100644
103773 --- a/net/ipv6/ip6_gre.c
103774 +++ b/net/ipv6/ip6_gre.c
103775 @@ -71,8 +71,8 @@ struct ip6gre_net {
103776 struct net_device *fb_tunnel_dev;
103777 };
103778
103779 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103780 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103781 +static struct rtnl_link_ops ip6gre_link_ops;
103782 +static struct rtnl_link_ops ip6gre_tap_ops;
103783 static int ip6gre_tunnel_init(struct net_device *dev);
103784 static void ip6gre_tunnel_setup(struct net_device *dev);
103785 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103786 @@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103787 }
103788
103789
103790 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103791 +static struct inet6_protocol ip6gre_protocol = {
103792 .handler = ip6gre_rcv,
103793 .err_handler = ip6gre_err,
103794 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103795 @@ -1645,7 +1645,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103796 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103797 };
103798
103799 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103800 +static struct rtnl_link_ops ip6gre_link_ops = {
103801 .kind = "ip6gre",
103802 .maxtype = IFLA_GRE_MAX,
103803 .policy = ip6gre_policy,
103804 @@ -1659,7 +1659,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103805 .fill_info = ip6gre_fill_info,
103806 };
103807
103808 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103809 +static struct rtnl_link_ops ip6gre_tap_ops = {
103810 .kind = "ip6gretap",
103811 .maxtype = IFLA_GRE_MAX,
103812 .policy = ip6gre_policy,
103813 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
103814 index 65eda2a..620a102 100644
103815 --- a/net/ipv6/ip6_offload.c
103816 +++ b/net/ipv6/ip6_offload.c
103817 @@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
103818 if (unlikely(!pskb_may_pull(skb, len)))
103819 break;
103820
103821 + opth = (void *)skb->data;
103822 proto = opth->nexthdr;
103823 __skb_pull(skb, len);
103824 }
103825 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103826 index 69a84b4..881c319 100644
103827 --- a/net/ipv6/ip6_tunnel.c
103828 +++ b/net/ipv6/ip6_tunnel.c
103829 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103830
103831 static int ip6_tnl_dev_init(struct net_device *dev);
103832 static void ip6_tnl_dev_setup(struct net_device *dev);
103833 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103834 +static struct rtnl_link_ops ip6_link_ops;
103835
103836 static int ip6_tnl_net_id __read_mostly;
103837 struct ip6_tnl_net {
103838 @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103839 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103840 };
103841
103842 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103843 +static struct rtnl_link_ops ip6_link_ops = {
103844 .kind = "ip6tnl",
103845 .maxtype = IFLA_IPTUN_MAX,
103846 .policy = ip6_tnl_policy,
103847 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103848 index 5833a22..6631377 100644
103849 --- a/net/ipv6/ip6_vti.c
103850 +++ b/net/ipv6/ip6_vti.c
103851 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103852
103853 static int vti6_dev_init(struct net_device *dev);
103854 static void vti6_dev_setup(struct net_device *dev);
103855 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103856 +static struct rtnl_link_ops vti6_link_ops;
103857
103858 static int vti6_net_id __read_mostly;
103859 struct vti6_net {
103860 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103861 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103862 };
103863
103864 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103865 +static struct rtnl_link_ops vti6_link_ops = {
103866 .kind = "vti6",
103867 .maxtype = IFLA_VTI_MAX,
103868 .policy = vti6_policy,
103869 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103870 index 0c28998..d0a2ecd 100644
103871 --- a/net/ipv6/ipv6_sockglue.c
103872 +++ b/net/ipv6/ipv6_sockglue.c
103873 @@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103874 if (sk->sk_type != SOCK_STREAM)
103875 return -ENOPROTOOPT;
103876
103877 - msg.msg_control = optval;
103878 + msg.msg_control = (void __force_kernel *)optval;
103879 msg.msg_controllen = len;
103880 msg.msg_flags = flags;
103881
103882 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103883 index e080fbb..412b3cf 100644
103884 --- a/net/ipv6/netfilter/ip6_tables.c
103885 +++ b/net/ipv6/netfilter/ip6_tables.c
103886 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103887 #endif
103888
103889 static int get_info(struct net *net, void __user *user,
103890 - const int *len, int compat)
103891 + int len, int compat)
103892 {
103893 char name[XT_TABLE_MAXNAMELEN];
103894 struct xt_table *t;
103895 int ret;
103896
103897 - if (*len != sizeof(struct ip6t_getinfo)) {
103898 - duprintf("length %u != %zu\n", *len,
103899 + if (len != sizeof(struct ip6t_getinfo)) {
103900 + duprintf("length %u != %zu\n", len,
103901 sizeof(struct ip6t_getinfo));
103902 return -EINVAL;
103903 }
103904 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103905 info.size = private->size;
103906 strcpy(info.name, name);
103907
103908 - if (copy_to_user(user, &info, *len) != 0)
103909 + if (copy_to_user(user, &info, len) != 0)
103910 ret = -EFAULT;
103911 else
103912 ret = 0;
103913 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103914
103915 switch (cmd) {
103916 case IP6T_SO_GET_INFO:
103917 - ret = get_info(sock_net(sk), user, len, 1);
103918 + ret = get_info(sock_net(sk), user, *len, 1);
103919 break;
103920 case IP6T_SO_GET_ENTRIES:
103921 ret = compat_get_entries(sock_net(sk), user, len);
103922 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103923
103924 switch (cmd) {
103925 case IP6T_SO_GET_INFO:
103926 - ret = get_info(sock_net(sk), user, len, 0);
103927 + ret = get_info(sock_net(sk), user, *len, 0);
103928 break;
103929
103930 case IP6T_SO_GET_ENTRIES:
103931 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103932 index 6f187c8..34b367f 100644
103933 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103934 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103935 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103936
103937 static int nf_ct_frag6_sysctl_register(struct net *net)
103938 {
103939 - struct ctl_table *table;
103940 + ctl_table_no_const *table = NULL;
103941 struct ctl_table_header *hdr;
103942
103943 - table = nf_ct_frag6_sysctl_table;
103944 if (!net_eq(net, &init_net)) {
103945 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103946 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103947 GFP_KERNEL);
103948 if (table == NULL)
103949 goto err_alloc;
103950 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103951 table[2].data = &net->nf_frag.frags.high_thresh;
103952 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103953 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103954 - }
103955 -
103956 - hdr = register_net_sysctl(net, "net/netfilter", table);
103957 + hdr = register_net_sysctl(net, "net/netfilter", table);
103958 + } else
103959 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103960 if (hdr == NULL)
103961 goto err_reg;
103962
103963 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103964 return 0;
103965
103966 err_reg:
103967 - if (!net_eq(net, &init_net))
103968 - kfree(table);
103969 + kfree(table);
103970 err_alloc:
103971 return -ENOMEM;
103972 }
103973 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103974 index 5b7a1ed..d9da205 100644
103975 --- a/net/ipv6/ping.c
103976 +++ b/net/ipv6/ping.c
103977 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103978 };
103979 #endif
103980
103981 +static struct pingv6_ops real_pingv6_ops = {
103982 + .ipv6_recv_error = ipv6_recv_error,
103983 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103984 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103985 + .icmpv6_err_convert = icmpv6_err_convert,
103986 + .ipv6_icmp_error = ipv6_icmp_error,
103987 + .ipv6_chk_addr = ipv6_chk_addr,
103988 +};
103989 +
103990 +static struct pingv6_ops dummy_pingv6_ops = {
103991 + .ipv6_recv_error = dummy_ipv6_recv_error,
103992 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103993 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103994 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
103995 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
103996 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
103997 +};
103998 +
103999 int __init pingv6_init(void)
104000 {
104001 #ifdef CONFIG_PROC_FS
104002 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104003 if (ret)
104004 return ret;
104005 #endif
104006 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104007 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104008 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104009 - ip6_datagram_recv_specific_ctl;
104010 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104011 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104012 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104013 + pingv6_ops = &real_pingv6_ops;
104014 return inet6_register_protosw(&pingv6_protosw);
104015 }
104016
104017 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104018 */
104019 void pingv6_exit(void)
104020 {
104021 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104022 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104023 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104024 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104025 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104026 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104027 #ifdef CONFIG_PROC_FS
104028 unregister_pernet_subsys(&ping_v6_net_ops);
104029 #endif
104030 + pingv6_ops = &dummy_pingv6_ops;
104031 inet6_unregister_protosw(&pingv6_protosw);
104032 }
104033 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104034 index 2d6f860..b0165f5 100644
104035 --- a/net/ipv6/proc.c
104036 +++ b/net/ipv6/proc.c
104037 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104038 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104039 goto proc_snmp6_fail;
104040
104041 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104042 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104043 if (!net->mib.proc_net_devsnmp6)
104044 goto proc_dev_snmp6_fail;
104045 return 0;
104046 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104047 index 39d4422..b0979547 100644
104048 --- a/net/ipv6/raw.c
104049 +++ b/net/ipv6/raw.c
104050 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104051 {
104052 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104053 skb_checksum_complete(skb)) {
104054 - atomic_inc(&sk->sk_drops);
104055 + atomic_inc_unchecked(&sk->sk_drops);
104056 kfree_skb(skb);
104057 return NET_RX_DROP;
104058 }
104059 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104060 struct raw6_sock *rp = raw6_sk(sk);
104061
104062 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104063 - atomic_inc(&sk->sk_drops);
104064 + atomic_inc_unchecked(&sk->sk_drops);
104065 kfree_skb(skb);
104066 return NET_RX_DROP;
104067 }
104068 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104069
104070 if (inet->hdrincl) {
104071 if (skb_checksum_complete(skb)) {
104072 - atomic_inc(&sk->sk_drops);
104073 + atomic_inc_unchecked(&sk->sk_drops);
104074 kfree_skb(skb);
104075 return NET_RX_DROP;
104076 }
104077 @@ -608,7 +608,7 @@ out:
104078 return err;
104079 }
104080
104081 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104082 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104083 struct flowi6 *fl6, struct dst_entry **dstp,
104084 unsigned int flags)
104085 {
104086 @@ -914,12 +914,15 @@ do_confirm:
104087 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104088 char __user *optval, int optlen)
104089 {
104090 + struct icmp6_filter filter;
104091 +
104092 switch (optname) {
104093 case ICMPV6_FILTER:
104094 if (optlen > sizeof(struct icmp6_filter))
104095 optlen = sizeof(struct icmp6_filter);
104096 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104097 + if (copy_from_user(&filter, optval, optlen))
104098 return -EFAULT;
104099 + raw6_sk(sk)->filter = filter;
104100 return 0;
104101 default:
104102 return -ENOPROTOOPT;
104103 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104104 char __user *optval, int __user *optlen)
104105 {
104106 int len;
104107 + struct icmp6_filter filter;
104108
104109 switch (optname) {
104110 case ICMPV6_FILTER:
104111 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104112 len = sizeof(struct icmp6_filter);
104113 if (put_user(len, optlen))
104114 return -EFAULT;
104115 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104116 + filter = raw6_sk(sk)->filter;
104117 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104118 return -EFAULT;
104119 return 0;
104120 default:
104121 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104122 index c6557d9..173e728 100644
104123 --- a/net/ipv6/reassembly.c
104124 +++ b/net/ipv6/reassembly.c
104125 @@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104126
104127 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104128 {
104129 - struct ctl_table *table;
104130 + ctl_table_no_const *table = NULL;
104131 struct ctl_table_header *hdr;
104132
104133 - table = ip6_frags_ns_ctl_table;
104134 if (!net_eq(net, &init_net)) {
104135 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104136 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104137 if (table == NULL)
104138 goto err_alloc;
104139
104140 @@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104141 /* Don't export sysctls to unprivileged users */
104142 if (net->user_ns != &init_user_ns)
104143 table[0].procname = NULL;
104144 - }
104145 + hdr = register_net_sysctl(net, "net/ipv6", table);
104146 + } else
104147 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104148
104149 - hdr = register_net_sysctl(net, "net/ipv6", table);
104150 if (hdr == NULL)
104151 goto err_reg;
104152
104153 @@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104154 return 0;
104155
104156 err_reg:
104157 - if (!net_eq(net, &init_net))
104158 - kfree(table);
104159 + kfree(table);
104160 err_alloc:
104161 return -ENOMEM;
104162 }
104163 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104164 index bafde82..af2c91f 100644
104165 --- a/net/ipv6/route.c
104166 +++ b/net/ipv6/route.c
104167 @@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
104168
104169 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104170 {
104171 - struct ctl_table *table;
104172 + ctl_table_no_const *table;
104173
104174 table = kmemdup(ipv6_route_table_template,
104175 sizeof(ipv6_route_table_template),
104176 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104177 index 6163f85..0070823 100644
104178 --- a/net/ipv6/sit.c
104179 +++ b/net/ipv6/sit.c
104180 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104181 static void ipip6_dev_free(struct net_device *dev);
104182 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104183 __be32 *v4dst);
104184 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104185 +static struct rtnl_link_ops sit_link_ops;
104186
104187 static int sit_net_id __read_mostly;
104188 struct sit_net {
104189 @@ -485,11 +485,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
104190 */
104191 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104192 {
104193 - const struct iphdr *iph = (const struct iphdr *) skb->data;
104194 + int ihl = ((const struct iphdr *)skb->data)->ihl*4;
104195 struct rt6_info *rt;
104196 struct sk_buff *skb2;
104197
104198 - if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
104199 + if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
104200 return 1;
104201
104202 skb2 = skb_clone(skb, GFP_ATOMIC);
104203 @@ -498,7 +498,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104204 return 1;
104205
104206 skb_dst_drop(skb2);
104207 - skb_pull(skb2, iph->ihl * 4);
104208 + skb_pull(skb2, ihl);
104209 skb_reset_network_header(skb2);
104210
104211 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
104212 @@ -1662,7 +1662,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104213 unregister_netdevice_queue(dev, head);
104214 }
104215
104216 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104217 +static struct rtnl_link_ops sit_link_ops = {
104218 .kind = "sit",
104219 .maxtype = IFLA_IPTUN_MAX,
104220 .policy = ipip6_policy,
104221 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104222 index 0c56c93..ece50df 100644
104223 --- a/net/ipv6/sysctl_net_ipv6.c
104224 +++ b/net/ipv6/sysctl_net_ipv6.c
104225 @@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
104226
104227 static int __net_init ipv6_sysctl_net_init(struct net *net)
104228 {
104229 - struct ctl_table *ipv6_table;
104230 + ctl_table_no_const *ipv6_table;
104231 struct ctl_table *ipv6_route_table;
104232 struct ctl_table *ipv6_icmp_table;
104233 int err;
104234 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104235 index 29964c3..b8caecf 100644
104236 --- a/net/ipv6/tcp_ipv6.c
104237 +++ b/net/ipv6/tcp_ipv6.c
104238 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104239 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
104240 }
104241
104242 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104243 +extern int grsec_enable_blackhole;
104244 +#endif
104245 +
104246 static void tcp_v6_hash(struct sock *sk)
104247 {
104248 if (sk->sk_state != TCP_CLOSE) {
104249 @@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104250 return 0;
104251
104252 reset:
104253 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104254 + if (!grsec_enable_blackhole)
104255 +#endif
104256 tcp_v6_send_reset(sk, skb);
104257 discard:
104258 if (opt_skb)
104259 @@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104260 TCP_SKB_CB(skb)->sacked = 0;
104261
104262 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104263 - if (!sk)
104264 + if (!sk) {
104265 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104266 + ret = 1;
104267 +#endif
104268 goto no_tcp_socket;
104269 + }
104270
104271 process:
104272 - if (sk->sk_state == TCP_TIME_WAIT)
104273 + if (sk->sk_state == TCP_TIME_WAIT) {
104274 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104275 + ret = 2;
104276 +#endif
104277 goto do_time_wait;
104278 + }
104279
104280 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104281 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104282 @@ -1479,6 +1494,10 @@ csum_error:
104283 bad_packet:
104284 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104285 } else {
104286 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104287 + if (!grsec_enable_blackhole || (ret == 1 &&
104288 + (skb->dev->flags & IFF_LOOPBACK)))
104289 +#endif
104290 tcp_v6_send_reset(NULL, skb);
104291 }
104292
104293 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104294 index 4836af8..0e52bbd 100644
104295 --- a/net/ipv6/udp.c
104296 +++ b/net/ipv6/udp.c
104297 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104298 udp_ipv6_hash_secret + net_hash_mix(net));
104299 }
104300
104301 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104302 +extern int grsec_enable_blackhole;
104303 +#endif
104304 +
104305 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104306 {
104307 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104308 @@ -434,7 +438,7 @@ try_again:
104309 if (unlikely(err)) {
104310 trace_kfree_skb(skb, udpv6_recvmsg);
104311 if (!peeked) {
104312 - atomic_inc(&sk->sk_drops);
104313 + atomic_inc_unchecked(&sk->sk_drops);
104314 if (is_udp4)
104315 UDP_INC_STATS_USER(sock_net(sk),
104316 UDP_MIB_INERRORS,
104317 @@ -701,7 +705,7 @@ csum_error:
104318 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104319 drop:
104320 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104321 - atomic_inc(&sk->sk_drops);
104322 + atomic_inc_unchecked(&sk->sk_drops);
104323 kfree_skb(skb);
104324 return -1;
104325 }
104326 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104327 if (likely(skb1 == NULL))
104328 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104329 if (!skb1) {
104330 - atomic_inc(&sk->sk_drops);
104331 + atomic_inc_unchecked(&sk->sk_drops);
104332 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104333 IS_UDPLITE(sk));
104334 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104335 @@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104336 goto csum_error;
104337
104338 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104339 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104340 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104341 +#endif
104342 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104343
104344 kfree_skb(skb);
104345 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104346 index 2a0bbda..442240d 100644
104347 --- a/net/ipv6/xfrm6_policy.c
104348 +++ b/net/ipv6/xfrm6_policy.c
104349 @@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104350 case IPPROTO_DCCP:
104351 if (!onlyproto && (nh + offset + 4 < skb->data ||
104352 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
104353 - __be16 *ports = (__be16 *)exthdr;
104354 + __be16 *ports;
104355
104356 + nh = skb_network_header(skb);
104357 + ports = (__be16 *)(nh + offset);
104358 fl6->fl6_sport = ports[!!reverse];
104359 fl6->fl6_dport = ports[!reverse];
104360 }
104361 @@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104362
104363 case IPPROTO_ICMPV6:
104364 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
104365 - u8 *icmp = (u8 *)exthdr;
104366 + u8 *icmp;
104367
104368 + nh = skb_network_header(skb);
104369 + icmp = (u8 *)(nh + offset);
104370 fl6->fl6_icmp_type = icmp[0];
104371 fl6->fl6_icmp_code = icmp[1];
104372 }
104373 @@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104374 case IPPROTO_MH:
104375 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
104376 struct ip6_mh *mh;
104377 - mh = (struct ip6_mh *)exthdr;
104378
104379 + nh = skb_network_header(skb);
104380 + mh = (struct ip6_mh *)(nh + offset);
104381 fl6->fl6_mh_type = mh->ip6mh_type;
104382 }
104383 fl6->flowi6_proto = nexthdr;
104384 @@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104385 }
104386 }
104387
104388 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104389 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104390 {
104391 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104392
104393 - xfrm6_policy_afinfo.garbage_collect(net);
104394 + xfrm_garbage_collect_deferred(net);
104395 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104396 }
104397
104398 @@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104399
104400 static int __net_init xfrm6_net_init(struct net *net)
104401 {
104402 - struct ctl_table *table;
104403 + ctl_table_no_const *table = NULL;
104404 struct ctl_table_header *hdr;
104405
104406 - table = xfrm6_policy_table;
104407 if (!net_eq(net, &init_net)) {
104408 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104409 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104410 if (!table)
104411 goto err_alloc;
104412
104413 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104414 - }
104415 + hdr = register_net_sysctl(net, "net/ipv6", table);
104416 + } else
104417 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104418
104419 - hdr = register_net_sysctl(net, "net/ipv6", table);
104420 if (!hdr)
104421 goto err_reg;
104422
104423 @@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104424 return 0;
104425
104426 err_reg:
104427 - if (!net_eq(net, &init_net))
104428 - kfree(table);
104429 + kfree(table);
104430 err_alloc:
104431 return -ENOMEM;
104432 }
104433 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104434 index e15c16a..7cf07aa 100644
104435 --- a/net/ipx/ipx_proc.c
104436 +++ b/net/ipx/ipx_proc.c
104437 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104438 struct proc_dir_entry *p;
104439 int rc = -ENOMEM;
104440
104441 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104442 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104443
104444 if (!ipx_proc_dir)
104445 goto out;
104446 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104447 index 61ceb4c..e788eb8 100644
104448 --- a/net/irda/ircomm/ircomm_tty.c
104449 +++ b/net/irda/ircomm/ircomm_tty.c
104450 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104451 add_wait_queue(&port->open_wait, &wait);
104452
104453 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104454 - __FILE__, __LINE__, tty->driver->name, port->count);
104455 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104456
104457 spin_lock_irqsave(&port->lock, flags);
104458 - port->count--;
104459 + atomic_dec(&port->count);
104460 port->blocked_open++;
104461 spin_unlock_irqrestore(&port->lock, flags);
104462
104463 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104464 }
104465
104466 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104467 - __FILE__, __LINE__, tty->driver->name, port->count);
104468 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104469
104470 schedule();
104471 }
104472 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104473
104474 spin_lock_irqsave(&port->lock, flags);
104475 if (!tty_hung_up_p(filp))
104476 - port->count++;
104477 + atomic_inc(&port->count);
104478 port->blocked_open--;
104479 spin_unlock_irqrestore(&port->lock, flags);
104480
104481 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104482 - __FILE__, __LINE__, tty->driver->name, port->count);
104483 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104484
104485 if (!retval)
104486 port->flags |= ASYNC_NORMAL_ACTIVE;
104487 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104488
104489 /* ++ is not atomic, so this should be protected - Jean II */
104490 spin_lock_irqsave(&self->port.lock, flags);
104491 - self->port.count++;
104492 + atomic_inc(&self->port.count);
104493 spin_unlock_irqrestore(&self->port.lock, flags);
104494 tty_port_tty_set(&self->port, tty);
104495
104496 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104497 - self->line, self->port.count);
104498 + self->line, atomic_read(&self->port.count));
104499
104500 /* Not really used by us, but lets do it anyway */
104501 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104502 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104503 tty_kref_put(port->tty);
104504 }
104505 port->tty = NULL;
104506 - port->count = 0;
104507 + atomic_set(&port->count, 0);
104508 spin_unlock_irqrestore(&port->lock, flags);
104509
104510 wake_up_interruptible(&port->open_wait);
104511 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104512 seq_putc(m, '\n');
104513
104514 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104515 - seq_printf(m, "Open count: %d\n", self->port.count);
104516 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104517 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104518 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104519
104520 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104521 index b9ac598..f88cc56 100644
104522 --- a/net/irda/irproc.c
104523 +++ b/net/irda/irproc.c
104524 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104525 {
104526 int i;
104527
104528 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104529 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104530 if (proc_irda == NULL)
104531 return;
104532
104533 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104534 index a089b6b..3ca3b60 100644
104535 --- a/net/iucv/af_iucv.c
104536 +++ b/net/iucv/af_iucv.c
104537 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104538 {
104539 char name[12];
104540
104541 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104542 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104543 while (__iucv_get_sock_by_name(name)) {
104544 sprintf(name, "%08x",
104545 - atomic_inc_return(&iucv_sk_list.autobind_name));
104546 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104547 }
104548 memcpy(iucv->src_name, name, 8);
104549 }
104550 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104551 index da78793..bdd78cf 100644
104552 --- a/net/iucv/iucv.c
104553 +++ b/net/iucv/iucv.c
104554 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104555 return NOTIFY_OK;
104556 }
104557
104558 -static struct notifier_block __refdata iucv_cpu_notifier = {
104559 +static struct notifier_block iucv_cpu_notifier = {
104560 .notifier_call = iucv_cpu_notify,
104561 };
104562
104563 diff --git a/net/key/af_key.c b/net/key/af_key.c
104564 index 1847ec4..26ef732 100644
104565 --- a/net/key/af_key.c
104566 +++ b/net/key/af_key.c
104567 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104568 static u32 get_acqseq(void)
104569 {
104570 u32 res;
104571 - static atomic_t acqseq;
104572 + static atomic_unchecked_t acqseq;
104573
104574 do {
104575 - res = atomic_inc_return(&acqseq);
104576 + res = atomic_inc_return_unchecked(&acqseq);
104577 } while (!res);
104578 return res;
104579 }
104580 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104581 index edb78e6..8dc654a 100644
104582 --- a/net/l2tp/l2tp_eth.c
104583 +++ b/net/l2tp/l2tp_eth.c
104584 @@ -42,12 +42,12 @@ struct l2tp_eth {
104585 struct sock *tunnel_sock;
104586 struct l2tp_session *session;
104587 struct list_head list;
104588 - atomic_long_t tx_bytes;
104589 - atomic_long_t tx_packets;
104590 - atomic_long_t tx_dropped;
104591 - atomic_long_t rx_bytes;
104592 - atomic_long_t rx_packets;
104593 - atomic_long_t rx_errors;
104594 + atomic_long_unchecked_t tx_bytes;
104595 + atomic_long_unchecked_t tx_packets;
104596 + atomic_long_unchecked_t tx_dropped;
104597 + atomic_long_unchecked_t rx_bytes;
104598 + atomic_long_unchecked_t rx_packets;
104599 + atomic_long_unchecked_t rx_errors;
104600 };
104601
104602 /* via l2tp_session_priv() */
104603 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104604 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104605
104606 if (likely(ret == NET_XMIT_SUCCESS)) {
104607 - atomic_long_add(len, &priv->tx_bytes);
104608 - atomic_long_inc(&priv->tx_packets);
104609 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104610 + atomic_long_inc_unchecked(&priv->tx_packets);
104611 } else {
104612 - atomic_long_inc(&priv->tx_dropped);
104613 + atomic_long_inc_unchecked(&priv->tx_dropped);
104614 }
104615 return NETDEV_TX_OK;
104616 }
104617 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104618 {
104619 struct l2tp_eth *priv = netdev_priv(dev);
104620
104621 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104622 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104623 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104624 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104625 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104626 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104627 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104628 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104629 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104630 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104631 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104632 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104633 return stats;
104634 }
104635
104636 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104637 nf_reset(skb);
104638
104639 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104640 - atomic_long_inc(&priv->rx_packets);
104641 - atomic_long_add(data_len, &priv->rx_bytes);
104642 + atomic_long_inc_unchecked(&priv->rx_packets);
104643 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104644 } else {
104645 - atomic_long_inc(&priv->rx_errors);
104646 + atomic_long_inc_unchecked(&priv->rx_errors);
104647 }
104648 return;
104649
104650 error:
104651 - atomic_long_inc(&priv->rx_errors);
104652 + atomic_long_inc_unchecked(&priv->rx_errors);
104653 kfree_skb(skb);
104654 }
104655
104656 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104657 index 1a3c7e0..80f8b0c 100644
104658 --- a/net/llc/llc_proc.c
104659 +++ b/net/llc/llc_proc.c
104660 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104661 int rc = -ENOMEM;
104662 struct proc_dir_entry *p;
104663
104664 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104665 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104666 if (!llc_proc_dir)
104667 goto out;
104668
104669 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104670 index 927b4ea..88a30e2 100644
104671 --- a/net/mac80211/cfg.c
104672 +++ b/net/mac80211/cfg.c
104673 @@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104674 ret = ieee80211_vif_use_channel(sdata, chandef,
104675 IEEE80211_CHANCTX_EXCLUSIVE);
104676 }
104677 - } else if (local->open_count == local->monitors) {
104678 + } else if (local_read(&local->open_count) == local->monitors) {
104679 local->_oper_chandef = *chandef;
104680 ieee80211_hw_config(local, 0);
104681 }
104682 @@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104683 else
104684 local->probe_req_reg--;
104685
104686 - if (!local->open_count)
104687 + if (!local_read(&local->open_count))
104688 break;
104689
104690 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104691 @@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104692 if (chanctx_conf) {
104693 *chandef = chanctx_conf->def;
104694 ret = 0;
104695 - } else if (local->open_count > 0 &&
104696 - local->open_count == local->monitors &&
104697 + } else if (local_read(&local->open_count) > 0 &&
104698 + local_read(&local->open_count) == local->monitors &&
104699 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104700 if (local->use_chanctx)
104701 *chandef = local->monitor_chandef;
104702 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104703 index ef7a089..fe1caf7 100644
104704 --- a/net/mac80211/ieee80211_i.h
104705 +++ b/net/mac80211/ieee80211_i.h
104706 @@ -28,6 +28,7 @@
104707 #include <net/ieee80211_radiotap.h>
104708 #include <net/cfg80211.h>
104709 #include <net/mac80211.h>
104710 +#include <asm/local.h>
104711 #include "key.h"
104712 #include "sta_info.h"
104713 #include "debug.h"
104714 @@ -1055,7 +1056,7 @@ struct ieee80211_local {
104715 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104716 spinlock_t queue_stop_reason_lock;
104717
104718 - int open_count;
104719 + local_t open_count;
104720 int monitors, cooked_mntrs;
104721 /* number of interfaces with corresponding FIF_ flags */
104722 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104723 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104724 index f75e5f1..3d9ad4f 100644
104725 --- a/net/mac80211/iface.c
104726 +++ b/net/mac80211/iface.c
104727 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104728 break;
104729 }
104730
104731 - if (local->open_count == 0) {
104732 + if (local_read(&local->open_count) == 0) {
104733 res = drv_start(local);
104734 if (res)
104735 goto err_del_bss;
104736 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104737 res = drv_add_interface(local, sdata);
104738 if (res)
104739 goto err_stop;
104740 - } else if (local->monitors == 0 && local->open_count == 0) {
104741 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104742 res = ieee80211_add_virtual_monitor(local);
104743 if (res)
104744 goto err_stop;
104745 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104746 atomic_inc(&local->iff_promiscs);
104747
104748 if (coming_up)
104749 - local->open_count++;
104750 + local_inc(&local->open_count);
104751
104752 if (hw_reconf_flags)
104753 ieee80211_hw_config(local, hw_reconf_flags);
104754 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104755 err_del_interface:
104756 drv_remove_interface(local, sdata);
104757 err_stop:
104758 - if (!local->open_count)
104759 + if (!local_read(&local->open_count))
104760 drv_stop(local);
104761 err_del_bss:
104762 sdata->bss = NULL;
104763 @@ -889,7 +889,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104764 }
104765
104766 if (going_down)
104767 - local->open_count--;
104768 + local_dec(&local->open_count);
104769
104770 switch (sdata->vif.type) {
104771 case NL80211_IFTYPE_AP_VLAN:
104772 @@ -950,7 +950,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104773 }
104774 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104775
104776 - if (local->open_count == 0)
104777 + if (local_read(&local->open_count) == 0)
104778 ieee80211_clear_tx_pending(local);
104779
104780 /*
104781 @@ -990,7 +990,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104782
104783 ieee80211_recalc_ps(local, -1);
104784
104785 - if (local->open_count == 0) {
104786 + if (local_read(&local->open_count) == 0) {
104787 ieee80211_stop_device(local);
104788
104789 /* no reconfiguring after stop! */
104790 @@ -1001,7 +1001,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104791 ieee80211_configure_filter(local);
104792 ieee80211_hw_config(local, hw_reconf_flags);
104793
104794 - if (local->monitors == local->open_count)
104795 + if (local->monitors == local_read(&local->open_count))
104796 ieee80211_add_virtual_monitor(local);
104797 }
104798
104799 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104800 index e0ab432..36b7b94 100644
104801 --- a/net/mac80211/main.c
104802 +++ b/net/mac80211/main.c
104803 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104804 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104805 IEEE80211_CONF_CHANGE_POWER);
104806
104807 - if (changed && local->open_count) {
104808 + if (changed && local_read(&local->open_count)) {
104809 ret = drv_config(local, changed);
104810 /*
104811 * Goal:
104812 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104813 index 4c5192e..04cc0d8 100644
104814 --- a/net/mac80211/pm.c
104815 +++ b/net/mac80211/pm.c
104816 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104817 struct ieee80211_sub_if_data *sdata;
104818 struct sta_info *sta;
104819
104820 - if (!local->open_count)
104821 + if (!local_read(&local->open_count))
104822 goto suspend;
104823
104824 ieee80211_scan_cancel(local);
104825 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104826 cancel_work_sync(&local->dynamic_ps_enable_work);
104827 del_timer_sync(&local->dynamic_ps_timer);
104828
104829 - local->wowlan = wowlan && local->open_count;
104830 + local->wowlan = wowlan && local_read(&local->open_count);
104831 if (local->wowlan) {
104832 int err = drv_suspend(local, wowlan);
104833 if (err < 0) {
104834 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104835 WARN_ON(!list_empty(&local->chanctx_list));
104836
104837 /* stop hardware - this must stop RX */
104838 - if (local->open_count)
104839 + if (local_read(&local->open_count))
104840 ieee80211_stop_device(local);
104841
104842 suspend:
104843 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104844 index 8fdadfd..a4f72b8 100644
104845 --- a/net/mac80211/rate.c
104846 +++ b/net/mac80211/rate.c
104847 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104848
104849 ASSERT_RTNL();
104850
104851 - if (local->open_count)
104852 + if (local_read(&local->open_count))
104853 return -EBUSY;
104854
104855 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104856 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104857 index 725af7a..a21a20a 100644
104858 --- a/net/mac80211/util.c
104859 +++ b/net/mac80211/util.c
104860 @@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104861 }
104862 #endif
104863 /* everything else happens only if HW was up & running */
104864 - if (!local->open_count)
104865 + if (!local_read(&local->open_count))
104866 goto wake_up;
104867
104868 /*
104869 @@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104870 local->in_reconfig = false;
104871 barrier();
104872
104873 - if (local->monitors == local->open_count && local->monitors > 0)
104874 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104875 ieee80211_add_virtual_monitor(local);
104876
104877 /*
104878 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104879 index 6d77cce..36e2fc3 100644
104880 --- a/net/netfilter/Kconfig
104881 +++ b/net/netfilter/Kconfig
104882 @@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
104883
104884 To compile it as a module, choose M here. If unsure, say N.
104885
104886 +config NETFILTER_XT_MATCH_GRADM
104887 + tristate '"gradm" match support'
104888 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104889 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104890 + ---help---
104891 + The gradm match allows to match on grsecurity RBAC being enabled.
104892 + It is useful when iptables rules are applied early on bootup to
104893 + prevent connections to the machine (except from a trusted host)
104894 + while the RBAC system is disabled.
104895 +
104896 config NETFILTER_XT_MATCH_HASHLIMIT
104897 tristate '"hashlimit" match support'
104898 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104899 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104900 index fad5fdb..ba3672a 100644
104901 --- a/net/netfilter/Makefile
104902 +++ b/net/netfilter/Makefile
104903 @@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104904 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104905 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104906 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104907 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104908 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104909 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104910 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104911 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104912 index ec8114f..6b2bfba 100644
104913 --- a/net/netfilter/ipset/ip_set_core.c
104914 +++ b/net/netfilter/ipset/ip_set_core.c
104915 @@ -1921,7 +1921,7 @@ done:
104916 return ret;
104917 }
104918
104919 -static struct nf_sockopt_ops so_set __read_mostly = {
104920 +static struct nf_sockopt_ops so_set = {
104921 .pf = PF_INET,
104922 .get_optmin = SO_IP_SET,
104923 .get_optmax = SO_IP_SET + 1,
104924 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104925 index 610e19c..08d0c3f 100644
104926 --- a/net/netfilter/ipvs/ip_vs_conn.c
104927 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104928 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104929 /* Increase the refcnt counter of the dest */
104930 ip_vs_dest_hold(dest);
104931
104932 - conn_flags = atomic_read(&dest->conn_flags);
104933 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104934 if (cp->protocol != IPPROTO_UDP)
104935 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104936 flags = cp->flags;
104937 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
104938
104939 cp->control = NULL;
104940 atomic_set(&cp->n_control, 0);
104941 - atomic_set(&cp->in_pkts, 0);
104942 + atomic_set_unchecked(&cp->in_pkts, 0);
104943
104944 cp->packet_xmit = NULL;
104945 cp->app = NULL;
104946 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104947
104948 /* Don't drop the entry if its number of incoming packets is not
104949 located in [0, 8] */
104950 - i = atomic_read(&cp->in_pkts);
104951 + i = atomic_read_unchecked(&cp->in_pkts);
104952 if (i > 8 || i < 0) return 0;
104953
104954 if (!todrop_rate[i]) return 0;
104955 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104956 index 5c34e8d..0d8eb7f 100644
104957 --- a/net/netfilter/ipvs/ip_vs_core.c
104958 +++ b/net/netfilter/ipvs/ip_vs_core.c
104959 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104960 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104961 /* do not touch skb anymore */
104962
104963 - atomic_inc(&cp->in_pkts);
104964 + atomic_inc_unchecked(&cp->in_pkts);
104965 ip_vs_conn_put(cp);
104966 return ret;
104967 }
104968 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104969 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104970 pkts = sysctl_sync_threshold(ipvs);
104971 else
104972 - pkts = atomic_add_return(1, &cp->in_pkts);
104973 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104974
104975 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104976 ip_vs_sync_conn(net, cp, pkts);
104977 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104978 index fd3f444..ab28fa24 100644
104979 --- a/net/netfilter/ipvs/ip_vs_ctl.c
104980 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
104981 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104982 */
104983 ip_vs_rs_hash(ipvs, dest);
104984 }
104985 - atomic_set(&dest->conn_flags, conn_flags);
104986 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
104987
104988 /* bind the service */
104989 old_svc = rcu_dereference_protected(dest->svc, 1);
104990 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104991 * align with netns init in ip_vs_control_net_init()
104992 */
104993
104994 -static struct ctl_table vs_vars[] = {
104995 +static ctl_table_no_const vs_vars[] __read_only = {
104996 {
104997 .procname = "amemthresh",
104998 .maxlen = sizeof(int),
104999 @@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105000 " %-7s %-6d %-10d %-10d\n",
105001 &dest->addr.in6,
105002 ntohs(dest->port),
105003 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105004 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105005 atomic_read(&dest->weight),
105006 atomic_read(&dest->activeconns),
105007 atomic_read(&dest->inactconns));
105008 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105009 "%-7s %-6d %-10d %-10d\n",
105010 ntohl(dest->addr.ip),
105011 ntohs(dest->port),
105012 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105013 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105014 atomic_read(&dest->weight),
105015 atomic_read(&dest->activeconns),
105016 atomic_read(&dest->inactconns));
105017 @@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105018
105019 entry.addr = dest->addr.ip;
105020 entry.port = dest->port;
105021 - entry.conn_flags = atomic_read(&dest->conn_flags);
105022 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105023 entry.weight = atomic_read(&dest->weight);
105024 entry.u_threshold = dest->u_threshold;
105025 entry.l_threshold = dest->l_threshold;
105026 @@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105027 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105028 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105029 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105030 - (atomic_read(&dest->conn_flags) &
105031 + (atomic_read_unchecked(&dest->conn_flags) &
105032 IP_VS_CONN_F_FWD_MASK)) ||
105033 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105034 atomic_read(&dest->weight)) ||
105035 @@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105036 {
105037 int idx;
105038 struct netns_ipvs *ipvs = net_ipvs(net);
105039 - struct ctl_table *tbl;
105040 + ctl_table_no_const *tbl;
105041
105042 atomic_set(&ipvs->dropentry, 0);
105043 spin_lock_init(&ipvs->dropentry_lock);
105044 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105045 index 547ff33..c8c8117 100644
105046 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105047 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105048 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105049 * IPVS LBLC sysctl table
105050 */
105051 #ifdef CONFIG_SYSCTL
105052 -static struct ctl_table vs_vars_table[] = {
105053 +static ctl_table_no_const vs_vars_table[] __read_only = {
105054 {
105055 .procname = "lblc_expiration",
105056 .data = NULL,
105057 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105058 index 3f21a2f..a112e85 100644
105059 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105060 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105061 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105062 * IPVS LBLCR sysctl table
105063 */
105064
105065 -static struct ctl_table vs_vars_table[] = {
105066 +static ctl_table_no_const vs_vars_table[] __read_only = {
105067 {
105068 .procname = "lblcr_expiration",
105069 .data = NULL,
105070 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105071 index eadffb2..c2feeae 100644
105072 --- a/net/netfilter/ipvs/ip_vs_sync.c
105073 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105074 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105075 cp = cp->control;
105076 if (cp) {
105077 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105078 - pkts = atomic_add_return(1, &cp->in_pkts);
105079 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105080 else
105081 pkts = sysctl_sync_threshold(ipvs);
105082 ip_vs_sync_conn(net, cp->control, pkts);
105083 @@ -771,7 +771,7 @@ control:
105084 if (!cp)
105085 return;
105086 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105087 - pkts = atomic_add_return(1, &cp->in_pkts);
105088 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105089 else
105090 pkts = sysctl_sync_threshold(ipvs);
105091 goto sloop;
105092 @@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105093
105094 if (opt)
105095 memcpy(&cp->in_seq, opt, sizeof(*opt));
105096 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105097 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105098 cp->state = state;
105099 cp->old_state = cp->state;
105100 /*
105101 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105102 index 56896a4..dfe3806 100644
105103 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105104 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105105 @@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105106 else
105107 rc = NF_ACCEPT;
105108 /* do not touch skb anymore */
105109 - atomic_inc(&cp->in_pkts);
105110 + atomic_inc_unchecked(&cp->in_pkts);
105111 goto out;
105112 }
105113
105114 @@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105115 else
105116 rc = NF_ACCEPT;
105117 /* do not touch skb anymore */
105118 - atomic_inc(&cp->in_pkts);
105119 + atomic_inc_unchecked(&cp->in_pkts);
105120 goto out;
105121 }
105122
105123 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105124 index a4b5e2a..13b1de3 100644
105125 --- a/net/netfilter/nf_conntrack_acct.c
105126 +++ b/net/netfilter/nf_conntrack_acct.c
105127 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105128 #ifdef CONFIG_SYSCTL
105129 static int nf_conntrack_acct_init_sysctl(struct net *net)
105130 {
105131 - struct ctl_table *table;
105132 + ctl_table_no_const *table;
105133
105134 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105135 GFP_KERNEL);
105136 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105137 index de88c4a..ec84234 100644
105138 --- a/net/netfilter/nf_conntrack_core.c
105139 +++ b/net/netfilter/nf_conntrack_core.c
105140 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105141 #define DYING_NULLS_VAL ((1<<30)+1)
105142 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105143
105144 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105145 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105146 +#endif
105147 +
105148 int nf_conntrack_init_net(struct net *net)
105149 {
105150 int ret = -ENOMEM;
105151 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
105152 if (!net->ct.stat)
105153 goto err_pcpu_lists;
105154
105155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105156 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105157 +#else
105158 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105159 +#endif
105160 if (!net->ct.slabname)
105161 goto err_slabname;
105162
105163 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105164 index 4e78c57..ec8fb74 100644
105165 --- a/net/netfilter/nf_conntrack_ecache.c
105166 +++ b/net/netfilter/nf_conntrack_ecache.c
105167 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105168 #ifdef CONFIG_SYSCTL
105169 static int nf_conntrack_event_init_sysctl(struct net *net)
105170 {
105171 - struct ctl_table *table;
105172 + ctl_table_no_const *table;
105173
105174 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105175 GFP_KERNEL);
105176 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105177 index 5b3eae7..dd4b8fe 100644
105178 --- a/net/netfilter/nf_conntrack_helper.c
105179 +++ b/net/netfilter/nf_conntrack_helper.c
105180 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105181
105182 static int nf_conntrack_helper_init_sysctl(struct net *net)
105183 {
105184 - struct ctl_table *table;
105185 + ctl_table_no_const *table;
105186
105187 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105188 GFP_KERNEL);
105189 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105190 index b65d586..beec902 100644
105191 --- a/net/netfilter/nf_conntrack_proto.c
105192 +++ b/net/netfilter/nf_conntrack_proto.c
105193 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105194
105195 static void
105196 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105197 - struct ctl_table **table,
105198 + ctl_table_no_const **table,
105199 unsigned int users)
105200 {
105201 if (users > 0)
105202 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105203 index f641751..d3c5b51 100644
105204 --- a/net/netfilter/nf_conntrack_standalone.c
105205 +++ b/net/netfilter/nf_conntrack_standalone.c
105206 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105207
105208 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105209 {
105210 - struct ctl_table *table;
105211 + ctl_table_no_const *table;
105212
105213 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105214 GFP_KERNEL);
105215 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105216 index 7a394df..bd91a8a 100644
105217 --- a/net/netfilter/nf_conntrack_timestamp.c
105218 +++ b/net/netfilter/nf_conntrack_timestamp.c
105219 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105220 #ifdef CONFIG_SYSCTL
105221 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105222 {
105223 - struct ctl_table *table;
105224 + ctl_table_no_const *table;
105225
105226 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105227 GFP_KERNEL);
105228 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105229 index daad602..384be13 100644
105230 --- a/net/netfilter/nf_log.c
105231 +++ b/net/netfilter/nf_log.c
105232 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105233
105234 #ifdef CONFIG_SYSCTL
105235 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105236 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105237 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105238
105239 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105240 void __user *buffer, size_t *lenp, loff_t *ppos)
105241 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105242 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105243 mutex_unlock(&nf_log_mutex);
105244 } else {
105245 + ctl_table_no_const nf_log_table = *table;
105246 +
105247 mutex_lock(&nf_log_mutex);
105248 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105249 lockdep_is_held(&nf_log_mutex));
105250 if (!logger)
105251 - table->data = "NONE";
105252 + nf_log_table.data = "NONE";
105253 else
105254 - table->data = logger->name;
105255 - r = proc_dostring(table, write, buffer, lenp, ppos);
105256 + nf_log_table.data = logger->name;
105257 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105258 mutex_unlock(&nf_log_mutex);
105259 }
105260
105261 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105262 index c68c1e5..8b5d670 100644
105263 --- a/net/netfilter/nf_sockopt.c
105264 +++ b/net/netfilter/nf_sockopt.c
105265 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105266 }
105267 }
105268
105269 - list_add(&reg->list, &nf_sockopts);
105270 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105271 out:
105272 mutex_unlock(&nf_sockopt_mutex);
105273 return ret;
105274 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105275 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105276 {
105277 mutex_lock(&nf_sockopt_mutex);
105278 - list_del(&reg->list);
105279 + pax_list_del((struct list_head *)&reg->list);
105280 mutex_unlock(&nf_sockopt_mutex);
105281 }
105282 EXPORT_SYMBOL(nf_unregister_sockopt);
105283 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105284 index a11c5ff..aa413a7 100644
105285 --- a/net/netfilter/nfnetlink_log.c
105286 +++ b/net/netfilter/nfnetlink_log.c
105287 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
105288 struct nfnl_log_net {
105289 spinlock_t instances_lock;
105290 struct hlist_head instance_table[INSTANCE_BUCKETS];
105291 - atomic_t global_seq;
105292 + atomic_unchecked_t global_seq;
105293 };
105294
105295 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105296 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
105297 /* global sequence number */
105298 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105299 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105300 - htonl(atomic_inc_return(&log->global_seq))))
105301 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105302 goto nla_put_failure;
105303
105304 if (data_len) {
105305 diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
105306 index 108120f..5b169db 100644
105307 --- a/net/netfilter/nfnetlink_queue_core.c
105308 +++ b/net/netfilter/nfnetlink_queue_core.c
105309 @@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
105310 * returned by nf_queue. For instance, callers rely on -ECANCELED to
105311 * mean 'ignore this hook'.
105312 */
105313 - if (IS_ERR(segs))
105314 + if (IS_ERR_OR_NULL(segs))
105315 goto out_err;
105316 queued = 0;
105317 err = 0;
105318 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
105319 index 1840989..6895744 100644
105320 --- a/net/netfilter/nft_compat.c
105321 +++ b/net/netfilter/nft_compat.c
105322 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
105323 /* We want to reuse existing compat_to_user */
105324 old_fs = get_fs();
105325 set_fs(KERNEL_DS);
105326 - t->compat_to_user(out, in);
105327 + t->compat_to_user((void __force_user *)out, in);
105328 set_fs(old_fs);
105329 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
105330 kfree(out);
105331 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
105332 /* We want to reuse existing compat_to_user */
105333 old_fs = get_fs();
105334 set_fs(KERNEL_DS);
105335 - m->compat_to_user(out, in);
105336 + m->compat_to_user((void __force_user *)out, in);
105337 set_fs(old_fs);
105338 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
105339 kfree(out);
105340 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105341 new file mode 100644
105342 index 0000000..c566332
105343 --- /dev/null
105344 +++ b/net/netfilter/xt_gradm.c
105345 @@ -0,0 +1,51 @@
105346 +/*
105347 + * gradm match for netfilter
105348 + * Copyright © Zbigniew Krzystolik, 2010
105349 + *
105350 + * This program is free software; you can redistribute it and/or modify
105351 + * it under the terms of the GNU General Public License; either version
105352 + * 2 or 3 as published by the Free Software Foundation.
105353 + */
105354 +#include <linux/module.h>
105355 +#include <linux/moduleparam.h>
105356 +#include <linux/skbuff.h>
105357 +#include <linux/netfilter/x_tables.h>
105358 +#include <linux/grsecurity.h>
105359 +#include <linux/netfilter/xt_gradm.h>
105360 +
105361 +static bool
105362 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105363 +{
105364 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105365 + bool retval = false;
105366 + if (gr_acl_is_enabled())
105367 + retval = true;
105368 + return retval ^ info->invflags;
105369 +}
105370 +
105371 +static struct xt_match gradm_mt_reg __read_mostly = {
105372 + .name = "gradm",
105373 + .revision = 0,
105374 + .family = NFPROTO_UNSPEC,
105375 + .match = gradm_mt,
105376 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105377 + .me = THIS_MODULE,
105378 +};
105379 +
105380 +static int __init gradm_mt_init(void)
105381 +{
105382 + return xt_register_match(&gradm_mt_reg);
105383 +}
105384 +
105385 +static void __exit gradm_mt_exit(void)
105386 +{
105387 + xt_unregister_match(&gradm_mt_reg);
105388 +}
105389 +
105390 +module_init(gradm_mt_init);
105391 +module_exit(gradm_mt_exit);
105392 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105393 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105394 +MODULE_LICENSE("GPL");
105395 +MODULE_ALIAS("ipt_gradm");
105396 +MODULE_ALIAS("ip6t_gradm");
105397 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105398 index 47dc683..2e0d52c 100644
105399 --- a/net/netfilter/xt_hashlimit.c
105400 +++ b/net/netfilter/xt_hashlimit.c
105401 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105402 {
105403 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105404
105405 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105406 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105407 if (!hashlimit_net->ipt_hashlimit)
105408 return -ENOMEM;
105409 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105410 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105411 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105412 if (!hashlimit_net->ip6t_hashlimit) {
105413 remove_proc_entry("ipt_hashlimit", net->proc_net);
105414 return -ENOMEM;
105415 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105416 index a9faae8..1ea30e0 100644
105417 --- a/net/netfilter/xt_recent.c
105418 +++ b/net/netfilter/xt_recent.c
105419 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105420 {
105421 struct recent_net *recent_net = recent_pernet(net);
105422
105423 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105424 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105425 if (!recent_net->xt_recent)
105426 return -ENOMEM;
105427 return 0;
105428 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105429 index 11de55e..f25e448 100644
105430 --- a/net/netfilter/xt_statistic.c
105431 +++ b/net/netfilter/xt_statistic.c
105432 @@ -19,7 +19,7 @@
105433 #include <linux/module.h>
105434
105435 struct xt_statistic_priv {
105436 - atomic_t count;
105437 + atomic_unchecked_t count;
105438 } ____cacheline_aligned_in_smp;
105439
105440 MODULE_LICENSE("GPL");
105441 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105442 break;
105443 case XT_STATISTIC_MODE_NTH:
105444 do {
105445 - oval = atomic_read(&info->master->count);
105446 + oval = atomic_read_unchecked(&info->master->count);
105447 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105448 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105449 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105450 if (nval == 0)
105451 ret = !ret;
105452 break;
105453 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105454 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105455 if (info->master == NULL)
105456 return -ENOMEM;
105457 - atomic_set(&info->master->count, info->u.nth.count);
105458 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105459
105460 return 0;
105461 }
105462 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105463 index c416725..bd22eea 100644
105464 --- a/net/netlink/af_netlink.c
105465 +++ b/net/netlink/af_netlink.c
105466 @@ -265,7 +265,7 @@ static void netlink_overrun(struct sock *sk)
105467 sk->sk_error_report(sk);
105468 }
105469 }
105470 - atomic_inc(&sk->sk_drops);
105471 + atomic_inc_unchecked(&sk->sk_drops);
105472 }
105473
105474 static void netlink_rcv_wake(struct sock *sk)
105475 @@ -715,7 +715,7 @@ static int netlink_mmap_sendmsg(struct sock *sk, struct msghdr *msg,
105476 * after validation, the socket and the ring may only be used by a
105477 * single process, otherwise we fall back to copying.
105478 */
105479 - if (atomic_long_read(&sk->sk_socket->file->f_count) > 2 ||
105480 + if (atomic_long_read(&sk->sk_socket->file->f_count) > 1 ||
105481 atomic_read(&nlk->mapped) > 1)
105482 excl = false;
105483
105484 @@ -2996,7 +2996,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105485 sk_wmem_alloc_get(s),
105486 nlk->cb_running,
105487 atomic_read(&s->sk_refcnt),
105488 - atomic_read(&s->sk_drops),
105489 + atomic_read_unchecked(&s->sk_drops),
105490 sock_i_ino(s)
105491 );
105492
105493 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
105494 index 64dc864..7a9e2a4 100644
105495 --- a/net/openvswitch/datapath.c
105496 +++ b/net/openvswitch/datapath.c
105497 @@ -332,6 +332,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
105498 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
105499 if (IS_ERR(segs))
105500 return PTR_ERR(segs);
105501 + if (segs == NULL)
105502 + return -EINVAL;
105503
105504 /* Queue all of the segments. */
105505 skb = segs;
105506 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105507 index 93896d2..b701c88 100644
105508 --- a/net/packet/af_packet.c
105509 +++ b/net/packet/af_packet.c
105510 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105511
105512 return ret;
105513 drop:
105514 - atomic_long_inc(&dev->tx_dropped);
105515 + atomic_long_inc_unchecked(&dev->tx_dropped);
105516 kfree_skb(skb);
105517 return NET_XMIT_DROP;
105518 }
105519 @@ -1842,7 +1842,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105520
105521 spin_lock(&sk->sk_receive_queue.lock);
105522 po->stats.stats1.tp_packets++;
105523 - skb->dropcount = atomic_read(&sk->sk_drops);
105524 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105525 __skb_queue_tail(&sk->sk_receive_queue, skb);
105526 spin_unlock(&sk->sk_receive_queue.lock);
105527 sk->sk_data_ready(sk);
105528 @@ -1851,7 +1851,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105529 drop_n_acct:
105530 spin_lock(&sk->sk_receive_queue.lock);
105531 po->stats.stats1.tp_drops++;
105532 - atomic_inc(&sk->sk_drops);
105533 + atomic_inc_unchecked(&sk->sk_drops);
105534 spin_unlock(&sk->sk_receive_queue.lock);
105535
105536 drop_n_restore:
105537 @@ -3466,7 +3466,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105538 case PACKET_HDRLEN:
105539 if (len > sizeof(int))
105540 len = sizeof(int);
105541 - if (copy_from_user(&val, optval, len))
105542 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105543 return -EFAULT;
105544 switch (val) {
105545 case TPACKET_V1:
105546 @@ -3512,7 +3512,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105547 len = lv;
105548 if (put_user(len, optlen))
105549 return -EFAULT;
105550 - if (copy_to_user(optval, data, len))
105551 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105552 return -EFAULT;
105553 return 0;
105554 }
105555 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105556 index 70a547e..23477fe 100644
105557 --- a/net/phonet/pep.c
105558 +++ b/net/phonet/pep.c
105559 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105560
105561 case PNS_PEP_CTRL_REQ:
105562 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105563 - atomic_inc(&sk->sk_drops);
105564 + atomic_inc_unchecked(&sk->sk_drops);
105565 break;
105566 }
105567 __skb_pull(skb, 4);
105568 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105569 }
105570
105571 if (pn->rx_credits == 0) {
105572 - atomic_inc(&sk->sk_drops);
105573 + atomic_inc_unchecked(&sk->sk_drops);
105574 err = -ENOBUFS;
105575 break;
105576 }
105577 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105578 }
105579
105580 if (pn->rx_credits == 0) {
105581 - atomic_inc(&sk->sk_drops);
105582 + atomic_inc_unchecked(&sk->sk_drops);
105583 err = NET_RX_DROP;
105584 break;
105585 }
105586 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105587 index 008214a..bb68240 100644
105588 --- a/net/phonet/socket.c
105589 +++ b/net/phonet/socket.c
105590 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105591 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105592 sock_i_ino(sk),
105593 atomic_read(&sk->sk_refcnt), sk,
105594 - atomic_read(&sk->sk_drops));
105595 + atomic_read_unchecked(&sk->sk_drops));
105596 }
105597 seq_pad(seq, '\n');
105598 return 0;
105599 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105600 index c02a8c4..3c5b600 100644
105601 --- a/net/phonet/sysctl.c
105602 +++ b/net/phonet/sysctl.c
105603 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105604 {
105605 int ret;
105606 int range[2] = {local_port_range[0], local_port_range[1]};
105607 - struct ctl_table tmp = {
105608 + ctl_table_no_const tmp = {
105609 .data = &range,
105610 .maxlen = sizeof(range),
105611 .mode = table->mode,
105612 diff --git a/net/rds/cong.c b/net/rds/cong.c
105613 index e5b65ac..f3b6fb7 100644
105614 --- a/net/rds/cong.c
105615 +++ b/net/rds/cong.c
105616 @@ -78,7 +78,7 @@
105617 * finds that the saved generation number is smaller than the global generation
105618 * number, it wakes up the process.
105619 */
105620 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105621 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105622
105623 /*
105624 * Congestion monitoring
105625 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105626 rdsdebug("waking map %p for %pI4\n",
105627 map, &map->m_addr);
105628 rds_stats_inc(s_cong_update_received);
105629 - atomic_inc(&rds_cong_generation);
105630 + atomic_inc_unchecked(&rds_cong_generation);
105631 if (waitqueue_active(&map->m_waitq))
105632 wake_up(&map->m_waitq);
105633 if (waitqueue_active(&rds_poll_waitq))
105634 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105635
105636 int rds_cong_updated_since(unsigned long *recent)
105637 {
105638 - unsigned long gen = atomic_read(&rds_cong_generation);
105639 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105640
105641 if (likely(*recent == gen))
105642 return 0;
105643 diff --git a/net/rds/ib.h b/net/rds/ib.h
105644 index 7280ab8..e04f4ea 100644
105645 --- a/net/rds/ib.h
105646 +++ b/net/rds/ib.h
105647 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105648 /* sending acks */
105649 unsigned long i_ack_flags;
105650 #ifdef KERNEL_HAS_ATOMIC64
105651 - atomic64_t i_ack_next; /* next ACK to send */
105652 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105653 #else
105654 spinlock_t i_ack_lock; /* protect i_ack_next */
105655 u64 i_ack_next; /* next ACK to send */
105656 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105657 index 31b74f5..dc1fbfa 100644
105658 --- a/net/rds/ib_cm.c
105659 +++ b/net/rds/ib_cm.c
105660 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105661 /* Clear the ACK state */
105662 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105663 #ifdef KERNEL_HAS_ATOMIC64
105664 - atomic64_set(&ic->i_ack_next, 0);
105665 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105666 #else
105667 ic->i_ack_next = 0;
105668 #endif
105669 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105670 index d67de45..73dbf51 100644
105671 --- a/net/rds/ib_recv.c
105672 +++ b/net/rds/ib_recv.c
105673 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105674 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105675 int ack_required)
105676 {
105677 - atomic64_set(&ic->i_ack_next, seq);
105678 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105679 if (ack_required) {
105680 smp_mb__before_atomic();
105681 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105682 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105683 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105684 smp_mb__after_atomic();
105685
105686 - return atomic64_read(&ic->i_ack_next);
105687 + return atomic64_read_unchecked(&ic->i_ack_next);
105688 }
105689 #endif
105690
105691 diff --git a/net/rds/iw.h b/net/rds/iw.h
105692 index 04ce3b1..48119a6 100644
105693 --- a/net/rds/iw.h
105694 +++ b/net/rds/iw.h
105695 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105696 /* sending acks */
105697 unsigned long i_ack_flags;
105698 #ifdef KERNEL_HAS_ATOMIC64
105699 - atomic64_t i_ack_next; /* next ACK to send */
105700 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105701 #else
105702 spinlock_t i_ack_lock; /* protect i_ack_next */
105703 u64 i_ack_next; /* next ACK to send */
105704 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105705 index a91e1db..cf3053f 100644
105706 --- a/net/rds/iw_cm.c
105707 +++ b/net/rds/iw_cm.c
105708 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105709 /* Clear the ACK state */
105710 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105711 #ifdef KERNEL_HAS_ATOMIC64
105712 - atomic64_set(&ic->i_ack_next, 0);
105713 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105714 #else
105715 ic->i_ack_next = 0;
105716 #endif
105717 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105718 index aa8bf67..b70133c 100644
105719 --- a/net/rds/iw_recv.c
105720 +++ b/net/rds/iw_recv.c
105721 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105722 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105723 int ack_required)
105724 {
105725 - atomic64_set(&ic->i_ack_next, seq);
105726 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105727 if (ack_required) {
105728 smp_mb__before_atomic();
105729 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105730 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105731 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105732 smp_mb__after_atomic();
105733
105734 - return atomic64_read(&ic->i_ack_next);
105735 + return atomic64_read_unchecked(&ic->i_ack_next);
105736 }
105737 #endif
105738
105739 diff --git a/net/rds/rdma.c b/net/rds/rdma.c
105740 index 4e37c1c..40084d8 100644
105741 --- a/net/rds/rdma.c
105742 +++ b/net/rds/rdma.c
105743 @@ -564,12 +564,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105744
105745 if (rs->rs_bound_addr == 0) {
105746 ret = -ENOTCONN; /* XXX not a great errno */
105747 - goto out;
105748 + goto out_ret;
105749 }
105750
105751 if (args->nr_local > UIO_MAXIOV) {
105752 ret = -EMSGSIZE;
105753 - goto out;
105754 + goto out_ret;
105755 }
105756
105757 /* Check whether to allocate the iovec area */
105758 @@ -578,7 +578,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105759 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
105760 if (!iovs) {
105761 ret = -ENOMEM;
105762 - goto out;
105763 + goto out_ret;
105764 }
105765 }
105766
105767 @@ -696,6 +696,7 @@ out:
105768 if (iovs != iovstack)
105769 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
105770 kfree(pages);
105771 +out_ret:
105772 if (ret)
105773 rds_rdma_free_op(op);
105774 else
105775 diff --git a/net/rds/rds.h b/net/rds/rds.h
105776 index 48f8ffc..0ef3eec 100644
105777 --- a/net/rds/rds.h
105778 +++ b/net/rds/rds.h
105779 @@ -449,7 +449,7 @@ struct rds_transport {
105780 void (*sync_mr)(void *trans_private, int direction);
105781 void (*free_mr)(void *trans_private, int invalidate);
105782 void (*flush_mrs)(void);
105783 -};
105784 +} __do_const;
105785
105786 struct rds_sock {
105787 struct sock rs_sk;
105788 diff --git a/net/rds/send.c b/net/rds/send.c
105789 index 2371816..0a64541 100644
105790 --- a/net/rds/send.c
105791 +++ b/net/rds/send.c
105792 @@ -593,8 +593,11 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
105793 sock_put(rds_rs_to_sk(rs));
105794 }
105795 rs = rm->m_rs;
105796 - sock_hold(rds_rs_to_sk(rs));
105797 + if (rs)
105798 + sock_hold(rds_rs_to_sk(rs));
105799 }
105800 + if (!rs)
105801 + goto unlock_and_drop;
105802 spin_lock(&rs->rs_lock);
105803
105804 if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
105805 @@ -638,9 +641,6 @@ unlock_and_drop:
105806 * queue. This means that in the TCP case, the message may not have been
105807 * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
105808 * checks the RDS_MSG_HAS_ACK_SEQ bit.
105809 - *
105810 - * XXX It's not clear to me how this is safely serialized with socket
105811 - * destruction. Maybe it should bail if it sees SOCK_DEAD.
105812 */
105813 void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
105814 is_acked_func is_acked)
105815 @@ -711,6 +711,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
105816 */
105817 if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
105818 spin_unlock_irqrestore(&conn->c_lock, flags);
105819 + spin_lock_irqsave(&rm->m_rs_lock, flags);
105820 + rm->m_rs = NULL;
105821 + spin_unlock_irqrestore(&rm->m_rs_lock, flags);
105822 continue;
105823 }
105824 list_del_init(&rm->m_conn_item);
105825 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105826 index edac9ef..16bcb98 100644
105827 --- a/net/rds/tcp.c
105828 +++ b/net/rds/tcp.c
105829 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105830 int val = 1;
105831
105832 set_fs(KERNEL_DS);
105833 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105834 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105835 sizeof(val));
105836 set_fs(oldfs);
105837 }
105838 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105839 index 53b17ca..45463e7 100644
105840 --- a/net/rds/tcp_send.c
105841 +++ b/net/rds/tcp_send.c
105842 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105843
105844 oldfs = get_fs();
105845 set_fs(KERNEL_DS);
105846 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105847 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105848 sizeof(val));
105849 set_fs(oldfs);
105850 }
105851 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105852 index 7b16704..9628ec6 100644
105853 --- a/net/rxrpc/af_rxrpc.c
105854 +++ b/net/rxrpc/af_rxrpc.c
105855 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105856 __be32 rxrpc_epoch;
105857
105858 /* current debugging ID */
105859 -atomic_t rxrpc_debug_id;
105860 +atomic_unchecked_t rxrpc_debug_id;
105861
105862 /* count of skbs currently in use */
105863 atomic_t rxrpc_n_skbs;
105864 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105865 index c6be17a..2a6200a 100644
105866 --- a/net/rxrpc/ar-ack.c
105867 +++ b/net/rxrpc/ar-ack.c
105868 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105869
105870 _enter("{%d,%d,%d,%d},",
105871 call->acks_hard, call->acks_unacked,
105872 - atomic_read(&call->sequence),
105873 + atomic_read_unchecked(&call->sequence),
105874 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105875
105876 stop = 0;
105877 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105878
105879 /* each Tx packet has a new serial number */
105880 sp->hdr.serial =
105881 - htonl(atomic_inc_return(&call->conn->serial));
105882 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105883
105884 hdr = (struct rxrpc_header *) txb->head;
105885 hdr->serial = sp->hdr.serial;
105886 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
105887 */
105888 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
105889 {
105890 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
105891 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
105892 }
105893
105894 /*
105895 @@ -677,7 +677,7 @@ process_further:
105896
105897 latest = ntohl(sp->hdr.serial);
105898 hard = ntohl(ack.firstPacket);
105899 - tx = atomic_read(&call->sequence);
105900 + tx = atomic_read_unchecked(&call->sequence);
105901
105902 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105903 latest,
105904 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105905 goto maybe_reschedule;
105906
105907 send_ACK_with_skew:
105908 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105909 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105910 ntohl(ack.serial));
105911 send_ACK:
105912 mtu = call->conn->trans->peer->if_mtu;
105913 @@ -1221,7 +1221,7 @@ send_ACK:
105914 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105915 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105916
105917 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105918 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105919 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105920 ntohl(hdr.serial),
105921 ntohs(ack.maxSkew),
105922 @@ -1239,7 +1239,7 @@ send_ACK:
105923 send_message:
105924 _debug("send message");
105925
105926 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105927 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105928 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105929 send_message_2:
105930
105931 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105932 index a9e05db..194e793 100644
105933 --- a/net/rxrpc/ar-call.c
105934 +++ b/net/rxrpc/ar-call.c
105935 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105936 spin_lock_init(&call->lock);
105937 rwlock_init(&call->state_lock);
105938 atomic_set(&call->usage, 1);
105939 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105940 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105941 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105942
105943 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105944 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105945 index 6631f4f..bfdf056 100644
105946 --- a/net/rxrpc/ar-connection.c
105947 +++ b/net/rxrpc/ar-connection.c
105948 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105949 rwlock_init(&conn->lock);
105950 spin_lock_init(&conn->state_lock);
105951 atomic_set(&conn->usage, 1);
105952 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105953 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105954 conn->avail_calls = RXRPC_MAXCALLS;
105955 conn->size_align = 4;
105956 conn->header_size = sizeof(struct rxrpc_header);
105957 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105958 index e7ed43a..6afa140 100644
105959 --- a/net/rxrpc/ar-connevent.c
105960 +++ b/net/rxrpc/ar-connevent.c
105961 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105962
105963 len = iov[0].iov_len + iov[1].iov_len;
105964
105965 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105966 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105967 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
105968
105969 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105970 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
105971 index 63b21e5..330232e 100644
105972 --- a/net/rxrpc/ar-input.c
105973 +++ b/net/rxrpc/ar-input.c
105974 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
105975 /* track the latest serial number on this connection for ACK packet
105976 * information */
105977 serial = ntohl(sp->hdr.serial);
105978 - hi_serial = atomic_read(&call->conn->hi_serial);
105979 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
105980 while (serial > hi_serial)
105981 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
105982 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
105983 serial);
105984
105985 /* request ACK generation for any ACK or DATA packet that requests
105986 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
105987 index ba9fd36..9bbfe01 100644
105988 --- a/net/rxrpc/ar-internal.h
105989 +++ b/net/rxrpc/ar-internal.h
105990 @@ -272,8 +272,8 @@ struct rxrpc_connection {
105991 int error; /* error code for local abort */
105992 int debug_id; /* debug ID for printks */
105993 unsigned int call_counter; /* call ID counter */
105994 - atomic_t serial; /* packet serial number counter */
105995 - atomic_t hi_serial; /* highest serial number received */
105996 + atomic_unchecked_t serial; /* packet serial number counter */
105997 + atomic_unchecked_t hi_serial; /* highest serial number received */
105998 u8 avail_calls; /* number of calls available */
105999 u8 size_align; /* data size alignment (for security) */
106000 u8 header_size; /* rxrpc + security header size */
106001 @@ -346,7 +346,7 @@ struct rxrpc_call {
106002 spinlock_t lock;
106003 rwlock_t state_lock; /* lock for state transition */
106004 atomic_t usage;
106005 - atomic_t sequence; /* Tx data packet sequence counter */
106006 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106007 u32 abort_code; /* local/remote abort code */
106008 enum { /* current state of call */
106009 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106010 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106011 */
106012 extern atomic_t rxrpc_n_skbs;
106013 extern __be32 rxrpc_epoch;
106014 -extern atomic_t rxrpc_debug_id;
106015 +extern atomic_unchecked_t rxrpc_debug_id;
106016 extern struct workqueue_struct *rxrpc_workqueue;
106017
106018 /*
106019 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106020 index 87f7135..74d3703 100644
106021 --- a/net/rxrpc/ar-local.c
106022 +++ b/net/rxrpc/ar-local.c
106023 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106024 spin_lock_init(&local->lock);
106025 rwlock_init(&local->services_lock);
106026 atomic_set(&local->usage, 1);
106027 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106028 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106029 memcpy(&local->srx, srx, sizeof(*srx));
106030 }
106031
106032 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106033 index 0b4b9a7..966ffbb 100644
106034 --- a/net/rxrpc/ar-output.c
106035 +++ b/net/rxrpc/ar-output.c
106036 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106037 memset(skb_put(skb, pad), 0, pad);
106038 }
106039
106040 - seq = atomic_inc_return(&call->sequence);
106041 + seq = atomic_inc_return_unchecked(&call->sequence);
106042
106043 sp->hdr.epoch = conn->epoch;
106044 sp->hdr.cid = call->cid;
106045 sp->hdr.callNumber = call->call_id;
106046 sp->hdr.seq = htonl(seq);
106047 sp->hdr.serial =
106048 - htonl(atomic_inc_return(&conn->serial));
106049 + htonl(atomic_inc_return_unchecked(&conn->serial));
106050 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106051 sp->hdr.userStatus = 0;
106052 sp->hdr.securityIndex = conn->security_ix;
106053 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106054 index bebaa43..2644591 100644
106055 --- a/net/rxrpc/ar-peer.c
106056 +++ b/net/rxrpc/ar-peer.c
106057 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106058 INIT_LIST_HEAD(&peer->error_targets);
106059 spin_lock_init(&peer->lock);
106060 atomic_set(&peer->usage, 1);
106061 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106062 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106063 memcpy(&peer->srx, srx, sizeof(*srx));
106064
106065 rxrpc_assess_MTU_size(peer);
106066 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106067 index 38047f7..9f48511 100644
106068 --- a/net/rxrpc/ar-proc.c
106069 +++ b/net/rxrpc/ar-proc.c
106070 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106071 atomic_read(&conn->usage),
106072 rxrpc_conn_states[conn->state],
106073 key_serial(conn->key),
106074 - atomic_read(&conn->serial),
106075 - atomic_read(&conn->hi_serial));
106076 + atomic_read_unchecked(&conn->serial),
106077 + atomic_read_unchecked(&conn->hi_serial));
106078
106079 return 0;
106080 }
106081 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106082 index 1976dec..aa70be5 100644
106083 --- a/net/rxrpc/ar-transport.c
106084 +++ b/net/rxrpc/ar-transport.c
106085 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106086 spin_lock_init(&trans->client_lock);
106087 rwlock_init(&trans->conn_lock);
106088 atomic_set(&trans->usage, 1);
106089 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106090 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106091
106092 if (peer->srx.transport.family == AF_INET) {
106093 switch (peer->srx.transport_type) {
106094 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106095 index f226709..0e735a8 100644
106096 --- a/net/rxrpc/rxkad.c
106097 +++ b/net/rxrpc/rxkad.c
106098 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106099
106100 len = iov[0].iov_len + iov[1].iov_len;
106101
106102 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106103 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106104 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106105
106106 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106107 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106108
106109 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106110
106111 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106112 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106113 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106114
106115 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106116 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106117 index fc04fe9..8167357 100644
106118 --- a/net/sched/sch_generic.c
106119 +++ b/net/sched/sch_generic.c
106120 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
106121 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106122 if (dev->reg_state == NETREG_UNINITIALIZED)
106123 return;
106124 - atomic_inc(&dev->carrier_changes);
106125 + atomic_inc_unchecked(&dev->carrier_changes);
106126 linkwatch_fire_event(dev);
106127 if (netif_running(dev))
106128 __netdev_watchdog_up(dev);
106129 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
106130 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106131 if (dev->reg_state == NETREG_UNINITIALIZED)
106132 return;
106133 - atomic_inc(&dev->carrier_changes);
106134 + atomic_inc_unchecked(&dev->carrier_changes);
106135 linkwatch_fire_event(dev);
106136 }
106137 }
106138 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106139 index 0e4198e..f94193e 100644
106140 --- a/net/sctp/ipv6.c
106141 +++ b/net/sctp/ipv6.c
106142 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106143 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106144 };
106145
106146 -static struct sctp_af sctp_af_inet6 = {
106147 +static struct sctp_af sctp_af_inet6 __read_only = {
106148 .sa_family = AF_INET6,
106149 .sctp_xmit = sctp_v6_xmit,
106150 .setsockopt = ipv6_setsockopt,
106151 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106152 #endif
106153 };
106154
106155 -static struct sctp_pf sctp_pf_inet6 = {
106156 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106157 .event_msgname = sctp_inet6_event_msgname,
106158 .skb_msgname = sctp_inet6_skb_msgname,
106159 .af_supported = sctp_inet6_af_supported,
106160 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106161
106162 void sctp_v6_pf_exit(void)
106163 {
106164 - list_del(&sctp_af_inet6.list);
106165 + pax_list_del(&sctp_af_inet6.list);
106166 }
106167
106168 /* Initialize IPv6 support and register with socket layer. */
106169 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106170 index 6240834..cac4b52 100644
106171 --- a/net/sctp/protocol.c
106172 +++ b/net/sctp/protocol.c
106173 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106174 return 0;
106175 }
106176
106177 + pax_open_kernel();
106178 INIT_LIST_HEAD(&af->list);
106179 - list_add_tail(&af->list, &sctp_address_families);
106180 + pax_close_kernel();
106181 + pax_list_add_tail(&af->list, &sctp_address_families);
106182 return 1;
106183 }
106184
106185 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106186
106187 static struct sctp_af sctp_af_inet;
106188
106189 -static struct sctp_pf sctp_pf_inet = {
106190 +static struct sctp_pf sctp_pf_inet __read_only = {
106191 .event_msgname = sctp_inet_event_msgname,
106192 .skb_msgname = sctp_inet_skb_msgname,
106193 .af_supported = sctp_inet_af_supported,
106194 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106195 };
106196
106197 /* IPv4 address related functions. */
106198 -static struct sctp_af sctp_af_inet = {
106199 +static struct sctp_af sctp_af_inet __read_only = {
106200 .sa_family = AF_INET,
106201 .sctp_xmit = sctp_v4_xmit,
106202 .setsockopt = ip_setsockopt,
106203 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106204
106205 static void sctp_v4_pf_exit(void)
106206 {
106207 - list_del(&sctp_af_inet.list);
106208 + pax_list_del(&sctp_af_inet.list);
106209 }
106210
106211 static int sctp_v4_protosw_init(void)
106212 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106213 index fef2acd..c705c4f 100644
106214 --- a/net/sctp/sm_sideeffect.c
106215 +++ b/net/sctp/sm_sideeffect.c
106216 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106217 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106218 }
106219
106220 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106221 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106222 NULL,
106223 sctp_generate_t1_cookie_event,
106224 sctp_generate_t1_init_event,
106225 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106226 index 634a2ab..8e93929 100644
106227 --- a/net/sctp/socket.c
106228 +++ b/net/sctp/socket.c
106229 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106230 {
106231 struct sctp_association *asoc;
106232 struct sctp_ulpevent *event;
106233 + struct sctp_event_subscribe subscribe;
106234
106235 if (optlen > sizeof(struct sctp_event_subscribe))
106236 return -EINVAL;
106237 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106238 + if (copy_from_user(&subscribe, optval, optlen))
106239 return -EFAULT;
106240 + sctp_sk(sk)->subscribe = subscribe;
106241
106242 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106243 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106244 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106245 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106246 int __user *optlen)
106247 {
106248 + struct sctp_event_subscribe subscribe;
106249 +
106250 if (len <= 0)
106251 return -EINVAL;
106252 if (len > sizeof(struct sctp_event_subscribe))
106253 len = sizeof(struct sctp_event_subscribe);
106254 if (put_user(len, optlen))
106255 return -EFAULT;
106256 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106257 + subscribe = sctp_sk(sk)->subscribe;
106258 + if (copy_to_user(optval, &subscribe, len))
106259 return -EFAULT;
106260 return 0;
106261 }
106262 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106263 */
106264 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106265 {
106266 + __u32 autoclose;
106267 +
106268 /* Applicable to UDP-style socket only */
106269 if (sctp_style(sk, TCP))
106270 return -EOPNOTSUPP;
106271 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106272 len = sizeof(int);
106273 if (put_user(len, optlen))
106274 return -EFAULT;
106275 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106276 + autoclose = sctp_sk(sk)->autoclose;
106277 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106278 return -EFAULT;
106279 return 0;
106280 }
106281 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106282 */
106283 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106284 {
106285 + struct sctp_initmsg initmsg;
106286 +
106287 if (len < sizeof(struct sctp_initmsg))
106288 return -EINVAL;
106289 len = sizeof(struct sctp_initmsg);
106290 if (put_user(len, optlen))
106291 return -EFAULT;
106292 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106293 + initmsg = sctp_sk(sk)->initmsg;
106294 + if (copy_to_user(optval, &initmsg, len))
106295 return -EFAULT;
106296 return 0;
106297 }
106298 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106299 ->addr_to_user(sp, &temp);
106300 if (space_left < addrlen)
106301 return -ENOMEM;
106302 + if (addrlen > sizeof(temp) || addrlen < 0)
106303 + return -EFAULT;
106304 if (copy_to_user(to, &temp, addrlen))
106305 return -EFAULT;
106306 to += addrlen;
106307 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106308 index 2e9ada1..40f425d 100644
106309 --- a/net/sctp/sysctl.c
106310 +++ b/net/sctp/sysctl.c
106311 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106312 loff_t *ppos)
106313 {
106314 struct net *net = current->nsproxy->net_ns;
106315 - struct ctl_table tbl;
106316 + ctl_table_no_const tbl;
106317 bool changed = false;
106318 char *none = "none";
106319 char tmp[8];
106320 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106321 struct net *net = current->nsproxy->net_ns;
106322 unsigned int min = *(unsigned int *) ctl->extra1;
106323 unsigned int max = *(unsigned int *) ctl->extra2;
106324 - struct ctl_table tbl;
106325 + ctl_table_no_const tbl;
106326 int ret, new_value;
106327
106328 memset(&tbl, 0, sizeof(struct ctl_table));
106329 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106330 struct net *net = current->nsproxy->net_ns;
106331 unsigned int min = *(unsigned int *) ctl->extra1;
106332 unsigned int max = *(unsigned int *) ctl->extra2;
106333 - struct ctl_table tbl;
106334 + ctl_table_no_const tbl;
106335 int ret, new_value;
106336
106337 memset(&tbl, 0, sizeof(struct ctl_table));
106338 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106339 loff_t *ppos)
106340 {
106341 struct net *net = current->nsproxy->net_ns;
106342 - struct ctl_table tbl;
106343 + ctl_table_no_const tbl;
106344 int new_value, ret;
106345
106346 memset(&tbl, 0, sizeof(struct ctl_table));
106347 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106348
106349 int sctp_sysctl_net_register(struct net *net)
106350 {
106351 - struct ctl_table *table;
106352 + ctl_table_no_const *table;
106353 int i;
106354
106355 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106356 diff --git a/net/socket.c b/net/socket.c
106357 index 4cdbc10..f075204 100644
106358 --- a/net/socket.c
106359 +++ b/net/socket.c
106360 @@ -89,6 +89,7 @@
106361 #include <linux/magic.h>
106362 #include <linux/slab.h>
106363 #include <linux/xattr.h>
106364 +#include <linux/in.h>
106365
106366 #include <asm/uaccess.h>
106367 #include <asm/unistd.h>
106368 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106369 unsigned int sysctl_net_busy_poll __read_mostly;
106370 #endif
106371
106372 +#include <linux/grsock.h>
106373 +
106374 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106375 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106376 unsigned long nr_segs, loff_t pos);
106377 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106378 */
106379
106380 static DEFINE_SPINLOCK(net_family_lock);
106381 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106382 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106383
106384 /*
106385 * Statistics counters of the socket lists
106386 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106387 &sockfs_dentry_operations, SOCKFS_MAGIC);
106388 }
106389
106390 -static struct vfsmount *sock_mnt __read_mostly;
106391 +struct vfsmount *sock_mnt __read_mostly;
106392
106393 static struct file_system_type sock_fs_type = {
106394 .name = "sockfs",
106395 @@ -1265,6 +1268,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106396 return -EAFNOSUPPORT;
106397 if (type < 0 || type >= SOCK_MAX)
106398 return -EINVAL;
106399 + if (protocol < 0)
106400 + return -EINVAL;
106401
106402 /* Compatibility.
106403
106404 @@ -1285,6 +1290,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106405 if (err)
106406 return err;
106407
106408 + if(!kern && !gr_search_socket(family, type, protocol)) {
106409 + if (rcu_access_pointer(net_families[family]) == NULL)
106410 + return -EAFNOSUPPORT;
106411 + else
106412 + return -EACCES;
106413 + }
106414 +
106415 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106416 + if (rcu_access_pointer(net_families[family]) == NULL)
106417 + return -EAFNOSUPPORT;
106418 + else
106419 + return -EACCES;
106420 + }
106421 +
106422 /*
106423 * Allocate the socket and allow the family to set things up. if
106424 * the protocol is 0, the family is instructed to select an appropriate
106425 @@ -1536,6 +1555,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106426 if (sock) {
106427 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106428 if (err >= 0) {
106429 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106430 + err = -EACCES;
106431 + goto error;
106432 + }
106433 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106434 + if (err)
106435 + goto error;
106436 +
106437 err = security_socket_bind(sock,
106438 (struct sockaddr *)&address,
106439 addrlen);
106440 @@ -1544,6 +1571,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106441 (struct sockaddr *)
106442 &address, addrlen);
106443 }
106444 +error:
106445 fput_light(sock->file, fput_needed);
106446 }
106447 return err;
106448 @@ -1567,10 +1595,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106449 if ((unsigned int)backlog > somaxconn)
106450 backlog = somaxconn;
106451
106452 + if (gr_handle_sock_server_other(sock->sk)) {
106453 + err = -EPERM;
106454 + goto error;
106455 + }
106456 +
106457 + err = gr_search_listen(sock);
106458 + if (err)
106459 + goto error;
106460 +
106461 err = security_socket_listen(sock, backlog);
106462 if (!err)
106463 err = sock->ops->listen(sock, backlog);
106464
106465 +error:
106466 fput_light(sock->file, fput_needed);
106467 }
106468 return err;
106469 @@ -1614,6 +1652,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106470 newsock->type = sock->type;
106471 newsock->ops = sock->ops;
106472
106473 + if (gr_handle_sock_server_other(sock->sk)) {
106474 + err = -EPERM;
106475 + sock_release(newsock);
106476 + goto out_put;
106477 + }
106478 +
106479 + err = gr_search_accept(sock);
106480 + if (err) {
106481 + sock_release(newsock);
106482 + goto out_put;
106483 + }
106484 +
106485 /*
106486 * We don't need try_module_get here, as the listening socket (sock)
106487 * has the protocol module (sock->ops->owner) held.
106488 @@ -1659,6 +1709,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106489 fd_install(newfd, newfile);
106490 err = newfd;
106491
106492 + gr_attach_curr_ip(newsock->sk);
106493 +
106494 out_put:
106495 fput_light(sock->file, fput_needed);
106496 out:
106497 @@ -1691,6 +1743,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106498 int, addrlen)
106499 {
106500 struct socket *sock;
106501 + struct sockaddr *sck;
106502 struct sockaddr_storage address;
106503 int err, fput_needed;
106504
106505 @@ -1701,6 +1754,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106506 if (err < 0)
106507 goto out_put;
106508
106509 + sck = (struct sockaddr *)&address;
106510 +
106511 + if (gr_handle_sock_client(sck)) {
106512 + err = -EACCES;
106513 + goto out_put;
106514 + }
106515 +
106516 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106517 + if (err)
106518 + goto out_put;
106519 +
106520 err =
106521 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106522 if (err)
106523 @@ -1782,6 +1846,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106524 * the protocol.
106525 */
106526
106527 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106528 +
106529 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106530 unsigned int, flags, struct sockaddr __user *, addr,
106531 int, addr_len)
106532 @@ -1848,7 +1914,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106533 struct socket *sock;
106534 struct iovec iov;
106535 struct msghdr msg;
106536 - struct sockaddr_storage address;
106537 + struct sockaddr_storage address = { };
106538 int err, err2;
106539 int fput_needed;
106540
106541 @@ -2077,7 +2143,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106542 * checking falls down on this.
106543 */
106544 if (copy_from_user(ctl_buf,
106545 - (void __user __force *)msg_sys->msg_control,
106546 + (void __force_user *)msg_sys->msg_control,
106547 ctl_len))
106548 goto out_freectl;
106549 msg_sys->msg_control = ctl_buf;
106550 @@ -2228,7 +2294,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106551 int err, total_len, len;
106552
106553 /* kernel mode address */
106554 - struct sockaddr_storage addr;
106555 + struct sockaddr_storage addr = { };
106556
106557 /* user mode address pointers */
106558 struct sockaddr __user *uaddr;
106559 @@ -2257,7 +2323,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106560 /* Save the user-mode address (verify_iovec will change the
106561 * kernel msghdr to use the kernel address space)
106562 */
106563 - uaddr = (__force void __user *)msg_sys->msg_name;
106564 + uaddr = (void __force_user *)msg_sys->msg_name;
106565 uaddr_len = COMPAT_NAMELEN(msg);
106566 if (MSG_CMSG_COMPAT & flags)
106567 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106568 @@ -2898,7 +2964,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106569 ifr = compat_alloc_user_space(buf_size);
106570 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106571
106572 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106573 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106574 return -EFAULT;
106575
106576 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106577 @@ -3009,7 +3075,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106578 old_fs = get_fs();
106579 set_fs(KERNEL_DS);
106580 err = dev_ioctl(net, cmd,
106581 - (struct ifreq __user __force *) &kifr);
106582 + (struct ifreq __force_user *) &kifr);
106583 set_fs(old_fs);
106584
106585 return err;
106586 @@ -3102,7 +3168,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106587
106588 old_fs = get_fs();
106589 set_fs(KERNEL_DS);
106590 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106591 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106592 set_fs(old_fs);
106593
106594 if (cmd == SIOCGIFMAP && !err) {
106595 @@ -3186,7 +3252,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106596 ret |= get_user(rtdev, &(ur4->rt_dev));
106597 if (rtdev) {
106598 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106599 - r4.rt_dev = (char __user __force *)devname;
106600 + r4.rt_dev = (char __force_user *)devname;
106601 devname[15] = 0;
106602 } else
106603 r4.rt_dev = NULL;
106604 @@ -3413,8 +3479,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106605 int __user *uoptlen;
106606 int err;
106607
106608 - uoptval = (char __user __force *) optval;
106609 - uoptlen = (int __user __force *) optlen;
106610 + uoptval = (char __force_user *) optval;
106611 + uoptlen = (int __force_user *) optlen;
106612
106613 set_fs(KERNEL_DS);
106614 if (level == SOL_SOCKET)
106615 @@ -3434,7 +3500,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106616 char __user *uoptval;
106617 int err;
106618
106619 - uoptval = (char __user __force *) optval;
106620 + uoptval = (char __force_user *) optval;
106621
106622 set_fs(KERNEL_DS);
106623 if (level == SOL_SOCKET)
106624 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106625 index c548ab2..4e1b68b 100644
106626 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106627 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106628 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106629 uint64_t *handle)
106630 {
106631 struct rsc rsci, *rscp = NULL;
106632 - static atomic64_t ctxhctr;
106633 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106634 long long ctxh;
106635 struct gss_api_mech *gm = NULL;
106636 time_t expiry;
106637 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106638 status = -ENOMEM;
106639 /* the handle needs to be just a unique id,
106640 * use a static counter */
106641 - ctxh = atomic64_inc_return(&ctxhctr);
106642 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106643
106644 /* make a copy for the caller */
106645 *handle = ctxh;
106646 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106647 index 0663621..c4928d4 100644
106648 --- a/net/sunrpc/cache.c
106649 +++ b/net/sunrpc/cache.c
106650 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106651 struct sunrpc_net *sn;
106652
106653 sn = net_generic(net, sunrpc_net_id);
106654 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106655 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106656 if (cd->u.procfs.proc_ent == NULL)
106657 goto out_nomem;
106658 cd->u.procfs.channel_ent = NULL;
106659 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106660 index 488ddee..1b31487 100644
106661 --- a/net/sunrpc/clnt.c
106662 +++ b/net/sunrpc/clnt.c
106663 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
106664 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106665
106666 /* Increment call count */
106667 - task->tk_msg.rpc_proc->p_count++;
106668 + pax_open_kernel();
106669 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106670 + pax_close_kernel();
106671 clnt->cl_stats->rpccnt++;
106672 task->tk_action = call_reserve;
106673 }
106674 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106675 index 9358c79..22d0a5b 100644
106676 --- a/net/sunrpc/sched.c
106677 +++ b/net/sunrpc/sched.c
106678 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106679 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106680 static void rpc_task_set_debuginfo(struct rpc_task *task)
106681 {
106682 - static atomic_t rpc_pid;
106683 + static atomic_unchecked_t rpc_pid;
106684
106685 - task->tk_pid = atomic_inc_return(&rpc_pid);
106686 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106687 }
106688 #else
106689 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106690 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106691 index 5453049..465669a 100644
106692 --- a/net/sunrpc/stats.c
106693 +++ b/net/sunrpc/stats.c
106694 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106695
106696 dprintk("RPC: registering /proc/net/rpc\n");
106697 sn = net_generic(net, sunrpc_net_id);
106698 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106699 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106700 if (sn->proc_net_rpc == NULL)
106701 return -ENOMEM;
106702
106703 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106704 index 1db5007..6e66296 100644
106705 --- a/net/sunrpc/svc.c
106706 +++ b/net/sunrpc/svc.c
106707 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106708 svc_putnl(resv, RPC_SUCCESS);
106709
106710 /* Bump per-procedure stats counter */
106711 - procp->pc_count++;
106712 + pax_open_kernel();
106713 + (*(unsigned int *)&procp->pc_count)++;
106714 + pax_close_kernel();
106715
106716 /* Initialize storage for argp and resp */
106717 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106718 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106719 index 621ca7b..59421dd 100644
106720 --- a/net/sunrpc/svcauth_unix.c
106721 +++ b/net/sunrpc/svcauth_unix.c
106722 @@ -414,7 +414,7 @@ struct unix_gid {
106723 struct group_info *gi;
106724 };
106725
106726 -static int unix_gid_hash(kuid_t uid)
106727 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106728 {
106729 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106730 }
106731 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106732 (*bpp)[-1] = '\n';
106733 }
106734
106735 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106736 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106737
106738 static int unix_gid_parse(struct cache_detail *cd,
106739 char *mesg, int mlen)
106740 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106741 index c1b6270..05089c1 100644
106742 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106743 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106744 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106745 static unsigned int min_max_inline = 4096;
106746 static unsigned int max_max_inline = 65536;
106747
106748 -atomic_t rdma_stat_recv;
106749 -atomic_t rdma_stat_read;
106750 -atomic_t rdma_stat_write;
106751 -atomic_t rdma_stat_sq_starve;
106752 -atomic_t rdma_stat_rq_starve;
106753 -atomic_t rdma_stat_rq_poll;
106754 -atomic_t rdma_stat_rq_prod;
106755 -atomic_t rdma_stat_sq_poll;
106756 -atomic_t rdma_stat_sq_prod;
106757 +atomic_unchecked_t rdma_stat_recv;
106758 +atomic_unchecked_t rdma_stat_read;
106759 +atomic_unchecked_t rdma_stat_write;
106760 +atomic_unchecked_t rdma_stat_sq_starve;
106761 +atomic_unchecked_t rdma_stat_rq_starve;
106762 +atomic_unchecked_t rdma_stat_rq_poll;
106763 +atomic_unchecked_t rdma_stat_rq_prod;
106764 +atomic_unchecked_t rdma_stat_sq_poll;
106765 +atomic_unchecked_t rdma_stat_sq_prod;
106766
106767 /* Temporary NFS request map and context caches */
106768 struct kmem_cache *svc_rdma_map_cachep;
106769 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106770 len -= *ppos;
106771 if (len > *lenp)
106772 len = *lenp;
106773 - if (len && copy_to_user(buffer, str_buf, len))
106774 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106775 return -EFAULT;
106776 *lenp = len;
106777 *ppos += len;
106778 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
106779 {
106780 .procname = "rdma_stat_read",
106781 .data = &rdma_stat_read,
106782 - .maxlen = sizeof(atomic_t),
106783 + .maxlen = sizeof(atomic_unchecked_t),
106784 .mode = 0644,
106785 .proc_handler = read_reset_stat,
106786 },
106787 {
106788 .procname = "rdma_stat_recv",
106789 .data = &rdma_stat_recv,
106790 - .maxlen = sizeof(atomic_t),
106791 + .maxlen = sizeof(atomic_unchecked_t),
106792 .mode = 0644,
106793 .proc_handler = read_reset_stat,
106794 },
106795 {
106796 .procname = "rdma_stat_write",
106797 .data = &rdma_stat_write,
106798 - .maxlen = sizeof(atomic_t),
106799 + .maxlen = sizeof(atomic_unchecked_t),
106800 .mode = 0644,
106801 .proc_handler = read_reset_stat,
106802 },
106803 {
106804 .procname = "rdma_stat_sq_starve",
106805 .data = &rdma_stat_sq_starve,
106806 - .maxlen = sizeof(atomic_t),
106807 + .maxlen = sizeof(atomic_unchecked_t),
106808 .mode = 0644,
106809 .proc_handler = read_reset_stat,
106810 },
106811 {
106812 .procname = "rdma_stat_rq_starve",
106813 .data = &rdma_stat_rq_starve,
106814 - .maxlen = sizeof(atomic_t),
106815 + .maxlen = sizeof(atomic_unchecked_t),
106816 .mode = 0644,
106817 .proc_handler = read_reset_stat,
106818 },
106819 {
106820 .procname = "rdma_stat_rq_poll",
106821 .data = &rdma_stat_rq_poll,
106822 - .maxlen = sizeof(atomic_t),
106823 + .maxlen = sizeof(atomic_unchecked_t),
106824 .mode = 0644,
106825 .proc_handler = read_reset_stat,
106826 },
106827 {
106828 .procname = "rdma_stat_rq_prod",
106829 .data = &rdma_stat_rq_prod,
106830 - .maxlen = sizeof(atomic_t),
106831 + .maxlen = sizeof(atomic_unchecked_t),
106832 .mode = 0644,
106833 .proc_handler = read_reset_stat,
106834 },
106835 {
106836 .procname = "rdma_stat_sq_poll",
106837 .data = &rdma_stat_sq_poll,
106838 - .maxlen = sizeof(atomic_t),
106839 + .maxlen = sizeof(atomic_unchecked_t),
106840 .mode = 0644,
106841 .proc_handler = read_reset_stat,
106842 },
106843 {
106844 .procname = "rdma_stat_sq_prod",
106845 .data = &rdma_stat_sq_prod,
106846 - .maxlen = sizeof(atomic_t),
106847 + .maxlen = sizeof(atomic_unchecked_t),
106848 .mode = 0644,
106849 .proc_handler = read_reset_stat,
106850 },
106851 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106852 index e011027..9d3c4e1 100644
106853 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106854 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106855 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
106856 *page_no = pg_no;
106857 *page_offset = pg_off;
106858 ret = read;
106859 - atomic_inc(&rdma_stat_read);
106860 + atomic_inc_unchecked(&rdma_stat_read);
106861 return ret;
106862 err:
106863 svc_rdma_unmap_dma(ctxt);
106864 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
106865 *page_no = pg_no;
106866 *page_offset = pg_off;
106867 ret = read;
106868 - atomic_inc(&rdma_stat_read);
106869 + atomic_inc_unchecked(&rdma_stat_read);
106870 return ret;
106871 err:
106872 svc_rdma_unmap_dma(ctxt);
106873 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106874 dto_q);
106875 list_del_init(&ctxt->dto_q);
106876 } else {
106877 - atomic_inc(&rdma_stat_rq_starve);
106878 + atomic_inc_unchecked(&rdma_stat_rq_starve);
106879 clear_bit(XPT_DATA, &xprt->xpt_flags);
106880 ctxt = NULL;
106881 }
106882 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106883 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
106884 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
106885 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
106886 - atomic_inc(&rdma_stat_recv);
106887 + atomic_inc_unchecked(&rdma_stat_recv);
106888
106889 /* Build up the XDR from the receive buffers. */
106890 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
106891 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106892 index 9f1b506..2e0b321 100644
106893 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106894 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106895 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
106896 write_wr.wr.rdma.remote_addr = to;
106897
106898 /* Post It */
106899 - atomic_inc(&rdma_stat_write);
106900 + atomic_inc_unchecked(&rdma_stat_write);
106901 if (svc_rdma_send(xprt, &write_wr))
106902 goto err;
106903 return write_len - bc;
106904 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106905 index 374feb4..46487d5 100644
106906 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
106907 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106908 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106909 return;
106910
106911 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
106912 - atomic_inc(&rdma_stat_rq_poll);
106913 + atomic_inc_unchecked(&rdma_stat_rq_poll);
106914
106915 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
106916 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
106917 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106918 }
106919
106920 if (ctxt)
106921 - atomic_inc(&rdma_stat_rq_prod);
106922 + atomic_inc_unchecked(&rdma_stat_rq_prod);
106923
106924 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
106925 /*
106926 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106927 return;
106928
106929 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
106930 - atomic_inc(&rdma_stat_sq_poll);
106931 + atomic_inc_unchecked(&rdma_stat_sq_poll);
106932 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
106933 int i;
106934
106935 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106936 }
106937
106938 if (ctxt)
106939 - atomic_inc(&rdma_stat_sq_prod);
106940 + atomic_inc_unchecked(&rdma_stat_sq_prod);
106941 }
106942
106943 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
106944 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
106945 spin_lock_bh(&xprt->sc_lock);
106946 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
106947 spin_unlock_bh(&xprt->sc_lock);
106948 - atomic_inc(&rdma_stat_sq_starve);
106949 + atomic_inc_unchecked(&rdma_stat_sq_starve);
106950
106951 /* See if we can opportunistically reap SQ WR to make room */
106952 sq_cq_reap(xprt);
106953 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
106954 index e7000be..e3b0ba7 100644
106955 --- a/net/sysctl_net.c
106956 +++ b/net/sysctl_net.c
106957 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
106958 kgid_t root_gid = make_kgid(net->user_ns, 0);
106959
106960 /* Allow network administrator to have same access as root. */
106961 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
106962 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
106963 uid_eq(root_uid, current_euid())) {
106964 int mode = (table->mode >> 6) & 7;
106965 return (mode << 6) | (mode << 3) | mode;
106966 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
106967 index 6424372..afd36e9 100644
106968 --- a/net/tipc/subscr.c
106969 +++ b/net/tipc/subscr.c
106970 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
106971 struct tipc_subscriber *subscriber = sub->subscriber;
106972 struct kvec msg_sect;
106973
106974 - msg_sect.iov_base = (void *)&sub->evt;
106975 + msg_sect.iov_base = &sub->evt;
106976 msg_sect.iov_len = sizeof(struct tipc_event);
106977 sub->evt.event = htohl(event, sub->swap);
106978 sub->evt.found_lower = htohl(found_lower, sub->swap);
106979 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
106980 index e968843..bc95776 100644
106981 --- a/net/unix/af_unix.c
106982 +++ b/net/unix/af_unix.c
106983 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
106984 err = -ECONNREFUSED;
106985 if (!S_ISSOCK(inode->i_mode))
106986 goto put_fail;
106987 +
106988 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
106989 + err = -EACCES;
106990 + goto put_fail;
106991 + }
106992 +
106993 u = unix_find_socket_byinode(inode);
106994 if (!u)
106995 goto put_fail;
106996 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
106997 if (u) {
106998 struct dentry *dentry;
106999 dentry = unix_sk(u)->path.dentry;
107000 +
107001 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107002 + err = -EPERM;
107003 + sock_put(u);
107004 + goto fail;
107005 + }
107006 +
107007 if (dentry)
107008 touch_atime(&unix_sk(u)->path);
107009 } else
107010 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107011 */
107012 err = security_path_mknod(&path, dentry, mode, 0);
107013 if (!err) {
107014 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107015 + err = -EACCES;
107016 + goto out;
107017 + }
107018 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107019 if (!err) {
107020 res->mnt = mntget(path.mnt);
107021 res->dentry = dget(dentry);
107022 + gr_handle_create(dentry, path.mnt);
107023 }
107024 }
107025 +out:
107026 done_path_create(&path, dentry);
107027 return err;
107028 }
107029 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107030 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107031 "Inode Path\n");
107032 else {
107033 - struct sock *s = v;
107034 + struct sock *s = v, *peer;
107035 struct unix_sock *u = unix_sk(s);
107036 unix_state_lock(s);
107037 + peer = unix_peer(s);
107038 + unix_state_unlock(s);
107039 +
107040 + unix_state_double_lock(s, peer);
107041
107042 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107043 s,
107044 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107045 }
107046 for ( ; i < len; i++)
107047 seq_putc(seq, u->addr->name->sun_path[i]);
107048 - }
107049 - unix_state_unlock(s);
107050 + } else if (peer)
107051 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107052 +
107053 + unix_state_double_unlock(s, peer);
107054 seq_putc(seq, '\n');
107055 }
107056
107057 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107058 index b3d5150..ff3a837 100644
107059 --- a/net/unix/sysctl_net_unix.c
107060 +++ b/net/unix/sysctl_net_unix.c
107061 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107062
107063 int __net_init unix_sysctl_register(struct net *net)
107064 {
107065 - struct ctl_table *table;
107066 + ctl_table_no_const *table;
107067
107068 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107069 if (table == NULL)
107070 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107071 index 9b7f207..2596621 100644
107072 --- a/net/vmw_vsock/vmci_transport_notify.c
107073 +++ b/net/vmw_vsock/vmci_transport_notify.c
107074 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107075
107076 /* Socket control packet based operations. */
107077 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107078 - vmci_transport_notify_pkt_socket_init,
107079 - vmci_transport_notify_pkt_socket_destruct,
107080 - vmci_transport_notify_pkt_poll_in,
107081 - vmci_transport_notify_pkt_poll_out,
107082 - vmci_transport_notify_pkt_handle_pkt,
107083 - vmci_transport_notify_pkt_recv_init,
107084 - vmci_transport_notify_pkt_recv_pre_block,
107085 - vmci_transport_notify_pkt_recv_pre_dequeue,
107086 - vmci_transport_notify_pkt_recv_post_dequeue,
107087 - vmci_transport_notify_pkt_send_init,
107088 - vmci_transport_notify_pkt_send_pre_block,
107089 - vmci_transport_notify_pkt_send_pre_enqueue,
107090 - vmci_transport_notify_pkt_send_post_enqueue,
107091 - vmci_transport_notify_pkt_process_request,
107092 - vmci_transport_notify_pkt_process_negotiate,
107093 + .socket_init = vmci_transport_notify_pkt_socket_init,
107094 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107095 + .poll_in = vmci_transport_notify_pkt_poll_in,
107096 + .poll_out = vmci_transport_notify_pkt_poll_out,
107097 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107098 + .recv_init = vmci_transport_notify_pkt_recv_init,
107099 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107100 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107101 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107102 + .send_init = vmci_transport_notify_pkt_send_init,
107103 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107104 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107105 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107106 + .process_request = vmci_transport_notify_pkt_process_request,
107107 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107108 };
107109 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107110 index dc9c792..3089de0 100644
107111 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107112 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107113 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107114
107115 /* Socket always on control packet based operations. */
107116 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107117 - vmci_transport_notify_pkt_socket_init,
107118 - vmci_transport_notify_pkt_socket_destruct,
107119 - vmci_transport_notify_pkt_poll_in,
107120 - vmci_transport_notify_pkt_poll_out,
107121 - vmci_transport_notify_pkt_handle_pkt,
107122 - vmci_transport_notify_pkt_recv_init,
107123 - vmci_transport_notify_pkt_recv_pre_block,
107124 - vmci_transport_notify_pkt_recv_pre_dequeue,
107125 - vmci_transport_notify_pkt_recv_post_dequeue,
107126 - vmci_transport_notify_pkt_send_init,
107127 - vmci_transport_notify_pkt_send_pre_block,
107128 - vmci_transport_notify_pkt_send_pre_enqueue,
107129 - vmci_transport_notify_pkt_send_post_enqueue,
107130 - vmci_transport_notify_pkt_process_request,
107131 - vmci_transport_notify_pkt_process_negotiate,
107132 + .socket_init = vmci_transport_notify_pkt_socket_init,
107133 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107134 + .poll_in = vmci_transport_notify_pkt_poll_in,
107135 + .poll_out = vmci_transport_notify_pkt_poll_out,
107136 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107137 + .recv_init = vmci_transport_notify_pkt_recv_init,
107138 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107139 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107140 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107141 + .send_init = vmci_transport_notify_pkt_send_init,
107142 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107143 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107144 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107145 + .process_request = vmci_transport_notify_pkt_process_request,
107146 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107147 };
107148 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107149 index c8717c1..08539f5 100644
107150 --- a/net/wireless/wext-core.c
107151 +++ b/net/wireless/wext-core.c
107152 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107153 */
107154
107155 /* Support for very large requests */
107156 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107157 - (user_length > descr->max_tokens)) {
107158 + if (user_length > descr->max_tokens) {
107159 /* Allow userspace to GET more than max so
107160 * we can support any size GET requests.
107161 * There is still a limit : -ENOMEM.
107162 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107163 }
107164 }
107165
107166 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107167 - /*
107168 - * If this is a GET, but not NOMAX, it means that the extra
107169 - * data is not bounded by userspace, but by max_tokens. Thus
107170 - * set the length to max_tokens. This matches the extra data
107171 - * allocation.
107172 - * The driver should fill it with the number of tokens it
107173 - * provided, and it may check iwp->length rather than having
107174 - * knowledge of max_tokens. If the driver doesn't change the
107175 - * iwp->length, this ioctl just copies back max_token tokens
107176 - * filled with zeroes. Hopefully the driver isn't claiming
107177 - * them to be valid data.
107178 - */
107179 - iwp->length = descr->max_tokens;
107180 - }
107181 -
107182 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107183
107184 iwp->length += essid_compat;
107185 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107186 index 4323952..a06dfe1 100644
107187 --- a/net/x25/sysctl_net_x25.c
107188 +++ b/net/x25/sysctl_net_x25.c
107189 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107190 .mode = 0644,
107191 .proc_handler = proc_dointvec,
107192 },
107193 - { 0, },
107194 + { },
107195 };
107196
107197 void __init x25_register_sysctl(void)
107198 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107199 index 0917f04..f4e3d8c 100644
107200 --- a/net/x25/x25_proc.c
107201 +++ b/net/x25/x25_proc.c
107202 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107203
107204 int __init x25_proc_init(void)
107205 {
107206 - if (!proc_mkdir("x25", init_net.proc_net))
107207 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107208 return -ENOMEM;
107209
107210 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107211 diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
107212 index c51e8f7b..e44f360 100644
107213 --- a/net/xfrm/xfrm_output.c
107214 +++ b/net/xfrm/xfrm_output.c
107215 @@ -157,6 +157,8 @@ static int xfrm_output_gso(struct sk_buff *skb)
107216 kfree_skb(skb);
107217 if (IS_ERR(segs))
107218 return PTR_ERR(segs);
107219 + if (segs == NULL)
107220 + return -EINVAL;
107221
107222 do {
107223 struct sk_buff *nskb = segs->next;
107224 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107225 index fdde51f..4839450 100644
107226 --- a/net/xfrm/xfrm_policy.c
107227 +++ b/net/xfrm/xfrm_policy.c
107228 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107229 {
107230 policy->walk.dead = 1;
107231
107232 - atomic_inc(&policy->genid);
107233 + atomic_inc_unchecked(&policy->genid);
107234
107235 if (del_timer(&policy->polq.hold_timer))
107236 xfrm_pol_put(policy);
107237 @@ -664,7 +664,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107238 hlist_add_head(&policy->bydst, chain);
107239 xfrm_pol_hold(policy);
107240 net->xfrm.policy_count[dir]++;
107241 - atomic_inc(&net->xfrm.flow_cache_genid);
107242 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107243
107244 /* After previous checking, family can either be AF_INET or AF_INET6 */
107245 if (policy->family == AF_INET)
107246 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107247
107248 xdst->num_pols = num_pols;
107249 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107250 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107251 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107252
107253 return xdst;
107254 }
107255 @@ -2570,10 +2570,11 @@ void xfrm_garbage_collect(struct net *net)
107256 }
107257 EXPORT_SYMBOL(xfrm_garbage_collect);
107258
107259 -static void xfrm_garbage_collect_deferred(struct net *net)
107260 +void xfrm_garbage_collect_deferred(struct net *net)
107261 {
107262 flow_cache_flush_deferred(net);
107263 }
107264 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107265
107266 static void xfrm_init_pmtu(struct dst_entry *dst)
107267 {
107268 @@ -2623,7 +2624,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107269 if (xdst->xfrm_genid != dst->xfrm->genid)
107270 return 0;
107271 if (xdst->num_pols > 0 &&
107272 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107273 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107274 return 0;
107275
107276 mtu = dst_mtu(dst->child);
107277 @@ -2711,8 +2712,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107278 dst_ops->link_failure = xfrm_link_failure;
107279 if (likely(dst_ops->neigh_lookup == NULL))
107280 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107281 - if (likely(afinfo->garbage_collect == NULL))
107282 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107283 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107284 }
107285 spin_unlock(&xfrm_policy_afinfo_lock);
107286 @@ -2766,7 +2765,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107287 dst_ops->check = NULL;
107288 dst_ops->negative_advice = NULL;
107289 dst_ops->link_failure = NULL;
107290 - afinfo->garbage_collect = NULL;
107291 }
107292 return err;
107293 }
107294 @@ -3151,7 +3149,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107295 sizeof(pol->xfrm_vec[i].saddr));
107296 pol->xfrm_vec[i].encap_family = mp->new_family;
107297 /* flush bundles */
107298 - atomic_inc(&pol->genid);
107299 + atomic_inc_unchecked(&pol->genid);
107300 }
107301 }
107302
107303 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107304 index 0ab5413..73dd2cf 100644
107305 --- a/net/xfrm/xfrm_state.c
107306 +++ b/net/xfrm/xfrm_state.c
107307 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107308
107309 if (unlikely(afinfo == NULL))
107310 return -EAFNOSUPPORT;
107311 - typemap = afinfo->type_map;
107312 + typemap = (const struct xfrm_type **)afinfo->type_map;
107313 spin_lock_bh(&xfrm_type_lock);
107314
107315 - if (likely(typemap[type->proto] == NULL))
107316 + if (likely(typemap[type->proto] == NULL)) {
107317 + pax_open_kernel();
107318 typemap[type->proto] = type;
107319 - else
107320 + pax_close_kernel();
107321 + } else
107322 err = -EEXIST;
107323 spin_unlock_bh(&xfrm_type_lock);
107324 xfrm_state_put_afinfo(afinfo);
107325 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107326
107327 if (unlikely(afinfo == NULL))
107328 return -EAFNOSUPPORT;
107329 - typemap = afinfo->type_map;
107330 + typemap = (const struct xfrm_type **)afinfo->type_map;
107331 spin_lock_bh(&xfrm_type_lock);
107332
107333 if (unlikely(typemap[type->proto] != type))
107334 err = -ENOENT;
107335 - else
107336 + else {
107337 + pax_open_kernel();
107338 typemap[type->proto] = NULL;
107339 + pax_close_kernel();
107340 + }
107341 spin_unlock_bh(&xfrm_type_lock);
107342 xfrm_state_put_afinfo(afinfo);
107343 return err;
107344 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107345 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107346 {
107347 struct xfrm_state_afinfo *afinfo;
107348 - const struct xfrm_type **typemap;
107349 const struct xfrm_type *type;
107350 int modload_attempted = 0;
107351
107352 @@ -218,9 +222,8 @@ retry:
107353 afinfo = xfrm_state_get_afinfo(family);
107354 if (unlikely(afinfo == NULL))
107355 return NULL;
107356 - typemap = afinfo->type_map;
107357
107358 - type = typemap[proto];
107359 + type = afinfo->type_map[proto];
107360 if (unlikely(type && !try_module_get(type->owner)))
107361 type = NULL;
107362 if (!type && !modload_attempted) {
107363 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107364 return -EAFNOSUPPORT;
107365
107366 err = -EEXIST;
107367 - modemap = afinfo->mode_map;
107368 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107369 spin_lock_bh(&xfrm_mode_lock);
107370 if (modemap[mode->encap])
107371 goto out;
107372 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107373 if (!try_module_get(afinfo->owner))
107374 goto out;
107375
107376 - mode->afinfo = afinfo;
107377 + pax_open_kernel();
107378 + *(const void **)&mode->afinfo = afinfo;
107379 modemap[mode->encap] = mode;
107380 + pax_close_kernel();
107381 err = 0;
107382
107383 out:
107384 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107385 return -EAFNOSUPPORT;
107386
107387 err = -ENOENT;
107388 - modemap = afinfo->mode_map;
107389 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107390 spin_lock_bh(&xfrm_mode_lock);
107391 if (likely(modemap[mode->encap] == mode)) {
107392 + pax_open_kernel();
107393 modemap[mode->encap] = NULL;
107394 + pax_close_kernel();
107395 module_put(mode->afinfo->owner);
107396 err = 0;
107397 }
107398 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107399 u32 xfrm_get_acqseq(void)
107400 {
107401 u32 res;
107402 - static atomic_t acqseq;
107403 + static atomic_unchecked_t acqseq;
107404
107405 do {
107406 - res = atomic_inc_return(&acqseq);
107407 + res = atomic_inc_return_unchecked(&acqseq);
107408 } while (!res);
107409
107410 return res;
107411 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107412 index 05a6e3d..6716ec9 100644
107413 --- a/net/xfrm/xfrm_sysctl.c
107414 +++ b/net/xfrm/xfrm_sysctl.c
107415 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107416
107417 int __net_init xfrm_sysctl_init(struct net *net)
107418 {
107419 - struct ctl_table *table;
107420 + ctl_table_no_const *table;
107421
107422 __xfrm_sysctl_init(net);
107423
107424 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107425 index bf3e677..c7d426e 100644
107426 --- a/scripts/Makefile.build
107427 +++ b/scripts/Makefile.build
107428 @@ -60,7 +60,7 @@ endif
107429 endif
107430
107431 # Do not include host rules unless needed
107432 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107433 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107434 include scripts/Makefile.host
107435 endif
107436
107437 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107438 index a651cee..6b3b9a3 100644
107439 --- a/scripts/Makefile.clean
107440 +++ b/scripts/Makefile.clean
107441 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107442 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107443 $(always) $(targets) $(clean-files) \
107444 $(host-progs) \
107445 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107446 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107447 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107448
107449 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107450
107451 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107452 index ab5980f..85fd3e1 100644
107453 --- a/scripts/Makefile.host
107454 +++ b/scripts/Makefile.host
107455 @@ -20,7 +20,19 @@
107456 # Will compile qconf as a C++ program, and menu as a C program.
107457 # They are linked as C++ code to the executable qconf
107458
107459 +# hostprogs-y := conf
107460 +# conf-objs := conf.o libkconfig.so
107461 +# libkconfig-objs := expr.o type.o
107462 +# Will create a shared library named libkconfig.so that consists of
107463 +# expr.o and type.o (they are both compiled as C code and the object files
107464 +# are made as position independent code).
107465 +# conf.c is compiled as a C program, and conf.o is linked together with
107466 +# libkconfig.so as the executable conf.
107467 +# Note: Shared libraries consisting of C++ files are not supported
107468 +
107469 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107470 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107471 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107472
107473 # C code
107474 # Executables compiled from a single .c file
107475 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107476 # C++ Object (.o) files compiled from .cc files
107477 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107478
107479 +# Shared libaries (only .c supported)
107480 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107481 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107482 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107483 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107484 +# Remove .so files from "xxx-objs"
107485 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107486 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107487 +
107488 +# Object (.o) files used by the shared libaries
107489 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107490 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107491 +
107492 # output directory for programs/.o files
107493 # hostprogs-y := tools/build may have been specified.
107494 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107495 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107496 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107497 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107498 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107499 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107500 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107501 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107502 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107503 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107504
107505 obj-dirs += $(host-objdirs)
107506 @@ -96,7 +125,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
107507 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
107508 $(addprefix $(obj)/,$($(@F)-objs)) \
107509 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107510 -$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
107511 +$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
107512 $(call if_changed,host-cmulti)
107513
107514 # Create .o file from a single .c file
107515 @@ -113,7 +142,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
107516 $(foreach o,objs cxxobjs,\
107517 $(addprefix $(obj)/,$($(@F)-$(o)))) \
107518 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107519 -$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
107520 +$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
107521 $(call if_changed,host-cxxmulti)
107522
107523 # Create .o file from a single .cc (C++) file
107524 @@ -122,5 +151,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107525 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107526 $(call if_changed_dep,host-cxxobjs)
107527
107528 +# Compile .c file, create position independent .o file
107529 +# host-cshobjs -> .o
107530 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107531 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107532 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107533 + $(call if_changed_dep,host-cshobjs)
107534 +
107535 +# Compile .c file, create position independent .o file
107536 +# host-cxxshobjs -> .o
107537 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107538 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107539 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107540 + $(call if_changed_dep,host-cxxshobjs)
107541 +
107542 +# Link a shared library, based on position independent .o files
107543 +# *.o -> .so shared library (host-cshlib)
107544 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107545 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107546 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107547 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107548 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107549 + $(call if_changed,host-cshlib)
107550 +
107551 +# Link a shared library, based on position independent .o files
107552 +# *.o -> .so shared library (host-cxxshlib)
107553 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107554 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107555 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107556 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107557 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107558 + $(call if_changed,host-cxxshlib)
107559 +
107560 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107561 - $(host-cxxmulti) $(host-cxxobjs)
107562 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107563 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107564 index b304068..462d24e 100644
107565 --- a/scripts/basic/fixdep.c
107566 +++ b/scripts/basic/fixdep.c
107567 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107568 /*
107569 * Lookup a value in the configuration string.
107570 */
107571 -static int is_defined_config(const char *name, int len, unsigned int hash)
107572 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107573 {
107574 struct item *aux;
107575
107576 @@ -211,10 +211,10 @@ static void clear_config(void)
107577 /*
107578 * Record the use of a CONFIG_* word.
107579 */
107580 -static void use_config(const char *m, int slen)
107581 +static void use_config(const char *m, unsigned int slen)
107582 {
107583 unsigned int hash = strhash(m, slen);
107584 - int c, i;
107585 + unsigned int c, i;
107586
107587 if (is_defined_config(m, slen, hash))
107588 return;
107589 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107590
107591 static void parse_config_file(const char *map, size_t len)
107592 {
107593 - const int *end = (const int *) (map + len);
107594 + const unsigned int *end = (const unsigned int *) (map + len);
107595 /* start at +1, so that p can never be < map */
107596 - const int *m = (const int *) map + 1;
107597 + const unsigned int *m = (const unsigned int *) map + 1;
107598 const char *p, *q;
107599
107600 for (; m < end; m++) {
107601 @@ -435,7 +435,7 @@ static void print_deps(void)
107602 static void traps(void)
107603 {
107604 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107605 - int *p = (int *)test;
107606 + unsigned int *p = (unsigned int *)test;
107607
107608 if (*p != INT_CONF) {
107609 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107610 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107611 new file mode 100644
107612 index 0000000..42018ed
107613 --- /dev/null
107614 +++ b/scripts/gcc-plugin.sh
107615 @@ -0,0 +1,51 @@
107616 +#!/bin/sh
107617 +srctree=$(dirname "$0")
107618 +gccplugins_dir=$($3 -print-file-name=plugin)
107619 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107620 +#include "gcc-common.h"
107621 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107622 +#warning $2 CXX
107623 +#else
107624 +#warning $1 CC
107625 +#endif
107626 +EOF
107627 +)
107628 +
107629 +if [ $? -ne 0 ]
107630 +then
107631 + exit 1
107632 +fi
107633 +
107634 +case "$plugincc" in
107635 + *"$1 CC"*)
107636 + echo "$1"
107637 + exit 0
107638 + ;;
107639 +
107640 + *"$2 CXX"*)
107641 + # the c++ compiler needs another test, see below
107642 + ;;
107643 +
107644 + *)
107645 + exit 1
107646 + ;;
107647 +esac
107648 +
107649 +# we need a c++ compiler that supports the designated initializer GNU extension
107650 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107651 +#include "gcc-common.h"
107652 +class test {
107653 +public:
107654 + int test;
107655 +} test = {
107656 + .test = 1
107657 +};
107658 +EOF
107659 +)
107660 +
107661 +if [ $? -eq 0 ]
107662 +then
107663 + echo "$2"
107664 + exit 0
107665 +fi
107666 +exit 1
107667 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107668 index 5de5660..d3deb89 100644
107669 --- a/scripts/headers_install.sh
107670 +++ b/scripts/headers_install.sh
107671 @@ -32,6 +32,7 @@ do
107672 FILE="$(basename "$i")"
107673 sed -r \
107674 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107675 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107676 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107677 -e 's@^#include <linux/compiler.h>@@' \
107678 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107679 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107680 index 86a4fe7..99e91f9 100644
107681 --- a/scripts/link-vmlinux.sh
107682 +++ b/scripts/link-vmlinux.sh
107683 @@ -166,7 +166,7 @@ else
107684 fi;
107685
107686 # final build of init/
107687 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107688 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107689
107690 kallsymso=""
107691 kallsyms_vmlinux=""
107692 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107693 index e614ef6..d9d2b01 100644
107694 --- a/scripts/mod/file2alias.c
107695 +++ b/scripts/mod/file2alias.c
107696 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107697 unsigned long size, unsigned long id_size,
107698 void *symval)
107699 {
107700 - int i;
107701 + unsigned int i;
107702
107703 if (size % id_size || size < id_size) {
107704 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107705 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107706 /* USB is special because the bcdDevice can be matched against a numeric range */
107707 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107708 static void do_usb_entry(void *symval,
107709 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107710 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107711 unsigned char range_lo, unsigned char range_hi,
107712 unsigned char max, struct module *mod)
107713 {
107714 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107715 {
107716 unsigned int devlo, devhi;
107717 unsigned char chi, clo, max;
107718 - int ndigits;
107719 + unsigned int ndigits;
107720
107721 DEF_FIELD(symval, usb_device_id, match_flags);
107722 DEF_FIELD(symval, usb_device_id, idVendor);
107723 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107724 for (i = 0; i < count; i++) {
107725 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107726 char acpi_id[sizeof(*id)];
107727 - int j;
107728 + unsigned int j;
107729
107730 buf_printf(&mod->dev_table_buf,
107731 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107732 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107733
107734 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107735 const char *id = (char *)(*devs)[j].id;
107736 - int i2, j2;
107737 + unsigned int i2, j2;
107738 int dup = 0;
107739
107740 if (!id[0])
107741 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107742 /* add an individual alias for every device entry */
107743 if (!dup) {
107744 char acpi_id[PNP_ID_LEN];
107745 - int k;
107746 + unsigned int k;
107747
107748 buf_printf(&mod->dev_table_buf,
107749 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107750 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107751 static int do_dmi_entry(const char *filename, void *symval,
107752 char *alias)
107753 {
107754 - int i, j;
107755 + unsigned int i, j;
107756 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107757 sprintf(alias, "dmi*");
107758
107759 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107760 index 091d905..77b88c7 100644
107761 --- a/scripts/mod/modpost.c
107762 +++ b/scripts/mod/modpost.c
107763 @@ -920,6 +920,7 @@ enum mismatch {
107764 ANY_INIT_TO_ANY_EXIT,
107765 ANY_EXIT_TO_ANY_INIT,
107766 EXPORT_TO_INIT_EXIT,
107767 + DATA_TO_TEXT
107768 };
107769
107770 struct sectioncheck {
107771 @@ -1006,6 +1007,12 @@ const struct sectioncheck sectioncheck[] = {
107772 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107773 .mismatch = EXPORT_TO_INIT_EXIT,
107774 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107775 +},
107776 +/* Do not reference code from writable data */
107777 +{
107778 + .fromsec = { DATA_SECTIONS, NULL },
107779 + .tosec = { TEXT_SECTIONS, NULL },
107780 + .mismatch = DATA_TO_TEXT
107781 }
107782 };
107783
107784 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107785 continue;
107786 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107787 continue;
107788 - if (sym->st_value == addr)
107789 - return sym;
107790 /* Find a symbol nearby - addr are maybe negative */
107791 d = sym->st_value - addr;
107792 + if (d == 0)
107793 + return sym;
107794 if (d < 0)
107795 d = addr - sym->st_value;
107796 if (d < distance) {
107797 @@ -1407,6 +1414,14 @@ static void report_sec_mismatch(const char *modname,
107798 tosym, prl_to, prl_to, tosym);
107799 free(prl_to);
107800 break;
107801 + case DATA_TO_TEXT:
107802 +#if 0
107803 + fprintf(stderr,
107804 + "The %s %s:%s references\n"
107805 + "the %s %s:%s%s\n",
107806 + from, fromsec, fromsym, to, tosec, tosym, to_p);
107807 +#endif
107808 + break;
107809 }
107810 fprintf(stderr, "\n");
107811 }
107812 @@ -1658,7 +1673,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
107813 static void check_sec_ref(struct module *mod, const char *modname,
107814 struct elf_info *elf)
107815 {
107816 - int i;
107817 + unsigned int i;
107818 Elf_Shdr *sechdrs = elf->sechdrs;
107819
107820 /* Walk through all sections */
107821 @@ -1789,7 +1804,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
107822 va_end(ap);
107823 }
107824
107825 -void buf_write(struct buffer *buf, const char *s, int len)
107826 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
107827 {
107828 if (buf->size - buf->pos < len) {
107829 buf->size += len + SZ;
107830 @@ -2008,7 +2023,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
107831 if (fstat(fileno(file), &st) < 0)
107832 goto close_write;
107833
107834 - if (st.st_size != b->pos)
107835 + if (st.st_size != (off_t)b->pos)
107836 goto close_write;
107837
107838 tmp = NOFAIL(malloc(b->pos));
107839 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
107840 index 168b43d..77914bf 100644
107841 --- a/scripts/mod/modpost.h
107842 +++ b/scripts/mod/modpost.h
107843 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
107844
107845 struct buffer {
107846 char *p;
107847 - int pos;
107848 - int size;
107849 + unsigned int pos;
107850 + unsigned int size;
107851 };
107852
107853 void __attribute__((format(printf, 2, 3)))
107854 buf_printf(struct buffer *buf, const char *fmt, ...);
107855
107856 void
107857 -buf_write(struct buffer *buf, const char *s, int len);
107858 +buf_write(struct buffer *buf, const char *s, unsigned int len);
107859
107860 struct module {
107861 struct module *next;
107862 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
107863 index 944418d..15291e4 100644
107864 --- a/scripts/mod/sumversion.c
107865 +++ b/scripts/mod/sumversion.c
107866 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
107867 goto out;
107868 }
107869
107870 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
107871 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
107872 warn("writing sum in %s failed: %s\n",
107873 filename, strerror(errno));
107874 goto out;
107875 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
107876 index 0865b3e..7235dd4 100644
107877 --- a/scripts/module-common.lds
107878 +++ b/scripts/module-common.lds
107879 @@ -6,6 +6,10 @@
107880 SECTIONS {
107881 /DISCARD/ : { *(.discard) }
107882
107883 + .rodata : {
107884 + *(.rodata) *(.rodata.*)
107885 + *(.data..read_only)
107886 + }
107887 __ksymtab : { *(SORT(___ksymtab+*)) }
107888 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
107889 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
107890 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
107891 index 35d5a58..9e04789 100644
107892 --- a/scripts/package/builddeb
107893 +++ b/scripts/package/builddeb
107894 @@ -295,6 +295,7 @@ fi
107895 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
107896 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
107897 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
107898 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
107899 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
107900 mkdir -p "$destdir"
107901 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
107902 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
107903 index 4718d78..9220d58 100644
107904 --- a/scripts/pnmtologo.c
107905 +++ b/scripts/pnmtologo.c
107906 @@ -244,14 +244,14 @@ static void write_header(void)
107907 fprintf(out, " * Linux logo %s\n", logoname);
107908 fputs(" */\n\n", out);
107909 fputs("#include <linux/linux_logo.h>\n\n", out);
107910 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
107911 + fprintf(out, "static unsigned char %s_data[] = {\n",
107912 logoname);
107913 }
107914
107915 static void write_footer(void)
107916 {
107917 fputs("\n};\n\n", out);
107918 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
107919 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
107920 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
107921 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
107922 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
107923 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
107924 fputs("\n};\n\n", out);
107925
107926 /* write logo clut */
107927 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
107928 + fprintf(out, "static unsigned char %s_clut[] = {\n",
107929 logoname);
107930 write_hex_cnt = 0;
107931 for (i = 0; i < logo_clutsize; i++) {
107932 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
107933 index 8fac3fd..32ff38d 100644
107934 --- a/scripts/sortextable.h
107935 +++ b/scripts/sortextable.h
107936 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
107937 const char *secstrtab;
107938 const char *strtab;
107939 char *extab_image;
107940 - int extab_index = 0;
107941 - int i;
107942 - int idx;
107943 + unsigned int extab_index = 0;
107944 + unsigned int i;
107945 + unsigned int idx;
107946 unsigned int num_sections;
107947 unsigned int secindex_strings;
107948
107949 diff --git a/scripts/tags.sh b/scripts/tags.sh
107950 index 293828b..9fbe696 100755
107951 --- a/scripts/tags.sh
107952 +++ b/scripts/tags.sh
107953 @@ -26,7 +26,7 @@ else
107954 fi
107955
107956 # ignore userspace tools
107957 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
107958 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
107959
107960 # Find all available archs
107961 find_all_archs()
107962 diff --git a/security/Kconfig b/security/Kconfig
107963 index beb86b5..9becb4a 100644
107964 --- a/security/Kconfig
107965 +++ b/security/Kconfig
107966 @@ -4,6 +4,965 @@
107967
107968 menu "Security options"
107969
107970 +menu "Grsecurity"
107971 +
107972 + config ARCH_TRACK_EXEC_LIMIT
107973 + bool
107974 +
107975 + config PAX_KERNEXEC_PLUGIN
107976 + bool
107977 +
107978 + config PAX_PER_CPU_PGD
107979 + bool
107980 +
107981 + config TASK_SIZE_MAX_SHIFT
107982 + int
107983 + depends on X86_64
107984 + default 47 if !PAX_PER_CPU_PGD
107985 + default 42 if PAX_PER_CPU_PGD
107986 +
107987 + config PAX_ENABLE_PAE
107988 + bool
107989 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
107990 +
107991 + config PAX_USERCOPY_SLABS
107992 + bool
107993 +
107994 +config GRKERNSEC
107995 + bool "Grsecurity"
107996 + select CRYPTO
107997 + select CRYPTO_SHA256
107998 + select PROC_FS
107999 + select STOP_MACHINE
108000 + select TTY
108001 + select DEBUG_KERNEL
108002 + select DEBUG_LIST
108003 + help
108004 + If you say Y here, you will be able to configure many features
108005 + that will enhance the security of your system. It is highly
108006 + recommended that you say Y here and read through the help
108007 + for each option so that you fully understand the features and
108008 + can evaluate their usefulness for your machine.
108009 +
108010 +choice
108011 + prompt "Configuration Method"
108012 + depends on GRKERNSEC
108013 + default GRKERNSEC_CONFIG_CUSTOM
108014 + help
108015 +
108016 +config GRKERNSEC_CONFIG_AUTO
108017 + bool "Automatic"
108018 + help
108019 + If you choose this configuration method, you'll be able to answer a small
108020 + number of simple questions about how you plan to use this kernel.
108021 + The settings of grsecurity and PaX will be automatically configured for
108022 + the highest commonly-used settings within the provided constraints.
108023 +
108024 + If you require additional configuration, custom changes can still be made
108025 + from the "custom configuration" menu.
108026 +
108027 +config GRKERNSEC_CONFIG_CUSTOM
108028 + bool "Custom"
108029 + help
108030 + If you choose this configuration method, you'll be able to configure all
108031 + grsecurity and PaX settings manually. Via this method, no options are
108032 + automatically enabled.
108033 +
108034 +endchoice
108035 +
108036 +choice
108037 + prompt "Usage Type"
108038 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108039 + default GRKERNSEC_CONFIG_SERVER
108040 + help
108041 +
108042 +config GRKERNSEC_CONFIG_SERVER
108043 + bool "Server"
108044 + help
108045 + Choose this option if you plan to use this kernel on a server.
108046 +
108047 +config GRKERNSEC_CONFIG_DESKTOP
108048 + bool "Desktop"
108049 + help
108050 + Choose this option if you plan to use this kernel on a desktop.
108051 +
108052 +endchoice
108053 +
108054 +choice
108055 + prompt "Virtualization Type"
108056 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108057 + default GRKERNSEC_CONFIG_VIRT_NONE
108058 + help
108059 +
108060 +config GRKERNSEC_CONFIG_VIRT_NONE
108061 + bool "None"
108062 + help
108063 + Choose this option if this kernel will be run on bare metal.
108064 +
108065 +config GRKERNSEC_CONFIG_VIRT_GUEST
108066 + bool "Guest"
108067 + help
108068 + Choose this option if this kernel will be run as a VM guest.
108069 +
108070 +config GRKERNSEC_CONFIG_VIRT_HOST
108071 + bool "Host"
108072 + help
108073 + Choose this option if this kernel will be run as a VM host.
108074 +
108075 +endchoice
108076 +
108077 +choice
108078 + prompt "Virtualization Hardware"
108079 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108080 + help
108081 +
108082 +config GRKERNSEC_CONFIG_VIRT_EPT
108083 + bool "EPT/RVI Processor Support"
108084 + depends on X86
108085 + help
108086 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108087 + hardware virtualization. This allows for additional kernel hardening protections
108088 + to operate without additional performance impact.
108089 +
108090 + To see if your Intel processor supports EPT, see:
108091 + http://ark.intel.com/Products/VirtualizationTechnology
108092 + (Most Core i3/5/7 support EPT)
108093 +
108094 + To see if your AMD processor supports RVI, see:
108095 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108096 +
108097 +config GRKERNSEC_CONFIG_VIRT_SOFT
108098 + bool "First-gen/No Hardware Virtualization"
108099 + help
108100 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108101 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108102 +
108103 +endchoice
108104 +
108105 +choice
108106 + prompt "Virtualization Software"
108107 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108108 + help
108109 +
108110 +config GRKERNSEC_CONFIG_VIRT_XEN
108111 + bool "Xen"
108112 + help
108113 + Choose this option if this kernel is running as a Xen guest or host.
108114 +
108115 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108116 + bool "VMWare"
108117 + help
108118 + Choose this option if this kernel is running as a VMWare guest or host.
108119 +
108120 +config GRKERNSEC_CONFIG_VIRT_KVM
108121 + bool "KVM"
108122 + help
108123 + Choose this option if this kernel is running as a KVM guest or host.
108124 +
108125 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108126 + bool "VirtualBox"
108127 + help
108128 + Choose this option if this kernel is running as a VirtualBox guest or host.
108129 +
108130 +endchoice
108131 +
108132 +choice
108133 + prompt "Required Priorities"
108134 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108135 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108136 + help
108137 +
108138 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108139 + bool "Performance"
108140 + help
108141 + Choose this option if performance is of highest priority for this deployment
108142 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108143 + clearing of structures intended for userland, and freed memory sanitizing will
108144 + be disabled.
108145 +
108146 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108147 + bool "Security"
108148 + help
108149 + Choose this option if security is of highest priority for this deployment of
108150 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108151 + for userland, and freed memory sanitizing will be enabled for this kernel.
108152 + In a worst-case scenario, these features can introduce a 20% performance hit
108153 + (UDEREF on x64 contributing half of this hit).
108154 +
108155 +endchoice
108156 +
108157 +menu "Default Special Groups"
108158 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108159 +
108160 +config GRKERNSEC_PROC_GID
108161 + int "GID exempted from /proc restrictions"
108162 + default 1001
108163 + help
108164 + Setting this GID determines which group will be exempted from
108165 + grsecurity's /proc restrictions, allowing users of the specified
108166 + group to view network statistics and the existence of other users'
108167 + processes on the system. This GID may also be chosen at boot time
108168 + via "grsec_proc_gid=" on the kernel commandline.
108169 +
108170 +config GRKERNSEC_TPE_UNTRUSTED_GID
108171 + int "GID for TPE-untrusted users"
108172 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108173 + default 1005
108174 + help
108175 + Setting this GID determines which group untrusted users should
108176 + be added to. These users will be placed under grsecurity's Trusted Path
108177 + Execution mechanism, preventing them from executing their own binaries.
108178 + The users will only be able to execute binaries in directories owned and
108179 + writable only by the root user. If the sysctl option is enabled, a sysctl
108180 + option with name "tpe_gid" is created.
108181 +
108182 +config GRKERNSEC_TPE_TRUSTED_GID
108183 + int "GID for TPE-trusted users"
108184 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108185 + default 1005
108186 + help
108187 + Setting this GID determines what group TPE restrictions will be
108188 + *disabled* for. If the sysctl option is enabled, a sysctl option
108189 + with name "tpe_gid" is created.
108190 +
108191 +config GRKERNSEC_SYMLINKOWN_GID
108192 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108193 + depends on GRKERNSEC_CONFIG_SERVER
108194 + default 1006
108195 + help
108196 + Setting this GID determines what group kernel-enforced
108197 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108198 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108199 +
108200 +
108201 +endmenu
108202 +
108203 +menu "Customize Configuration"
108204 +depends on GRKERNSEC
108205 +
108206 +menu "PaX"
108207 +
108208 +config PAX
108209 + bool "Enable various PaX features"
108210 + default y if GRKERNSEC_CONFIG_AUTO
108211 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108212 + help
108213 + This allows you to enable various PaX features. PaX adds
108214 + intrusion prevention mechanisms to the kernel that reduce
108215 + the risks posed by exploitable memory corruption bugs.
108216 +
108217 +menu "PaX Control"
108218 + depends on PAX
108219 +
108220 +config PAX_SOFTMODE
108221 + bool 'Support soft mode'
108222 + help
108223 + Enabling this option will allow you to run PaX in soft mode, that
108224 + is, PaX features will not be enforced by default, only on executables
108225 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108226 + support as they are the only way to mark executables for soft mode use.
108227 +
108228 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108229 + line option on boot. Furthermore you can control various PaX features
108230 + at runtime via the entries in /proc/sys/kernel/pax.
108231 +
108232 +config PAX_EI_PAX
108233 + bool 'Use legacy ELF header marking'
108234 + default y if GRKERNSEC_CONFIG_AUTO
108235 + help
108236 + Enabling this option will allow you to control PaX features on
108237 + a per executable basis via the 'chpax' utility available at
108238 + http://pax.grsecurity.net/. The control flags will be read from
108239 + an otherwise reserved part of the ELF header. This marking has
108240 + numerous drawbacks (no support for soft-mode, toolchain does not
108241 + know about the non-standard use of the ELF header) therefore it
108242 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108243 + support.
108244 +
108245 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108246 + support as well, they will override the legacy EI_PAX marks.
108247 +
108248 + If you enable none of the marking options then all applications
108249 + will run with PaX enabled on them by default.
108250 +
108251 +config PAX_PT_PAX_FLAGS
108252 + bool 'Use ELF program header marking'
108253 + default y if GRKERNSEC_CONFIG_AUTO
108254 + help
108255 + Enabling this option will allow you to control PaX features on
108256 + a per executable basis via the 'paxctl' utility available at
108257 + http://pax.grsecurity.net/. The control flags will be read from
108258 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108259 + has the benefits of supporting both soft mode and being fully
108260 + integrated into the toolchain (the binutils patch is available
108261 + from http://pax.grsecurity.net).
108262 +
108263 + Note that if you enable the legacy EI_PAX marking support as well,
108264 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108265 +
108266 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108267 + must make sure that the marks are the same if a binary has both marks.
108268 +
108269 + If you enable none of the marking options then all applications
108270 + will run with PaX enabled on them by default.
108271 +
108272 +config PAX_XATTR_PAX_FLAGS
108273 + bool 'Use filesystem extended attributes marking'
108274 + default y if GRKERNSEC_CONFIG_AUTO
108275 + select CIFS_XATTR if CIFS
108276 + select F2FS_FS_XATTR if F2FS_FS
108277 + select EXT2_FS_XATTR if EXT2_FS
108278 + select EXT3_FS_XATTR if EXT3_FS
108279 + select JFFS2_FS_XATTR if JFFS2_FS
108280 + select REISERFS_FS_XATTR if REISERFS_FS
108281 + select SQUASHFS_XATTR if SQUASHFS
108282 + select TMPFS_XATTR if TMPFS
108283 + help
108284 + Enabling this option will allow you to control PaX features on
108285 + a per executable basis via the 'setfattr' utility. The control
108286 + flags will be read from the user.pax.flags extended attribute of
108287 + the file. This marking has the benefit of supporting binary-only
108288 + applications that self-check themselves (e.g., skype) and would
108289 + not tolerate chpax/paxctl changes. The main drawback is that
108290 + extended attributes are not supported by some filesystems (e.g.,
108291 + isofs, udf, vfat) so copying files through such filesystems will
108292 + lose the extended attributes and these PaX markings.
108293 +
108294 + Note that if you enable the legacy EI_PAX marking support as well,
108295 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108296 +
108297 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108298 + must make sure that the marks are the same if a binary has both marks.
108299 +
108300 + If you enable none of the marking options then all applications
108301 + will run with PaX enabled on them by default.
108302 +
108303 +choice
108304 + prompt 'MAC system integration'
108305 + default PAX_HAVE_ACL_FLAGS
108306 + help
108307 + Mandatory Access Control systems have the option of controlling
108308 + PaX flags on a per executable basis, choose the method supported
108309 + by your particular system.
108310 +
108311 + - "none": if your MAC system does not interact with PaX,
108312 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108313 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108314 +
108315 + NOTE: this option is for developers/integrators only.
108316 +
108317 + config PAX_NO_ACL_FLAGS
108318 + bool 'none'
108319 +
108320 + config PAX_HAVE_ACL_FLAGS
108321 + bool 'direct'
108322 +
108323 + config PAX_HOOK_ACL_FLAGS
108324 + bool 'hook'
108325 +endchoice
108326 +
108327 +endmenu
108328 +
108329 +menu "Non-executable pages"
108330 + depends on PAX
108331 +
108332 +config PAX_NOEXEC
108333 + bool "Enforce non-executable pages"
108334 + default y if GRKERNSEC_CONFIG_AUTO
108335 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108336 + help
108337 + By design some architectures do not allow for protecting memory
108338 + pages against execution or even if they do, Linux does not make
108339 + use of this feature. In practice this means that if a page is
108340 + readable (such as the stack or heap) it is also executable.
108341 +
108342 + There is a well known exploit technique that makes use of this
108343 + fact and a common programming mistake where an attacker can
108344 + introduce code of his choice somewhere in the attacked program's
108345 + memory (typically the stack or the heap) and then execute it.
108346 +
108347 + If the attacked program was running with different (typically
108348 + higher) privileges than that of the attacker, then he can elevate
108349 + his own privilege level (e.g. get a root shell, write to files for
108350 + which he does not have write access to, etc).
108351 +
108352 + Enabling this option will let you choose from various features
108353 + that prevent the injection and execution of 'foreign' code in
108354 + a program.
108355 +
108356 + This will also break programs that rely on the old behaviour and
108357 + expect that dynamically allocated memory via the malloc() family
108358 + of functions is executable (which it is not). Notable examples
108359 + are the XFree86 4.x server, the java runtime and wine.
108360 +
108361 +config PAX_PAGEEXEC
108362 + bool "Paging based non-executable pages"
108363 + default y if GRKERNSEC_CONFIG_AUTO
108364 + 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)
108365 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108366 + help
108367 + This implementation is based on the paging feature of the CPU.
108368 + On i386 without hardware non-executable bit support there is a
108369 + variable but usually low performance impact, however on Intel's
108370 + P4 core based CPUs it is very high so you should not enable this
108371 + for kernels meant to be used on such CPUs.
108372 +
108373 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108374 + with hardware non-executable bit support there is no performance
108375 + impact, on ppc the impact is negligible.
108376 +
108377 + Note that several architectures require various emulations due to
108378 + badly designed userland ABIs, this will cause a performance impact
108379 + but will disappear as soon as userland is fixed. For example, ppc
108380 + userland MUST have been built with secure-plt by a recent toolchain.
108381 +
108382 +config PAX_SEGMEXEC
108383 + bool "Segmentation based non-executable pages"
108384 + default y if GRKERNSEC_CONFIG_AUTO
108385 + depends on PAX_NOEXEC && X86_32
108386 + help
108387 + This implementation is based on the segmentation feature of the
108388 + CPU and has a very small performance impact, however applications
108389 + will be limited to a 1.5 GB address space instead of the normal
108390 + 3 GB.
108391 +
108392 +config PAX_EMUTRAMP
108393 + bool "Emulate trampolines"
108394 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108395 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108396 + help
108397 + There are some programs and libraries that for one reason or
108398 + another attempt to execute special small code snippets from
108399 + non-executable memory pages. Most notable examples are the
108400 + signal handler return code generated by the kernel itself and
108401 + the GCC trampolines.
108402 +
108403 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108404 + such programs will no longer work under your kernel.
108405 +
108406 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108407 + utilities to enable trampoline emulation for the affected programs
108408 + yet still have the protection provided by the non-executable pages.
108409 +
108410 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108411 + your system will not even boot.
108412 +
108413 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108414 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108415 + for the affected files.
108416 +
108417 + NOTE: enabling this feature *may* open up a loophole in the
108418 + protection provided by non-executable pages that an attacker
108419 + could abuse. Therefore the best solution is to not have any
108420 + files on your system that would require this option. This can
108421 + be achieved by not using libc5 (which relies on the kernel
108422 + signal handler return code) and not using or rewriting programs
108423 + that make use of the nested function implementation of GCC.
108424 + Skilled users can just fix GCC itself so that it implements
108425 + nested function calls in a way that does not interfere with PaX.
108426 +
108427 +config PAX_EMUSIGRT
108428 + bool "Automatically emulate sigreturn trampolines"
108429 + depends on PAX_EMUTRAMP && PARISC
108430 + default y
108431 + help
108432 + Enabling this option will have the kernel automatically detect
108433 + and emulate signal return trampolines executing on the stack
108434 + that would otherwise lead to task termination.
108435 +
108436 + This solution is intended as a temporary one for users with
108437 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108438 + Modula-3 runtime, etc) or executables linked to such, basically
108439 + everything that does not specify its own SA_RESTORER function in
108440 + normal executable memory like glibc 2.1+ does.
108441 +
108442 + On parisc you MUST enable this option, otherwise your system will
108443 + not even boot.
108444 +
108445 + NOTE: this feature cannot be disabled on a per executable basis
108446 + and since it *does* open up a loophole in the protection provided
108447 + by non-executable pages, the best solution is to not have any
108448 + files on your system that would require this option.
108449 +
108450 +config PAX_MPROTECT
108451 + bool "Restrict mprotect()"
108452 + default y if GRKERNSEC_CONFIG_AUTO
108453 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108454 + help
108455 + Enabling this option will prevent programs from
108456 + - changing the executable status of memory pages that were
108457 + not originally created as executable,
108458 + - making read-only executable pages writable again,
108459 + - creating executable pages from anonymous memory,
108460 + - making read-only-after-relocations (RELRO) data pages writable again.
108461 +
108462 + You should say Y here to complete the protection provided by
108463 + the enforcement of non-executable pages.
108464 +
108465 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108466 + this feature on a per file basis.
108467 +
108468 +config PAX_MPROTECT_COMPAT
108469 + bool "Use legacy/compat protection demoting (read help)"
108470 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108471 + depends on PAX_MPROTECT
108472 + help
108473 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108474 + by sending the proper error code to the application. For some broken
108475 + userland, this can cause problems with Python or other applications. The
108476 + current implementation however allows for applications like clamav to
108477 + detect if JIT compilation/execution is allowed and to fall back gracefully
108478 + to an interpreter-based mode if it does not. While we encourage everyone
108479 + to use the current implementation as-is and push upstream to fix broken
108480 + userland (note that the RWX logging option can assist with this), in some
108481 + environments this may not be possible. Having to disable MPROTECT
108482 + completely on certain binaries reduces the security benefit of PaX,
108483 + so this option is provided for those environments to revert to the old
108484 + behavior.
108485 +
108486 +config PAX_ELFRELOCS
108487 + bool "Allow ELF text relocations (read help)"
108488 + depends on PAX_MPROTECT
108489 + default n
108490 + help
108491 + Non-executable pages and mprotect() restrictions are effective
108492 + in preventing the introduction of new executable code into an
108493 + attacked task's address space. There remain only two venues
108494 + for this kind of attack: if the attacker can execute already
108495 + existing code in the attacked task then he can either have it
108496 + create and mmap() a file containing his code or have it mmap()
108497 + an already existing ELF library that does not have position
108498 + independent code in it and use mprotect() on it to make it
108499 + writable and copy his code there. While protecting against
108500 + the former approach is beyond PaX, the latter can be prevented
108501 + by having only PIC ELF libraries on one's system (which do not
108502 + need to relocate their code). If you are sure this is your case,
108503 + as is the case with all modern Linux distributions, then leave
108504 + this option disabled. You should say 'n' here.
108505 +
108506 +config PAX_ETEXECRELOCS
108507 + bool "Allow ELF ET_EXEC text relocations"
108508 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108509 + select PAX_ELFRELOCS
108510 + default y
108511 + help
108512 + On some architectures there are incorrectly created applications
108513 + that require text relocations and would not work without enabling
108514 + this option. If you are an alpha, ia64 or parisc user, you should
108515 + enable this option and disable it once you have made sure that
108516 + none of your applications need it.
108517 +
108518 +config PAX_EMUPLT
108519 + bool "Automatically emulate ELF PLT"
108520 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108521 + default y
108522 + help
108523 + Enabling this option will have the kernel automatically detect
108524 + and emulate the Procedure Linkage Table entries in ELF files.
108525 + On some architectures such entries are in writable memory, and
108526 + become non-executable leading to task termination. Therefore
108527 + it is mandatory that you enable this option on alpha, parisc,
108528 + sparc and sparc64, otherwise your system would not even boot.
108529 +
108530 + NOTE: this feature *does* open up a loophole in the protection
108531 + provided by the non-executable pages, therefore the proper
108532 + solution is to modify the toolchain to produce a PLT that does
108533 + not need to be writable.
108534 +
108535 +config PAX_DLRESOLVE
108536 + bool 'Emulate old glibc resolver stub'
108537 + depends on PAX_EMUPLT && SPARC
108538 + default n
108539 + help
108540 + This option is needed if userland has an old glibc (before 2.4)
108541 + that puts a 'save' instruction into the runtime generated resolver
108542 + stub that needs special emulation.
108543 +
108544 +config PAX_KERNEXEC
108545 + bool "Enforce non-executable kernel pages"
108546 + 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))
108547 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108548 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108549 + select PAX_KERNEXEC_PLUGIN if X86_64
108550 + help
108551 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108552 + that is, enabling this option will make it harder to inject
108553 + and execute 'foreign' code in kernel memory itself.
108554 +
108555 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108556 + the kernel command-line will result in an RWX physical map.
108557 +
108558 + Likewise, the EFI runtime services are necessarily mapped as
108559 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108560 + is recommended that you boot with "noefi" on the kernel
108561 + command-line if possible to eliminate the mapping.
108562 +
108563 +choice
108564 + prompt "Return Address Instrumentation Method"
108565 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108566 + depends on PAX_KERNEXEC_PLUGIN
108567 + help
108568 + Select the method used to instrument function pointer dereferences.
108569 + Note that binary modules cannot be instrumented by this approach.
108570 +
108571 + Note that the implementation requires a gcc with plugin support,
108572 + i.e., gcc 4.5 or newer. You may need to install the supporting
108573 + headers explicitly in addition to the normal gcc package.
108574 +
108575 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108576 + bool "bts"
108577 + help
108578 + This method is compatible with binary only modules but has
108579 + a higher runtime overhead.
108580 +
108581 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108582 + bool "or"
108583 + depends on !PARAVIRT
108584 + help
108585 + This method is incompatible with binary only modules but has
108586 + a lower runtime overhead.
108587 +endchoice
108588 +
108589 +config PAX_KERNEXEC_PLUGIN_METHOD
108590 + string
108591 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108592 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108593 + default ""
108594 +
108595 +config PAX_KERNEXEC_MODULE_TEXT
108596 + int "Minimum amount of memory reserved for module code"
108597 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108598 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108599 + depends on PAX_KERNEXEC && X86_32
108600 + help
108601 + Due to implementation details the kernel must reserve a fixed
108602 + amount of memory for runtime allocated code (such as modules)
108603 + at compile time that cannot be changed at runtime. Here you
108604 + can specify the minimum amount in MB that will be reserved.
108605 + Due to the same implementation details this size will always
108606 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108607 + the actually available memory for runtime allocated code will
108608 + usually be more than this minimum.
108609 +
108610 + The default 4 MB should be enough for most users but if you have
108611 + an excessive number of modules (e.g., most distribution configs
108612 + compile many drivers as modules) or use huge modules such as
108613 + nvidia's kernel driver, you will need to adjust this amount.
108614 + A good rule of thumb is to look at your currently loaded kernel
108615 + modules and add up their sizes.
108616 +
108617 +endmenu
108618 +
108619 +menu "Address Space Layout Randomization"
108620 + depends on PAX
108621 +
108622 +config PAX_ASLR
108623 + bool "Address Space Layout Randomization"
108624 + default y if GRKERNSEC_CONFIG_AUTO
108625 + help
108626 + Many if not most exploit techniques rely on the knowledge of
108627 + certain addresses in the attacked program. The following options
108628 + will allow the kernel to apply a certain amount of randomization
108629 + to specific parts of the program thereby forcing an attacker to
108630 + guess them in most cases. Any failed guess will most likely crash
108631 + the attacked program which allows the kernel to detect such attempts
108632 + and react on them. PaX itself provides no reaction mechanisms,
108633 + instead it is strongly encouraged that you make use of grsecurity's
108634 + (http://www.grsecurity.net/) built-in crash detection features or
108635 + develop one yourself.
108636 +
108637 + By saying Y here you can choose to randomize the following areas:
108638 + - top of the task's kernel stack
108639 + - top of the task's userland stack
108640 + - base address for mmap() requests that do not specify one
108641 + (this includes all libraries)
108642 + - base address of the main executable
108643 +
108644 + It is strongly recommended to say Y here as address space layout
108645 + randomization has negligible impact on performance yet it provides
108646 + a very effective protection.
108647 +
108648 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108649 + this feature on a per file basis.
108650 +
108651 +config PAX_RANDKSTACK
108652 + bool "Randomize kernel stack base"
108653 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108654 + depends on X86_TSC && X86
108655 + help
108656 + By saying Y here the kernel will randomize every task's kernel
108657 + stack on every system call. This will not only force an attacker
108658 + to guess it but also prevent him from making use of possible
108659 + leaked information about it.
108660 +
108661 + Since the kernel stack is a rather scarce resource, randomization
108662 + may cause unexpected stack overflows, therefore you should very
108663 + carefully test your system. Note that once enabled in the kernel
108664 + configuration, this feature cannot be disabled on a per file basis.
108665 +
108666 +config PAX_RANDUSTACK
108667 + bool
108668 +
108669 +config PAX_RANDMMAP
108670 + bool "Randomize user stack and mmap() bases"
108671 + default y if GRKERNSEC_CONFIG_AUTO
108672 + depends on PAX_ASLR
108673 + select PAX_RANDUSTACK
108674 + help
108675 + By saying Y here the kernel will randomize every task's userland
108676 + stack and use a randomized base address for mmap() requests that
108677 + do not specify one themselves.
108678 +
108679 + The stack randomization is done in two steps where the second
108680 + one may apply a big amount of shift to the top of the stack and
108681 + cause problems for programs that want to use lots of memory (more
108682 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108683 +
108684 + As a result of mmap randomization all dynamically loaded libraries
108685 + will appear at random addresses and therefore be harder to exploit
108686 + by a technique where an attacker attempts to execute library code
108687 + for his purposes (e.g. spawn a shell from an exploited program that
108688 + is running at an elevated privilege level).
108689 +
108690 + Furthermore, if a program is relinked as a dynamic ELF file, its
108691 + base address will be randomized as well, completing the full
108692 + randomization of the address space layout. Attacking such programs
108693 + becomes a guess game. You can find an example of doing this at
108694 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108695 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108696 +
108697 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108698 + feature on a per file basis.
108699 +
108700 +endmenu
108701 +
108702 +menu "Miscellaneous hardening features"
108703 +
108704 +config PAX_MEMORY_SANITIZE
108705 + bool "Sanitize all freed memory"
108706 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108707 + help
108708 + By saying Y here the kernel will erase memory pages and slab objects
108709 + as soon as they are freed. This in turn reduces the lifetime of data
108710 + stored in them, making it less likely that sensitive information such
108711 + as passwords, cryptographic secrets, etc stay in memory for too long.
108712 +
108713 + This is especially useful for programs whose runtime is short, long
108714 + lived processes and the kernel itself benefit from this as long as
108715 + they ensure timely freeing of memory that may hold sensitive
108716 + information.
108717 +
108718 + A nice side effect of the sanitization of slab objects is the
108719 + reduction of possible info leaks caused by padding bytes within the
108720 + leaky structures. Use-after-free bugs for structures containing
108721 + pointers can also be detected as dereferencing the sanitized pointer
108722 + will generate an access violation.
108723 +
108724 + The tradeoff is performance impact, on a single CPU system kernel
108725 + compilation sees a 3% slowdown, other systems and workloads may vary
108726 + and you are advised to test this feature on your expected workload
108727 + before deploying it.
108728 +
108729 + To reduce the performance penalty by sanitizing pages only, albeit
108730 + limiting the effectiveness of this feature at the same time, slab
108731 + sanitization can be disabled with the kernel commandline parameter
108732 + "pax_sanitize_slab=0".
108733 +
108734 + Note that this feature does not protect data stored in live pages,
108735 + e.g., process memory swapped to disk may stay there for a long time.
108736 +
108737 +config PAX_MEMORY_STACKLEAK
108738 + bool "Sanitize kernel stack"
108739 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108740 + depends on X86
108741 + help
108742 + By saying Y here the kernel will erase the kernel stack before it
108743 + returns from a system call. This in turn reduces the information
108744 + that a kernel stack leak bug can reveal.
108745 +
108746 + Note that such a bug can still leak information that was put on
108747 + the stack by the current system call (the one eventually triggering
108748 + the bug) but traces of earlier system calls on the kernel stack
108749 + cannot leak anymore.
108750 +
108751 + The tradeoff is performance impact: on a single CPU system kernel
108752 + compilation sees a 1% slowdown, other systems and workloads may vary
108753 + and you are advised to test this feature on your expected workload
108754 + before deploying it.
108755 +
108756 + Note that the full feature requires a gcc with plugin support,
108757 + i.e., gcc 4.5 or newer. You may need to install the supporting
108758 + headers explicitly in addition to the normal gcc package. Using
108759 + older gcc versions means that functions with large enough stack
108760 + frames may leave uninitialized memory behind that may be exposed
108761 + to a later syscall leaking the stack.
108762 +
108763 +config PAX_MEMORY_STRUCTLEAK
108764 + bool "Forcibly initialize local variables copied to userland"
108765 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108766 + help
108767 + By saying Y here the kernel will zero initialize some local
108768 + variables that are going to be copied to userland. This in
108769 + turn prevents unintended information leakage from the kernel
108770 + stack should later code forget to explicitly set all parts of
108771 + the copied variable.
108772 +
108773 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
108774 + at a much smaller coverage.
108775 +
108776 + Note that the implementation requires a gcc with plugin support,
108777 + i.e., gcc 4.5 or newer. You may need to install the supporting
108778 + headers explicitly in addition to the normal gcc package.
108779 +
108780 +config PAX_MEMORY_UDEREF
108781 + bool "Prevent invalid userland pointer dereference"
108782 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
108783 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
108784 + select PAX_PER_CPU_PGD if X86_64
108785 + help
108786 + By saying Y here the kernel will be prevented from dereferencing
108787 + userland pointers in contexts where the kernel expects only kernel
108788 + pointers. This is both a useful runtime debugging feature and a
108789 + security measure that prevents exploiting a class of kernel bugs.
108790 +
108791 + The tradeoff is that some virtualization solutions may experience
108792 + a huge slowdown and therefore you should not enable this feature
108793 + for kernels meant to run in such environments. Whether a given VM
108794 + solution is affected or not is best determined by simply trying it
108795 + out, the performance impact will be obvious right on boot as this
108796 + mechanism engages from very early on. A good rule of thumb is that
108797 + VMs running on CPUs without hardware virtualization support (i.e.,
108798 + the majority of IA-32 CPUs) will likely experience the slowdown.
108799 +
108800 + On X86_64 the kernel will make use of PCID support when available
108801 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
108802 + or performance impact. Pass pax_weakuderef on the kernel command
108803 + line to choose the latter.
108804 +
108805 +config PAX_REFCOUNT
108806 + bool "Prevent various kernel object reference counter overflows"
108807 + default y if GRKERNSEC_CONFIG_AUTO
108808 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
108809 + help
108810 + By saying Y here the kernel will detect and prevent overflowing
108811 + various (but not all) kinds of object reference counters. Such
108812 + overflows can normally occur due to bugs only and are often, if
108813 + not always, exploitable.
108814 +
108815 + The tradeoff is that data structures protected by an overflowed
108816 + refcount will never be freed and therefore will leak memory. Note
108817 + that this leak also happens even without this protection but in
108818 + that case the overflow can eventually trigger the freeing of the
108819 + data structure while it is still being used elsewhere, resulting
108820 + in the exploitable situation that this feature prevents.
108821 +
108822 + Since this has a negligible performance impact, you should enable
108823 + this feature.
108824 +
108825 +config PAX_CONSTIFY_PLUGIN
108826 + bool "Automatically constify eligible structures"
108827 + default y
108828 + depends on !UML && PAX_KERNEXEC
108829 + help
108830 + By saying Y here the compiler will automatically constify a class
108831 + of types that contain only function pointers. This reduces the
108832 + kernel's attack surface and also produces a better memory layout.
108833 +
108834 + Note that the implementation requires a gcc with plugin support,
108835 + i.e., gcc 4.5 or newer. You may need to install the supporting
108836 + headers explicitly in addition to the normal gcc package.
108837 +
108838 + Note that if some code really has to modify constified variables
108839 + then the source code will have to be patched to allow it. Examples
108840 + can be found in PaX itself (the no_const attribute) and for some
108841 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
108842 +
108843 +config PAX_USERCOPY
108844 + bool "Harden heap object copies between kernel and userland"
108845 + default y if GRKERNSEC_CONFIG_AUTO
108846 + depends on ARM || IA64 || PPC || SPARC || X86
108847 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
108848 + select PAX_USERCOPY_SLABS
108849 + help
108850 + By saying Y here the kernel will enforce the size of heap objects
108851 + when they are copied in either direction between the kernel and
108852 + userland, even if only a part of the heap object is copied.
108853 +
108854 + Specifically, this checking prevents information leaking from the
108855 + kernel heap during kernel to userland copies (if the kernel heap
108856 + object is otherwise fully initialized) and prevents kernel heap
108857 + overflows during userland to kernel copies.
108858 +
108859 + Note that the current implementation provides the strictest bounds
108860 + checks for the SLUB allocator.
108861 +
108862 + Enabling this option also enables per-slab cache protection against
108863 + data in a given cache being copied into/out of via userland
108864 + accessors. Though the whitelist of regions will be reduced over
108865 + time, it notably protects important data structures like task structs.
108866 +
108867 + If frame pointers are enabled on x86, this option will also restrict
108868 + copies into and out of the kernel stack to local variables within a
108869 + single frame.
108870 +
108871 + Since this has a negligible performance impact, you should enable
108872 + this feature.
108873 +
108874 +config PAX_USERCOPY_DEBUG
108875 + bool
108876 + depends on X86 && PAX_USERCOPY
108877 + default n
108878 +
108879 +config PAX_SIZE_OVERFLOW
108880 + bool "Prevent various integer overflows in function size parameters"
108881 + default y if GRKERNSEC_CONFIG_AUTO
108882 + depends on X86
108883 + help
108884 + By saying Y here the kernel recomputes expressions of function
108885 + arguments marked by a size_overflow attribute with double integer
108886 + precision (DImode/TImode for 32/64 bit integer types).
108887 +
108888 + The recomputed argument is checked against TYPE_MAX and an event
108889 + is logged on overflow and the triggering process is killed.
108890 +
108891 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
108892 +
108893 + Note that the implementation requires a gcc with plugin support,
108894 + i.e., gcc 4.5 or newer. You may need to install the supporting
108895 + headers explicitly in addition to the normal gcc package.
108896 +
108897 +config PAX_LATENT_ENTROPY
108898 + bool "Generate some entropy during boot and runtime"
108899 + default y if GRKERNSEC_CONFIG_AUTO
108900 + help
108901 + By saying Y here the kernel will instrument some kernel code to
108902 + extract some entropy from both original and artificially created
108903 + program state. This will help especially embedded systems where
108904 + there is little 'natural' source of entropy normally. The cost
108905 + is some slowdown of the boot process and fork and irq processing.
108906 +
108907 + When pax_extra_latent_entropy is passed on the kernel command line,
108908 + entropy will be extracted from up to the first 4GB of RAM while the
108909 + runtime memory allocator is being initialized. This costs even more
108910 + slowdown of the boot process.
108911 +
108912 + Note that the implementation requires a gcc with plugin support,
108913 + i.e., gcc 4.5 or newer. You may need to install the supporting
108914 + headers explicitly in addition to the normal gcc package.
108915 +
108916 + Note that entropy extracted this way is not cryptographically
108917 + secure!
108918 +
108919 +endmenu
108920 +
108921 +endmenu
108922 +
108923 +source grsecurity/Kconfig
108924 +
108925 +endmenu
108926 +
108927 +endmenu
108928 +
108929 source security/keys/Kconfig
108930
108931 config SECURITY_DMESG_RESTRICT
108932 @@ -103,7 +1062,7 @@ config INTEL_TXT
108933 config LSM_MMAP_MIN_ADDR
108934 int "Low address space for LSM to protect from user allocation"
108935 depends on SECURITY && SECURITY_SELINUX
108936 - default 32768 if ARM || (ARM64 && COMPAT)
108937 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
108938 default 65536
108939 help
108940 This is the portion of low virtual memory which should be protected
108941 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
108942 index fdaa50c..2761dcb 100644
108943 --- a/security/apparmor/file.c
108944 +++ b/security/apparmor/file.c
108945 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
108946 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
108947 struct path *new_dir, struct dentry *new_dentry)
108948 {
108949 - struct path link = { new_dir->mnt, new_dentry };
108950 - struct path target = { new_dir->mnt, old_dentry };
108951 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
108952 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
108953 struct path_cond cond = {
108954 old_dentry->d_inode->i_uid,
108955 old_dentry->d_inode->i_mode
108956 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
108957 index 9981000..eb21356 100644
108958 --- a/security/apparmor/lsm.c
108959 +++ b/security/apparmor/lsm.c
108960 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108961 struct dentry *dentry, u32 mask,
108962 struct path_cond *cond)
108963 {
108964 - struct path path = { dir->mnt, dentry };
108965 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
108966
108967 return common_perm(op, &path, mask, cond);
108968 }
108969 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108970 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
108971 struct dentry *dentry, u32 mask)
108972 {
108973 - struct path path = { mnt, dentry };
108974 + struct path path = { .mnt = mnt, .dentry = dentry };
108975 struct path_cond cond = { dentry->d_inode->i_uid,
108976 dentry->d_inode->i_mode
108977 };
108978 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
108979
108980 profile = aa_current_profile();
108981 if (!unconfined(profile)) {
108982 - struct path old_path = { old_dir->mnt, old_dentry };
108983 - struct path new_path = { new_dir->mnt, new_dentry };
108984 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
108985 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
108986 struct path_cond cond = { old_dentry->d_inode->i_uid,
108987 old_dentry->d_inode->i_mode
108988 };
108989 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
108990 return error;
108991 }
108992
108993 -static struct security_operations apparmor_ops = {
108994 +static struct security_operations apparmor_ops __read_only = {
108995 .name = "apparmor",
108996
108997 .ptrace_access_check = apparmor_ptrace_access_check,
108998 diff --git a/security/commoncap.c b/security/commoncap.c
108999 index bab0611..f9a0ff5 100644
109000 --- a/security/commoncap.c
109001 +++ b/security/commoncap.c
109002 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109003 return 0;
109004 }
109005
109006 +/* returns:
109007 + 1 for suid privilege
109008 + 2 for sgid privilege
109009 + 3 for fscap privilege
109010 +*/
109011 +int is_privileged_binary(const struct dentry *dentry)
109012 +{
109013 + struct cpu_vfs_cap_data capdata;
109014 + struct inode *inode = dentry->d_inode;
109015 +
109016 + if (!inode || S_ISDIR(inode->i_mode))
109017 + return 0;
109018 +
109019 + if (inode->i_mode & S_ISUID)
109020 + return 1;
109021 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109022 + return 2;
109023 +
109024 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109025 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109026 + return 3;
109027 + }
109028 +
109029 + return 0;
109030 +}
109031 +
109032 /*
109033 * Attempt to get the on-exec apply capability sets for an executable file from
109034 * its xattrs and, if present, apply them to the proposed credentials being
109035 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109036 const struct cred *cred = current_cred();
109037 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109038
109039 + if (gr_acl_enable_at_secure())
109040 + return 1;
109041 +
109042 if (!uid_eq(cred->uid, root_uid)) {
109043 if (bprm->cap_effective)
109044 return 1;
109045 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109046 index 57da4bd..db453a2 100644
109047 --- a/security/integrity/ima/ima.h
109048 +++ b/security/integrity/ima/ima.h
109049 @@ -118,8 +118,8 @@ int ima_init_template(void);
109050 extern spinlock_t ima_queue_lock;
109051
109052 struct ima_h_table {
109053 - atomic_long_t len; /* number of stored measurements in the list */
109054 - atomic_long_t violations;
109055 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109056 + atomic_long_unchecked_t violations;
109057 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109058 };
109059 extern struct ima_h_table ima_htable;
109060 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109061 index d9cd5ce..c5c29ac 100644
109062 --- a/security/integrity/ima/ima_api.c
109063 +++ b/security/integrity/ima/ima_api.c
109064 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109065 int result;
109066
109067 /* can overflow, only indicator */
109068 - atomic_long_inc(&ima_htable.violations);
109069 + atomic_long_inc_unchecked(&ima_htable.violations);
109070
109071 result = ima_alloc_init_template(NULL, file, filename,
109072 NULL, 0, &entry);
109073 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109074 index da92fcc..8a5d390 100644
109075 --- a/security/integrity/ima/ima_fs.c
109076 +++ b/security/integrity/ima/ima_fs.c
109077 @@ -28,12 +28,12 @@
109078 static int valid_policy = 1;
109079 #define TMPBUFLEN 12
109080 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109081 - loff_t *ppos, atomic_long_t *val)
109082 + loff_t *ppos, atomic_long_unchecked_t *val)
109083 {
109084 char tmpbuf[TMPBUFLEN];
109085 ssize_t len;
109086
109087 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109088 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109089 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109090 }
109091
109092 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109093 index 552705d..9920f4fb 100644
109094 --- a/security/integrity/ima/ima_queue.c
109095 +++ b/security/integrity/ima/ima_queue.c
109096 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109097 INIT_LIST_HEAD(&qe->later);
109098 list_add_tail_rcu(&qe->later, &ima_measurements);
109099
109100 - atomic_long_inc(&ima_htable.len);
109101 + atomic_long_inc_unchecked(&ima_htable.len);
109102 key = ima_hash_key(entry->digest);
109103 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109104 return 0;
109105 diff --git a/security/keys/compat.c b/security/keys/compat.c
109106 index 3478965..ec7bb9e 100644
109107 --- a/security/keys/compat.c
109108 +++ b/security/keys/compat.c
109109 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109110 if (ret == 0)
109111 goto no_payload_free;
109112
109113 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109114 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109115 err:
109116 if (iov != iovstack)
109117 kfree(iov);
109118 diff --git a/security/keys/internal.h b/security/keys/internal.h
109119 index 5f20da0..444ccf1 100644
109120 --- a/security/keys/internal.h
109121 +++ b/security/keys/internal.h
109122 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109123 extern long keyctl_invalidate_key(key_serial_t);
109124
109125 extern long keyctl_instantiate_key_common(key_serial_t,
109126 - const struct iovec *,
109127 + const struct iovec __user *,
109128 unsigned, size_t, key_serial_t);
109129 #ifdef CONFIG_PERSISTENT_KEYRINGS
109130 extern long keyctl_get_persistent(uid_t, key_serial_t);
109131 diff --git a/security/keys/key.c b/security/keys/key.c
109132 index 6d0cad1..8f957df 100644
109133 --- a/security/keys/key.c
109134 +++ b/security/keys/key.c
109135 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109136
109137 atomic_set(&key->usage, 1);
109138 init_rwsem(&key->sem);
109139 - lockdep_set_class(&key->sem, &type->lock_class);
109140 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109141 key->index_key.type = type;
109142 key->user = user;
109143 key->quotalen = quotalen;
109144 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109145 struct key_type *p;
109146 int ret;
109147
109148 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109149 + pax_open_kernel();
109150 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109151 + pax_close_kernel();
109152
109153 ret = -EEXIST;
109154 down_write(&key_types_sem);
109155 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109156 }
109157
109158 /* store the type */
109159 - list_add(&ktype->link, &key_types_list);
109160 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109161
109162 pr_notice("Key type %s registered\n", ktype->name);
109163 ret = 0;
109164 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109165 void unregister_key_type(struct key_type *ktype)
109166 {
109167 down_write(&key_types_sem);
109168 - list_del_init(&ktype->link);
109169 + pax_list_del_init((struct list_head *)&ktype->link);
109170 downgrade_write(&key_types_sem);
109171 key_gc_keytype(ktype);
109172 pr_notice("Key type %s unregistered\n", ktype->name);
109173 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109174 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109175
109176 /* add the special key types */
109177 - list_add_tail(&key_type_keyring.link, &key_types_list);
109178 - list_add_tail(&key_type_dead.link, &key_types_list);
109179 - list_add_tail(&key_type_user.link, &key_types_list);
109180 - list_add_tail(&key_type_logon.link, &key_types_list);
109181 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109182 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109183 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109184 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109185
109186 /* record the root user tracking */
109187 rb_link_node(&root_key_user.node,
109188 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109189 index e26f860..dcbe7ea 100644
109190 --- a/security/keys/keyctl.c
109191 +++ b/security/keys/keyctl.c
109192 @@ -1002,7 +1002,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109193 /*
109194 * Copy the iovec data from userspace
109195 */
109196 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109197 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109198 unsigned ioc)
109199 {
109200 for (; ioc > 0; ioc--) {
109201 @@ -1024,7 +1024,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109202 * If successful, 0 will be returned.
109203 */
109204 long keyctl_instantiate_key_common(key_serial_t id,
109205 - const struct iovec *payload_iov,
109206 + const struct iovec __user *payload_iov,
109207 unsigned ioc,
109208 size_t plen,
109209 key_serial_t ringid)
109210 @@ -1119,7 +1119,7 @@ long keyctl_instantiate_key(key_serial_t id,
109211 [0].iov_len = plen
109212 };
109213
109214 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109215 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109216 }
109217
109218 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109219 @@ -1152,7 +1152,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109220 if (ret == 0)
109221 goto no_payload_free;
109222
109223 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109224 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109225 err:
109226 if (iov != iovstack)
109227 kfree(iov);
109228 diff --git a/security/min_addr.c b/security/min_addr.c
109229 index f728728..6457a0c 100644
109230 --- a/security/min_addr.c
109231 +++ b/security/min_addr.c
109232 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109233 */
109234 static void update_mmap_min_addr(void)
109235 {
109236 +#ifndef SPARC
109237 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109238 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109239 mmap_min_addr = dac_mmap_min_addr;
109240 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109241 #else
109242 mmap_min_addr = dac_mmap_min_addr;
109243 #endif
109244 +#endif
109245 }
109246
109247 /*
109248 diff --git a/security/security.c b/security/security.c
109249 index e41b1a8..b66a558 100644
109250 --- a/security/security.c
109251 +++ b/security/security.c
109252 @@ -33,8 +33,8 @@
109253 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109254 CONFIG_DEFAULT_SECURITY;
109255
109256 -static struct security_operations *security_ops;
109257 -static struct security_operations default_security_ops = {
109258 +struct security_operations *security_ops __read_only;
109259 +struct security_operations default_security_ops __read_only = {
109260 .name = "default",
109261 };
109262
109263 @@ -73,11 +73,6 @@ int __init security_init(void)
109264 return 0;
109265 }
109266
109267 -void reset_security_ops(void)
109268 -{
109269 - security_ops = &default_security_ops;
109270 -}
109271 -
109272 /* Save user chosen LSM */
109273 static int __init choose_lsm(char *str)
109274 {
109275 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109276 index a18f1fa..c9b9fc4 100644
109277 --- a/security/selinux/avc.c
109278 +++ b/security/selinux/avc.c
109279 @@ -59,7 +59,7 @@ struct avc_node {
109280 struct avc_cache {
109281 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109282 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109283 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109284 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109285 atomic_t active_nodes;
109286 u32 latest_notif; /* latest revocation notification */
109287 };
109288 @@ -167,7 +167,7 @@ void __init avc_init(void)
109289 spin_lock_init(&avc_cache.slots_lock[i]);
109290 }
109291 atomic_set(&avc_cache.active_nodes, 0);
109292 - atomic_set(&avc_cache.lru_hint, 0);
109293 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109294
109295 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109296 0, SLAB_PANIC, NULL);
109297 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109298 spinlock_t *lock;
109299
109300 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109301 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109302 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109303 head = &avc_cache.slots[hvalue];
109304 lock = &avc_cache.slots_lock[hvalue];
109305
109306 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109307 index b0e9404..b15da09 100644
109308 --- a/security/selinux/hooks.c
109309 +++ b/security/selinux/hooks.c
109310 @@ -95,8 +95,6 @@
109311 #include "audit.h"
109312 #include "avc_ss.h"
109313
109314 -extern struct security_operations *security_ops;
109315 -
109316 /* SECMARK reference count */
109317 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109318
109319 @@ -481,6 +479,7 @@ next_inode:
109320 list_entry(sbsec->isec_head.next,
109321 struct inode_security_struct, list);
109322 struct inode *inode = isec->inode;
109323 + list_del_init(&isec->list);
109324 spin_unlock(&sbsec->isec_lock);
109325 inode = igrab(inode);
109326 if (inode) {
109327 @@ -489,7 +488,6 @@ next_inode:
109328 iput(inode);
109329 }
109330 spin_lock(&sbsec->isec_lock);
109331 - list_del_init(&isec->list);
109332 goto next_inode;
109333 }
109334 spin_unlock(&sbsec->isec_lock);
109335 @@ -5772,7 +5770,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109336
109337 #endif
109338
109339 -static struct security_operations selinux_ops = {
109340 +static struct security_operations selinux_ops __read_only = {
109341 .name = "selinux",
109342
109343 .ptrace_access_check = selinux_ptrace_access_check,
109344 @@ -6128,6 +6126,9 @@ static void selinux_nf_ip_exit(void)
109345 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109346 static int selinux_disabled;
109347
109348 +extern struct security_operations *security_ops;
109349 +extern struct security_operations default_security_ops;
109350 +
109351 int selinux_disable(void)
109352 {
109353 if (ss_initialized) {
109354 @@ -6145,7 +6146,9 @@ int selinux_disable(void)
109355 selinux_disabled = 1;
109356 selinux_enabled = 0;
109357
109358 - reset_security_ops();
109359 + pax_open_kernel();
109360 + security_ops = &default_security_ops;
109361 + pax_close_kernel();
109362
109363 /* Try to destroy the avc node cache */
109364 avc_disable();
109365 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109366 index 1450f85..a91e0bc 100644
109367 --- a/security/selinux/include/xfrm.h
109368 +++ b/security/selinux/include/xfrm.h
109369 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109370
109371 rtnl_lock();
109372 for_each_net(net) {
109373 - atomic_inc(&net->xfrm.flow_cache_genid);
109374 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109375 rt_genid_bump_all(net);
109376 }
109377 rtnl_unlock();
109378 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109379 index e6ab307..2008c98 100644
109380 --- a/security/smack/smack_lsm.c
109381 +++ b/security/smack/smack_lsm.c
109382 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109383 return 0;
109384 }
109385
109386 -struct security_operations smack_ops = {
109387 +struct security_operations smack_ops __read_only = {
109388 .name = "smack",
109389
109390 .ptrace_access_check = smack_ptrace_access_check,
109391 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109392 index 4003907..13a2b55 100644
109393 --- a/security/tomoyo/file.c
109394 +++ b/security/tomoyo/file.c
109395 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109396 {
109397 struct tomoyo_request_info r;
109398 struct tomoyo_obj_info obj = {
109399 - .path1 = *path,
109400 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109401 };
109402 int error = -ENOMEM;
109403 struct tomoyo_path_info buf;
109404 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109405 struct tomoyo_path_info buf;
109406 struct tomoyo_request_info r;
109407 struct tomoyo_obj_info obj = {
109408 - .path1 = *path,
109409 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109410 };
109411 int idx;
109412
109413 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109414 {
109415 struct tomoyo_request_info r;
109416 struct tomoyo_obj_info obj = {
109417 - .path1 = *path,
109418 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109419 };
109420 int error;
109421 struct tomoyo_path_info buf;
109422 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109423 {
109424 struct tomoyo_request_info r;
109425 struct tomoyo_obj_info obj = {
109426 - .path1 = *path,
109427 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109428 };
109429 int error = -ENOMEM;
109430 struct tomoyo_path_info buf;
109431 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109432 struct tomoyo_path_info buf2;
109433 struct tomoyo_request_info r;
109434 struct tomoyo_obj_info obj = {
109435 - .path1 = *path1,
109436 - .path2 = *path2,
109437 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109438 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109439 };
109440 int idx;
109441
109442 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109443 index 390c646..f2f8db3 100644
109444 --- a/security/tomoyo/mount.c
109445 +++ b/security/tomoyo/mount.c
109446 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109447 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109448 need_dev = -1; /* dev_name is a directory */
109449 } else {
109450 + if (!capable(CAP_SYS_ADMIN)) {
109451 + error = -EPERM;
109452 + goto out;
109453 + }
109454 fstype = get_fs_type(type);
109455 if (!fstype) {
109456 error = -ENODEV;
109457 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109458 index f0b756e..8aa497b 100644
109459 --- a/security/tomoyo/tomoyo.c
109460 +++ b/security/tomoyo/tomoyo.c
109461 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109462 */
109463 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109464 {
109465 - struct path path = { mnt, dentry };
109466 + struct path path = { .mnt = mnt, .dentry = dentry };
109467 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109468 }
109469
109470 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109471 */
109472 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109473 {
109474 - struct path path = { parent->mnt, dentry };
109475 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109476 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109477 }
109478
109479 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109480 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109481 umode_t mode)
109482 {
109483 - struct path path = { parent->mnt, dentry };
109484 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109485 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109486 mode & S_IALLUGO);
109487 }
109488 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109489 */
109490 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109491 {
109492 - struct path path = { parent->mnt, dentry };
109493 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109494 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109495 }
109496
109497 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109498 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109499 const char *old_name)
109500 {
109501 - struct path path = { parent->mnt, dentry };
109502 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109503 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109504 }
109505
109506 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109507 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109508 umode_t mode, unsigned int dev)
109509 {
109510 - struct path path = { parent->mnt, dentry };
109511 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109512 int type = TOMOYO_TYPE_CREATE;
109513 const unsigned int perm = mode & S_IALLUGO;
109514
109515 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109516 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109517 struct dentry *new_dentry)
109518 {
109519 - struct path path1 = { new_dir->mnt, old_dentry };
109520 - struct path path2 = { new_dir->mnt, new_dentry };
109521 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109522 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109523 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109524 }
109525
109526 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109527 struct path *new_parent,
109528 struct dentry *new_dentry)
109529 {
109530 - struct path path1 = { old_parent->mnt, old_dentry };
109531 - struct path path2 = { new_parent->mnt, new_dentry };
109532 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109533 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109534 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109535 }
109536
109537 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109538 */
109539 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109540 {
109541 - struct path path = { mnt, mnt->mnt_root };
109542 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109543 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109544 }
109545
109546 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109547 * tomoyo_security_ops is a "struct security_operations" which is used for
109548 * registering TOMOYO.
109549 */
109550 -static struct security_operations tomoyo_security_ops = {
109551 +static struct security_operations tomoyo_security_ops __read_only = {
109552 .name = "tomoyo",
109553 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109554 .cred_prepare = tomoyo_cred_prepare,
109555 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109556 index 20ef514..4182bed 100644
109557 --- a/security/yama/Kconfig
109558 +++ b/security/yama/Kconfig
109559 @@ -1,6 +1,6 @@
109560 config SECURITY_YAMA
109561 bool "Yama support"
109562 - depends on SECURITY
109563 + depends on SECURITY && !GRKERNSEC
109564 select SECURITYFS
109565 select SECURITY_PATH
109566 default n
109567 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109568 index 13c88fbc..f8c115e 100644
109569 --- a/security/yama/yama_lsm.c
109570 +++ b/security/yama/yama_lsm.c
109571 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109572 }
109573
109574 #ifndef CONFIG_SECURITY_YAMA_STACKED
109575 -static struct security_operations yama_ops = {
109576 +static struct security_operations yama_ops __read_only = {
109577 .name = "yama",
109578
109579 .ptrace_access_check = yama_ptrace_access_check,
109580 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109581 #endif
109582
109583 #ifdef CONFIG_SYSCTL
109584 +static int zero __read_only;
109585 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109586 +
109587 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109588 void __user *buffer, size_t *lenp, loff_t *ppos)
109589 {
109590 - int rc;
109591 + ctl_table_no_const yama_table;
109592
109593 if (write && !capable(CAP_SYS_PTRACE))
109594 return -EPERM;
109595
109596 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109597 - if (rc)
109598 - return rc;
109599 -
109600 + yama_table = *table;
109601 /* Lock the max value if it ever gets set. */
109602 - if (write && *(int *)table->data == *(int *)table->extra2)
109603 - table->extra1 = table->extra2;
109604 -
109605 - return rc;
109606 + if (ptrace_scope == max_scope)
109607 + yama_table.extra1 = &max_scope;
109608 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109609 }
109610
109611 -static int zero;
109612 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109613 -
109614 struct ctl_path yama_sysctl_path[] = {
109615 { .procname = "kernel", },
109616 { .procname = "yama", },
109617 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109618 index 401107b..b9c47c6 100644
109619 --- a/sound/aoa/codecs/onyx.c
109620 +++ b/sound/aoa/codecs/onyx.c
109621 @@ -54,7 +54,7 @@ struct onyx {
109622 spdif_locked:1,
109623 analog_locked:1,
109624 original_mute:2;
109625 - int open_count;
109626 + local_t open_count;
109627 struct codec_info *codec_info;
109628
109629 /* mutex serializes concurrent access to the device
109630 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109631 struct onyx *onyx = cii->codec_data;
109632
109633 mutex_lock(&onyx->mutex);
109634 - onyx->open_count++;
109635 + local_inc(&onyx->open_count);
109636 mutex_unlock(&onyx->mutex);
109637
109638 return 0;
109639 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109640 struct onyx *onyx = cii->codec_data;
109641
109642 mutex_lock(&onyx->mutex);
109643 - onyx->open_count--;
109644 - if (!onyx->open_count)
109645 + if (local_dec_and_test(&onyx->open_count))
109646 onyx->spdif_locked = onyx->analog_locked = 0;
109647 mutex_unlock(&onyx->mutex);
109648
109649 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109650 index ffd2025..df062c9 100644
109651 --- a/sound/aoa/codecs/onyx.h
109652 +++ b/sound/aoa/codecs/onyx.h
109653 @@ -11,6 +11,7 @@
109654 #include <linux/i2c.h>
109655 #include <asm/pmac_low_i2c.h>
109656 #include <asm/prom.h>
109657 +#include <asm/local.h>
109658
109659 /* PCM3052 register definitions */
109660
109661 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109662 index ada69d7..5f65386 100644
109663 --- a/sound/core/oss/pcm_oss.c
109664 +++ b/sound/core/oss/pcm_oss.c
109665 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109666 if (in_kernel) {
109667 mm_segment_t fs;
109668 fs = snd_enter_user();
109669 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109670 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109671 snd_leave_user(fs);
109672 } else {
109673 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109674 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109675 }
109676 if (ret != -EPIPE && ret != -ESTRPIPE)
109677 break;
109678 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109679 if (in_kernel) {
109680 mm_segment_t fs;
109681 fs = snd_enter_user();
109682 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109683 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109684 snd_leave_user(fs);
109685 } else {
109686 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109687 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109688 }
109689 if (ret == -EPIPE) {
109690 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109691 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109692 struct snd_pcm_plugin_channel *channels;
109693 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109694 if (!in_kernel) {
109695 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109696 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109697 return -EFAULT;
109698 buf = runtime->oss.buffer;
109699 }
109700 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109701 }
109702 } else {
109703 tmp = snd_pcm_oss_write2(substream,
109704 - (const char __force *)buf,
109705 + (const char __force_kernel *)buf,
109706 runtime->oss.period_bytes, 0);
109707 if (tmp <= 0)
109708 goto err;
109709 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109710 struct snd_pcm_runtime *runtime = substream->runtime;
109711 snd_pcm_sframes_t frames, frames1;
109712 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
109713 - char __user *final_dst = (char __force __user *)buf;
109714 + char __user *final_dst = (char __force_user *)buf;
109715 if (runtime->oss.plugin_first) {
109716 struct snd_pcm_plugin_channel *channels;
109717 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
109718 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
109719 xfer += tmp;
109720 runtime->oss.buffer_used -= tmp;
109721 } else {
109722 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
109723 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
109724 runtime->oss.period_bytes, 0);
109725 if (tmp <= 0)
109726 goto err;
109727 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
109728 size1);
109729 size1 /= runtime->channels; /* frames */
109730 fs = snd_enter_user();
109731 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
109732 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
109733 snd_leave_user(fs);
109734 }
109735 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
109736 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
109737 index 102e8fd..7263bb8 100644
109738 --- a/sound/core/pcm_compat.c
109739 +++ b/sound/core/pcm_compat.c
109740 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
109741 int err;
109742
109743 fs = snd_enter_user();
109744 - err = snd_pcm_delay(substream, &delay);
109745 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
109746 snd_leave_user(fs);
109747 if (err < 0)
109748 return err;
109749 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
109750 index 8cd2f93..8412c57 100644
109751 --- a/sound/core/pcm_native.c
109752 +++ b/sound/core/pcm_native.c
109753 @@ -2815,11 +2815,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
109754 switch (substream->stream) {
109755 case SNDRV_PCM_STREAM_PLAYBACK:
109756 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
109757 - (void __user *)arg);
109758 + (void __force_user *)arg);
109759 break;
109760 case SNDRV_PCM_STREAM_CAPTURE:
109761 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
109762 - (void __user *)arg);
109763 + (void __force_user *)arg);
109764 break;
109765 default:
109766 result = -EINVAL;
109767 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
109768 index 16d4267..fe8b49b 100644
109769 --- a/sound/core/seq/oss/seq_oss.c
109770 +++ b/sound/core/seq/oss/seq_oss.c
109771 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
109772 {
109773 int rc;
109774 static struct snd_seq_dev_ops ops = {
109775 - snd_seq_oss_synth_register,
109776 - snd_seq_oss_synth_unregister,
109777 + .init_device = snd_seq_oss_synth_register,
109778 + .free_device = snd_seq_oss_synth_unregister,
109779 };
109780
109781 snd_seq_autoload_lock();
109782 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
109783 index 91a786a..4c07ed4 100644
109784 --- a/sound/core/seq/seq_device.c
109785 +++ b/sound/core/seq/seq_device.c
109786 @@ -64,7 +64,7 @@ struct ops_list {
109787 int argsize; /* argument size */
109788
109789 /* operators */
109790 - struct snd_seq_dev_ops ops;
109791 + struct snd_seq_dev_ops *ops;
109792
109793 /* registered devices */
109794 struct list_head dev_list; /* list of devices */
109795 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
109796
109797 mutex_lock(&ops->reg_mutex);
109798 /* copy driver operators */
109799 - ops->ops = *entry;
109800 + ops->ops = entry;
109801 ops->driver |= DRIVER_LOADED;
109802 ops->argsize = argsize;
109803
109804 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
109805 dev->name, ops->id, ops->argsize, dev->argsize);
109806 return -EINVAL;
109807 }
109808 - if (ops->ops.init_device(dev) >= 0) {
109809 + if (ops->ops->init_device(dev) >= 0) {
109810 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
109811 ops->num_init_devices++;
109812 } else {
109813 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
109814 dev->name, ops->id, ops->argsize, dev->argsize);
109815 return -EINVAL;
109816 }
109817 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
109818 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
109819 dev->status = SNDRV_SEQ_DEVICE_FREE;
109820 dev->driver_data = NULL;
109821 ops->num_init_devices--;
109822 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
109823 index a1fd77a..69cd659 100644
109824 --- a/sound/core/seq/seq_midi.c
109825 +++ b/sound/core/seq/seq_midi.c
109826 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
109827 static int __init alsa_seq_midi_init(void)
109828 {
109829 static struct snd_seq_dev_ops ops = {
109830 - snd_seq_midisynth_register_port,
109831 - snd_seq_midisynth_unregister_port,
109832 + .init_device = snd_seq_midisynth_register_port,
109833 + .free_device = snd_seq_midisynth_unregister_port,
109834 };
109835 memset(&synths, 0, sizeof(synths));
109836 snd_seq_autoload_lock();
109837 diff --git a/sound/core/sound.c b/sound/core/sound.c
109838 index 38ad1a0..5010a40 100644
109839 --- a/sound/core/sound.c
109840 +++ b/sound/core/sound.c
109841 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
109842 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
109843 default: return;
109844 }
109845 - request_module(str);
109846 + request_module("%s", str);
109847 }
109848
109849 #endif /* modular kernel */
109850 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
109851 index f5fd448..6ae276da 100644
109852 --- a/sound/drivers/mts64.c
109853 +++ b/sound/drivers/mts64.c
109854 @@ -29,6 +29,7 @@
109855 #include <sound/initval.h>
109856 #include <sound/rawmidi.h>
109857 #include <sound/control.h>
109858 +#include <asm/local.h>
109859
109860 #define CARD_NAME "Miditerminal 4140"
109861 #define DRIVER_NAME "MTS64"
109862 @@ -67,7 +68,7 @@ struct mts64 {
109863 struct pardevice *pardev;
109864 int pardev_claimed;
109865
109866 - int open_count;
109867 + local_t open_count;
109868 int current_midi_output_port;
109869 int current_midi_input_port;
109870 u8 mode[MTS64_NUM_INPUT_PORTS];
109871 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109872 {
109873 struct mts64 *mts = substream->rmidi->private_data;
109874
109875 - if (mts->open_count == 0) {
109876 + if (local_read(&mts->open_count) == 0) {
109877 /* We don't need a spinlock here, because this is just called
109878 if the device has not been opened before.
109879 So there aren't any IRQs from the device */
109880 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109881
109882 msleep(50);
109883 }
109884 - ++(mts->open_count);
109885 + local_inc(&mts->open_count);
109886
109887 return 0;
109888 }
109889 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109890 struct mts64 *mts = substream->rmidi->private_data;
109891 unsigned long flags;
109892
109893 - --(mts->open_count);
109894 - if (mts->open_count == 0) {
109895 + if (local_dec_return(&mts->open_count) == 0) {
109896 /* We need the spinlock_irqsave here because we can still
109897 have IRQs at this point */
109898 spin_lock_irqsave(&mts->lock, flags);
109899 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109900
109901 msleep(500);
109902
109903 - } else if (mts->open_count < 0)
109904 - mts->open_count = 0;
109905 + } else if (local_read(&mts->open_count) < 0)
109906 + local_set(&mts->open_count, 0);
109907
109908 return 0;
109909 }
109910 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
109911 index 6839953..7a0f4b9 100644
109912 --- a/sound/drivers/opl3/opl3_seq.c
109913 +++ b/sound/drivers/opl3/opl3_seq.c
109914 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
109915 {
109916 static struct snd_seq_dev_ops ops =
109917 {
109918 - snd_opl3_seq_new_device,
109919 - snd_opl3_seq_delete_device
109920 + .init_device = snd_opl3_seq_new_device,
109921 + .free_device = snd_opl3_seq_delete_device
109922 };
109923
109924 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
109925 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
109926 index b953fb4..1999c01 100644
109927 --- a/sound/drivers/opl4/opl4_lib.c
109928 +++ b/sound/drivers/opl4/opl4_lib.c
109929 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
109930 MODULE_DESCRIPTION("OPL4 driver");
109931 MODULE_LICENSE("GPL");
109932
109933 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
109934 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
109935 {
109936 int timeout = 10;
109937 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
109938 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
109939 index 9919769..d7de36c 100644
109940 --- a/sound/drivers/opl4/opl4_seq.c
109941 +++ b/sound/drivers/opl4/opl4_seq.c
109942 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
109943 static int __init alsa_opl4_synth_init(void)
109944 {
109945 static struct snd_seq_dev_ops ops = {
109946 - snd_opl4_seq_new_device,
109947 - snd_opl4_seq_delete_device
109948 + .init_device = snd_opl4_seq_new_device,
109949 + .free_device = snd_opl4_seq_delete_device
109950 };
109951
109952 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
109953 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
109954 index 78ccfa4..7a0857b 100644
109955 --- a/sound/drivers/portman2x4.c
109956 +++ b/sound/drivers/portman2x4.c
109957 @@ -48,6 +48,7 @@
109958 #include <sound/initval.h>
109959 #include <sound/rawmidi.h>
109960 #include <sound/control.h>
109961 +#include <asm/local.h>
109962
109963 #define CARD_NAME "Portman 2x4"
109964 #define DRIVER_NAME "portman"
109965 @@ -85,7 +86,7 @@ struct portman {
109966 struct pardevice *pardev;
109967 int pardev_claimed;
109968
109969 - int open_count;
109970 + local_t open_count;
109971 int mode[PORTMAN_NUM_INPUT_PORTS];
109972 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
109973 };
109974 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
109975 index 95fc2eaf..ea5d6a7 100644
109976 --- a/sound/firewire/amdtp.c
109977 +++ b/sound/firewire/amdtp.c
109978 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
109979 ptr = s->pcm_buffer_pointer + frames;
109980 if (ptr >= pcm->runtime->buffer_size)
109981 ptr -= pcm->runtime->buffer_size;
109982 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
109983 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
109984
109985 s->pcm_period_pointer += frames;
109986 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
109987 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
109988 */
109989 void amdtp_stream_update(struct amdtp_stream *s)
109990 {
109991 - ACCESS_ONCE(s->source_node_id_field) =
109992 + ACCESS_ONCE_RW(s->source_node_id_field) =
109993 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
109994 }
109995 EXPORT_SYMBOL(amdtp_stream_update);
109996 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
109997 index 4823c08..47a5f7c 100644
109998 --- a/sound/firewire/amdtp.h
109999 +++ b/sound/firewire/amdtp.h
110000 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110001 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110002 struct snd_pcm_substream *pcm)
110003 {
110004 - ACCESS_ONCE(s->pcm) = pcm;
110005 + ACCESS_ONCE_RW(s->pcm) = pcm;
110006 }
110007
110008 /**
110009 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110010 struct snd_rawmidi_substream *midi)
110011 {
110012 if (port < s->midi_ports)
110013 - ACCESS_ONCE(s->midi[port]) = midi;
110014 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110015 }
110016
110017 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110018 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110019 index 7ac9443..0ec6274 100644
110020 --- a/sound/firewire/isight.c
110021 +++ b/sound/firewire/isight.c
110022 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110023 ptr += count;
110024 if (ptr >= runtime->buffer_size)
110025 ptr -= runtime->buffer_size;
110026 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110027 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110028
110029 isight->period_counter += count;
110030 if (isight->period_counter >= runtime->period_size) {
110031 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110032 if (err < 0)
110033 return err;
110034
110035 - ACCESS_ONCE(isight->pcm_active) = true;
110036 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110037
110038 return 0;
110039 }
110040 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110041 {
110042 struct isight *isight = substream->private_data;
110043
110044 - ACCESS_ONCE(isight->pcm_active) = false;
110045 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110046
110047 mutex_lock(&isight->mutex);
110048 isight_stop_streaming(isight);
110049 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110050
110051 switch (cmd) {
110052 case SNDRV_PCM_TRIGGER_START:
110053 - ACCESS_ONCE(isight->pcm_running) = true;
110054 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110055 break;
110056 case SNDRV_PCM_TRIGGER_STOP:
110057 - ACCESS_ONCE(isight->pcm_running) = false;
110058 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110059 break;
110060 default:
110061 return -EINVAL;
110062 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110063 index 2dba848..c682aef 100644
110064 --- a/sound/firewire/scs1x.c
110065 +++ b/sound/firewire/scs1x.c
110066 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110067 {
110068 struct scs *scs = stream->rmidi->private_data;
110069
110070 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110071 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110072 if (up) {
110073 scs->output_idle = false;
110074 tasklet_schedule(&scs->tasklet);
110075 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110076 {
110077 struct scs *scs = stream->rmidi->private_data;
110078
110079 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110080 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110081 }
110082
110083 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110084 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110085
110086 snd_card_disconnect(scs->card);
110087
110088 - ACCESS_ONCE(scs->output) = NULL;
110089 - ACCESS_ONCE(scs->input) = NULL;
110090 + ACCESS_ONCE_RW(scs->output) = NULL;
110091 + ACCESS_ONCE_RW(scs->input) = NULL;
110092
110093 wait_event(scs->idle_wait, scs->output_idle);
110094
110095 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110096 index 4e3fcfb..ab45a9d 100644
110097 --- a/sound/isa/sb/emu8000_synth.c
110098 +++ b/sound/isa/sb/emu8000_synth.c
110099 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110100 {
110101
110102 static struct snd_seq_dev_ops ops = {
110103 - snd_emu8000_new_device,
110104 - snd_emu8000_delete_device,
110105 + .init_device = snd_emu8000_new_device,
110106 + .free_device = snd_emu8000_delete_device,
110107 };
110108 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110109 sizeof(struct snd_emu8000*));
110110 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110111 index 048439a..3be9f6f 100644
110112 --- a/sound/oss/sb_audio.c
110113 +++ b/sound/oss/sb_audio.c
110114 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110115 buf16 = (signed short *)(localbuf + localoffs);
110116 while (c)
110117 {
110118 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110119 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110120 if (copy_from_user(lbuf8,
110121 userbuf+useroffs + p,
110122 locallen))
110123 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110124 index a33e8ce..2262303 100644
110125 --- a/sound/oss/swarm_cs4297a.c
110126 +++ b/sound/oss/swarm_cs4297a.c
110127 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110128 {
110129 struct cs4297a_state *s;
110130 u32 pwr, id;
110131 - mm_segment_t fs;
110132 int rval;
110133 u64 cfg;
110134 int mdio_val;
110135 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110136 if (!rval) {
110137 char *sb1250_duart_present;
110138
110139 +#if 0
110140 + mm_segment_t fs;
110141 fs = get_fs();
110142 set_fs(KERNEL_DS);
110143 -#if 0
110144 val = SOUND_MASK_LINE;
110145 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110146 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110147 val = initvol[i].vol;
110148 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110149 }
110150 + set_fs(fs);
110151 // cs4297a_write_ac97(s, 0x18, 0x0808);
110152 #else
110153 // cs4297a_write_ac97(s, 0x5e, 0x180);
110154 cs4297a_write_ac97(s, 0x02, 0x0808);
110155 cs4297a_write_ac97(s, 0x18, 0x0808);
110156 #endif
110157 - set_fs(fs);
110158
110159 list_add(&s->list, &cs4297a_devs);
110160
110161 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110162 index 4c41c90..37f3631 100644
110163 --- a/sound/pci/emu10k1/emu10k1_synth.c
110164 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110165 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110166 {
110167
110168 static struct snd_seq_dev_ops ops = {
110169 - snd_emu10k1_synth_new_device,
110170 - snd_emu10k1_synth_delete_device,
110171 + .init_device = snd_emu10k1_synth_new_device,
110172 + .free_device = snd_emu10k1_synth_delete_device,
110173 };
110174 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110175 sizeof(struct snd_emu10k1_synth_arg));
110176 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110177 index ec6a7d0..4e578f7 100644
110178 --- a/sound/pci/hda/hda_codec.c
110179 +++ b/sound/pci/hda/hda_codec.c
110180 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
110181 mutex_unlock(&preset_mutex);
110182
110183 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110184 - char name[32];
110185 if (!mod_requested)
110186 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110187 - codec->vendor_id);
110188 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110189 else
110190 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110191 - (codec->vendor_id >> 16) & 0xffff);
110192 - request_module(name);
110193 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110194 mod_requested++;
110195 goto again;
110196 }
110197 @@ -2780,7 +2776,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110198 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110199 mm_segment_t fs = get_fs();
110200 set_fs(get_ds());
110201 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110202 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110203 tlv = _tlv;
110204 set_fs(fs);
110205 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110206 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110207 index 4631a23..001ae57 100644
110208 --- a/sound/pci/ymfpci/ymfpci.h
110209 +++ b/sound/pci/ymfpci/ymfpci.h
110210 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110211 spinlock_t reg_lock;
110212 spinlock_t voice_lock;
110213 wait_queue_head_t interrupt_sleep;
110214 - atomic_t interrupt_sleep_count;
110215 + atomic_unchecked_t interrupt_sleep_count;
110216 struct snd_info_entry *proc_entry;
110217 const struct firmware *dsp_microcode;
110218 const struct firmware *controller_microcode;
110219 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110220 index 81c916a..516f0bf 100644
110221 --- a/sound/pci/ymfpci/ymfpci_main.c
110222 +++ b/sound/pci/ymfpci/ymfpci_main.c
110223 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110224 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110225 break;
110226 }
110227 - if (atomic_read(&chip->interrupt_sleep_count)) {
110228 - atomic_set(&chip->interrupt_sleep_count, 0);
110229 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110230 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110231 wake_up(&chip->interrupt_sleep);
110232 }
110233 __end:
110234 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110235 continue;
110236 init_waitqueue_entry(&wait, current);
110237 add_wait_queue(&chip->interrupt_sleep, &wait);
110238 - atomic_inc(&chip->interrupt_sleep_count);
110239 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110240 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110241 remove_wait_queue(&chip->interrupt_sleep, &wait);
110242 }
110243 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110244 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110245 spin_unlock(&chip->reg_lock);
110246
110247 - if (atomic_read(&chip->interrupt_sleep_count)) {
110248 - atomic_set(&chip->interrupt_sleep_count, 0);
110249 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110250 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110251 wake_up(&chip->interrupt_sleep);
110252 }
110253 }
110254 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110255 spin_lock_init(&chip->reg_lock);
110256 spin_lock_init(&chip->voice_lock);
110257 init_waitqueue_head(&chip->interrupt_sleep);
110258 - atomic_set(&chip->interrupt_sleep_count, 0);
110259 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110260 chip->card = card;
110261 chip->pci = pci;
110262 chip->irq = -1;
110263 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110264 index d074aa9..ce3cc44 100644
110265 --- a/sound/soc/soc-core.c
110266 +++ b/sound/soc/soc-core.c
110267 @@ -2286,8 +2286,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110268 if (ret)
110269 return ret;
110270
110271 - ops->warm_reset = snd_soc_ac97_warm_reset;
110272 - ops->reset = snd_soc_ac97_reset;
110273 + pax_open_kernel();
110274 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110275 + *(void **)&ops->reset = snd_soc_ac97_reset;
110276 + pax_close_kernel();
110277
110278 snd_ac97_rst_cfg = cfg;
110279 return 0;
110280 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110281 index 7778b8e..3d619fc 100644
110282 --- a/sound/synth/emux/emux_seq.c
110283 +++ b/sound/synth/emux/emux_seq.c
110284 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110285 * MIDI emulation operators
110286 */
110287 static struct snd_midi_op emux_ops = {
110288 - snd_emux_note_on,
110289 - snd_emux_note_off,
110290 - snd_emux_key_press,
110291 - snd_emux_terminate_note,
110292 - snd_emux_control,
110293 - snd_emux_nrpn,
110294 - snd_emux_sysex,
110295 + .note_on = snd_emux_note_on,
110296 + .note_off = snd_emux_note_off,
110297 + .key_press = snd_emux_key_press,
110298 + .note_terminate = snd_emux_terminate_note,
110299 + .control = snd_emux_control,
110300 + .nrpn = snd_emux_nrpn,
110301 + .sysex = snd_emux_sysex,
110302 };
110303
110304
110305 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110306 new file mode 100644
110307 index 0000000..de92ed9
110308 --- /dev/null
110309 +++ b/tools/gcc/.gitignore
110310 @@ -0,0 +1 @@
110311 +randomize_layout_seed.h
110312 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110313 new file mode 100644
110314 index 0000000..7b8921f
110315 --- /dev/null
110316 +++ b/tools/gcc/Makefile
110317 @@ -0,0 +1,52 @@
110318 +#CC := gcc
110319 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110320 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110321 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110322 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110323 +
110324 +ifeq ($(PLUGINCC),$(HOSTCC))
110325 +HOSTLIBS := hostlibs
110326 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110327 +export HOST_EXTRACFLAGS
110328 +else
110329 +HOSTLIBS := hostcxxlibs
110330 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110331 +export HOST_EXTRACXXFLAGS
110332 +endif
110333 +
110334 +export GCCPLUGINS_DIR HOSTLIBS
110335 +
110336 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110337 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110338 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110339 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110340 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110341 +$(HOSTLIBS)-y += colorize_plugin.so
110342 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110343 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110344 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110345 +
110346 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110347 +subdir- += size_overflow_plugin
110348 +
110349 +always := $($(HOSTLIBS)-y)
110350 +
110351 +constify_plugin-objs := constify_plugin.o
110352 +stackleak_plugin-objs := stackleak_plugin.o
110353 +kallocstat_plugin-objs := kallocstat_plugin.o
110354 +kernexec_plugin-objs := kernexec_plugin.o
110355 +checker_plugin-objs := checker_plugin.o
110356 +colorize_plugin-objs := colorize_plugin.o
110357 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110358 +structleak_plugin-objs := structleak_plugin.o
110359 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110360 +
110361 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110362 +
110363 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110364 + cmd_create_randomize_layout_seed = \
110365 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110366 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110367 + $(call if_changed,create_randomize_layout_seed)
110368 +
110369 +targets += randomize_layout_seed.h randomize_layout_hash.h
110370 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110371 new file mode 100644
110372 index 0000000..5452feea
110373 --- /dev/null
110374 +++ b/tools/gcc/checker_plugin.c
110375 @@ -0,0 +1,150 @@
110376 +/*
110377 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110378 + * Licensed under the GPL v2
110379 + *
110380 + * Note: the choice of the license means that the compilation process is
110381 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110382 + * but for the kernel it doesn't matter since it doesn't link against
110383 + * any of the gcc libraries
110384 + *
110385 + * gcc plugin to implement various sparse (source code checker) features
110386 + *
110387 + * TODO:
110388 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110389 + *
110390 + * BUGS:
110391 + * - none known
110392 + */
110393 +
110394 +#include "gcc-common.h"
110395 +
110396 +extern void c_register_addr_space (const char *str, addr_space_t as);
110397 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110398 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110399 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110400 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110401 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110402 +
110403 +int plugin_is_GPL_compatible;
110404 +
110405 +static struct plugin_info checker_plugin_info = {
110406 + .version = "201304082245",
110407 + .help = NULL,
110408 +};
110409 +
110410 +#define ADDR_SPACE_KERNEL 0
110411 +#define ADDR_SPACE_FORCE_KERNEL 1
110412 +#define ADDR_SPACE_USER 2
110413 +#define ADDR_SPACE_FORCE_USER 3
110414 +#define ADDR_SPACE_IOMEM 0
110415 +#define ADDR_SPACE_FORCE_IOMEM 0
110416 +#define ADDR_SPACE_PERCPU 0
110417 +#define ADDR_SPACE_FORCE_PERCPU 0
110418 +#define ADDR_SPACE_RCU 0
110419 +#define ADDR_SPACE_FORCE_RCU 0
110420 +
110421 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110422 +{
110423 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110424 +}
110425 +
110426 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110427 +{
110428 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110429 +}
110430 +
110431 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110432 +{
110433 + return default_addr_space_valid_pointer_mode(mode, as);
110434 +}
110435 +
110436 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110437 +{
110438 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110439 +}
110440 +
110441 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110442 +{
110443 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110444 +}
110445 +
110446 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110447 +{
110448 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110449 + return true;
110450 +
110451 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110452 + return true;
110453 +
110454 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110455 + return true;
110456 +
110457 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110458 + return true;
110459 +
110460 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110461 + return true;
110462 +
110463 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110464 + return true;
110465 +
110466 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110467 + return true;
110468 +
110469 + return subset == superset;
110470 +}
110471 +
110472 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110473 +{
110474 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110475 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110476 +
110477 + return op;
110478 +}
110479 +
110480 +static void register_checker_address_spaces(void *event_data, void *data)
110481 +{
110482 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110483 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110484 + c_register_addr_space("__user", ADDR_SPACE_USER);
110485 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110486 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110487 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110488 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110489 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110490 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110491 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110492 +
110493 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110494 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110495 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110496 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110497 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110498 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110499 + targetm.addr_space.convert = checker_addr_space_convert;
110500 +}
110501 +
110502 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110503 +{
110504 + const char * const plugin_name = plugin_info->base_name;
110505 + const int argc = plugin_info->argc;
110506 + const struct plugin_argument * const argv = plugin_info->argv;
110507 + int i;
110508 +
110509 + if (!plugin_default_version_check(version, &gcc_version)) {
110510 + error(G_("incompatible gcc/plugin versions"));
110511 + return 1;
110512 + }
110513 +
110514 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110515 +
110516 + for (i = 0; i < argc; ++i)
110517 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110518 +
110519 + if (TARGET_64BIT == 0)
110520 + return 0;
110521 +
110522 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110523 +
110524 + return 0;
110525 +}
110526 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110527 new file mode 100644
110528 index 0000000..54461af
110529 --- /dev/null
110530 +++ b/tools/gcc/colorize_plugin.c
110531 @@ -0,0 +1,210 @@
110532 +/*
110533 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110534 + * Licensed under the GPL v2
110535 + *
110536 + * Note: the choice of the license means that the compilation process is
110537 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110538 + * but for the kernel it doesn't matter since it doesn't link against
110539 + * any of the gcc libraries
110540 + *
110541 + * gcc plugin to colorize diagnostic output
110542 + *
110543 + */
110544 +
110545 +#include "gcc-common.h"
110546 +
110547 +int plugin_is_GPL_compatible;
110548 +
110549 +static struct plugin_info colorize_plugin_info = {
110550 + .version = "201404202350",
110551 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110552 +};
110553 +
110554 +#define GREEN "\033[32m\033[K"
110555 +#define LIGHTGREEN "\033[1;32m\033[K"
110556 +#define YELLOW "\033[33m\033[K"
110557 +#define LIGHTYELLOW "\033[1;33m\033[K"
110558 +#define RED "\033[31m\033[K"
110559 +#define LIGHTRED "\033[1;31m\033[K"
110560 +#define BLUE "\033[34m\033[K"
110561 +#define LIGHTBLUE "\033[1;34m\033[K"
110562 +#define BRIGHT "\033[1;m\033[K"
110563 +#define NORMAL "\033[m\033[K"
110564 +
110565 +static diagnostic_starter_fn old_starter;
110566 +static diagnostic_finalizer_fn old_finalizer;
110567 +
110568 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110569 +{
110570 + const char *color;
110571 + char *newprefix;
110572 +
110573 + switch (diagnostic->kind) {
110574 + case DK_NOTE:
110575 + color = LIGHTBLUE;
110576 + break;
110577 +
110578 + case DK_PEDWARN:
110579 + case DK_WARNING:
110580 + color = LIGHTYELLOW;
110581 + break;
110582 +
110583 + case DK_ERROR:
110584 + case DK_FATAL:
110585 + case DK_ICE:
110586 + case DK_PERMERROR:
110587 + case DK_SORRY:
110588 + color = LIGHTRED;
110589 + break;
110590 +
110591 + default:
110592 + color = NORMAL;
110593 + }
110594 +
110595 + old_starter(context, diagnostic);
110596 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110597 + return;
110598 + pp_destroy_prefix(context->printer);
110599 + pp_set_prefix(context->printer, newprefix);
110600 +}
110601 +
110602 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110603 +{
110604 + old_finalizer(context, diagnostic);
110605 +}
110606 +
110607 +static void colorize_arm(void)
110608 +{
110609 + old_starter = diagnostic_starter(global_dc);
110610 + old_finalizer = diagnostic_finalizer(global_dc);
110611 +
110612 + diagnostic_starter(global_dc) = start_colorize;
110613 + diagnostic_finalizer(global_dc) = finalize_colorize;
110614 +}
110615 +
110616 +static unsigned int execute_colorize_rearm(void)
110617 +{
110618 + if (diagnostic_starter(global_dc) == start_colorize)
110619 + return 0;
110620 +
110621 + colorize_arm();
110622 + return 0;
110623 +}
110624 +
110625 +#if BUILDING_GCC_VERSION >= 4009
110626 +static const struct pass_data colorize_rearm_pass_data = {
110627 +#else
110628 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110629 + .pass = {
110630 +#endif
110631 + .type = SIMPLE_IPA_PASS,
110632 + .name = "colorize_rearm",
110633 +#if BUILDING_GCC_VERSION >= 4008
110634 + .optinfo_flags = OPTGROUP_NONE,
110635 +#endif
110636 +#if BUILDING_GCC_VERSION >= 4009
110637 + .has_gate = false,
110638 + .has_execute = true,
110639 +#else
110640 + .gate = NULL,
110641 + .execute = execute_colorize_rearm,
110642 + .sub = NULL,
110643 + .next = NULL,
110644 + .static_pass_number = 0,
110645 +#endif
110646 + .tv_id = TV_NONE,
110647 + .properties_required = 0,
110648 + .properties_provided = 0,
110649 + .properties_destroyed = 0,
110650 + .todo_flags_start = 0,
110651 + .todo_flags_finish = 0
110652 +#if BUILDING_GCC_VERSION < 4009
110653 + }
110654 +#endif
110655 +};
110656 +
110657 +#if BUILDING_GCC_VERSION >= 4009
110658 +namespace {
110659 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110660 +public:
110661 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110662 + unsigned int execute() { return execute_colorize_rearm(); }
110663 +};
110664 +}
110665 +
110666 +static opt_pass *make_colorize_rearm_pass(void)
110667 +{
110668 + return new colorize_rearm_pass();
110669 +}
110670 +#else
110671 +static struct opt_pass *make_colorize_rearm_pass(void)
110672 +{
110673 + return &colorize_rearm_pass.pass;
110674 +}
110675 +#endif
110676 +
110677 +static void colorize_start_unit(void *gcc_data, void *user_data)
110678 +{
110679 + colorize_arm();
110680 +}
110681 +
110682 +static bool should_colorize(void)
110683 +{
110684 +#if BUILDING_GCC_VERSION >= 4009
110685 + return false;
110686 +#else
110687 + char const *t = getenv("TERM");
110688 +
110689 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110690 +#endif
110691 +}
110692 +
110693 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110694 +{
110695 + const char * const plugin_name = plugin_info->base_name;
110696 + const int argc = plugin_info->argc;
110697 + const struct plugin_argument * const argv = plugin_info->argv;
110698 + int i;
110699 + struct register_pass_info colorize_rearm_pass_info;
110700 + bool colorize;
110701 +
110702 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110703 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110704 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110705 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110706 +
110707 + if (!plugin_default_version_check(version, &gcc_version)) {
110708 + error(G_("incompatible gcc/plugin versions"));
110709 + return 1;
110710 + }
110711 +
110712 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
110713 +
110714 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
110715 +
110716 + for (i = 0; i < argc; ++i) {
110717 + if (!strcmp(argv[i].key, "color")) {
110718 + if (!argv[i].value) {
110719 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110720 + continue;
110721 + }
110722 + if (!strcmp(argv[i].value, "always"))
110723 + colorize = true;
110724 + else if (!strcmp(argv[i].value, "never"))
110725 + colorize = false;
110726 + else if (!strcmp(argv[i].value, "auto"))
110727 + colorize = should_colorize();
110728 + else
110729 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
110730 + continue;
110731 + }
110732 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110733 + }
110734 +
110735 + if (colorize) {
110736 + // TODO: parse GCC_COLORS as used by gcc 4.9+
110737 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
110738 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
110739 + }
110740 + return 0;
110741 +}
110742 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
110743 new file mode 100644
110744 index 0000000..82bc5a8
110745 --- /dev/null
110746 +++ b/tools/gcc/constify_plugin.c
110747 @@ -0,0 +1,557 @@
110748 +/*
110749 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
110750 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
110751 + * Licensed under the GPL v2, or (at your option) v3
110752 + *
110753 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
110754 + *
110755 + * Homepage:
110756 + * http://www.grsecurity.net/~ephox/const_plugin/
110757 + *
110758 + * Usage:
110759 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
110760 + * $ gcc -fplugin=constify_plugin.so test.c -O2
110761 + */
110762 +
110763 +#include "gcc-common.h"
110764 +
110765 +// unused C type flag in all versions 4.5-4.9
110766 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
110767 +
110768 +int plugin_is_GPL_compatible;
110769 +
110770 +static struct plugin_info const_plugin_info = {
110771 + .version = "201401270210",
110772 + .help = "no-constify\tturn off constification\n",
110773 +};
110774 +
110775 +typedef struct {
110776 + bool has_fptr_field;
110777 + bool has_writable_field;
110778 + bool has_do_const_field;
110779 + bool has_no_const_field;
110780 +} constify_info;
110781 +
110782 +static const_tree get_field_type(const_tree field)
110783 +{
110784 + return strip_array_types(TREE_TYPE(field));
110785 +}
110786 +
110787 +static bool is_fptr(const_tree field)
110788 +{
110789 + const_tree ptr = get_field_type(field);
110790 +
110791 + if (TREE_CODE(ptr) != POINTER_TYPE)
110792 + return false;
110793 +
110794 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
110795 +}
110796 +
110797 +/*
110798 + * determine whether the given structure type meets the requirements for automatic constification,
110799 + * including the constification attributes on nested structure types
110800 + */
110801 +static void constifiable(const_tree node, constify_info *cinfo)
110802 +{
110803 + const_tree field;
110804 +
110805 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110806 +
110807 + // e.g., pointer to structure fields while still constructing the structure type
110808 + if (TYPE_FIELDS(node) == NULL_TREE)
110809 + return;
110810 +
110811 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110812 + const_tree type = get_field_type(field);
110813 + enum tree_code code = TREE_CODE(type);
110814 +
110815 + if (node == type)
110816 + continue;
110817 +
110818 + if (is_fptr(field))
110819 + cinfo->has_fptr_field = true;
110820 + else if (!TREE_READONLY(field))
110821 + cinfo->has_writable_field = true;
110822 +
110823 + if (code == RECORD_TYPE || code == UNION_TYPE) {
110824 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110825 + cinfo->has_do_const_field = true;
110826 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
110827 + cinfo->has_no_const_field = true;
110828 + else
110829 + constifiable(type, cinfo);
110830 + }
110831 + }
110832 +}
110833 +
110834 +static bool constified(const_tree node)
110835 +{
110836 + constify_info cinfo = {
110837 + .has_fptr_field = false,
110838 + .has_writable_field = false,
110839 + .has_do_const_field = false,
110840 + .has_no_const_field = false
110841 + };
110842 +
110843 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110844 +
110845 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
110846 +// gcc_assert(!TYPE_READONLY(node));
110847 + return false;
110848 + }
110849 +
110850 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
110851 + gcc_assert(TYPE_READONLY(node));
110852 + return true;
110853 + }
110854 +
110855 + constifiable(node, &cinfo);
110856 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
110857 + return false;
110858 +
110859 + return TYPE_READONLY(node);
110860 +}
110861 +
110862 +static void deconstify_tree(tree node);
110863 +
110864 +static void deconstify_type(tree type)
110865 +{
110866 + tree field;
110867 +
110868 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
110869 +
110870 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
110871 + const_tree fieldtype = get_field_type(field);
110872 +
110873 + // special case handling of simple ptr-to-same-array-type members
110874 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
110875 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
110876 +
110877 + if (TREE_TYPE(TREE_TYPE(field)) == type)
110878 + continue;
110879 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
110880 + continue;
110881 + if (!constified(ptrtype))
110882 + continue;
110883 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
110884 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
110885 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
110886 + }
110887 + continue;
110888 + }
110889 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
110890 + continue;
110891 + if (!constified(fieldtype))
110892 + continue;
110893 +
110894 + deconstify_tree(field);
110895 + TREE_READONLY(field) = 0;
110896 + }
110897 + TYPE_READONLY(type) = 0;
110898 + C_TYPE_FIELDS_READONLY(type) = 0;
110899 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110900 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110901 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
110902 + }
110903 +}
110904 +
110905 +static void deconstify_tree(tree node)
110906 +{
110907 + tree old_type, new_type, field;
110908 +
110909 + old_type = TREE_TYPE(node);
110910 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
110911 + node = TREE_TYPE(node) = copy_node(old_type);
110912 + old_type = TREE_TYPE(old_type);
110913 + }
110914 +
110915 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
110916 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
110917 +
110918 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
110919 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
110920 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
110921 + DECL_FIELD_CONTEXT(field) = new_type;
110922 +
110923 + deconstify_type(new_type);
110924 +
110925 + TREE_TYPE(node) = new_type;
110926 +}
110927 +
110928 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110929 +{
110930 + tree type;
110931 + constify_info cinfo = {
110932 + .has_fptr_field = false,
110933 + .has_writable_field = false,
110934 + .has_do_const_field = false,
110935 + .has_no_const_field = false
110936 + };
110937 +
110938 + *no_add_attrs = true;
110939 + if (TREE_CODE(*node) == FUNCTION_DECL) {
110940 + error("%qE attribute does not apply to functions (%qF)", name, *node);
110941 + return NULL_TREE;
110942 + }
110943 +
110944 + if (TREE_CODE(*node) == PARM_DECL) {
110945 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
110946 + return NULL_TREE;
110947 + }
110948 +
110949 + if (TREE_CODE(*node) == VAR_DECL) {
110950 + error("%qE attribute does not apply to variables (%qD)", name, *node);
110951 + return NULL_TREE;
110952 + }
110953 +
110954 + if (TYPE_P(*node)) {
110955 + type = *node;
110956 + } else {
110957 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
110958 + type = TREE_TYPE(*node);
110959 + }
110960 +
110961 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
110962 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
110963 + return NULL_TREE;
110964 + }
110965 +
110966 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
110967 + error("%qE attribute is already applied to the type %qT", name, type);
110968 + return NULL_TREE;
110969 + }
110970 +
110971 + if (TYPE_P(*node)) {
110972 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110973 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
110974 + else
110975 + *no_add_attrs = false;
110976 + return NULL_TREE;
110977 + }
110978 +
110979 + constifiable(type, &cinfo);
110980 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110981 + deconstify_tree(*node);
110982 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
110983 + return NULL_TREE;
110984 + }
110985 +
110986 + error("%qE attribute used on type %qT that is not constified", name, type);
110987 + return NULL_TREE;
110988 +}
110989 +
110990 +static void constify_type(tree type)
110991 +{
110992 + TYPE_READONLY(type) = 1;
110993 + C_TYPE_FIELDS_READONLY(type) = 1;
110994 + TYPE_CONSTIFY_VISITED(type) = 1;
110995 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110996 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
110997 +}
110998 +
110999 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111000 +{
111001 + *no_add_attrs = true;
111002 + if (!TYPE_P(*node)) {
111003 + error("%qE attribute applies to types only (%qD)", name, *node);
111004 + return NULL_TREE;
111005 + }
111006 +
111007 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111008 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111009 + return NULL_TREE;
111010 + }
111011 +
111012 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111013 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111014 + return NULL_TREE;
111015 + }
111016 +
111017 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111018 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111019 + return NULL_TREE;
111020 + }
111021 +
111022 + *no_add_attrs = false;
111023 + return NULL_TREE;
111024 +}
111025 +
111026 +static struct attribute_spec no_const_attr = {
111027 + .name = "no_const",
111028 + .min_length = 0,
111029 + .max_length = 0,
111030 + .decl_required = false,
111031 + .type_required = false,
111032 + .function_type_required = false,
111033 + .handler = handle_no_const_attribute,
111034 +#if BUILDING_GCC_VERSION >= 4007
111035 + .affects_type_identity = true
111036 +#endif
111037 +};
111038 +
111039 +static struct attribute_spec do_const_attr = {
111040 + .name = "do_const",
111041 + .min_length = 0,
111042 + .max_length = 0,
111043 + .decl_required = false,
111044 + .type_required = false,
111045 + .function_type_required = false,
111046 + .handler = handle_do_const_attribute,
111047 +#if BUILDING_GCC_VERSION >= 4007
111048 + .affects_type_identity = true
111049 +#endif
111050 +};
111051 +
111052 +static void register_attributes(void *event_data, void *data)
111053 +{
111054 + register_attribute(&no_const_attr);
111055 + register_attribute(&do_const_attr);
111056 +}
111057 +
111058 +static void finish_type(void *event_data, void *data)
111059 +{
111060 + tree type = (tree)event_data;
111061 + constify_info cinfo = {
111062 + .has_fptr_field = false,
111063 + .has_writable_field = false,
111064 + .has_do_const_field = false,
111065 + .has_no_const_field = false
111066 + };
111067 +
111068 + if (type == NULL_TREE || type == error_mark_node)
111069 + return;
111070 +
111071 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111072 + return;
111073 +
111074 + constifiable(type, &cinfo);
111075 +
111076 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111077 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111078 + deconstify_type(type);
111079 + TYPE_CONSTIFY_VISITED(type) = 1;
111080 + } else
111081 + error("'no_const' attribute used on type %qT that is not constified", type);
111082 + return;
111083 + }
111084 +
111085 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111086 + if (!cinfo.has_writable_field) {
111087 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111088 + return;
111089 + }
111090 + constify_type(type);
111091 + return;
111092 + }
111093 +
111094 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111095 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111096 + error("'do_const' attribute used on type %qT that is constified", type);
111097 + return;
111098 + }
111099 + constify_type(type);
111100 + return;
111101 + }
111102 +
111103 + deconstify_type(type);
111104 + TYPE_CONSTIFY_VISITED(type) = 1;
111105 +}
111106 +
111107 +static void check_global_variables(void *event_data, void *data)
111108 +{
111109 +#if BUILDING_GCC_VERSION >= 4009
111110 + varpool_node *node;
111111 +#else
111112 + struct varpool_node *node;
111113 +#endif
111114 +
111115 + FOR_EACH_VARIABLE(node) {
111116 + tree var = NODE_DECL(node);
111117 + tree type = TREE_TYPE(var);
111118 +
111119 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111120 + continue;
111121 +
111122 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111123 + continue;
111124 +
111125 + if (!TYPE_CONSTIFY_VISITED(type))
111126 + continue;
111127 +
111128 + if (DECL_EXTERNAL(var))
111129 + continue;
111130 +
111131 + if (DECL_INITIAL(var))
111132 + continue;
111133 +
111134 + // this works around a gcc bug/feature where uninitialized globals
111135 + // are moved into the .bss section regardless of any constification
111136 + DECL_INITIAL(var) = build_constructor(type, NULL);
111137 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111138 + }
111139 +}
111140 +
111141 +static unsigned int check_local_variables(void)
111142 +{
111143 + unsigned int ret = 0;
111144 + tree var;
111145 +
111146 + unsigned int i;
111147 +
111148 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111149 + tree type = TREE_TYPE(var);
111150 +
111151 + gcc_assert(DECL_P(var));
111152 + if (is_global_var(var))
111153 + continue;
111154 +
111155 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111156 + continue;
111157 +
111158 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111159 + continue;
111160 +
111161 + if (!TYPE_CONSTIFY_VISITED(type))
111162 + continue;
111163 +
111164 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111165 + ret = 1;
111166 + }
111167 + return ret;
111168 +}
111169 +
111170 +#if BUILDING_GCC_VERSION >= 4009
111171 +static const struct pass_data check_local_variables_pass_data = {
111172 +#else
111173 +static struct gimple_opt_pass check_local_variables_pass = {
111174 + .pass = {
111175 +#endif
111176 + .type = GIMPLE_PASS,
111177 + .name = "check_local_variables",
111178 +#if BUILDING_GCC_VERSION >= 4008
111179 + .optinfo_flags = OPTGROUP_NONE,
111180 +#endif
111181 +#if BUILDING_GCC_VERSION >= 4009
111182 + .has_gate = false,
111183 + .has_execute = true,
111184 +#else
111185 + .gate = NULL,
111186 + .execute = check_local_variables,
111187 + .sub = NULL,
111188 + .next = NULL,
111189 + .static_pass_number = 0,
111190 +#endif
111191 + .tv_id = TV_NONE,
111192 + .properties_required = 0,
111193 + .properties_provided = 0,
111194 + .properties_destroyed = 0,
111195 + .todo_flags_start = 0,
111196 + .todo_flags_finish = 0
111197 +#if BUILDING_GCC_VERSION < 4009
111198 + }
111199 +#endif
111200 +};
111201 +
111202 +#if BUILDING_GCC_VERSION >= 4009
111203 +namespace {
111204 +class check_local_variables_pass : public gimple_opt_pass {
111205 +public:
111206 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111207 + unsigned int execute() { return check_local_variables(); }
111208 +};
111209 +}
111210 +
111211 +static opt_pass *make_check_local_variables_pass(void)
111212 +{
111213 + return new check_local_variables_pass();
111214 +}
111215 +#else
111216 +static struct opt_pass *make_check_local_variables_pass(void)
111217 +{
111218 + return &check_local_variables_pass.pass;
111219 +}
111220 +#endif
111221 +
111222 +static struct {
111223 + const char *name;
111224 + const char *asm_op;
111225 +} sections[] = {
111226 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111227 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111228 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111229 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111230 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111231 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111232 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111233 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111234 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111235 +};
111236 +
111237 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111238 +
111239 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111240 +{
111241 + size_t i;
111242 +
111243 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111244 + if (!strcmp(sections[i].name, name))
111245 + return 0;
111246 + return old_section_type_flags(decl, name, reloc);
111247 +}
111248 +
111249 +static void constify_start_unit(void *gcc_data, void *user_data)
111250 +{
111251 +// size_t i;
111252 +
111253 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111254 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111255 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111256 +
111257 + old_section_type_flags = targetm.section_type_flags;
111258 + targetm.section_type_flags = constify_section_type_flags;
111259 +}
111260 +
111261 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111262 +{
111263 + const char * const plugin_name = plugin_info->base_name;
111264 + const int argc = plugin_info->argc;
111265 + const struct plugin_argument * const argv = plugin_info->argv;
111266 + int i;
111267 + bool constify = true;
111268 +
111269 + struct register_pass_info check_local_variables_pass_info;
111270 +
111271 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111272 + check_local_variables_pass_info.reference_pass_name = "ssa";
111273 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111274 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111275 +
111276 + if (!plugin_default_version_check(version, &gcc_version)) {
111277 + error(G_("incompatible gcc/plugin versions"));
111278 + return 1;
111279 + }
111280 +
111281 + for (i = 0; i < argc; ++i) {
111282 + if (!(strcmp(argv[i].key, "no-constify"))) {
111283 + constify = false;
111284 + continue;
111285 + }
111286 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111287 + }
111288 +
111289 + if (strcmp(lang_hooks.name, "GNU C")) {
111290 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
111291 + constify = false;
111292 + }
111293 +
111294 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111295 + if (constify) {
111296 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111297 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111298 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111299 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111300 + }
111301 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111302 +
111303 + return 0;
111304 +}
111305 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111306 new file mode 100644
111307 index 0000000..e90c205
111308 --- /dev/null
111309 +++ b/tools/gcc/gcc-common.h
111310 @@ -0,0 +1,295 @@
111311 +#ifndef GCC_COMMON_H_INCLUDED
111312 +#define GCC_COMMON_H_INCLUDED
111313 +
111314 +#include "plugin.h"
111315 +#include "bversion.h"
111316 +#include "plugin-version.h"
111317 +#include "config.h"
111318 +#include "system.h"
111319 +#include "coretypes.h"
111320 +#include "tm.h"
111321 +#include "line-map.h"
111322 +#include "input.h"
111323 +#include "tree.h"
111324 +
111325 +#include "tree-inline.h"
111326 +#include "version.h"
111327 +#include "rtl.h"
111328 +#include "tm_p.h"
111329 +#include "flags.h"
111330 +//#include "insn-attr.h"
111331 +//#include "insn-config.h"
111332 +//#include "insn-flags.h"
111333 +#include "hard-reg-set.h"
111334 +//#include "recog.h"
111335 +#include "output.h"
111336 +#include "except.h"
111337 +#include "function.h"
111338 +#include "toplev.h"
111339 +//#include "expr.h"
111340 +#include "basic-block.h"
111341 +#include "intl.h"
111342 +#include "ggc.h"
111343 +//#include "regs.h"
111344 +#include "timevar.h"
111345 +
111346 +#include "params.h"
111347 +#include "pointer-set.h"
111348 +#include "emit-rtl.h"
111349 +//#include "reload.h"
111350 +//#include "ira.h"
111351 +//#include "dwarf2asm.h"
111352 +#include "debug.h"
111353 +#include "target.h"
111354 +#include "langhooks.h"
111355 +#include "cfgloop.h"
111356 +//#include "hosthooks.h"
111357 +#include "cgraph.h"
111358 +#include "opts.h"
111359 +//#include "coverage.h"
111360 +//#include "value-prof.h"
111361 +
111362 +#if BUILDING_GCC_VERSION >= 4007
111363 +#include "tree-pretty-print.h"
111364 +#include "gimple-pretty-print.h"
111365 +#include "c-tree.h"
111366 +//#include "alloc-pool.h"
111367 +#endif
111368 +
111369 +#if BUILDING_GCC_VERSION <= 4008
111370 +#include "tree-flow.h"
111371 +#else
111372 +#include "tree-cfgcleanup.h"
111373 +#endif
111374 +
111375 +#include "diagnostic.h"
111376 +//#include "tree-diagnostic.h"
111377 +#include "tree-dump.h"
111378 +#include "tree-pass.h"
111379 +//#include "df.h"
111380 +#include "predict.h"
111381 +#include "ipa-utils.h"
111382 +
111383 +#if BUILDING_GCC_VERSION >= 4009
111384 +#include "varasm.h"
111385 +#include "stor-layout.h"
111386 +#include "internal-fn.h"
111387 +#include "gimple-expr.h"
111388 +//#include "diagnostic-color.h"
111389 +#include "context.h"
111390 +#include "tree-ssa-alias.h"
111391 +#include "stringpool.h"
111392 +#include "tree-ssanames.h"
111393 +#include "print-tree.h"
111394 +#include "tree-eh.h"
111395 +#include "stmt.h"
111396 +#endif
111397 +
111398 +#include "gimple.h"
111399 +
111400 +#if BUILDING_GCC_VERSION >= 4009
111401 +#include "tree-ssa-operands.h"
111402 +#include "tree-phinodes.h"
111403 +#include "tree-cfg.h"
111404 +#include "gimple-iterator.h"
111405 +#include "gimple-ssa.h"
111406 +#include "ssa-iterators.h"
111407 +#endif
111408 +
111409 +//#include "lto/lto.h"
111410 +//#include "data-streamer.h"
111411 +//#include "lto-compress.h"
111412 +
111413 +//#include "expr.h" where are you...
111414 +extern rtx emit_move_insn(rtx x, rtx y);
111415 +
111416 +// missing from basic_block.h...
111417 +extern void debug_dominance_info(enum cdi_direction dir);
111418 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111419 +
111420 +#define __unused __attribute__((__unused__))
111421 +
111422 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111423 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111424 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111425 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111426 +
111427 +#if BUILDING_GCC_VERSION == 4005
111428 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111429 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111430 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111431 +#define TODO_rebuild_cgraph_edges 0
111432 +
111433 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111434 +{
111435 + tree fndecl;
111436 +
111437 + if (!is_gimple_call(stmt))
111438 + return false;
111439 + fndecl = gimple_call_fndecl(stmt);
111440 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111441 + return false;
111442 +// print_node(stderr, "pax", fndecl, 4);
111443 + return DECL_FUNCTION_CODE(fndecl) == code;
111444 +}
111445 +
111446 +static inline bool is_simple_builtin(tree decl)
111447 +{
111448 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111449 + return false;
111450 +
111451 + switch (DECL_FUNCTION_CODE(decl)) {
111452 + /* Builtins that expand to constants. */
111453 + case BUILT_IN_CONSTANT_P:
111454 + case BUILT_IN_EXPECT:
111455 + case BUILT_IN_OBJECT_SIZE:
111456 + case BUILT_IN_UNREACHABLE:
111457 + /* Simple register moves or loads from stack. */
111458 + case BUILT_IN_RETURN_ADDRESS:
111459 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111460 + case BUILT_IN_FROB_RETURN_ADDR:
111461 + case BUILT_IN_RETURN:
111462 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111463 + case BUILT_IN_FRAME_ADDRESS:
111464 + case BUILT_IN_VA_END:
111465 + case BUILT_IN_STACK_SAVE:
111466 + case BUILT_IN_STACK_RESTORE:
111467 + /* Exception state returns or moves registers around. */
111468 + case BUILT_IN_EH_FILTER:
111469 + case BUILT_IN_EH_POINTER:
111470 + case BUILT_IN_EH_COPY_VALUES:
111471 + return true;
111472 +
111473 + default:
111474 + return false;
111475 + }
111476 +}
111477 +#endif
111478 +
111479 +#if BUILDING_GCC_VERSION <= 4006
111480 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111481 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111482 +
111483 +// should come from c-tree.h if only it were installed for gcc 4.5...
111484 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111485 +
111486 +#define get_random_seed(noinit) ({ \
111487 + unsigned HOST_WIDE_INT seed; \
111488 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111489 + seed * seed; })
111490 +
111491 +static inline bool gimple_clobber_p(gimple s)
111492 +{
111493 + return false;
111494 +}
111495 +
111496 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111497 +{
111498 + return implicit_built_in_decls[fncode];
111499 +}
111500 +
111501 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111502 +{
111503 + struct cgraph_node *node = cgraph_get_node(decl);
111504 +
111505 + return node ? node : cgraph_node(decl);
111506 +}
111507 +
111508 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111509 +{
111510 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111511 +}
111512 +
111513 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111514 +{
111515 + struct cgraph_node *node;
111516 +
111517 + for (node = cgraph_nodes; node; node = node->next)
111518 + if (cgraph_function_with_gimple_body_p(node))
111519 + return node;
111520 + return NULL;
111521 +}
111522 +
111523 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111524 +{
111525 + for (node = node->next; node; node = node->next)
111526 + if (cgraph_function_with_gimple_body_p(node))
111527 + return node;
111528 + return NULL;
111529 +}
111530 +
111531 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111532 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111533 + (node) = cgraph_next_function_with_gimple_body(node))
111534 +#endif
111535 +
111536 +#if BUILDING_GCC_VERSION == 4006
111537 +extern void debug_gimple_stmt(gimple);
111538 +extern void debug_gimple_seq(gimple_seq);
111539 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111540 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111541 +extern void print_gimple_expr(FILE *, gimple, int, int);
111542 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111543 +#endif
111544 +
111545 +#if BUILDING_GCC_VERSION <= 4007
111546 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111547 +#define PROP_loops 0
111548 +
111549 +static inline int bb_loop_depth(const_basic_block bb)
111550 +{
111551 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111552 +}
111553 +
111554 +static inline bool gimple_store_p(gimple gs)
111555 +{
111556 + tree lhs = gimple_get_lhs(gs);
111557 + return lhs && !is_gimple_reg(lhs);
111558 +}
111559 +#endif
111560 +
111561 +#if BUILDING_GCC_VERSION >= 4007
111562 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111563 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111564 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111565 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111566 +#endif
111567 +
111568 +#if BUILDING_GCC_VERSION <= 4008
111569 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111570 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111571 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111572 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111573 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111574 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111575 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111576 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111577 +
111578 +static inline const char *get_tree_code_name(enum tree_code code)
111579 +{
111580 + gcc_assert(code < MAX_TREE_CODES);
111581 + return tree_code_name[code];
111582 +}
111583 +
111584 +#define ipa_remove_stmt_references(cnode, stmt)
111585 +#endif
111586 +
111587 +#if BUILDING_GCC_VERSION == 4008
111588 +#define NODE_DECL(node) node->symbol.decl
111589 +#else
111590 +#define NODE_DECL(node) node->decl
111591 +#endif
111592 +
111593 +#if BUILDING_GCC_VERSION >= 4008
111594 +#define add_referenced_var(var)
111595 +#define mark_sym_for_renaming(var)
111596 +#define varpool_mark_needed_node(node)
111597 +#define TODO_dump_func 0
111598 +#define TODO_dump_cgraph 0
111599 +#endif
111600 +
111601 +#if BUILDING_GCC_VERSION >= 4009
111602 +#define TODO_ggc_collect 0
111603 +#endif
111604 +
111605 +#endif
111606 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111607 new file mode 100644
111608 index 0000000..7514850
111609 --- /dev/null
111610 +++ b/tools/gcc/gen-random-seed.sh
111611 @@ -0,0 +1,8 @@
111612 +#!/bin/sh
111613 +
111614 +if [ ! -f "$1" ]; then
111615 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111616 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111617 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111618 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111619 +fi
111620 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111621 new file mode 100644
111622 index 0000000..d81c094
111623 --- /dev/null
111624 +++ b/tools/gcc/kallocstat_plugin.c
111625 @@ -0,0 +1,183 @@
111626 +/*
111627 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111628 + * Licensed under the GPL v2
111629 + *
111630 + * Note: the choice of the license means that the compilation process is
111631 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111632 + * but for the kernel it doesn't matter since it doesn't link against
111633 + * any of the gcc libraries
111634 + *
111635 + * gcc plugin to find the distribution of k*alloc sizes
111636 + *
111637 + * TODO:
111638 + *
111639 + * BUGS:
111640 + * - none known
111641 + */
111642 +
111643 +#include "gcc-common.h"
111644 +
111645 +int plugin_is_GPL_compatible;
111646 +
111647 +static struct plugin_info kallocstat_plugin_info = {
111648 + .version = "201401260140",
111649 + .help = NULL
111650 +};
111651 +
111652 +static const char * const kalloc_functions[] = {
111653 + "__kmalloc",
111654 + "kmalloc",
111655 + "kmalloc_large",
111656 + "kmalloc_node",
111657 + "kmalloc_order",
111658 + "kmalloc_order_trace",
111659 + "kmalloc_slab",
111660 + "kzalloc",
111661 + "kzalloc_node",
111662 +};
111663 +
111664 +static bool is_kalloc(const char *fnname)
111665 +{
111666 + size_t i;
111667 +
111668 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111669 + if (!strcmp(fnname, kalloc_functions[i]))
111670 + return true;
111671 + return false;
111672 +}
111673 +
111674 +static unsigned int execute_kallocstat(void)
111675 +{
111676 + basic_block bb;
111677 +
111678 + // 1. loop through BBs and GIMPLE statements
111679 + FOR_EACH_BB_FN(bb, cfun) {
111680 + gimple_stmt_iterator gsi;
111681 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111682 + // gimple match:
111683 + tree fndecl, size;
111684 + gimple stmt;
111685 + const char *fnname;
111686 +
111687 + // is it a call
111688 + stmt = gsi_stmt(gsi);
111689 + if (!is_gimple_call(stmt))
111690 + continue;
111691 + fndecl = gimple_call_fndecl(stmt);
111692 + if (fndecl == NULL_TREE)
111693 + continue;
111694 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111695 + continue;
111696 +
111697 + // is it a call to k*alloc
111698 + fnname = DECL_NAME_POINTER(fndecl);
111699 + if (!is_kalloc(fnname))
111700 + continue;
111701 +
111702 + // is the size arg const or the result of a simple const assignment
111703 + size = gimple_call_arg(stmt, 0);
111704 + while (true) {
111705 + expanded_location xloc;
111706 + size_t size_val;
111707 +
111708 + if (TREE_CONSTANT(size)) {
111709 + xloc = expand_location(gimple_location(stmt));
111710 + if (!xloc.file)
111711 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111712 + size_val = TREE_INT_CST_LOW(size);
111713 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
111714 + break;
111715 + }
111716 +
111717 + if (TREE_CODE(size) != SSA_NAME)
111718 + break;
111719 + stmt = SSA_NAME_DEF_STMT(size);
111720 +//debug_gimple_stmt(stmt);
111721 +//debug_tree(size);
111722 + if (!stmt || !is_gimple_assign(stmt))
111723 + break;
111724 + if (gimple_num_ops(stmt) != 2)
111725 + break;
111726 + size = gimple_assign_rhs1(stmt);
111727 + }
111728 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111729 +//debug_tree(gimple_call_fn(call_stmt));
111730 +//print_node(stderr, "pax", fndecl, 4);
111731 + }
111732 + }
111733 +
111734 + return 0;
111735 +}
111736 +
111737 +#if BUILDING_GCC_VERSION >= 4009
111738 +static const struct pass_data kallocstat_pass_data = {
111739 +#else
111740 +static struct gimple_opt_pass kallocstat_pass = {
111741 + .pass = {
111742 +#endif
111743 + .type = GIMPLE_PASS,
111744 + .name = "kallocstat",
111745 +#if BUILDING_GCC_VERSION >= 4008
111746 + .optinfo_flags = OPTGROUP_NONE,
111747 +#endif
111748 +#if BUILDING_GCC_VERSION >= 4009
111749 + .has_gate = false,
111750 + .has_execute = true,
111751 +#else
111752 + .gate = NULL,
111753 + .execute = execute_kallocstat,
111754 + .sub = NULL,
111755 + .next = NULL,
111756 + .static_pass_number = 0,
111757 +#endif
111758 + .tv_id = TV_NONE,
111759 + .properties_required = 0,
111760 + .properties_provided = 0,
111761 + .properties_destroyed = 0,
111762 + .todo_flags_start = 0,
111763 + .todo_flags_finish = 0
111764 +#if BUILDING_GCC_VERSION < 4009
111765 + }
111766 +#endif
111767 +};
111768 +
111769 +#if BUILDING_GCC_VERSION >= 4009
111770 +namespace {
111771 +class kallocstat_pass : public gimple_opt_pass {
111772 +public:
111773 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
111774 + unsigned int execute() { return execute_kallocstat(); }
111775 +};
111776 +}
111777 +
111778 +static opt_pass *make_kallocstat_pass(void)
111779 +{
111780 + return new kallocstat_pass();
111781 +}
111782 +#else
111783 +static struct opt_pass *make_kallocstat_pass(void)
111784 +{
111785 + return &kallocstat_pass.pass;
111786 +}
111787 +#endif
111788 +
111789 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111790 +{
111791 + const char * const plugin_name = plugin_info->base_name;
111792 + struct register_pass_info kallocstat_pass_info;
111793 +
111794 + kallocstat_pass_info.pass = make_kallocstat_pass();
111795 + kallocstat_pass_info.reference_pass_name = "ssa";
111796 + kallocstat_pass_info.ref_pass_instance_number = 1;
111797 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111798 +
111799 + if (!plugin_default_version_check(version, &gcc_version)) {
111800 + error(G_("incompatible gcc/plugin versions"));
111801 + return 1;
111802 + }
111803 +
111804 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
111805 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
111806 +
111807 + return 0;
111808 +}
111809 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
111810 new file mode 100644
111811 index 0000000..89f256d
111812 --- /dev/null
111813 +++ b/tools/gcc/kernexec_plugin.c
111814 @@ -0,0 +1,522 @@
111815 +/*
111816 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111817 + * Licensed under the GPL v2
111818 + *
111819 + * Note: the choice of the license means that the compilation process is
111820 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111821 + * but for the kernel it doesn't matter since it doesn't link against
111822 + * any of the gcc libraries
111823 + *
111824 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
111825 + *
111826 + * TODO:
111827 + *
111828 + * BUGS:
111829 + * - none known
111830 + */
111831 +
111832 +#include "gcc-common.h"
111833 +
111834 +int plugin_is_GPL_compatible;
111835 +
111836 +static struct plugin_info kernexec_plugin_info = {
111837 + .version = "201401260140",
111838 + .help = "method=[bts|or]\tinstrumentation method\n"
111839 +};
111840 +
111841 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
111842 +static void (*kernexec_instrument_retaddr)(rtx);
111843 +
111844 +/*
111845 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
111846 + */
111847 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
111848 +{
111849 + gimple asm_movabs_stmt;
111850 +
111851 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
111852 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
111853 + gimple_asm_set_volatile(asm_movabs_stmt, true);
111854 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
111855 + update_stmt(asm_movabs_stmt);
111856 +}
111857 +
111858 +/*
111859 + * find all asm() stmts that clobber r12 and add a reload of r12
111860 + */
111861 +static unsigned int execute_kernexec_reload(void)
111862 +{
111863 + basic_block bb;
111864 +
111865 + // 1. loop through BBs and GIMPLE statements
111866 + FOR_EACH_BB_FN(bb, cfun) {
111867 + gimple_stmt_iterator gsi;
111868 +
111869 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111870 + // gimple match: __asm__ ("" : : : "r12");
111871 + gimple asm_stmt;
111872 + size_t nclobbers;
111873 +
111874 + // is it an asm ...
111875 + asm_stmt = gsi_stmt(gsi);
111876 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
111877 + continue;
111878 +
111879 + // ... clobbering r12
111880 + nclobbers = gimple_asm_nclobbers(asm_stmt);
111881 + while (nclobbers--) {
111882 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
111883 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
111884 + continue;
111885 + kernexec_reload_fptr_mask(&gsi);
111886 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
111887 + break;
111888 + }
111889 + }
111890 + }
111891 +
111892 + return 0;
111893 +}
111894 +
111895 +/*
111896 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
111897 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
111898 + */
111899 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
111900 +{
111901 + gimple assign_intptr, assign_new_fptr, call_stmt;
111902 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
111903 +
111904 + call_stmt = gsi_stmt(*gsi);
111905 + old_fptr = gimple_call_fn(call_stmt);
111906 +
111907 + // create temporary unsigned long variable used for bitops and cast fptr to it
111908 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
111909 + add_referenced_var(intptr);
111910 + intptr = make_ssa_name(intptr, NULL);
111911 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
111912 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111913 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111914 + update_stmt(assign_intptr);
111915 +
111916 + // apply logical or to temporary unsigned long and bitmask
111917 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
111918 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
111919 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
111920 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
111921 + assign_intptr = gimple_build_assign(intptr, orptr);
111922 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111923 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111924 + update_stmt(assign_intptr);
111925 +
111926 + // cast temporary unsigned long back to a temporary fptr variable
111927 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
111928 + add_referenced_var(new_fptr);
111929 + new_fptr = make_ssa_name(new_fptr, NULL);
111930 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
111931 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
111932 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
111933 + update_stmt(assign_new_fptr);
111934 +
111935 + // replace call stmt fn with the new fptr
111936 + gimple_call_set_fn(call_stmt, new_fptr);
111937 + update_stmt(call_stmt);
111938 +}
111939 +
111940 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
111941 +{
111942 + gimple asm_or_stmt, call_stmt;
111943 + tree old_fptr, new_fptr, input, output;
111944 +#if BUILDING_GCC_VERSION <= 4007
111945 + VEC(tree, gc) *inputs = NULL;
111946 + VEC(tree, gc) *outputs = NULL;
111947 +#else
111948 + vec<tree, va_gc> *inputs = NULL;
111949 + vec<tree, va_gc> *outputs = NULL;
111950 +#endif
111951 +
111952 + call_stmt = gsi_stmt(*gsi);
111953 + old_fptr = gimple_call_fn(call_stmt);
111954 +
111955 + // create temporary fptr variable
111956 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
111957 + add_referenced_var(new_fptr);
111958 + new_fptr = make_ssa_name(new_fptr, NULL);
111959 +
111960 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
111961 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
111962 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
111963 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
111964 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
111965 +#if BUILDING_GCC_VERSION <= 4007
111966 + VEC_safe_push(tree, gc, inputs, input);
111967 + VEC_safe_push(tree, gc, outputs, output);
111968 +#else
111969 + vec_safe_push(inputs, input);
111970 + vec_safe_push(outputs, output);
111971 +#endif
111972 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
111973 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
111974 + gimple_asm_set_volatile(asm_or_stmt, true);
111975 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
111976 + update_stmt(asm_or_stmt);
111977 +
111978 + // replace call stmt fn with the new fptr
111979 + gimple_call_set_fn(call_stmt, new_fptr);
111980 + update_stmt(call_stmt);
111981 +}
111982 +
111983 +/*
111984 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
111985 + */
111986 +static unsigned int execute_kernexec_fptr(void)
111987 +{
111988 + basic_block bb;
111989 +
111990 + // 1. loop through BBs and GIMPLE statements
111991 + FOR_EACH_BB_FN(bb, cfun) {
111992 + gimple_stmt_iterator gsi;
111993 +
111994 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111995 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
111996 + tree fn;
111997 + gimple call_stmt;
111998 +
111999 + // is it a call ...
112000 + call_stmt = gsi_stmt(gsi);
112001 + if (!is_gimple_call(call_stmt))
112002 + continue;
112003 + fn = gimple_call_fn(call_stmt);
112004 + if (TREE_CODE(fn) == ADDR_EXPR)
112005 + continue;
112006 + if (TREE_CODE(fn) != SSA_NAME)
112007 + gcc_unreachable();
112008 +
112009 + // ... through a function pointer
112010 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112011 + fn = SSA_NAME_VAR(fn);
112012 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112013 + debug_tree(fn);
112014 + gcc_unreachable();
112015 + }
112016 + }
112017 + fn = TREE_TYPE(fn);
112018 + if (TREE_CODE(fn) != POINTER_TYPE)
112019 + continue;
112020 + fn = TREE_TYPE(fn);
112021 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112022 + continue;
112023 +
112024 + kernexec_instrument_fptr(&gsi);
112025 +
112026 +//debug_tree(gimple_call_fn(call_stmt));
112027 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112028 + }
112029 + }
112030 +
112031 + return 0;
112032 +}
112033 +
112034 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112035 +static void kernexec_instrument_retaddr_bts(rtx insn)
112036 +{
112037 + rtx btsq;
112038 + rtvec argvec, constraintvec, labelvec;
112039 + int line;
112040 +
112041 + // create asm volatile("btsq $63,(%%rsp)":::)
112042 + argvec = rtvec_alloc(0);
112043 + constraintvec = rtvec_alloc(0);
112044 + labelvec = rtvec_alloc(0);
112045 + line = expand_location(RTL_LOCATION(insn)).line;
112046 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112047 + MEM_VOLATILE_P(btsq) = 1;
112048 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112049 + emit_insn_before(btsq, insn);
112050 +}
112051 +
112052 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112053 +static void kernexec_instrument_retaddr_or(rtx insn)
112054 +{
112055 + rtx orq;
112056 + rtvec argvec, constraintvec, labelvec;
112057 + int line;
112058 +
112059 + // create asm volatile("orq %%r12,(%%rsp)":::)
112060 + argvec = rtvec_alloc(0);
112061 + constraintvec = rtvec_alloc(0);
112062 + labelvec = rtvec_alloc(0);
112063 + line = expand_location(RTL_LOCATION(insn)).line;
112064 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112065 + MEM_VOLATILE_P(orq) = 1;
112066 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112067 + emit_insn_before(orq, insn);
112068 +}
112069 +
112070 +/*
112071 + * find all asm level function returns and forcibly set the highest bit of the return address
112072 + */
112073 +static unsigned int execute_kernexec_retaddr(void)
112074 +{
112075 + rtx insn;
112076 +
112077 +// if (stack_realign_drap)
112078 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112079 +
112080 + // 1. find function returns
112081 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112082 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112083 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112084 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112085 + rtx body;
112086 +
112087 + // is it a retn
112088 + if (!JUMP_P(insn))
112089 + continue;
112090 + body = PATTERN(insn);
112091 + if (GET_CODE(body) == PARALLEL)
112092 + body = XVECEXP(body, 0, 0);
112093 + if (!ANY_RETURN_P(body))
112094 + continue;
112095 + kernexec_instrument_retaddr(insn);
112096 + }
112097 +
112098 +// print_simple_rtl(stderr, get_insns());
112099 +// print_rtl(stderr, get_insns());
112100 +
112101 + return 0;
112102 +}
112103 +
112104 +static bool kernexec_cmodel_check(void)
112105 +{
112106 + tree section;
112107 +
112108 + if (ix86_cmodel != CM_KERNEL)
112109 + return false;
112110 +
112111 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112112 + if (!section || !TREE_VALUE(section))
112113 + return true;
112114 +
112115 + section = TREE_VALUE(TREE_VALUE(section));
112116 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112117 + return true;
112118 +
112119 + return false;
112120 +}
112121 +
112122 +#if BUILDING_GCC_VERSION >= 4009
112123 +static const struct pass_data kernexec_reload_pass_data = {
112124 +#else
112125 +static struct gimple_opt_pass kernexec_reload_pass = {
112126 + .pass = {
112127 +#endif
112128 + .type = GIMPLE_PASS,
112129 + .name = "kernexec_reload",
112130 +#if BUILDING_GCC_VERSION >= 4008
112131 + .optinfo_flags = OPTGROUP_NONE,
112132 +#endif
112133 +#if BUILDING_GCC_VERSION >= 4009
112134 + .has_gate = true,
112135 + .has_execute = true,
112136 +#else
112137 + .gate = kernexec_cmodel_check,
112138 + .execute = execute_kernexec_reload,
112139 + .sub = NULL,
112140 + .next = NULL,
112141 + .static_pass_number = 0,
112142 +#endif
112143 + .tv_id = TV_NONE,
112144 + .properties_required = 0,
112145 + .properties_provided = 0,
112146 + .properties_destroyed = 0,
112147 + .todo_flags_start = 0,
112148 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112149 +#if BUILDING_GCC_VERSION < 4009
112150 + }
112151 +#endif
112152 +};
112153 +
112154 +#if BUILDING_GCC_VERSION >= 4009
112155 +static const struct pass_data kernexec_fptr_pass_data = {
112156 +#else
112157 +static struct gimple_opt_pass kernexec_fptr_pass = {
112158 + .pass = {
112159 +#endif
112160 + .type = GIMPLE_PASS,
112161 + .name = "kernexec_fptr",
112162 +#if BUILDING_GCC_VERSION >= 4008
112163 + .optinfo_flags = OPTGROUP_NONE,
112164 +#endif
112165 +#if BUILDING_GCC_VERSION >= 4009
112166 + .has_gate = true,
112167 + .has_execute = true,
112168 +#else
112169 + .gate = kernexec_cmodel_check,
112170 + .execute = execute_kernexec_fptr,
112171 + .sub = NULL,
112172 + .next = NULL,
112173 + .static_pass_number = 0,
112174 +#endif
112175 + .tv_id = TV_NONE,
112176 + .properties_required = 0,
112177 + .properties_provided = 0,
112178 + .properties_destroyed = 0,
112179 + .todo_flags_start = 0,
112180 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112181 +#if BUILDING_GCC_VERSION < 4009
112182 + }
112183 +#endif
112184 +};
112185 +
112186 +#if BUILDING_GCC_VERSION >= 4009
112187 +static const struct pass_data kernexec_retaddr_pass_data = {
112188 +#else
112189 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112190 + .pass = {
112191 +#endif
112192 + .type = RTL_PASS,
112193 + .name = "kernexec_retaddr",
112194 +#if BUILDING_GCC_VERSION >= 4008
112195 + .optinfo_flags = OPTGROUP_NONE,
112196 +#endif
112197 +#if BUILDING_GCC_VERSION >= 4009
112198 + .has_gate = true,
112199 + .has_execute = true,
112200 +#else
112201 + .gate = kernexec_cmodel_check,
112202 + .execute = execute_kernexec_retaddr,
112203 + .sub = NULL,
112204 + .next = NULL,
112205 + .static_pass_number = 0,
112206 +#endif
112207 + .tv_id = TV_NONE,
112208 + .properties_required = 0,
112209 + .properties_provided = 0,
112210 + .properties_destroyed = 0,
112211 + .todo_flags_start = 0,
112212 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112213 +#if BUILDING_GCC_VERSION < 4009
112214 + }
112215 +#endif
112216 +};
112217 +
112218 +#if BUILDING_GCC_VERSION >= 4009
112219 +namespace {
112220 +class kernexec_reload_pass : public gimple_opt_pass {
112221 +public:
112222 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112223 + bool gate() { return kernexec_cmodel_check(); }
112224 + unsigned int execute() { return execute_kernexec_reload(); }
112225 +};
112226 +
112227 +class kernexec_fptr_pass : public gimple_opt_pass {
112228 +public:
112229 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112230 + bool gate() { return kernexec_cmodel_check(); }
112231 + unsigned int execute() { return execute_kernexec_fptr(); }
112232 +};
112233 +
112234 +class kernexec_retaddr_pass : public rtl_opt_pass {
112235 +public:
112236 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112237 + bool gate() { return kernexec_cmodel_check(); }
112238 + unsigned int execute() { return execute_kernexec_retaddr(); }
112239 +};
112240 +}
112241 +
112242 +static opt_pass *make_kernexec_reload_pass(void)
112243 +{
112244 + return new kernexec_reload_pass();
112245 +}
112246 +
112247 +static opt_pass *make_kernexec_fptr_pass(void)
112248 +{
112249 + return new kernexec_fptr_pass();
112250 +}
112251 +
112252 +static opt_pass *make_kernexec_retaddr_pass(void)
112253 +{
112254 + return new kernexec_retaddr_pass();
112255 +}
112256 +#else
112257 +static struct opt_pass *make_kernexec_reload_pass(void)
112258 +{
112259 + return &kernexec_reload_pass.pass;
112260 +}
112261 +
112262 +static struct opt_pass *make_kernexec_fptr_pass(void)
112263 +{
112264 + return &kernexec_fptr_pass.pass;
112265 +}
112266 +
112267 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112268 +{
112269 + return &kernexec_retaddr_pass.pass;
112270 +}
112271 +#endif
112272 +
112273 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112274 +{
112275 + const char * const plugin_name = plugin_info->base_name;
112276 + const int argc = plugin_info->argc;
112277 + const struct plugin_argument * const argv = plugin_info->argv;
112278 + int i;
112279 + struct register_pass_info kernexec_reload_pass_info;
112280 + struct register_pass_info kernexec_fptr_pass_info;
112281 + struct register_pass_info kernexec_retaddr_pass_info;
112282 +
112283 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112284 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112285 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112286 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112287 +
112288 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112289 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112290 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112291 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112292 +
112293 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112294 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112295 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112296 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112297 +
112298 + if (!plugin_default_version_check(version, &gcc_version)) {
112299 + error(G_("incompatible gcc/plugin versions"));
112300 + return 1;
112301 + }
112302 +
112303 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112304 +
112305 + if (TARGET_64BIT == 0)
112306 + return 0;
112307 +
112308 + for (i = 0; i < argc; ++i) {
112309 + if (!strcmp(argv[i].key, "method")) {
112310 + if (!argv[i].value) {
112311 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112312 + continue;
112313 + }
112314 + if (!strcmp(argv[i].value, "bts")) {
112315 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112316 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112317 + } else if (!strcmp(argv[i].value, "or")) {
112318 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112319 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112320 + fix_register("r12", 1, 1);
112321 + } else
112322 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112323 + continue;
112324 + }
112325 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112326 + }
112327 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112328 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112329 +
112330 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112331 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112332 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112333 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112334 +
112335 + return 0;
112336 +}
112337 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112338 new file mode 100644
112339 index 0000000..e48b323
112340 --- /dev/null
112341 +++ b/tools/gcc/latent_entropy_plugin.c
112342 @@ -0,0 +1,466 @@
112343 +/*
112344 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112345 + * Licensed under the GPL v2
112346 + *
112347 + * Note: the choice of the license means that the compilation process is
112348 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112349 + * but for the kernel it doesn't matter since it doesn't link against
112350 + * any of the gcc libraries
112351 + *
112352 + * gcc plugin to help generate a little bit of entropy from program state,
112353 + * used throughout the uptime of the kernel
112354 + *
112355 + * TODO:
112356 + * - add ipa pass to identify not explicitly marked candidate functions
112357 + * - mix in more program state (function arguments/return values, loop variables, etc)
112358 + * - more instrumentation control via attribute parameters
112359 + *
112360 + * BUGS:
112361 + * - LTO needs -flto-partition=none for now
112362 + */
112363 +
112364 +#include "gcc-common.h"
112365 +
112366 +int plugin_is_GPL_compatible;
112367 +
112368 +static tree latent_entropy_decl;
112369 +
112370 +static struct plugin_info latent_entropy_plugin_info = {
112371 + .version = "201409101820",
112372 + .help = NULL
112373 +};
112374 +
112375 +static unsigned HOST_WIDE_INT seed;
112376 +static unsigned HOST_WIDE_INT get_random_const(void)
112377 +{
112378 + unsigned int i;
112379 + unsigned HOST_WIDE_INT ret = 0;
112380 +
112381 + for (i = 0; i < 8 * sizeof ret; i++) {
112382 + ret = (ret << 1) | (seed & 1);
112383 + seed >>= 1;
112384 + if (ret & 1)
112385 + seed ^= 0xD800000000000000ULL;
112386 + }
112387 +
112388 + return ret;
112389 +}
112390 +
112391 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112392 +{
112393 + tree type;
112394 + unsigned long long mask;
112395 +#if BUILDING_GCC_VERSION <= 4007
112396 + VEC(constructor_elt, gc) *vals;
112397 +#else
112398 + vec<constructor_elt, va_gc> *vals;
112399 +#endif
112400 +
112401 + switch (TREE_CODE(*node)) {
112402 + default:
112403 + *no_add_attrs = true;
112404 + error("%qE attribute only applies to functions and variables", name);
112405 + break;
112406 +
112407 + case VAR_DECL:
112408 + if (DECL_INITIAL(*node)) {
112409 + *no_add_attrs = true;
112410 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112411 + break;
112412 + }
112413 +
112414 + if (!TREE_STATIC(*node)) {
112415 + *no_add_attrs = true;
112416 + error("variable %qD with %qE attribute must not be local", *node, name);
112417 + break;
112418 + }
112419 +
112420 + type = TREE_TYPE(*node);
112421 + switch (TREE_CODE(type)) {
112422 + default:
112423 + *no_add_attrs = true;
112424 + 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);
112425 + break;
112426 +
112427 + case RECORD_TYPE: {
112428 + tree field;
112429 + unsigned int nelt = 0;
112430 +
112431 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112432 + tree fieldtype;
112433 +
112434 + fieldtype = TREE_TYPE(field);
112435 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112436 + *no_add_attrs = true;
112437 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112438 + break;
112439 + }
112440 + }
112441 +
112442 + if (field)
112443 + break;
112444 +
112445 +#if BUILDING_GCC_VERSION <= 4007
112446 + vals = VEC_alloc(constructor_elt, gc, nelt);
112447 +#else
112448 + vec_alloc(vals, nelt);
112449 +#endif
112450 +
112451 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112452 + tree fieldtype;
112453 +
112454 + fieldtype = TREE_TYPE(field);
112455 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112456 + mask = 2 * (mask - 1) + 1;
112457 +
112458 + if (TYPE_UNSIGNED(fieldtype))
112459 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112460 + else
112461 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112462 + }
112463 +
112464 + DECL_INITIAL(*node) = build_constructor(type, vals);
112465 +//debug_tree(DECL_INITIAL(*node));
112466 + break;
112467 + }
112468 +
112469 + case INTEGER_TYPE:
112470 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112471 + mask = 2 * (mask - 1) + 1;
112472 +
112473 + if (TYPE_UNSIGNED(type))
112474 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112475 + else
112476 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112477 + break;
112478 +
112479 + case ARRAY_TYPE: {
112480 + tree elt_type, array_size, elt_size;
112481 + unsigned int i, nelt;
112482 +
112483 + elt_type = TREE_TYPE(type);
112484 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112485 + array_size = TYPE_SIZE_UNIT(type);
112486 +
112487 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112488 + *no_add_attrs = true;
112489 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112490 + break;
112491 + }
112492 +
112493 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112494 +#if BUILDING_GCC_VERSION <= 4007
112495 + vals = VEC_alloc(constructor_elt, gc, nelt);
112496 +#else
112497 + vec_alloc(vals, nelt);
112498 +#endif
112499 +
112500 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112501 + mask = 2 * (mask - 1) + 1;
112502 +
112503 + for (i = 0; i < nelt; i++)
112504 + if (TYPE_UNSIGNED(elt_type))
112505 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112506 + else
112507 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112508 +
112509 + DECL_INITIAL(*node) = build_constructor(type, vals);
112510 +//debug_tree(DECL_INITIAL(*node));
112511 + break;
112512 + }
112513 + }
112514 + break;
112515 +
112516 + case FUNCTION_DECL:
112517 + break;
112518 + }
112519 +
112520 + return NULL_TREE;
112521 +}
112522 +
112523 +static struct attribute_spec latent_entropy_attr = {
112524 + .name = "latent_entropy",
112525 + .min_length = 0,
112526 + .max_length = 0,
112527 + .decl_required = true,
112528 + .type_required = false,
112529 + .function_type_required = false,
112530 + .handler = handle_latent_entropy_attribute,
112531 +#if BUILDING_GCC_VERSION >= 4007
112532 + .affects_type_identity = false
112533 +#endif
112534 +};
112535 +
112536 +static void register_attributes(void *event_data, void *data)
112537 +{
112538 + register_attribute(&latent_entropy_attr);
112539 +}
112540 +
112541 +static bool gate_latent_entropy(void)
112542 +{
112543 + // don't bother with noreturn functions for now
112544 + if (TREE_THIS_VOLATILE(current_function_decl))
112545 + return false;
112546 +
112547 + // gcc-4.5 doesn't discover some trivial noreturn functions
112548 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112549 + return false;
112550 +
112551 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112552 +}
112553 +
112554 +static enum tree_code get_op(tree *rhs)
112555 +{
112556 + static enum tree_code op;
112557 + unsigned HOST_WIDE_INT random_const;
112558 +
112559 + random_const = get_random_const();
112560 +
112561 + switch (op) {
112562 + case BIT_XOR_EXPR:
112563 + op = PLUS_EXPR;
112564 + break;
112565 +
112566 + case PLUS_EXPR:
112567 + if (rhs) {
112568 + op = LROTATE_EXPR;
112569 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112570 + break;
112571 + }
112572 +
112573 + case LROTATE_EXPR:
112574 + default:
112575 + op = BIT_XOR_EXPR;
112576 + break;
112577 + }
112578 + if (rhs)
112579 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112580 + return op;
112581 +}
112582 +
112583 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112584 +{
112585 + gimple_stmt_iterator gsi;
112586 + gimple assign;
112587 + tree addxorrol, rhs;
112588 + enum tree_code op;
112589 +
112590 + op = get_op(&rhs);
112591 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112592 + assign = gimple_build_assign(local_entropy, addxorrol);
112593 + gsi = gsi_after_labels(bb);
112594 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112595 + update_stmt(assign);
112596 +//debug_bb(bb);
112597 +}
112598 +
112599 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112600 +{
112601 + gimple_stmt_iterator gsi;
112602 + gimple assign;
112603 + tree addxorrol, temp;
112604 +
112605 + // 1. create temporary copy of latent_entropy
112606 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112607 + add_referenced_var(temp);
112608 +
112609 + // 2. read...
112610 + temp = make_ssa_name(temp, NULL);
112611 + assign = gimple_build_assign(temp, latent_entropy_decl);
112612 + SSA_NAME_DEF_STMT(temp) = assign;
112613 + add_referenced_var(latent_entropy_decl);
112614 + gsi = gsi_after_labels(bb);
112615 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112616 + update_stmt(assign);
112617 +
112618 + // 3. ...modify...
112619 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112620 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112621 + assign = gimple_build_assign(temp, addxorrol);
112622 + SSA_NAME_DEF_STMT(temp) = assign;
112623 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112624 + update_stmt(assign);
112625 +
112626 + // 4. ...write latent_entropy
112627 + assign = gimple_build_assign(latent_entropy_decl, temp);
112628 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112629 + update_stmt(assign);
112630 +}
112631 +
112632 +static unsigned int execute_latent_entropy(void)
112633 +{
112634 + basic_block bb;
112635 + gimple assign;
112636 + gimple_stmt_iterator gsi;
112637 + tree local_entropy;
112638 +
112639 + if (!latent_entropy_decl) {
112640 +#if BUILDING_GCC_VERSION >= 4009
112641 + varpool_node *node;
112642 +#else
112643 + struct varpool_node *node;
112644 +#endif
112645 +
112646 + FOR_EACH_VARIABLE(node) {
112647 + tree var = NODE_DECL(node);
112648 +
112649 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112650 + continue;
112651 + latent_entropy_decl = var;
112652 +// debug_tree(var);
112653 + break;
112654 + }
112655 + if (!latent_entropy_decl) {
112656 +// debug_tree(current_function_decl);
112657 + return 0;
112658 + }
112659 + }
112660 +
112661 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112662 +
112663 + // 1. create local entropy variable
112664 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112665 + add_referenced_var(local_entropy);
112666 + mark_sym_for_renaming(local_entropy);
112667 +
112668 + // 2. initialize local entropy variable
112669 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112670 + if (dom_info_available_p(CDI_DOMINATORS))
112671 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112672 + gsi = gsi_start_bb(bb);
112673 +
112674 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112675 +// gimple_set_location(assign, loc);
112676 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112677 + update_stmt(assign);
112678 +//debug_bb(bb);
112679 + gcc_assert(single_succ_p(bb));
112680 + bb = single_succ(bb);
112681 +
112682 + // 3. instrument each BB with an operation on the local entropy variable
112683 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112684 + perturb_local_entropy(bb, local_entropy);
112685 +//debug_bb(bb);
112686 + bb = bb->next_bb;
112687 + };
112688 +
112689 + // 4. mix local entropy into the global entropy variable
112690 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112691 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112692 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112693 + return 0;
112694 +}
112695 +
112696 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112697 +{
112698 + tree latent_entropy_type;
112699 +
112700 + seed = get_random_seed(false);
112701 +
112702 + if (in_lto_p)
112703 + return;
112704 +
112705 + // extern volatile u64 latent_entropy
112706 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112707 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112708 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112709 +
112710 + TREE_STATIC(latent_entropy_decl) = 1;
112711 + TREE_PUBLIC(latent_entropy_decl) = 1;
112712 + TREE_USED(latent_entropy_decl) = 1;
112713 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
112714 + DECL_EXTERNAL(latent_entropy_decl) = 1;
112715 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
112716 + lang_hooks.decls.pushdecl(latent_entropy_decl);
112717 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
112718 +// varpool_finalize_decl(latent_entropy_decl);
112719 +// varpool_mark_needed_node(latent_entropy_decl);
112720 +}
112721 +
112722 +#if BUILDING_GCC_VERSION >= 4009
112723 +static const struct pass_data latent_entropy_pass_data = {
112724 +#else
112725 +static struct gimple_opt_pass latent_entropy_pass = {
112726 + .pass = {
112727 +#endif
112728 + .type = GIMPLE_PASS,
112729 + .name = "latent_entropy",
112730 +#if BUILDING_GCC_VERSION >= 4008
112731 + .optinfo_flags = OPTGROUP_NONE,
112732 +#endif
112733 +#if BUILDING_GCC_VERSION >= 4009
112734 + .has_gate = true,
112735 + .has_execute = true,
112736 +#else
112737 + .gate = gate_latent_entropy,
112738 + .execute = execute_latent_entropy,
112739 + .sub = NULL,
112740 + .next = NULL,
112741 + .static_pass_number = 0,
112742 +#endif
112743 + .tv_id = TV_NONE,
112744 + .properties_required = PROP_gimple_leh | PROP_cfg,
112745 + .properties_provided = 0,
112746 + .properties_destroyed = 0,
112747 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
112748 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
112749 +#if BUILDING_GCC_VERSION < 4009
112750 + }
112751 +#endif
112752 +};
112753 +
112754 +#if BUILDING_GCC_VERSION >= 4009
112755 +namespace {
112756 +class latent_entropy_pass : public gimple_opt_pass {
112757 +public:
112758 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
112759 + bool gate() { return gate_latent_entropy(); }
112760 + unsigned int execute() { return execute_latent_entropy(); }
112761 +};
112762 +}
112763 +
112764 +static opt_pass *make_latent_entropy_pass(void)
112765 +{
112766 + return new latent_entropy_pass();
112767 +}
112768 +#else
112769 +static struct opt_pass *make_latent_entropy_pass(void)
112770 +{
112771 + return &latent_entropy_pass.pass;
112772 +}
112773 +#endif
112774 +
112775 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112776 +{
112777 + const char * const plugin_name = plugin_info->base_name;
112778 + struct register_pass_info latent_entropy_pass_info;
112779 +
112780 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
112781 + latent_entropy_pass_info.reference_pass_name = "optimized";
112782 + latent_entropy_pass_info.ref_pass_instance_number = 1;
112783 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112784 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
112785 + {
112786 + .base = &latent_entropy_decl,
112787 + .nelt = 1,
112788 + .stride = sizeof(latent_entropy_decl),
112789 + .cb = &gt_ggc_mx_tree_node,
112790 + .pchw = &gt_pch_nx_tree_node
112791 + },
112792 + LAST_GGC_ROOT_TAB
112793 + };
112794 +
112795 + if (!plugin_default_version_check(version, &gcc_version)) {
112796 + error(G_("incompatible gcc/plugin versions"));
112797 + return 1;
112798 + }
112799 +
112800 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
112801 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
112802 + if (!in_lto_p)
112803 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
112804 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
112805 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112806 +
112807 + return 0;
112808 +}
112809 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
112810 new file mode 100644
112811 index 0000000..a5cb46b
112812 --- /dev/null
112813 +++ b/tools/gcc/randomize_layout_plugin.c
112814 @@ -0,0 +1,915 @@
112815 +/*
112816 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
112817 + * and PaX Team <pageexec@freemail.hu>
112818 + * Licensed under the GPL v2
112819 + *
112820 + * Usage:
112821 + * $ # for 4.5/4.6/C based 4.7
112822 + * $ 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
112823 + * $ # for C++ based 4.7/4.8+
112824 + * $ 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
112825 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
112826 + */
112827 +
112828 +#include "gcc-common.h"
112829 +#include "randomize_layout_seed.h"
112830 +
112831 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
112832 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
112833 +#endif
112834 +
112835 +#define ORIG_TYPE_NAME(node) \
112836 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
112837 +
112838 +int plugin_is_GPL_compatible;
112839 +
112840 +static int performance_mode;
112841 +
112842 +static struct plugin_info randomize_layout_plugin_info = {
112843 + .version = "201402201816",
112844 + .help = "disable\t\t\tdo not activate plugin\n"
112845 + "performance-mode\tenable cacheline-aware layout randomization\n"
112846 +};
112847 +
112848 +/* from old Linux dcache.h */
112849 +static inline unsigned long
112850 +partial_name_hash(unsigned long c, unsigned long prevhash)
112851 +{
112852 + return (prevhash + (c << 4) + (c >> 4)) * 11;
112853 +}
112854 +static inline unsigned int
112855 +name_hash(const unsigned char *name)
112856 +{
112857 + unsigned long hash = 0;
112858 + unsigned int len = strlen((const char *)name);
112859 + while (len--)
112860 + hash = partial_name_hash(*name++, hash);
112861 + return (unsigned int)hash;
112862 +}
112863 +
112864 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112865 +{
112866 + tree type;
112867 +
112868 + *no_add_attrs = true;
112869 + if (TREE_CODE(*node) == FUNCTION_DECL) {
112870 + error("%qE attribute does not apply to functions (%qF)", name, *node);
112871 + return NULL_TREE;
112872 + }
112873 +
112874 + if (TREE_CODE(*node) == PARM_DECL) {
112875 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
112876 + return NULL_TREE;
112877 + }
112878 +
112879 + if (TREE_CODE(*node) == VAR_DECL) {
112880 + error("%qE attribute does not apply to variables (%qD)", name, *node);
112881 + return NULL_TREE;
112882 + }
112883 +
112884 + if (TYPE_P(*node)) {
112885 + type = *node;
112886 + } else {
112887 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
112888 + type = TREE_TYPE(*node);
112889 + }
112890 +
112891 + if (TREE_CODE(type) != RECORD_TYPE) {
112892 + error("%qE attribute used on %qT applies to struct types only", name, type);
112893 + return NULL_TREE;
112894 + }
112895 +
112896 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
112897 + error("%qE attribute is already applied to the type %qT", name, type);
112898 + return NULL_TREE;
112899 + }
112900 +
112901 + *no_add_attrs = false;
112902 +
112903 + return NULL_TREE;
112904 +}
112905 +
112906 +/* set on complete types that we don't need to inspect further at all */
112907 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112908 +{
112909 + *no_add_attrs = false;
112910 + return NULL_TREE;
112911 +}
112912 +
112913 +/*
112914 + * set on types that we've performed a shuffle on, to prevent re-shuffling
112915 + * this does not preclude us from inspecting its fields for potential shuffles
112916 + */
112917 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112918 +{
112919 + *no_add_attrs = false;
112920 + return NULL_TREE;
112921 +}
112922 +
112923 +/*
112924 + * 64bit variant of Bob Jenkins' public domain PRNG
112925 + * 256 bits of internal state
112926 + */
112927 +
112928 +typedef unsigned long long u64;
112929 +
112930 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
112931 +
112932 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
112933 +static u64 ranval(ranctx *x) {
112934 + u64 e = x->a - rot(x->b, 7);
112935 + x->a = x->b ^ rot(x->c, 13);
112936 + x->b = x->c + rot(x->d, 37);
112937 + x->c = x->d + e;
112938 + x->d = e + x->a;
112939 + return x->d;
112940 +}
112941 +
112942 +static void raninit(ranctx *x, u64 *seed) {
112943 + int i;
112944 +
112945 + x->a = seed[0];
112946 + x->b = seed[1];
112947 + x->c = seed[2];
112948 + x->d = seed[3];
112949 +
112950 + for (i=0; i < 30; ++i)
112951 + (void)ranval(x);
112952 +}
112953 +
112954 +static u64 shuffle_seed[4];
112955 +
112956 +struct partition_group {
112957 + tree tree_start;
112958 + unsigned long start;
112959 + unsigned long length;
112960 +};
112961 +
112962 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
112963 +{
112964 + unsigned long i;
112965 + unsigned long accum_size = 0;
112966 + unsigned long accum_length = 0;
112967 + unsigned long group_idx = 0;
112968 +
112969 + gcc_assert(length < INT_MAX);
112970 +
112971 + memset(size_groups, 0, sizeof(struct partition_group) * length);
112972 +
112973 + for (i = 0; i < length; i++) {
112974 + if (size_groups[group_idx].tree_start == NULL_TREE) {
112975 + size_groups[group_idx].tree_start = fields[i];
112976 + size_groups[group_idx].start = i;
112977 + accum_length = 0;
112978 + accum_size = 0;
112979 + }
112980 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
112981 + accum_length++;
112982 + if (accum_size >= 64) {
112983 + size_groups[group_idx].length = accum_length;
112984 + accum_length = 0;
112985 + group_idx++;
112986 + }
112987 + }
112988 +
112989 + if (size_groups[group_idx].tree_start != NULL_TREE &&
112990 + !size_groups[group_idx].length) {
112991 + size_groups[group_idx].length = accum_length;
112992 + group_idx++;
112993 + }
112994 +
112995 + *num_groups = group_idx;
112996 +}
112997 +
112998 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112999 +{
113000 + unsigned long i, x;
113001 + struct partition_group size_group[length];
113002 + unsigned long num_groups = 0;
113003 + unsigned long randnum;
113004 +
113005 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113006 + for (i = num_groups - 1; i > 0; i--) {
113007 + struct partition_group tmp;
113008 + randnum = ranval(prng_state) % (i + 1);
113009 + tmp = size_group[i];
113010 + size_group[i] = size_group[randnum];
113011 + size_group[randnum] = tmp;
113012 + }
113013 +
113014 + for (x = 0; x < num_groups; x++) {
113015 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113016 + tree tmp;
113017 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113018 + continue;
113019 + randnum = ranval(prng_state) % (i + 1);
113020 + // we could handle this case differently if desired
113021 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113022 + continue;
113023 + tmp = newtree[i];
113024 + newtree[i] = newtree[randnum];
113025 + newtree[randnum] = tmp;
113026 + }
113027 + }
113028 +}
113029 +
113030 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113031 +{
113032 + unsigned long i, randnum;
113033 +
113034 + for (i = length - 1; i > 0; i--) {
113035 + tree tmp;
113036 + randnum = ranval(prng_state) % (i + 1);
113037 + tmp = newtree[i];
113038 + newtree[i] = newtree[randnum];
113039 + newtree[randnum] = tmp;
113040 + }
113041 +}
113042 +
113043 +/* modern in-place Fisher-Yates shuffle */
113044 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113045 +{
113046 + unsigned long i;
113047 + u64 seed[4];
113048 + ranctx prng_state;
113049 + const unsigned char *structname;
113050 +
113051 + if (length == 0)
113052 + return;
113053 +
113054 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113055 +
113056 + structname = ORIG_TYPE_NAME(type);
113057 +
113058 +#ifdef __DEBUG_PLUGIN
113059 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113060 +#ifdef __DEBUG_VERBOSE
113061 + debug_tree((tree)type);
113062 +#endif
113063 +#endif
113064 +
113065 + for (i = 0; i < 4; i++) {
113066 + seed[i] = shuffle_seed[i];
113067 + seed[i] ^= name_hash(structname);
113068 + }
113069 +
113070 + raninit(&prng_state, (u64 *)&seed);
113071 +
113072 + if (performance_mode)
113073 + performance_shuffle(newtree, length, &prng_state);
113074 + else
113075 + full_shuffle(newtree, length, &prng_state);
113076 +}
113077 +
113078 +static bool is_flexible_array(const_tree field)
113079 +{
113080 + const_tree fieldtype;
113081 + const_tree typesize;
113082 + const_tree elemtype;
113083 + const_tree elemsize;
113084 +
113085 + fieldtype = TREE_TYPE(field);
113086 + typesize = TYPE_SIZE(fieldtype);
113087 +
113088 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113089 + return false;
113090 +
113091 + elemtype = TREE_TYPE(fieldtype);
113092 + elemsize = TYPE_SIZE(elemtype);
113093 +
113094 + /* size of type is represented in bits */
113095 +
113096 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113097 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113098 + return true;
113099 +
113100 + if (typesize != NULL_TREE &&
113101 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113102 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113103 + return true;
113104 +
113105 + return false;
113106 +}
113107 +
113108 +static int relayout_struct(tree type)
113109 +{
113110 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113111 + unsigned long shuffle_length = num_fields;
113112 + tree field;
113113 + tree newtree[num_fields];
113114 + unsigned long i;
113115 + tree list;
113116 + tree variant;
113117 + expanded_location xloc;
113118 +
113119 + if (TYPE_FIELDS(type) == NULL_TREE)
113120 + return 0;
113121 +
113122 + if (num_fields < 2)
113123 + return 0;
113124 +
113125 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113126 +
113127 + gcc_assert(num_fields < INT_MAX);
113128 +
113129 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113130 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113131 + return 0;
113132 +
113133 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113134 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113135 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113136 + return 0;
113137 +
113138 + /* throw out any structs in uapi */
113139 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113140 +
113141 + if (strstr(xloc.file, "/uapi/"))
113142 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113143 +
113144 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113145 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113146 + newtree[i] = field;
113147 + }
113148 +
113149 + /*
113150 + * enforce that we don't randomize the layout of the last
113151 + * element of a struct if it's a 0 or 1-length array
113152 + * or a proper flexible array
113153 + */
113154 + if (is_flexible_array(newtree[num_fields - 1]))
113155 + shuffle_length--;
113156 +
113157 + shuffle(type, (tree *)newtree, shuffle_length);
113158 +
113159 + /*
113160 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113161 + * as gcc provides no other way to detect such code
113162 + */
113163 + list = make_node(FIELD_DECL);
113164 + TREE_CHAIN(list) = newtree[0];
113165 + TREE_TYPE(list) = void_type_node;
113166 + DECL_SIZE(list) = bitsize_zero_node;
113167 + DECL_NONADDRESSABLE_P(list) = 1;
113168 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113169 + DECL_SIZE_UNIT(list) = size_zero_node;
113170 + DECL_FIELD_OFFSET(list) = size_zero_node;
113171 + // to satisfy the constify plugin
113172 + TREE_READONLY(list) = 1;
113173 +
113174 + for (i = 0; i < num_fields - 1; i++)
113175 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113176 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113177 +
113178 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113179 + TYPE_FIELDS(variant) = list;
113180 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113181 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113182 + // force a re-layout
113183 + TYPE_SIZE(variant) = NULL_TREE;
113184 + layout_type(variant);
113185 + }
113186 +
113187 + return 1;
113188 +}
113189 +
113190 +/* from constify plugin */
113191 +static const_tree get_field_type(const_tree field)
113192 +{
113193 + return strip_array_types(TREE_TYPE(field));
113194 +}
113195 +
113196 +/* from constify plugin */
113197 +static bool is_fptr(const_tree fieldtype)
113198 +{
113199 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113200 + return false;
113201 +
113202 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113203 +}
113204 +
113205 +/* derived from constify plugin */
113206 +static int is_pure_ops_struct(const_tree node)
113207 +{
113208 + const_tree field;
113209 +
113210 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113211 +
113212 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113213 + const_tree fieldtype = get_field_type(field);
113214 + enum tree_code code = TREE_CODE(fieldtype);
113215 +
113216 + if (node == fieldtype)
113217 + continue;
113218 +
113219 + if (!is_fptr(fieldtype))
113220 + return 0;
113221 +
113222 + if (code != RECORD_TYPE && code != UNION_TYPE)
113223 + continue;
113224 +
113225 + if (!is_pure_ops_struct(fieldtype))
113226 + return 0;
113227 + }
113228 +
113229 + return 1;
113230 +}
113231 +
113232 +static void randomize_type(tree type)
113233 +{
113234 + tree variant;
113235 +
113236 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113237 +
113238 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113239 + return;
113240 +
113241 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113242 + relayout_struct(type);
113243 +
113244 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113245 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113246 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113247 + }
113248 +#ifdef __DEBUG_PLUGIN
113249 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113250 +#ifdef __DEBUG_VERBOSE
113251 + debug_tree(type);
113252 +#endif
113253 +#endif
113254 +}
113255 +
113256 +static void randomize_layout_finish_decl(void *event_data, void *data)
113257 +{
113258 + tree decl = (tree)event_data;
113259 + tree type;
113260 +
113261 + if (decl == NULL_TREE || decl == error_mark_node)
113262 + return;
113263 +
113264 + type = TREE_TYPE(decl);
113265 +
113266 + if (TREE_CODE(decl) != VAR_DECL)
113267 + return;
113268 +
113269 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113270 + return;
113271 +
113272 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113273 + return;
113274 +
113275 + relayout_decl(decl);
113276 +}
113277 +
113278 +static void finish_type(void *event_data, void *data)
113279 +{
113280 + tree type = (tree)event_data;
113281 +
113282 + if (type == NULL_TREE || type == error_mark_node)
113283 + return;
113284 +
113285 + if (TREE_CODE(type) != RECORD_TYPE)
113286 + return;
113287 +
113288 + if (TYPE_FIELDS(type) == NULL_TREE)
113289 + return;
113290 +
113291 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113292 + return;
113293 +
113294 +#ifdef __DEBUG_PLUGIN
113295 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113296 +#endif
113297 +#ifdef __DEBUG_VERBOSE
113298 + debug_tree(type);
113299 +#endif
113300 + randomize_type(type);
113301 +
113302 + return;
113303 +}
113304 +
113305 +static struct attribute_spec randomize_layout_attr = {
113306 + .name = "randomize_layout",
113307 + // related to args
113308 + .min_length = 0,
113309 + .max_length = 0,
113310 + .decl_required = false,
113311 + // need type declaration
113312 + .type_required = true,
113313 + .function_type_required = false,
113314 + .handler = handle_randomize_layout_attr,
113315 +#if BUILDING_GCC_VERSION >= 4007
113316 + .affects_type_identity = true
113317 +#endif
113318 +};
113319 +
113320 +static struct attribute_spec no_randomize_layout_attr = {
113321 + .name = "no_randomize_layout",
113322 + // related to args
113323 + .min_length = 0,
113324 + .max_length = 0,
113325 + .decl_required = false,
113326 + // need type declaration
113327 + .type_required = true,
113328 + .function_type_required = false,
113329 + .handler = handle_randomize_layout_attr,
113330 +#if BUILDING_GCC_VERSION >= 4007
113331 + .affects_type_identity = true
113332 +#endif
113333 +};
113334 +
113335 +static struct attribute_spec randomize_considered_attr = {
113336 + .name = "randomize_considered",
113337 + // related to args
113338 + .min_length = 0,
113339 + .max_length = 0,
113340 + .decl_required = false,
113341 + // need type declaration
113342 + .type_required = true,
113343 + .function_type_required = false,
113344 + .handler = handle_randomize_considered_attr,
113345 +#if BUILDING_GCC_VERSION >= 4007
113346 + .affects_type_identity = false
113347 +#endif
113348 +};
113349 +
113350 +static struct attribute_spec randomize_performed_attr = {
113351 + .name = "randomize_performed",
113352 + // related to args
113353 + .min_length = 0,
113354 + .max_length = 0,
113355 + .decl_required = false,
113356 + // need type declaration
113357 + .type_required = true,
113358 + .function_type_required = false,
113359 + .handler = handle_randomize_performed_attr,
113360 +#if BUILDING_GCC_VERSION >= 4007
113361 + .affects_type_identity = false
113362 +#endif
113363 +};
113364 +
113365 +static void register_attributes(void *event_data, void *data)
113366 +{
113367 + register_attribute(&randomize_layout_attr);
113368 + register_attribute(&no_randomize_layout_attr);
113369 + register_attribute(&randomize_considered_attr);
113370 + register_attribute(&randomize_performed_attr);
113371 +}
113372 +
113373 +static void check_bad_casts_in_constructor(tree var, tree init)
113374 +{
113375 + unsigned HOST_WIDE_INT idx;
113376 + tree field, val;
113377 + tree field_type, val_type;
113378 +
113379 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113380 + if (TREE_CODE(val) == CONSTRUCTOR) {
113381 + check_bad_casts_in_constructor(var, val);
113382 + continue;
113383 + }
113384 +
113385 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113386 + normal code which all have valid 'field' trees. work around this */
113387 + if (field == NULL_TREE)
113388 + continue;
113389 + field_type = TREE_TYPE(field);
113390 + val_type = TREE_TYPE(val);
113391 +
113392 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113393 + continue;
113394 +
113395 + if (field_type == val_type)
113396 + continue;
113397 +
113398 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113399 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113400 +
113401 + if (field_type == void_type_node)
113402 + continue;
113403 + if (field_type == val_type)
113404 + continue;
113405 + if (TREE_CODE(val_type) != RECORD_TYPE)
113406 + continue;
113407 +
113408 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113409 + continue;
113410 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113411 + }
113412 +}
113413 +
113414 +/* derived from the constify plugin */
113415 +static void check_global_variables(void *event_data, void *data)
113416 +{
113417 + struct varpool_node *node;
113418 + tree init;
113419 +
113420 + FOR_EACH_VARIABLE(node) {
113421 + tree var = NODE_DECL(node);
113422 + init = DECL_INITIAL(var);
113423 + if (init == NULL_TREE)
113424 + continue;
113425 +
113426 + if (TREE_CODE(init) != CONSTRUCTOR)
113427 + continue;
113428 +
113429 + check_bad_casts_in_constructor(var, init);
113430 + }
113431 +}
113432 +
113433 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113434 +{
113435 + basic_block dom;
113436 + gimple dom_stmt;
113437 + gimple call_stmt;
113438 + const_tree dom_lhs;
113439 + const_tree poss_is_err_cond;
113440 + const_tree poss_is_err_func;
113441 + const_tree is_err_arg;
113442 +
113443 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113444 + if (!dom)
113445 + return false;
113446 +
113447 + dom_stmt = last_stmt(dom);
113448 + if (!dom_stmt)
113449 + return false;
113450 +
113451 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113452 + return false;
113453 +
113454 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113455 + return false;
113456 +
113457 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113458 + return false;
113459 +
113460 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113461 +
113462 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113463 + return false;
113464 +
113465 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113466 +
113467 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113468 + return false;
113469 +
113470 + dom_lhs = gimple_get_lhs(call_stmt);
113471 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113472 + if (!poss_is_err_func)
113473 + return false;
113474 + if (dom_lhs != poss_is_err_cond)
113475 + return false;
113476 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113477 + return false;
113478 +
113479 + is_err_arg = gimple_call_arg(call_stmt, 0);
113480 + if (!is_err_arg)
113481 + return false;
113482 +
113483 + if (is_err_arg != rhs)
113484 + return false;
113485 +
113486 + return true;
113487 +}
113488 +
113489 +static void handle_local_var_initializers(void)
113490 +{
113491 + tree var;
113492 + unsigned int i;
113493 +
113494 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113495 + tree init = DECL_INITIAL(var);
113496 + if (!init)
113497 + continue;
113498 + if (TREE_CODE(init) != CONSTRUCTOR)
113499 + continue;
113500 + check_bad_casts_in_constructor(var, init);
113501 + }
113502 +}
113503 +
113504 +/*
113505 + * iterate over all statements to find "bad" casts:
113506 + * those where the address of the start of a structure is cast
113507 + * to a pointer of a structure of a different type, or a
113508 + * structure pointer type is cast to a different structure pointer type
113509 + */
113510 +static unsigned int find_bad_casts(void)
113511 +{
113512 + basic_block bb;
113513 +
113514 + handle_local_var_initializers();
113515 +
113516 + FOR_ALL_BB_FN(bb, cfun) {
113517 + gimple_stmt_iterator gsi;
113518 +
113519 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113520 + gimple stmt;
113521 + const_tree lhs;
113522 + const_tree lhs_type;
113523 + const_tree rhs1;
113524 + const_tree rhs_type;
113525 + const_tree ptr_lhs_type;
113526 + const_tree ptr_rhs_type;
113527 + const_tree op0;
113528 + const_tree op0_type;
113529 + enum tree_code rhs_code;
113530 +
113531 + stmt = gsi_stmt(gsi);
113532 +
113533 +#ifdef __DEBUG_PLUGIN
113534 +#ifdef __DEBUG_VERBOSE
113535 + debug_gimple_stmt(stmt);
113536 + debug_tree(gimple_get_lhs(stmt));
113537 +#endif
113538 +#endif
113539 +
113540 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113541 + continue;
113542 +
113543 +#ifdef __DEBUG_PLUGIN
113544 +#ifdef __DEBUG_VERBOSE
113545 + debug_tree(gimple_assign_rhs1(stmt));
113546 +#endif
113547 +#endif
113548 +
113549 + rhs_code = gimple_assign_rhs_code(stmt);
113550 +
113551 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113552 + continue;
113553 +
113554 + lhs = gimple_get_lhs(stmt);
113555 + lhs_type = TREE_TYPE(lhs);
113556 + rhs1 = gimple_assign_rhs1(stmt);
113557 + rhs_type = TREE_TYPE(rhs1);
113558 +
113559 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113560 + TREE_CODE(lhs_type) != POINTER_TYPE)
113561 + continue;
113562 +
113563 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113564 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113565 +
113566 + if (ptr_rhs_type == void_type_node)
113567 + continue;
113568 +
113569 + if (ptr_lhs_type == void_type_node)
113570 + continue;
113571 +
113572 + if (dominated_by_is_err(rhs1, bb))
113573 + continue;
113574 +
113575 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113576 +#ifndef __DEBUG_PLUGIN
113577 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113578 +#endif
113579 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113580 + continue;
113581 + }
113582 +
113583 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113584 + continue;
113585 +
113586 + if (rhs_code == ADDR_EXPR) {
113587 + op0 = TREE_OPERAND(rhs1, 0);
113588 +
113589 + if (op0 == NULL_TREE)
113590 + continue;
113591 +
113592 + if (TREE_CODE(op0) != VAR_DECL)
113593 + continue;
113594 +
113595 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113596 + if (op0_type == ptr_lhs_type)
113597 + continue;
113598 +
113599 +#ifndef __DEBUG_PLUGIN
113600 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113601 +#endif
113602 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113603 + } else {
113604 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113605 + /* skip bogus type casts introduced by container_of */
113606 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113607 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113608 + continue;
113609 +#ifndef __DEBUG_PLUGIN
113610 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113611 +#endif
113612 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113613 + }
113614 +
113615 + }
113616 + }
113617 + return 0;
113618 +}
113619 +
113620 +#if BUILDING_GCC_VERSION >= 4009
113621 +static const struct pass_data randomize_layout_bad_cast_data = {
113622 +#else
113623 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113624 + .pass = {
113625 +#endif
113626 + .type = GIMPLE_PASS,
113627 + .name = "randomize_layout_bad_cast",
113628 +#if BUILDING_GCC_VERSION >= 4008
113629 + .optinfo_flags = OPTGROUP_NONE,
113630 +#endif
113631 +#if BUILDING_GCC_VERSION >= 4009
113632 + .has_gate = false,
113633 + .has_execute = true,
113634 +#else
113635 + .gate = NULL,
113636 + .execute = find_bad_casts,
113637 + .sub = NULL,
113638 + .next = NULL,
113639 + .static_pass_number = 0,
113640 +#endif
113641 + .tv_id = TV_NONE,
113642 + .properties_required = PROP_cfg,
113643 + .properties_provided = 0,
113644 + .properties_destroyed = 0,
113645 + .todo_flags_start = 0,
113646 + .todo_flags_finish = TODO_dump_func
113647 +#if BUILDING_GCC_VERSION < 4009
113648 + }
113649 +#endif
113650 +};
113651 +
113652 +#if BUILDING_GCC_VERSION >= 4009
113653 +namespace {
113654 +class randomize_layout_bad_cast : public gimple_opt_pass {
113655 +public:
113656 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113657 + unsigned int execute() { return find_bad_casts(); }
113658 +};
113659 +}
113660 +#endif
113661 +
113662 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113663 +{
113664 +#if BUILDING_GCC_VERSION >= 4009
113665 + return new randomize_layout_bad_cast();
113666 +#else
113667 + return &randomize_layout_bad_cast.pass;
113668 +#endif
113669 +}
113670 +
113671 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113672 +{
113673 + int i;
113674 + const char * const plugin_name = plugin_info->base_name;
113675 + const int argc = plugin_info->argc;
113676 + const struct plugin_argument * const argv = plugin_info->argv;
113677 + bool enable = true;
113678 + int obtained_seed = 0;
113679 + struct register_pass_info randomize_layout_bad_cast_info;
113680 +
113681 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113682 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113683 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113684 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113685 +
113686 + if (!plugin_default_version_check(version, &gcc_version)) {
113687 + error(G_("incompatible gcc/plugin versions"));
113688 + return 1;
113689 + }
113690 +
113691 + if (strcmp(lang_hooks.name, "GNU C")) {
113692 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113693 + enable = false;
113694 + }
113695 +
113696 + for (i = 0; i < argc; ++i) {
113697 + if (!strcmp(argv[i].key, "disable")) {
113698 + enable = false;
113699 + continue;
113700 + }
113701 + if (!strcmp(argv[i].key, "performance-mode")) {
113702 + performance_mode = 1;
113703 + continue;
113704 + }
113705 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113706 + }
113707 +
113708 + if (strlen(randstruct_seed) != 64) {
113709 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
113710 + return 1;
113711 + }
113712 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
113713 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
113714 + if (obtained_seed != 4) {
113715 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
113716 + return 1;
113717 + }
113718 +
113719 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
113720 + if (enable) {
113721 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
113722 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
113723 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
113724 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
113725 + }
113726 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113727 +
113728 + return 0;
113729 +}
113730 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
113731 new file mode 100644
113732 index 0000000..1f0214f
113733 --- /dev/null
113734 +++ b/tools/gcc/size_overflow_plugin/.gitignore
113735 @@ -0,0 +1,3 @@
113736 +randomize_layout_seed.h
113737 +size_overflow_hash.h
113738 +size_overflow_hash_aux.h
113739 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
113740 new file mode 100644
113741 index 0000000..1ae2ed5
113742 --- /dev/null
113743 +++ b/tools/gcc/size_overflow_plugin/Makefile
113744 @@ -0,0 +1,20 @@
113745 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
113746 +always := $($(HOSTLIBS)-y)
113747 +
113748 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
113749 +
113750 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
113751 +
113752 +quiet_cmd_build_size_overflow_hash = GENHASH $@
113753 + cmd_build_size_overflow_hash = \
113754 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
113755 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
113756 + $(call if_changed,build_size_overflow_hash)
113757 +
113758 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
113759 + cmd_build_size_overflow_hash_aux = \
113760 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
113761 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
113762 + $(call if_changed,build_size_overflow_hash_aux)
113763 +
113764 +targets += size_overflow_hash.h size_overflow_hash_aux.h
113765 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113766 new file mode 100644
113767 index 0000000..12b1e3b
113768 --- /dev/null
113769 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113770 @@ -0,0 +1,102 @@
113771 +#!/bin/bash
113772 +
113773 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
113774 +
113775 +header1="size_overflow_hash.h"
113776 +database="size_overflow_hash.data"
113777 +n=65536
113778 +hashtable_name="size_overflow_hash"
113779 +
113780 +usage() {
113781 +cat <<EOF
113782 +usage: $0 options
113783 +OPTIONS:
113784 + -h|--help help
113785 + -o header file
113786 + -d database file
113787 + -n hash array size
113788 + -s name of the hash table
113789 +EOF
113790 + return 0
113791 +}
113792 +
113793 +while true
113794 +do
113795 + case "$1" in
113796 + -h|--help) usage && exit 0;;
113797 + -n) n=$2; shift 2;;
113798 + -o) header1="$2"; shift 2;;
113799 + -d) database="$2"; shift 2;;
113800 + -s) hashtable_name="$2"; shift 2;;
113801 + --) shift 1; break ;;
113802 + *) break ;;
113803 + esac
113804 +done
113805 +
113806 +create_defines() {
113807 + for i in `seq 0 31`
113808 + do
113809 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
113810 + done
113811 + echo >> "$header1"
113812 +}
113813 +
113814 +create_structs() {
113815 + rm -f "$header1"
113816 +
113817 + create_defines
113818 +
113819 + cat "$database" | while read data
113820 + do
113821 + data_array=($data)
113822 + struct_hash_name="${data_array[0]}"
113823 + funcn="${data_array[1]}"
113824 + params="${data_array[2]}"
113825 + next="${data_array[4]}"
113826 +
113827 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
113828 +
113829 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
113830 + echo -en "\t.param\t= " >> "$header1"
113831 + line=
113832 + for param_num in ${params//-/ };
113833 + do
113834 + line="${line}PARAM"$param_num"|"
113835 + done
113836 +
113837 + echo -e "${line%?},\n};\n" >> "$header1"
113838 + done
113839 +}
113840 +
113841 +create_headers() {
113842 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
113843 +}
113844 +
113845 +create_array_elements() {
113846 + index=0
113847 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
113848 + do
113849 + data_array=($data)
113850 + i="${data_array[3]}"
113851 + hash="${data_array[0]}"
113852 + while [[ $index -lt $i ]]
113853 + do
113854 + echo -e "\t["$index"]\t= NULL," >> "$header1"
113855 + index=$(($index + 1))
113856 + done
113857 + index=$(($index + 1))
113858 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
113859 + done
113860 + echo '};' >> $header1
113861 +}
113862 +
113863 +size_overflow_plugin_dir=`dirname $header1`
113864 +if [ "$size_overflow_plugin_dir" != '.' ]; then
113865 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
113866 +fi
113867 +
113868 +create_structs
113869 +create_headers
113870 +create_array_elements
113871 +
113872 +exit 0
113873 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113874 new file mode 100644
113875 index 0000000..c43901f
113876 --- /dev/null
113877 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113878 @@ -0,0 +1,748 @@
113879 +/*
113880 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113881 + * Licensed under the GPL v2, or (at your option) v3
113882 + *
113883 + * Homepage:
113884 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113885 + *
113886 + * Documentation:
113887 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113888 + *
113889 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113890 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113891 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113892 + *
113893 + * Usage:
113894 + * $ make
113895 + * $ make run
113896 + */
113897 +
113898 +#include "gcc-common.h"
113899 +#include "size_overflow.h"
113900 +
113901 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
113902 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
113903 +
113904 +// data for the size_overflow asm stmt
113905 +struct asm_data {
113906 + gimple def_stmt;
113907 + tree input;
113908 + tree output;
113909 +};
113910 +
113911 +#if BUILDING_GCC_VERSION <= 4007
113912 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
113913 +#else
113914 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
113915 +#endif
113916 +{
113917 + tree list;
113918 +#if BUILDING_GCC_VERSION <= 4007
113919 + VEC(tree, gc) *vec_list = NULL;
113920 +#else
113921 + vec<tree, va_gc> *vec_list = NULL;
113922 +#endif
113923 +
113924 + list = build_tree_list(NULL_TREE, string);
113925 + list = chainon(NULL_TREE, build_tree_list(list, io));
113926 +#if BUILDING_GCC_VERSION <= 4007
113927 + VEC_safe_push(tree, gc, vec_list, list);
113928 +#else
113929 + vec_safe_push(vec_list, list);
113930 +#endif
113931 + return vec_list;
113932 +}
113933 +
113934 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
113935 +{
113936 + gimple asm_stmt;
113937 + gimple_stmt_iterator gsi;
113938 +#if BUILDING_GCC_VERSION <= 4007
113939 + VEC(tree, gc) *input, *output = NULL;
113940 +#else
113941 + vec<tree, va_gc> *input, *output = NULL;
113942 +#endif
113943 +
113944 + input = create_asm_io_list(str_input, asm_data->input);
113945 +
113946 + if (asm_data->output)
113947 + output = create_asm_io_list(str_output, asm_data->output);
113948 +
113949 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
113950 + gsi = gsi_for_stmt(asm_data->def_stmt);
113951 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
113952 +
113953 + if (asm_data->output)
113954 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
113955 +}
113956 +
113957 +static void replace_call_lhs(const struct asm_data *asm_data)
113958 +{
113959 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
113960 + update_stmt(asm_data->def_stmt);
113961 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
113962 +}
113963 +
113964 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
113965 +{
113966 + enum mark cur_fndecl_attr;
113967 + gimple phi = get_def_stmt(result);
113968 + unsigned int i, n = gimple_phi_num_args(phi);
113969 +
113970 + pointer_set_insert(visited, phi);
113971 + for (i = 0; i < n; i++) {
113972 + tree arg = gimple_phi_arg_def(phi, i);
113973 +
113974 + cur_fndecl_attr = search_intentional(visited, arg);
113975 + if (cur_fndecl_attr != MARK_NO)
113976 + return cur_fndecl_attr;
113977 + }
113978 + return MARK_NO;
113979 +}
113980 +
113981 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
113982 +{
113983 + enum mark cur_fndecl_attr;
113984 + const_tree rhs1, rhs2;
113985 + gimple def_stmt = get_def_stmt(lhs);
113986 +
113987 + rhs1 = gimple_assign_rhs1(def_stmt);
113988 + rhs2 = gimple_assign_rhs2(def_stmt);
113989 +
113990 + cur_fndecl_attr = search_intentional(visited, rhs1);
113991 + if (cur_fndecl_attr != MARK_NO)
113992 + return cur_fndecl_attr;
113993 + return search_intentional(visited, rhs2);
113994 +}
113995 +
113996 +// Look up the intentional_overflow attribute on the caller and the callee functions.
113997 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
113998 +{
113999 + const_gimple def_stmt;
114000 +
114001 + if (TREE_CODE(lhs) != SSA_NAME)
114002 + return get_intentional_attr_type(lhs);
114003 +
114004 + def_stmt = get_def_stmt(lhs);
114005 + if (!def_stmt)
114006 + return MARK_NO;
114007 +
114008 + if (pointer_set_contains(visited, def_stmt))
114009 + return MARK_NO;
114010 +
114011 + switch (gimple_code(def_stmt)) {
114012 + case GIMPLE_NOP:
114013 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114014 + case GIMPLE_ASM:
114015 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114016 + return MARK_TURN_OFF;
114017 + return MARK_NO;
114018 + case GIMPLE_CALL:
114019 + return MARK_NO;
114020 + case GIMPLE_PHI:
114021 + return search_intentional_phi(visited, lhs);
114022 + case GIMPLE_ASSIGN:
114023 + switch (gimple_num_ops(def_stmt)) {
114024 + case 2:
114025 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114026 + case 3:
114027 + return search_intentional_binary(visited, lhs);
114028 + }
114029 + case GIMPLE_RETURN:
114030 + return MARK_NO;
114031 + default:
114032 + debug_gimple_stmt((gimple)def_stmt);
114033 + error("%s: unknown gimple code", __func__);
114034 + gcc_unreachable();
114035 + }
114036 +}
114037 +
114038 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114039 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114040 +{
114041 + const_tree fndecl;
114042 + struct pointer_set_t *visited;
114043 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114044 +
114045 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114046 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114047 + decl_attr = MARK_NOT_INTENTIONAL;
114048 + else if (is_yes_intentional_attr(fndecl, argnum))
114049 + decl_attr = MARK_YES;
114050 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114051 + return MARK_TURN_OFF;
114052 + }
114053 +
114054 + visited = pointer_set_create();
114055 + cur_fndecl_attr = search_intentional(visited, arg);
114056 + pointer_set_destroy(visited);
114057 +
114058 + switch (cur_fndecl_attr) {
114059 + case MARK_NO:
114060 + case MARK_TURN_OFF:
114061 + return cur_fndecl_attr;
114062 + default:
114063 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114064 + return MARK_YES;
114065 + }
114066 +}
114067 +
114068 +static void check_missing_size_overflow_attribute(tree var)
114069 +{
114070 + tree orig_fndecl;
114071 + unsigned int num;
114072 +
114073 + if (is_a_return_check(var))
114074 + orig_fndecl = DECL_ORIGIN(var);
114075 + else
114076 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114077 +
114078 + num = get_function_num(var, orig_fndecl);
114079 + if (num == CANNOT_FIND_ARG)
114080 + return;
114081 +
114082 + is_missing_function(orig_fndecl, num);
114083 +}
114084 +
114085 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114086 +{
114087 + gimple phi = get_def_stmt(result);
114088 + unsigned int i, n = gimple_phi_num_args(phi);
114089 +
114090 + pointer_set_insert(visited, phi);
114091 + for (i = 0; i < n; i++) {
114092 + tree arg = gimple_phi_arg_def(phi, i);
114093 +
114094 + search_size_overflow_attribute(visited, arg);
114095 + }
114096 +}
114097 +
114098 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114099 +{
114100 + const_gimple def_stmt = get_def_stmt(lhs);
114101 + tree rhs1, rhs2;
114102 +
114103 + rhs1 = gimple_assign_rhs1(def_stmt);
114104 + rhs2 = gimple_assign_rhs2(def_stmt);
114105 +
114106 + search_size_overflow_attribute(visited, rhs1);
114107 + search_size_overflow_attribute(visited, rhs2);
114108 +}
114109 +
114110 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114111 +{
114112 + const_gimple def_stmt;
114113 +
114114 + if (TREE_CODE(lhs) == PARM_DECL) {
114115 + check_missing_size_overflow_attribute(lhs);
114116 + return;
114117 + }
114118 +
114119 + def_stmt = get_def_stmt(lhs);
114120 + if (!def_stmt)
114121 + return;
114122 +
114123 + if (pointer_set_insert(visited, def_stmt))
114124 + return;
114125 +
114126 + switch (gimple_code(def_stmt)) {
114127 + case GIMPLE_NOP:
114128 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114129 + case GIMPLE_ASM:
114130 + return;
114131 + case GIMPLE_CALL: {
114132 + tree fndecl = gimple_call_fndecl(def_stmt);
114133 +
114134 + if (fndecl == NULL_TREE)
114135 + return;
114136 + check_missing_size_overflow_attribute(fndecl);
114137 + return;
114138 + }
114139 + case GIMPLE_PHI:
114140 + return search_size_overflow_attribute_phi(visited, lhs);
114141 + case GIMPLE_ASSIGN:
114142 + switch (gimple_num_ops(def_stmt)) {
114143 + case 2:
114144 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114145 + case 3:
114146 + return search_size_overflow_attribute_binary(visited, lhs);
114147 + }
114148 + default:
114149 + debug_gimple_stmt((gimple)def_stmt);
114150 + error("%s: unknown gimple code", __func__);
114151 + gcc_unreachable();
114152 + }
114153 +}
114154 +
114155 +// Search missing entries in the hash table (invoked from the gimple pass)
114156 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114157 +{
114158 + tree fndecl = NULL_TREE;
114159 + tree lhs;
114160 + struct pointer_set_t *visited;
114161 +
114162 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114163 + return;
114164 +
114165 + if (num == 0) {
114166 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114167 + lhs = gimple_return_retval(stmt);
114168 + } else {
114169 + gcc_assert(is_gimple_call(stmt));
114170 + lhs = gimple_call_arg(stmt, num - 1);
114171 + fndecl = gimple_call_fndecl(stmt);
114172 + }
114173 +
114174 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114175 + return;
114176 +
114177 + visited = pointer_set_create();
114178 + search_size_overflow_attribute(visited, lhs);
114179 + pointer_set_destroy(visited);
114180 +}
114181 +
114182 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114183 +{
114184 + gimple_stmt_iterator gsi;
114185 + gimple assign;
114186 +
114187 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114188 + gsi = gsi_for_stmt(stmt);
114189 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114190 + asm_data->def_stmt = assign;
114191 +
114192 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114193 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114194 + if (gimple_code(stmt) == GIMPLE_RETURN)
114195 + gimple_return_set_retval(stmt, asm_data->output);
114196 + else
114197 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114198 + update_stmt(stmt);
114199 +}
114200 +
114201 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114202 +{
114203 + const char *fn_name;
114204 + char *asm_comment;
114205 + unsigned int len;
114206 +
114207 + if (argnum == 0)
114208 + fn_name = DECL_NAME_POINTER(current_function_decl);
114209 + else
114210 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114211 +
114212 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114213 + gcc_assert(len > 0);
114214 +
114215 + return asm_comment;
114216 +}
114217 +
114218 +static const char *convert_mark_to_str(enum mark mark)
114219 +{
114220 + switch (mark) {
114221 + case MARK_NO:
114222 + return OK_ASM_STR;
114223 + case MARK_YES:
114224 + case MARK_NOT_INTENTIONAL:
114225 + return YES_ASM_STR;
114226 + case MARK_TURN_OFF:
114227 + return TURN_OFF_ASM_STR;
114228 + }
114229 +
114230 + gcc_unreachable();
114231 +}
114232 +
114233 +/* Create the input of the size_overflow asm stmt.
114234 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114235 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114236 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114237 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114238 + */
114239 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114240 +{
114241 + if (!asm_data->def_stmt) {
114242 + asm_data->input = NULL_TREE;
114243 + return;
114244 + }
114245 +
114246 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114247 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114248 +
114249 + switch (gimple_code(asm_data->def_stmt)) {
114250 + case GIMPLE_ASSIGN:
114251 + case GIMPLE_CALL:
114252 + replace_call_lhs(asm_data);
114253 + break;
114254 + case GIMPLE_PHI:
114255 + create_output_from_phi(stmt, argnum, asm_data);
114256 + break;
114257 + case GIMPLE_NOP: {
114258 + enum mark mark;
114259 + const char *mark_str;
114260 + char *asm_comment;
114261 +
114262 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114263 +
114264 + asm_data->input = asm_data->output;
114265 + asm_data->output = NULL;
114266 + asm_data->def_stmt = stmt;
114267 +
114268 + mark_str = convert_mark_to_str(mark);
114269 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114270 +
114271 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114272 + free(asm_comment);
114273 + asm_data->input = NULL_TREE;
114274 + break;
114275 + }
114276 + case GIMPLE_ASM:
114277 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114278 + asm_data->input = NULL_TREE;
114279 + break;
114280 + }
114281 + default:
114282 + debug_gimple_stmt(asm_data->def_stmt);
114283 + gcc_unreachable();
114284 + }
114285 +}
114286 +
114287 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114288 + * is of the right kind create the appropriate size_overflow asm stmts:
114289 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114290 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114291 + */
114292 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114293 +{
114294 + struct asm_data asm_data;
114295 + const char *mark_str;
114296 + char *asm_comment;
114297 + enum mark mark;
114298 +
114299 + if (is_gimple_constant(output_node))
114300 + return;
114301 +
114302 + asm_data.output = output_node;
114303 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114304 + if (mark != MARK_TURN_OFF)
114305 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114306 +
114307 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114308 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114309 + return;
114310 +
114311 + create_asm_input(stmt, argnum, &asm_data);
114312 + if (asm_data.input == NULL_TREE)
114313 + return;
114314 +
114315 + mark_str = convert_mark_to_str(mark);
114316 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114317 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114318 + free(asm_comment);
114319 +}
114320 +
114321 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114322 +static bool create_mark_asm(gimple stmt, enum mark mark)
114323 +{
114324 + struct asm_data asm_data;
114325 + const char *asm_str;
114326 +
114327 + switch (mark) {
114328 + case MARK_TURN_OFF:
114329 + asm_str = TURN_OFF_ASM_STR;
114330 + break;
114331 + case MARK_NOT_INTENTIONAL:
114332 + case MARK_YES:
114333 + asm_str = YES_ASM_STR;
114334 + break;
114335 + default:
114336 + gcc_unreachable();
114337 + }
114338 +
114339 + asm_data.def_stmt = stmt;
114340 + asm_data.output = gimple_call_lhs(stmt);
114341 +
114342 + if (asm_data.output == NULL_TREE) {
114343 + asm_data.input = gimple_call_arg(stmt, 0);
114344 + if (is_gimple_constant(asm_data.input))
114345 + return false;
114346 + asm_data.output = NULL;
114347 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114348 + return true;
114349 + }
114350 +
114351 + create_asm_input(stmt, 0, &asm_data);
114352 + gcc_assert(asm_data.input != NULL_TREE);
114353 +
114354 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114355 + return true;
114356 +}
114357 +
114358 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114359 +{
114360 + gimple def_stmt;
114361 +
114362 + def_stmt = get_def_stmt(lhs);
114363 + if (!def_stmt)
114364 + return;
114365 +
114366 + if (pointer_set_insert(visited, def_stmt))
114367 + return;
114368 +
114369 + switch (gimple_code(def_stmt)) {
114370 + case GIMPLE_NOP:
114371 + case GIMPLE_ASM:
114372 + case GIMPLE_CALL:
114373 + break;
114374 + case GIMPLE_PHI: {
114375 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114376 +
114377 + pointer_set_insert(visited, def_stmt);
114378 +
114379 + for (i = 0; i < n; i++) {
114380 + tree arg = gimple_phi_arg_def(def_stmt, i);
114381 +
114382 + walk_use_def_ptr(visited, arg);
114383 + }
114384 + }
114385 + case GIMPLE_ASSIGN:
114386 + switch (gimple_num_ops(def_stmt)) {
114387 + case 2:
114388 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114389 + return;
114390 + case 3:
114391 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114392 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114393 + return;
114394 + default:
114395 + return;
114396 + }
114397 + default:
114398 + debug_gimple_stmt((gimple)def_stmt);
114399 + error("%s: unknown gimple code", __func__);
114400 + gcc_unreachable();
114401 + }
114402 +}
114403 +
114404 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114405 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114406 +{
114407 + struct pointer_set_t *visited;
114408 +
114409 + visited = pointer_set_create();
114410 + walk_use_def_ptr(visited, arg);
114411 + pointer_set_destroy(visited);
114412 +}
114413 +
114414 +// Determine the return value and insert the asm stmt to mark the return stmt.
114415 +static void insert_asm_ret(gimple stmt)
114416 +{
114417 + tree ret;
114418 +
114419 + ret = gimple_return_retval(stmt);
114420 + create_size_overflow_asm(stmt, ret, 0);
114421 +}
114422 +
114423 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114424 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114425 +{
114426 + tree arg;
114427 + unsigned int argnum;
114428 +
114429 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114430 + gcc_assert(argnum != 0);
114431 + if (argnum == CANNOT_FIND_ARG)
114432 + return;
114433 +
114434 + arg = gimple_call_arg(stmt, argnum - 1);
114435 + gcc_assert(arg != NULL_TREE);
114436 +
114437 + // skip all ptr - ptr expressions
114438 + insert_mark_not_intentional_asm_at_ptr(arg);
114439 +
114440 + create_size_overflow_asm(stmt, arg, argnum);
114441 +}
114442 +
114443 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114444 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114445 +{
114446 + unsigned int argnum;
114447 + tree attr_value;
114448 +
114449 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114450 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114451 + argnums[argnum] = true;
114452 + }
114453 +}
114454 +
114455 +// If a function arg or the return value is in the hash table then set its index in the array.
114456 +static void set_argnum_hash(tree fndecl, bool *argnums)
114457 +{
114458 + unsigned int num;
114459 + const struct size_overflow_hash *hash;
114460 +
114461 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114462 + if (!hash)
114463 + return;
114464 +
114465 + for (num = 0; num <= MAX_PARAM; num++) {
114466 + if (!(hash->param & (1U << num)))
114467 + continue;
114468 +
114469 + argnums[num] = true;
114470 + }
114471 +}
114472 +
114473 +static bool is_all_the_argnums_empty(bool *argnums)
114474 +{
114475 + unsigned int i;
114476 +
114477 + for (i = 0; i <= MAX_PARAM; i++)
114478 + if (argnums[i])
114479 + return false;
114480 + return true;
114481 +}
114482 +
114483 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114484 +static void search_interesting_args(tree fndecl, bool *argnums)
114485 +{
114486 + const_tree attr;
114487 +
114488 + set_argnum_hash(fndecl, argnums);
114489 + if (!is_all_the_argnums_empty(argnums))
114490 + return;
114491 +
114492 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114493 + if (attr && TREE_VALUE(attr))
114494 + set_argnum_attribute(attr, argnums);
114495 +}
114496 +
114497 +/*
114498 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114499 + * on the callee function.
114500 + */
114501 +static bool is_mark_turn_off_attribute(gimple stmt)
114502 +{
114503 + enum mark mark;
114504 + const_tree fndecl = gimple_call_fndecl(stmt);
114505 +
114506 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114507 + if (mark == MARK_TURN_OFF)
114508 + return true;
114509 + return false;
114510 +}
114511 +
114512 +// 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
114513 +static void handle_interesting_function(gimple stmt)
114514 +{
114515 + unsigned int argnum;
114516 + tree fndecl;
114517 + bool orig_argnums[MAX_PARAM + 1] = {false};
114518 +
114519 + if (gimple_call_num_args(stmt) == 0)
114520 + return;
114521 + fndecl = gimple_call_fndecl(stmt);
114522 + if (fndecl == NULL_TREE)
114523 + return;
114524 + fndecl = DECL_ORIGIN(fndecl);
114525 +
114526 + if (is_mark_turn_off_attribute(stmt)) {
114527 + create_mark_asm(stmt, MARK_TURN_OFF);
114528 + return;
114529 + }
114530 +
114531 + search_interesting_args(fndecl, orig_argnums);
114532 +
114533 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114534 + if (orig_argnums[argnum])
114535 + insert_asm_arg(stmt, argnum);
114536 +}
114537 +
114538 +// 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
114539 +static void handle_interesting_ret(gimple stmt)
114540 +{
114541 + bool orig_argnums[MAX_PARAM + 1] = {false};
114542 +
114543 + search_interesting_args(current_function_decl, orig_argnums);
114544 +
114545 + if (orig_argnums[0])
114546 + insert_asm_ret(stmt);
114547 +}
114548 +
114549 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114550 +static unsigned int search_interesting_functions(void)
114551 +{
114552 + basic_block bb;
114553 +
114554 + FOR_ALL_BB_FN(bb, cfun) {
114555 + gimple_stmt_iterator gsi;
114556 +
114557 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114558 + gimple stmt = gsi_stmt(gsi);
114559 +
114560 + if (is_size_overflow_asm(stmt))
114561 + continue;
114562 +
114563 + if (is_gimple_call(stmt))
114564 + handle_interesting_function(stmt);
114565 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114566 + handle_interesting_ret(stmt);
114567 + }
114568 + }
114569 + return 0;
114570 +}
114571 +
114572 +/*
114573 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114574 + * this pass inserts asm stmts to mark the interesting args
114575 + * that the ipa pass will detect and insert the size overflow checks for.
114576 + */
114577 +#if BUILDING_GCC_VERSION >= 4009
114578 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114579 +#else
114580 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114581 + .pass = {
114582 +#endif
114583 + .type = GIMPLE_PASS,
114584 + .name = "insert_size_overflow_asm",
114585 +#if BUILDING_GCC_VERSION >= 4008
114586 + .optinfo_flags = OPTGROUP_NONE,
114587 +#endif
114588 +#if BUILDING_GCC_VERSION >= 4009
114589 + .has_gate = false,
114590 + .has_execute = true,
114591 +#else
114592 + .gate = NULL,
114593 + .execute = search_interesting_functions,
114594 + .sub = NULL,
114595 + .next = NULL,
114596 + .static_pass_number = 0,
114597 +#endif
114598 + .tv_id = TV_NONE,
114599 + .properties_required = PROP_cfg,
114600 + .properties_provided = 0,
114601 + .properties_destroyed = 0,
114602 + .todo_flags_start = 0,
114603 + .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
114604 +#if BUILDING_GCC_VERSION < 4009
114605 + }
114606 +#endif
114607 +};
114608 +
114609 +#if BUILDING_GCC_VERSION >= 4009
114610 +namespace {
114611 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114612 +public:
114613 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114614 + unsigned int execute() { return search_interesting_functions(); }
114615 +};
114616 +}
114617 +#endif
114618 +
114619 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114620 +{
114621 +#if BUILDING_GCC_VERSION >= 4009
114622 + return new insert_size_overflow_asm_pass();
114623 +#else
114624 + return &insert_size_overflow_asm_pass.pass;
114625 +#endif
114626 +}
114627 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
114628 new file mode 100644
114629 index 0000000..73f0a12
114630 --- /dev/null
114631 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114632 @@ -0,0 +1,943 @@
114633 +/*
114634 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114635 + * Licensed under the GPL v2, or (at your option) v3
114636 + *
114637 + * Homepage:
114638 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114639 + *
114640 + * Documentation:
114641 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114642 + *
114643 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114644 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114645 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114646 + *
114647 + * Usage:
114648 + * $ make
114649 + * $ make run
114650 + */
114651 +
114652 +#include "gcc-common.h"
114653 +#include "size_overflow.h"
114654 +
114655 +#define MIN_CHECK true
114656 +#define MAX_CHECK false
114657 +
114658 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114659 +{
114660 + const_tree type;
114661 + tree new_type;
114662 +
114663 + gcc_assert(node != NULL_TREE);
114664 +
114665 + type = TREE_TYPE(node);
114666 +
114667 + if (pointer_set_contains(visited->my_stmts, stmt))
114668 + return TREE_TYPE(node);
114669 +
114670 + switch (TYPE_MODE(type)) {
114671 + case QImode:
114672 + new_type = size_overflow_type_HI;
114673 + break;
114674 + case HImode:
114675 + new_type = size_overflow_type_SI;
114676 + break;
114677 + case SImode:
114678 + new_type = size_overflow_type_DI;
114679 + break;
114680 + case DImode:
114681 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114682 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114683 + else
114684 + new_type = size_overflow_type_TI;
114685 + break;
114686 + case TImode:
114687 + gcc_assert(!TYPE_UNSIGNED(type));
114688 + new_type = size_overflow_type_TI;
114689 + break;
114690 + default:
114691 + debug_tree((tree)node);
114692 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114693 + gcc_unreachable();
114694 + }
114695 +
114696 + if (TYPE_QUALS(type) != 0)
114697 + return build_qualified_type(new_type, TYPE_QUALS(type));
114698 + return new_type;
114699 +}
114700 +
114701 +static tree get_lhs(const_gimple stmt)
114702 +{
114703 + switch (gimple_code(stmt)) {
114704 + case GIMPLE_ASSIGN:
114705 + case GIMPLE_CALL:
114706 + return gimple_get_lhs(stmt);
114707 + case GIMPLE_PHI:
114708 + return gimple_phi_result(stmt);
114709 + default:
114710 + return NULL_TREE;
114711 + }
114712 +}
114713 +
114714 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
114715 +{
114716 + gimple_stmt_iterator gsi;
114717 + tree lhs;
114718 + gimple new_stmt;
114719 +
114720 + if (rhs == NULL_TREE)
114721 + return NULL_TREE;
114722 +
114723 + gsi = gsi_for_stmt(stmt);
114724 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114725 + pointer_set_insert(visited->my_stmts, new_stmt);
114726 +
114727 + lhs = get_lhs(new_stmt);
114728 + gcc_assert(lhs != NULL_TREE);
114729 + return lhs;
114730 +}
114731 +
114732 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
114733 +{
114734 + tree lhs, dst_type;
114735 + gimple_stmt_iterator gsi;
114736 +
114737 + if (rhs1 == NULL_TREE) {
114738 + debug_gimple_stmt(oldstmt);
114739 + error("%s: rhs1 is NULL_TREE", __func__);
114740 + gcc_unreachable();
114741 + }
114742 +
114743 + switch (gimple_code(oldstmt)) {
114744 + case GIMPLE_ASM:
114745 + lhs = rhs1;
114746 + break;
114747 + case GIMPLE_CALL:
114748 + case GIMPLE_ASSIGN:
114749 + lhs = gimple_get_lhs(oldstmt);
114750 + break;
114751 + default:
114752 + debug_gimple_stmt(oldstmt);
114753 + gcc_unreachable();
114754 + }
114755 +
114756 + gsi = gsi_for_stmt(oldstmt);
114757 + pointer_set_insert(visited->stmts, oldstmt);
114758 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114759 + basic_block next_bb, cur_bb;
114760 + const_edge e;
114761 +
114762 + gcc_assert(before == false);
114763 + gcc_assert(stmt_can_throw_internal(oldstmt));
114764 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114765 + gcc_assert(!gsi_end_p(gsi));
114766 +
114767 + cur_bb = gimple_bb(oldstmt);
114768 + next_bb = cur_bb->next_bb;
114769 + e = find_edge(cur_bb, next_bb);
114770 + gcc_assert(e != NULL);
114771 + gcc_assert(e->flags & EDGE_FALLTHRU);
114772 +
114773 + gsi = gsi_after_labels(next_bb);
114774 + gcc_assert(!gsi_end_p(gsi));
114775 +
114776 + before = true;
114777 + oldstmt = gsi_stmt(gsi);
114778 + }
114779 +
114780 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
114781 +
114782 + if (is_gimple_constant(rhs1))
114783 + return cast_a_tree(dst_type, rhs1);
114784 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
114785 +}
114786 +
114787 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114788 +{
114789 + gimple stmt;
114790 + gimple_stmt_iterator gsi;
114791 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114792 +
114793 + if (pointer_set_contains(visited->my_stmts, oldstmt))
114794 + return lhs;
114795 +
114796 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114797 + rhs1 = gimple_assign_rhs1(oldstmt);
114798 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114799 + }
114800 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114801 + rhs2 = gimple_assign_rhs2(oldstmt);
114802 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114803 + }
114804 +
114805 + stmt = gimple_copy(oldstmt);
114806 + gimple_set_location(stmt, gimple_location(oldstmt));
114807 + pointer_set_insert(visited->my_stmts, stmt);
114808 +
114809 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
114810 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
114811 +
114812 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
114813 +
114814 + new_var = create_new_var(size_overflow_type);
114815 + new_var = make_ssa_name(new_var, stmt);
114816 + gimple_assign_set_lhs(stmt, new_var);
114817 +
114818 + if (rhs1 != NULL_TREE)
114819 + gimple_assign_set_rhs1(stmt, rhs1);
114820 +
114821 + if (rhs2 != NULL_TREE)
114822 + gimple_assign_set_rhs2(stmt, rhs2);
114823 +#if BUILDING_GCC_VERSION >= 4006
114824 + if (rhs3 != NULL_TREE)
114825 + gimple_assign_set_rhs3(stmt, rhs3);
114826 +#endif
114827 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
114828 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
114829 +
114830 + gsi = gsi_for_stmt(oldstmt);
114831 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
114832 + update_stmt(stmt);
114833 + pointer_set_insert(visited->stmts, oldstmt);
114834 + return gimple_assign_lhs(stmt);
114835 +}
114836 +
114837 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
114838 +{
114839 + gimple assign;
114840 + gimple_stmt_iterator gsi;
114841 + basic_block first_bb;
114842 +
114843 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
114844 +
114845 + if (bb->index == 0) {
114846 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
114847 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114848 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
114849 + bb = first_bb;
114850 + }
114851 +
114852 + gsi = gsi_after_labels(bb);
114853 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
114854 + pointer_set_insert(visited->my_stmts, assign);
114855 +
114856 + return gimple_assign_lhs(assign);
114857 +}
114858 +
114859 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
114860 +{
114861 + gimple_stmt_iterator gsi;
114862 + gimple assign, def_stmt = get_def_stmt(new_arg);
114863 +
114864 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114865 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114866 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114867 + } else {
114868 + gsi = gsi_for_stmt(def_stmt);
114869 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114870 + }
114871 +
114872 + pointer_set_insert(visited->my_stmts, assign);
114873 + return gimple_assign_lhs(assign);
114874 +}
114875 +
114876 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
114877 +{
114878 + basic_block bb;
114879 + gimple_stmt_iterator gsi;
114880 + const_gimple def_stmt;
114881 + gimple assign;
114882 +
114883 + def_stmt = get_def_stmt(arg);
114884 + bb = gimple_bb(def_stmt);
114885 + gcc_assert(bb->index != 0);
114886 + gsi = gsi_after_labels(bb);
114887 +
114888 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114889 + pointer_set_insert(visited->my_stmts, assign);
114890 + return gimple_assign_lhs(assign);
114891 +}
114892 +
114893 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114894 +{
114895 + tree size_overflow_type;
114896 + tree arg;
114897 + const_gimple def_stmt;
114898 +
114899 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114900 + return new_arg;
114901 +
114902 + arg = gimple_phi_arg_def(oldstmt, i);
114903 + def_stmt = get_def_stmt(arg);
114904 + gcc_assert(def_stmt != NULL);
114905 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114906 +
114907 + switch (gimple_code(def_stmt)) {
114908 + case GIMPLE_PHI:
114909 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
114910 + case GIMPLE_NOP: {
114911 + basic_block bb;
114912 +
114913 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114914 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
114915 + }
114916 + case GIMPLE_ASM: {
114917 + gimple_stmt_iterator gsi;
114918 + gimple assign, stmt = get_def_stmt(arg);
114919 +
114920 + gsi = gsi_for_stmt(stmt);
114921 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114922 + pointer_set_insert(visited->my_stmts, assign);
114923 + return gimple_assign_lhs(assign);
114924 + }
114925 + default:
114926 + gcc_assert(new_arg != NULL_TREE);
114927 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114928 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
114929 + }
114930 +}
114931 +
114932 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
114933 +{
114934 + basic_block bb;
114935 + gimple phi;
114936 + gimple_seq seq;
114937 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114938 +
114939 + bb = gsi_bb(gsi);
114940 +
114941 + if (result == NULL_TREE) {
114942 + tree old_result = gimple_phi_result(oldstmt);
114943 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
114944 +
114945 + result = create_new_var(size_overflow_type);
114946 + }
114947 +
114948 + phi = create_phi_node(result, bb);
114949 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114950 + seq = phi_nodes(bb);
114951 + gsi = gsi_last(seq);
114952 + gsi_remove(&gsi, false);
114953 +
114954 + gsi = gsi_for_stmt(oldstmt);
114955 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114956 + gimple_set_bb(phi, bb);
114957 + return phi;
114958 +}
114959 +
114960 +#if BUILDING_GCC_VERSION <= 4007
114961 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114962 +#else
114963 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114964 +#endif
114965 +{
114966 + gimple new_phi;
114967 + unsigned int i;
114968 + tree arg, result;
114969 + location_t loc = gimple_location(oldstmt);
114970 +
114971 +#if BUILDING_GCC_VERSION <= 4007
114972 + gcc_assert(!VEC_empty(tree, *args));
114973 +#else
114974 + gcc_assert(!args->is_empty());
114975 +#endif
114976 +
114977 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
114978 + result = gimple_phi_result(new_phi);
114979 + ssa_name_var = SSA_NAME_VAR(result);
114980 +
114981 +#if BUILDING_GCC_VERSION <= 4007
114982 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114983 +#else
114984 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114985 +#endif
114986 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
114987 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114988 + }
114989 +
114990 +#if BUILDING_GCC_VERSION <= 4007
114991 + VEC_free(tree, heap, *args);
114992 +#else
114993 + vec_free(args);
114994 +#endif
114995 + update_stmt(new_phi);
114996 + pointer_set_insert(visited->my_stmts, new_phi);
114997 + return result;
114998 +}
114999 +
115000 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115001 +{
115002 + tree ssa_name_var = NULL_TREE;
115003 +#if BUILDING_GCC_VERSION <= 4007
115004 + VEC(tree, heap) *args = NULL;
115005 +#else
115006 + vec<tree, va_heap, vl_embed> *args = NULL;
115007 +#endif
115008 + gimple oldstmt = get_def_stmt(orig_result);
115009 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115010 +
115011 + pointer_set_insert(visited->stmts, oldstmt);
115012 + for (i = 0; i < len; i++) {
115013 + tree arg, new_arg;
115014 +
115015 + arg = gimple_phi_arg_def(oldstmt, i);
115016 + new_arg = expand(visited, caller_node, arg);
115017 +
115018 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115019 + ssa_name_var = SSA_NAME_VAR(new_arg);
115020 +
115021 + if (is_gimple_constant(arg)) {
115022 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115023 +
115024 + new_arg = cast_a_tree(size_overflow_type, arg);
115025 + }
115026 +
115027 +#if BUILDING_GCC_VERSION <= 4007
115028 + VEC_safe_push(tree, heap, args, new_arg);
115029 +#else
115030 + vec_safe_push(args, new_arg);
115031 +#endif
115032 + }
115033 +
115034 +#if BUILDING_GCC_VERSION <= 4007
115035 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115036 +#else
115037 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115038 +#endif
115039 +}
115040 +
115041 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115042 +{
115043 + tree rhs1 = gimple_assign_rhs1(stmt);
115044 + tree lhs = gimple_assign_lhs(stmt);
115045 + const_tree rhs1_type = TREE_TYPE(rhs1);
115046 + const_tree lhs_type = TREE_TYPE(lhs);
115047 +
115048 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115049 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115050 +
115051 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115052 +}
115053 +
115054 +static bool skip_lhs_cast_check(const_gimple stmt)
115055 +{
115056 + const_tree rhs = gimple_assign_rhs1(stmt);
115057 + const_gimple def_stmt = get_def_stmt(rhs);
115058 +
115059 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115060 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115061 + return true;
115062 +
115063 + if (is_const_plus_unsigned_signed_truncation(rhs))
115064 + return true;
115065 +
115066 + return false;
115067 +}
115068 +
115069 +static tree create_string_param(tree string)
115070 +{
115071 + tree i_type, a_type;
115072 + const int length = TREE_STRING_LENGTH(string);
115073 +
115074 + gcc_assert(length > 0);
115075 +
115076 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115077 + a_type = build_array_type(char_type_node, i_type);
115078 +
115079 + TREE_TYPE(string) = a_type;
115080 + TREE_CONSTANT(string) = 1;
115081 + TREE_READONLY(string) = 1;
115082 +
115083 + return build1(ADDR_EXPR, ptr_type_node, string);
115084 +}
115085 +
115086 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115087 +{
115088 + gimple cond_stmt;
115089 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115090 +
115091 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115092 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115093 + update_stmt(cond_stmt);
115094 +}
115095 +
115096 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115097 +{
115098 + gimple func_stmt;
115099 + const_gimple def_stmt;
115100 + const_tree loc_line;
115101 + tree loc_file, ssa_name, current_func;
115102 + expanded_location xloc;
115103 + char *ssa_name_buf;
115104 + int len;
115105 + struct cgraph_edge *edge;
115106 + struct cgraph_node *callee_node;
115107 + int frequency;
115108 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115109 +
115110 + def_stmt = get_def_stmt(arg);
115111 + xloc = expand_location(gimple_location(def_stmt));
115112 +
115113 + if (!gimple_has_location(def_stmt)) {
115114 + xloc = expand_location(gimple_location(stmt));
115115 + if (!gimple_has_location(stmt))
115116 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115117 + }
115118 +
115119 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115120 +
115121 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115122 + loc_file = create_string_param(loc_file);
115123 +
115124 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115125 + current_func = create_string_param(current_func);
115126 +
115127 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115128 + call_count++;
115129 + 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);
115130 + gcc_assert(len > 0);
115131 + ssa_name = build_string(len + 1, ssa_name_buf);
115132 + free(ssa_name_buf);
115133 + ssa_name = create_string_param(ssa_name);
115134 +
115135 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115136 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115137 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115138 +
115139 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115140 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115141 +
115142 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115143 + gcc_assert(edge != NULL);
115144 +}
115145 +
115146 +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)
115147 +{
115148 + basic_block cond_bb, join_bb, bb_true;
115149 + edge e;
115150 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115151 +
115152 + cond_bb = gimple_bb(stmt);
115153 + if (before)
115154 + gsi_prev(&gsi);
115155 + if (gsi_end_p(gsi))
115156 + e = split_block_after_labels(cond_bb);
115157 + else
115158 + e = split_block(cond_bb, gsi_stmt(gsi));
115159 + cond_bb = e->src;
115160 + join_bb = e->dest;
115161 + e->flags = EDGE_FALSE_VALUE;
115162 + e->probability = REG_BR_PROB_BASE;
115163 +
115164 + bb_true = create_empty_bb(cond_bb);
115165 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115166 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115167 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115168 +
115169 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115170 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115171 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115172 +
115173 + if (current_loops != NULL) {
115174 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115175 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115176 + }
115177 +
115178 + insert_cond(cond_bb, arg, cond_code, type_value);
115179 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115180 +
115181 +// print_the_code_insertions(stmt);
115182 +}
115183 +
115184 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115185 +{
115186 + const_tree rhs_type = TREE_TYPE(rhs);
115187 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115188 +
115189 + gcc_assert(rhs_type != NULL_TREE);
115190 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115191 + return;
115192 +
115193 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115194 +
115195 + if (is_const_plus_unsigned_signed_truncation(rhs))
115196 + return;
115197 +
115198 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115199 + // typemax (-1) < typemin (0)
115200 + if (TREE_OVERFLOW(type_max))
115201 + return;
115202 +
115203 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115204 +
115205 + cast_rhs_type = TREE_TYPE(cast_rhs);
115206 + type_max_type = TREE_TYPE(type_max);
115207 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115208 +
115209 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115210 +
115211 + // special case: get_size_overflow_type(), 32, u64->s
115212 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115213 + return;
115214 +
115215 + type_min_type = TREE_TYPE(type_min);
115216 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115217 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115218 +}
115219 +
115220 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115221 +{
115222 + bool cast_lhs, cast_rhs;
115223 + tree lhs = gimple_assign_lhs(stmt);
115224 + tree rhs = gimple_assign_rhs1(stmt);
115225 + const_tree lhs_type = TREE_TYPE(lhs);
115226 + const_tree rhs_type = TREE_TYPE(rhs);
115227 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115228 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115229 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115230 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115231 +
115232 + static bool check_lhs[3][4] = {
115233 + // ss su us uu
115234 + { false, true, true, false }, // lhs > rhs
115235 + { false, false, false, false }, // lhs = rhs
115236 + { true, true, true, true }, // lhs < rhs
115237 + };
115238 +
115239 + static bool check_rhs[3][4] = {
115240 + // ss su us uu
115241 + { true, false, true, true }, // lhs > rhs
115242 + { true, false, true, true }, // lhs = rhs
115243 + { true, false, true, true }, // lhs < rhs
115244 + };
115245 +
115246 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115247 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115248 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115249 +
115250 + if (lhs_size > rhs_size) {
115251 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115252 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115253 + } else if (lhs_size == rhs_size) {
115254 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115255 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115256 + } else {
115257 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115258 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115259 + }
115260 +
115261 + if (!cast_lhs && !cast_rhs)
115262 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115263 +
115264 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115265 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115266 +
115267 + if (cast_rhs)
115268 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115269 +
115270 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115271 +}
115272 +
115273 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115274 +{
115275 + enum tree_code rhs_code;
115276 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115277 +
115278 + if (pointer_set_contains(visited->my_stmts, stmt))
115279 + return lhs;
115280 +
115281 + rhs1 = gimple_assign_rhs1(stmt);
115282 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115283 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115284 +
115285 + new_rhs1 = expand(visited, caller_node, rhs1);
115286 +
115287 + if (new_rhs1 == NULL_TREE)
115288 + return create_cast_assign(visited, stmt);
115289 +
115290 + if (pointer_set_contains(visited->no_cast_check, stmt))
115291 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115292 +
115293 + rhs_code = gimple_assign_rhs_code(stmt);
115294 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115295 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115296 +
115297 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115298 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115299 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115300 + }
115301 +
115302 + if (!gimple_assign_cast_p(stmt))
115303 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115304 +
115305 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115306 +}
115307 +
115308 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115309 +{
115310 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115311 + gimple def_stmt = get_def_stmt(lhs);
115312 +
115313 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115314 + rhs1 = gimple_assign_rhs1(def_stmt);
115315 +
115316 + if (is_gimple_constant(rhs1))
115317 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115318 +
115319 + switch (TREE_CODE(rhs1)) {
115320 + case SSA_NAME: {
115321 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115322 +
115323 + if (gimple_assign_cast_p(stmt))
115324 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115325 + return ret;
115326 + }
115327 + case ARRAY_REF:
115328 + case BIT_FIELD_REF:
115329 + case ADDR_EXPR:
115330 + case COMPONENT_REF:
115331 + case INDIRECT_REF:
115332 +#if BUILDING_GCC_VERSION >= 4006
115333 + case MEM_REF:
115334 +#endif
115335 + case TARGET_MEM_REF:
115336 + case VIEW_CONVERT_EXPR:
115337 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115338 + case PARM_DECL:
115339 + case VAR_DECL:
115340 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115341 +
115342 + default:
115343 + debug_gimple_stmt(def_stmt);
115344 + debug_tree(rhs1);
115345 + gcc_unreachable();
115346 + }
115347 +}
115348 +
115349 +static void __unused print_the_code_insertions(const_gimple stmt)
115350 +{
115351 + location_t loc = gimple_location(stmt);
115352 +
115353 + inform(loc, "Integer size_overflow check applied here.");
115354 +}
115355 +
115356 +static bool is_from_cast(const_tree node)
115357 +{
115358 + gimple def_stmt = get_def_stmt(node);
115359 +
115360 + if (!def_stmt)
115361 + return false;
115362 +
115363 + if (gimple_assign_cast_p(def_stmt))
115364 + return true;
115365 +
115366 + return false;
115367 +}
115368 +
115369 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115370 +static bool is_a_ptr_minus(gimple stmt)
115371 +{
115372 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115373 +
115374 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115375 + return false;
115376 +
115377 + rhs1 = gimple_assign_rhs1(stmt);
115378 + if (!is_from_cast(rhs1))
115379 + return false;
115380 +
115381 + rhs2 = gimple_assign_rhs2(stmt);
115382 + if (!is_from_cast(rhs2))
115383 + return false;
115384 +
115385 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115386 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115387 +
115388 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115389 + return false;
115390 +
115391 + return true;
115392 +}
115393 +
115394 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115395 +{
115396 + enum intentional_overflow_type res;
115397 + tree rhs1, rhs2, new_lhs;
115398 + gimple def_stmt = get_def_stmt(lhs);
115399 + tree new_rhs1 = NULL_TREE;
115400 + tree new_rhs2 = NULL_TREE;
115401 +
115402 + if (is_a_ptr_minus(def_stmt))
115403 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115404 +
115405 + rhs1 = gimple_assign_rhs1(def_stmt);
115406 + rhs2 = gimple_assign_rhs2(def_stmt);
115407 +
115408 + /* no DImode/TImode division in the 32/64 bit kernel */
115409 + switch (gimple_assign_rhs_code(def_stmt)) {
115410 + case RDIV_EXPR:
115411 + case TRUNC_DIV_EXPR:
115412 + case CEIL_DIV_EXPR:
115413 + case FLOOR_DIV_EXPR:
115414 + case ROUND_DIV_EXPR:
115415 + case TRUNC_MOD_EXPR:
115416 + case CEIL_MOD_EXPR:
115417 + case FLOOR_MOD_EXPR:
115418 + case ROUND_MOD_EXPR:
115419 + case EXACT_DIV_EXPR:
115420 + case POINTER_PLUS_EXPR:
115421 + case BIT_AND_EXPR:
115422 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115423 + default:
115424 + break;
115425 + }
115426 +
115427 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115428 + if (new_lhs != NULL_TREE)
115429 + return new_lhs;
115430 +
115431 + if (TREE_CODE(rhs1) == SSA_NAME)
115432 + new_rhs1 = expand(visited, caller_node, rhs1);
115433 + if (TREE_CODE(rhs2) == SSA_NAME)
115434 + new_rhs2 = expand(visited, caller_node, rhs2);
115435 +
115436 + res = add_mul_intentional_overflow(def_stmt);
115437 + if (res != NO_INTENTIONAL_OVERFLOW) {
115438 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115439 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115440 + return new_lhs;
115441 + }
115442 +
115443 + if (skip_expr_on_double_type(def_stmt)) {
115444 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115445 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115446 + return new_lhs;
115447 + }
115448 +
115449 + if (is_a_neg_overflow(def_stmt, rhs2))
115450 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115451 + if (is_a_neg_overflow(def_stmt, rhs1))
115452 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115453 +
115454 +
115455 + if (is_a_constant_overflow(def_stmt, rhs2))
115456 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115457 + if (is_a_constant_overflow(def_stmt, rhs1))
115458 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115459 +
115460 + // the const is between 0 and (signed) MAX
115461 + if (is_gimple_constant(rhs1))
115462 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115463 + if (is_gimple_constant(rhs2))
115464 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115465 +
115466 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115467 +}
115468 +
115469 +#if BUILDING_GCC_VERSION >= 4006
115470 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115471 +{
115472 + if (is_gimple_constant(rhs))
115473 + return cast_a_tree(size_overflow_type, rhs);
115474 + if (TREE_CODE(rhs) != SSA_NAME)
115475 + return NULL_TREE;
115476 + return expand(visited, caller_node, rhs);
115477 +}
115478 +
115479 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115480 +{
115481 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115482 + gimple def_stmt = get_def_stmt(lhs);
115483 +
115484 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115485 +
115486 + rhs1 = gimple_assign_rhs1(def_stmt);
115487 + rhs2 = gimple_assign_rhs2(def_stmt);
115488 + rhs3 = gimple_assign_rhs3(def_stmt);
115489 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115490 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115491 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115492 +
115493 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115494 +}
115495 +#endif
115496 +
115497 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115498 +{
115499 + gimple_stmt_iterator gsi;
115500 + gimple next_stmt = NULL;
115501 +
115502 + gsi = gsi_for_stmt(stmt);
115503 +
115504 + do {
115505 + gsi_next(&gsi);
115506 + next_stmt = gsi_stmt(gsi);
115507 +
115508 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115509 + return NULL_TREE;
115510 +
115511 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115512 + break;
115513 +
115514 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115515 + } while (!gsi_end_p(gsi));
115516 +
115517 + gcc_assert(next_stmt);
115518 + return get_lhs(next_stmt);
115519 +}
115520 +
115521 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115522 +{
115523 + gimple_stmt_iterator gsi;
115524 + enum gimple_code code = gimple_code(def_stmt);
115525 +
115526 + if (code == GIMPLE_ASM)
115527 + return NULL_TREE;
115528 +
115529 + gsi = gsi_for_stmt(def_stmt);
115530 + gsi_next(&gsi);
115531 +
115532 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115533 + return NULL_TREE;
115534 + return get_my_stmt_lhs(visited, def_stmt);
115535 +}
115536 +
115537 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115538 +{
115539 + gimple def_stmt;
115540 +
115541 + def_stmt = get_def_stmt(lhs);
115542 +
115543 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115544 + return NULL_TREE;
115545 +
115546 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115547 + return lhs;
115548 +
115549 + if (pointer_set_contains(visited->stmts, def_stmt))
115550 + return expand_visited(visited, def_stmt);
115551 +
115552 + switch (gimple_code(def_stmt)) {
115553 + case GIMPLE_PHI:
115554 + return handle_phi(visited, caller_node, lhs);
115555 + case GIMPLE_CALL:
115556 + case GIMPLE_ASM:
115557 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115558 + case GIMPLE_ASSIGN:
115559 + switch (gimple_num_ops(def_stmt)) {
115560 + case 2:
115561 + return handle_unary_ops(visited, caller_node, def_stmt);
115562 + case 3:
115563 + return handle_binary_ops(visited, caller_node, lhs);
115564 +#if BUILDING_GCC_VERSION >= 4006
115565 + case 4:
115566 + return handle_ternary_ops(visited, caller_node, lhs);
115567 +#endif
115568 + }
115569 + default:
115570 + debug_gimple_stmt(def_stmt);
115571 + error("%s: unknown gimple code", __func__);
115572 + gcc_unreachable();
115573 + }
115574 +}
115575 +
115576 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
115577 new file mode 100644
115578 index 0000000..df50164
115579 --- /dev/null
115580 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115581 @@ -0,0 +1,1141 @@
115582 +/*
115583 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115584 + * Licensed under the GPL v2, or (at your option) v3
115585 + *
115586 + * Homepage:
115587 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115588 + *
115589 + * Documentation:
115590 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115591 + *
115592 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115593 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115594 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115595 + *
115596 + * Usage:
115597 + * $ make
115598 + * $ make run
115599 + */
115600 +
115601 +#include "gcc-common.h"
115602 +#include "size_overflow.h"
115603 +
115604 +#define VEC_LEN 128
115605 +#define RET_CHECK NULL_TREE
115606 +#define WRONG_NODE 32
115607 +#define NOT_INTENTIONAL_ASM NULL
115608 +
115609 +unsigned int call_count;
115610 +
115611 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115612 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115613 +
115614 +struct visited_fns {
115615 + struct visited_fns *next;
115616 + const_tree fndecl;
115617 + unsigned int num;
115618 + const_gimple first_stmt;
115619 +};
115620 +
115621 +struct next_cgraph_node {
115622 + struct next_cgraph_node *next;
115623 + struct cgraph_node *current_function;
115624 + tree callee_fndecl;
115625 + unsigned int num;
115626 +};
115627 +
115628 +// Don't want to duplicate entries in next_cgraph_node
115629 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115630 +{
115631 + const_tree new_callee_fndecl;
115632 + struct next_cgraph_node *cur_node;
115633 +
115634 + if (fndecl == RET_CHECK)
115635 + new_callee_fndecl = NODE_DECL(node);
115636 + else
115637 + new_callee_fndecl = fndecl;
115638 +
115639 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115640 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115641 + continue;
115642 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115643 + continue;
115644 + if (num == cur_node->num)
115645 + return true;
115646 + }
115647 + return false;
115648 +}
115649 +
115650 +/* Add a next_cgraph_node into the list for handle_function().
115651 + * handle_function() iterates over all the next cgraph nodes and
115652 + * starts the overflow check insertion process.
115653 + */
115654 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115655 +{
115656 + struct next_cgraph_node *new_node;
115657 +
115658 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115659 + return head;
115660 +
115661 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115662 + new_node->current_function = node;
115663 + new_node->next = NULL;
115664 + new_node->num = num;
115665 + if (fndecl == RET_CHECK)
115666 + new_node->callee_fndecl = NODE_DECL(node);
115667 + else
115668 + new_node->callee_fndecl = fndecl;
115669 +
115670 + if (!head)
115671 + return new_node;
115672 +
115673 + new_node->next = head;
115674 + return new_node;
115675 +}
115676 +
115677 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115678 +{
115679 + struct cgraph_edge *e;
115680 +
115681 + if (num == 0)
115682 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115683 +
115684 + for (e = node->callers; e; e = e->next_caller) {
115685 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115686 +
115687 + gcc_assert(fndecl != NULL_TREE);
115688 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115689 + }
115690 +
115691 + return head;
115692 +}
115693 +
115694 +struct missing_functions {
115695 + struct missing_functions *next;
115696 + const_tree node;
115697 + tree fndecl;
115698 +};
115699 +
115700 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115701 +{
115702 + struct missing_functions *new_function;
115703 +
115704 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115705 + new_function->node = node;
115706 + new_function->next = NULL;
115707 +
115708 + if (TREE_CODE(node) == FUNCTION_DECL)
115709 + new_function->fndecl = node;
115710 + else
115711 + new_function->fndecl = current_function_decl;
115712 + gcc_assert(new_function->fndecl);
115713 +
115714 + if (!missing_fn_head)
115715 + return new_function;
115716 +
115717 + new_function->next = missing_fn_head;
115718 + return new_function;
115719 +}
115720 +
115721 +/* If the function is missing from the hash table and it is a static function
115722 + * then create a next_cgraph_node from it for handle_function()
115723 + */
115724 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115725 +{
115726 + unsigned int num;
115727 + const_tree orig_fndecl;
115728 + struct cgraph_node *next_node = NULL;
115729 +
115730 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115731 +
115732 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115733 + if (num == CANNOT_FIND_ARG)
115734 + return cnodes;
115735 +
115736 + if (!is_missing_function(orig_fndecl, num))
115737 + return cnodes;
115738 +
115739 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115740 + if (next_node && next_node->local.local)
115741 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115742 + return cnodes;
115743 +}
115744 +
115745 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115746 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115747 + */
115748 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115749 +{
115750 + unsigned int i;
115751 + tree node;
115752 + struct missing_functions *cur, *missing_fn_head = NULL;
115753 +
115754 +#if BUILDING_GCC_VERSION <= 4007
115755 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115756 +#else
115757 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115758 +#endif
115759 + switch (TREE_CODE(node)) {
115760 + case PARM_DECL:
115761 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115762 + break;
115763 + case FUNCTION_DECL:
115764 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115765 + break;
115766 + default:
115767 + break;
115768 + }
115769 + }
115770 +
115771 + while (missing_fn_head) {
115772 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115773 +
115774 + cur = missing_fn_head->next;
115775 + free(missing_fn_head);
115776 + missing_fn_head = cur;
115777 + }
115778 +
115779 + return cnodes;
115780 +}
115781 +
115782 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115783 +{
115784 + gimple phi = get_def_stmt(result);
115785 + unsigned int i, n = gimple_phi_num_args(phi);
115786 +
115787 + pointer_set_insert(visited, phi);
115788 + for (i = 0; i < n; i++) {
115789 + const_tree arg = gimple_phi_arg_def(phi, i);
115790 +
115791 + set_conditions(visited, interesting_conditions, arg);
115792 + }
115793 +}
115794 +
115795 +enum conditions {
115796 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
115797 +};
115798 +
115799 +// Search for constants, cast assignments and binary/ternary assignments
115800 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
115801 +{
115802 + gimple def_stmt = get_def_stmt(lhs);
115803 +
115804 + if (is_gimple_constant(lhs)) {
115805 + interesting_conditions[FROM_CONST] = true;
115806 + return;
115807 + }
115808 +
115809 + if (!def_stmt)
115810 + return;
115811 +
115812 + if (pointer_set_contains(visited, def_stmt))
115813 + return;
115814 +
115815 + switch (gimple_code(def_stmt)) {
115816 + case GIMPLE_CALL:
115817 + if (lhs == gimple_call_lhs(def_stmt))
115818 + interesting_conditions[RET] = true;
115819 + return;
115820 + case GIMPLE_NOP:
115821 + case GIMPLE_ASM:
115822 + return;
115823 + case GIMPLE_PHI:
115824 + interesting_conditions[PHI] = true;
115825 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
115826 + case GIMPLE_ASSIGN:
115827 + if (gimple_num_ops(def_stmt) == 2) {
115828 + const_tree rhs = gimple_assign_rhs1(def_stmt);
115829 +
115830 + if (gimple_assign_cast_p(def_stmt))
115831 + interesting_conditions[CAST] = true;
115832 +
115833 + return set_conditions(visited, interesting_conditions, rhs);
115834 + } else {
115835 + interesting_conditions[NOT_UNARY] = true;
115836 + return;
115837 + }
115838 + default:
115839 + debug_gimple_stmt(def_stmt);
115840 + gcc_unreachable();
115841 + }
115842 +}
115843 +
115844 +// determine whether duplication will be necessary or not.
115845 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
115846 +{
115847 + struct pointer_set_t *visited;
115848 +
115849 + if (gimple_assign_cast_p(cur_node->first_stmt))
115850 + interesting_conditions[CAST] = true;
115851 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
115852 + interesting_conditions[NOT_UNARY] = true;
115853 +
115854 + visited = pointer_set_create();
115855 + set_conditions(visited, interesting_conditions, cur_node->node);
115856 + pointer_set_destroy(visited);
115857 +}
115858 +
115859 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
115860 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
115861 +{
115862 + gimple assign;
115863 + gimple_stmt_iterator gsi;
115864 +
115865 + // already removed
115866 + if (gimple_bb(asm_stmt) == NULL)
115867 + return;
115868 + gsi = gsi_for_stmt(asm_stmt);
115869 +
115870 + assign = gimple_build_assign(lhs, rhs);
115871 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
115872 + SSA_NAME_DEF_STMT(lhs) = assign;
115873 +
115874 + gsi_remove(&gsi, true);
115875 +}
115876 +
115877 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
115878 + * stmt is a return otherwise it is the callee function.
115879 + */
115880 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
115881 +{
115882 + const_tree fndecl;
115883 +
115884 + if (argnum == 0)
115885 + fndecl = current_function_decl;
115886 + else
115887 + fndecl = gimple_call_fndecl(stmt);
115888 +
115889 + if (fndecl == NULL_TREE)
115890 + return NULL_TREE;
115891 +
115892 + return DECL_ORIGIN(fndecl);
115893 +}
115894 +
115895 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115896 +static bool skip_asm(const_tree arg)
115897 +{
115898 + gimple def_stmt = get_def_stmt(arg);
115899 +
115900 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115901 + return false;
115902 +
115903 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115904 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115905 +}
115906 +
115907 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115908 +{
115909 + gimple phi = get_def_stmt(result);
115910 + unsigned int i, n = gimple_phi_num_args(phi);
115911 +
115912 + pointer_set_insert(visited, phi);
115913 + for (i = 0; i < n; i++) {
115914 + tree arg = gimple_phi_arg_def(phi, i);
115915 +
115916 + walk_use_def(visited, cur_node, arg);
115917 + }
115918 +}
115919 +
115920 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115921 +{
115922 + gimple def_stmt = get_def_stmt(lhs);
115923 + tree rhs1, rhs2;
115924 +
115925 + rhs1 = gimple_assign_rhs1(def_stmt);
115926 + rhs2 = gimple_assign_rhs2(def_stmt);
115927 +
115928 + walk_use_def(visited, cur_node, rhs1);
115929 + walk_use_def(visited, cur_node, rhs2);
115930 +}
115931 +
115932 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115933 +{
115934 + unsigned int i;
115935 + tree element;
115936 + enum tree_code code;
115937 +
115938 + gcc_assert(node != NULL_TREE);
115939 +
115940 + if (is_gimple_constant(node))
115941 + return;
115942 +
115943 + code = TREE_CODE(node);
115944 + if (code == VAR_DECL) {
115945 + node = DECL_ORIGIN(node);
115946 + code = TREE_CODE(node);
115947 + }
115948 +
115949 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115950 + return;
115951 +
115952 +#if BUILDING_GCC_VERSION <= 4007
115953 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115954 +#else
115955 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115956 +#endif
115957 + if (operand_equal_p(node, element, 0))
115958 + return;
115959 + }
115960 +
115961 +#if BUILDING_GCC_VERSION <= 4007
115962 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115963 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115964 +#else
115965 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115966 + vec_safe_push(cur_node->last_nodes, node);
115967 +#endif
115968 +}
115969 +
115970 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115971 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115972 +{
115973 + if (!is_size_overflow_asm(stmt))
115974 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115975 +}
115976 +
115977 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115978 + * and component refs (for checking the intentional_overflow attribute).
115979 + */
115980 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115981 +{
115982 + const_gimple def_stmt;
115983 +
115984 + if (TREE_CODE(lhs) != SSA_NAME) {
115985 + insert_last_node(cur_node, lhs);
115986 + return;
115987 + }
115988 +
115989 + def_stmt = get_def_stmt(lhs);
115990 + if (!def_stmt)
115991 + return;
115992 +
115993 + if (pointer_set_insert(visited, def_stmt))
115994 + return;
115995 +
115996 + switch (gimple_code(def_stmt)) {
115997 + case GIMPLE_NOP:
115998 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115999 + case GIMPLE_ASM:
116000 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116001 + case GIMPLE_CALL: {
116002 + tree fndecl = gimple_call_fndecl(def_stmt);
116003 +
116004 + if (fndecl == NULL_TREE)
116005 + return;
116006 + insert_last_node(cur_node, fndecl);
116007 + return;
116008 + }
116009 + case GIMPLE_PHI:
116010 + return walk_use_def_phi(visited, cur_node, lhs);
116011 + case GIMPLE_ASSIGN:
116012 + switch (gimple_num_ops(def_stmt)) {
116013 + case 2:
116014 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116015 + case 3:
116016 + return walk_use_def_binary(visited, cur_node, lhs);
116017 + }
116018 + default:
116019 + debug_gimple_stmt((gimple)def_stmt);
116020 + error("%s: unknown gimple code", __func__);
116021 + gcc_unreachable();
116022 + }
116023 +}
116024 +
116025 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116026 +static void set_last_nodes(struct interesting_node *cur_node)
116027 +{
116028 + struct pointer_set_t *visited;
116029 +
116030 + visited = pointer_set_create();
116031 + walk_use_def(visited, cur_node, cur_node->node);
116032 + pointer_set_destroy(visited);
116033 +}
116034 +
116035 +enum precond {
116036 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116037 +};
116038 +
116039 +/* 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.
116040 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116041 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116042 + * It skips the possible error codes too.
116043 + */
116044 +static enum precond check_preconditions(struct interesting_node *cur_node)
116045 +{
116046 + bool interesting_conditions[5] = {false, false, false, false, false};
116047 +
116048 + set_last_nodes(cur_node);
116049 +
116050 + check_intentional_attribute_ipa(cur_node);
116051 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116052 + return NO_ATTRIBUTE_SEARCH;
116053 +
116054 + search_interesting_conditions(cur_node, interesting_conditions);
116055 +
116056 + // error code: a phi, unary assign (not cast) and returns only
116057 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116058 + return NO_ATTRIBUTE_SEARCH;
116059 +
116060 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116061 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116062 + return NO_ATTRIBUTE_SEARCH;
116063 +
116064 + // unnecessary overflow check
116065 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116066 + return NO_CHECK_INSERT;
116067 +
116068 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116069 + return NO_CHECK_INSERT;
116070 +
116071 + return NONE;
116072 +}
116073 +
116074 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116075 +{
116076 + const_gimple assign;
116077 + tree orig_type = TREE_TYPE(orig_node);
116078 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116079 +
116080 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116081 + return gimple_assign_lhs(assign);
116082 +}
116083 +
116084 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116085 +{
116086 + void (*set_rhs)(gimple, tree);
116087 + gimple stmt = cur_node->first_stmt;
116088 + const_tree orig_node = cur_node->node;
116089 +
116090 + switch (gimple_code(stmt)) {
116091 + case GIMPLE_RETURN:
116092 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116093 + break;
116094 + case GIMPLE_CALL:
116095 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116096 + break;
116097 + case GIMPLE_ASSIGN:
116098 + switch (cur_node->num) {
116099 + case 1:
116100 + set_rhs = &gimple_assign_set_rhs1;
116101 + break;
116102 + case 2:
116103 + set_rhs = &gimple_assign_set_rhs2;
116104 + break;
116105 +#if BUILDING_GCC_VERSION >= 4006
116106 + case 3:
116107 + set_rhs = &gimple_assign_set_rhs3;
116108 + break;
116109 +#endif
116110 + default:
116111 + gcc_unreachable();
116112 + }
116113 +
116114 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116115 + break;
116116 + default:
116117 + debug_gimple_stmt(stmt);
116118 + gcc_unreachable();
116119 + }
116120 +
116121 + update_stmt(stmt);
116122 +}
116123 +
116124 +static struct visited *create_visited(void)
116125 +{
116126 + struct visited *new_node;
116127 +
116128 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116129 + new_node->stmts = pointer_set_create();
116130 + new_node->my_stmts = pointer_set_create();
116131 + new_node->skip_expr_casts = pointer_set_create();
116132 + new_node->no_cast_check = pointer_set_create();
116133 + return new_node;
116134 +}
116135 +
116136 +static void free_visited(struct visited *visited)
116137 +{
116138 + pointer_set_destroy(visited->stmts);
116139 + pointer_set_destroy(visited->my_stmts);
116140 + pointer_set_destroy(visited->skip_expr_casts);
116141 + pointer_set_destroy(visited->no_cast_check);
116142 +
116143 + free(visited);
116144 +}
116145 +
116146 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116147 + * 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
116148 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116149 + */
116150 +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)
116151 +{
116152 + enum precond ret;
116153 + tree new_node, orig_node = cur_node->node;
116154 +
116155 + ret = check_preconditions(cur_node);
116156 + if (ret == NO_ATTRIBUTE_SEARCH)
116157 + return cnodes;
116158 +
116159 + cnodes = search_overflow_attribute(cnodes, cur_node);
116160 +
116161 + if (ret == NO_CHECK_INSERT)
116162 + return cnodes;
116163 +
116164 + new_node = expand(visited, caller_node, orig_node);
116165 + if (new_node == NULL_TREE)
116166 + return cnodes;
116167 +
116168 + change_orig_node(visited, cur_node, new_node);
116169 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116170 +
116171 + return cnodes;
116172 +}
116173 +
116174 +// Check visited_fns interesting nodes.
116175 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116176 +{
116177 + struct interesting_node *cur;
116178 +
116179 + for (cur = head; cur; cur = cur->next) {
116180 + if (!operand_equal_p(node, cur->node, 0))
116181 + continue;
116182 + if (num != cur->num)
116183 + continue;
116184 + if (first_stmt == cur->first_stmt)
116185 + return true;
116186 + }
116187 + return false;
116188 +}
116189 +
116190 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116191 + 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
116192 + 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
116193 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116194 + num: arg count of a call stmt or 0 when it is a ret
116195 + node: the recursion starts from here, it is a call arg or a return value
116196 + 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.
116197 + intentional_attr_decl: intentional_overflow attribute of the callee function
116198 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116199 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116200 + */
116201 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116202 +{
116203 + struct interesting_node *new_node;
116204 + tree fndecl;
116205 + enum gimple_code code;
116206 +
116207 + gcc_assert(node != NULL_TREE);
116208 + code = gimple_code(first_stmt);
116209 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116210 +
116211 + if (num == CANNOT_FIND_ARG)
116212 + return head;
116213 +
116214 + if (skip_types(node))
116215 + return head;
116216 +
116217 + if (skip_asm(node))
116218 + return head;
116219 +
116220 + if (is_gimple_call(first_stmt))
116221 + fndecl = gimple_call_fndecl(first_stmt);
116222 + else
116223 + fndecl = current_function_decl;
116224 +
116225 + if (fndecl == NULL_TREE)
116226 + return head;
116227 +
116228 + if (is_in_interesting_node(head, first_stmt, node, num))
116229 + return head;
116230 +
116231 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116232 +
116233 + new_node->next = NULL;
116234 + new_node->first_stmt = first_stmt;
116235 +#if BUILDING_GCC_VERSION <= 4007
116236 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116237 +#else
116238 + vec_alloc(new_node->last_nodes, VEC_LEN);
116239 +#endif
116240 + new_node->num = num;
116241 + new_node->node = node;
116242 + new_node->fndecl = fndecl;
116243 + new_node->intentional_attr_decl = MARK_NO;
116244 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116245 + new_node->intentional_mark_from_gimple = asm_stmt;
116246 +
116247 + if (!head)
116248 + return new_node;
116249 +
116250 + new_node->next = head;
116251 + return new_node;
116252 +}
116253 +
116254 +/* 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).
116255 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116256 + */
116257 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116258 +{
116259 + struct next_cgraph_node *cur_node;
116260 + tree ret = gimple_return_retval(stmt);
116261 +
116262 + if (ret == NULL_TREE)
116263 + return head;
116264 +
116265 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116266 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116267 + continue;
116268 + if (cur_node->num == 0)
116269 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116270 + }
116271 +
116272 + return head;
116273 +}
116274 +
116275 +/* 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).
116276 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116277 + */
116278 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116279 +{
116280 + unsigned int argnum;
116281 + tree arg;
116282 + const_tree fndecl;
116283 + struct next_cgraph_node *cur_node;
116284 +
116285 + fndecl = gimple_call_fndecl(stmt);
116286 + if (fndecl == NULL_TREE)
116287 + return head;
116288 +
116289 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116290 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116291 + continue;
116292 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116293 + gcc_assert(argnum != CANNOT_FIND_ARG);
116294 + if (argnum == 0)
116295 + continue;
116296 +
116297 + arg = gimple_call_arg(stmt, argnum - 1);
116298 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116299 + }
116300 +
116301 + return head;
116302 +}
116303 +
116304 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116305 +{
116306 + if (!operand_equal_p(orig_node, node, 0))
116307 + return WRONG_NODE;
116308 + if (skip_types(node))
116309 + return WRONG_NODE;
116310 + return ret_count;
116311 +}
116312 +
116313 +// Get the index of the rhs node in an assignment
116314 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116315 +{
116316 + const_tree rhs1, rhs2;
116317 + unsigned int ret;
116318 +
116319 + gcc_assert(stmt);
116320 + gcc_assert(is_gimple_assign(stmt));
116321 +
116322 + rhs1 = gimple_assign_rhs1(stmt);
116323 + gcc_assert(rhs1 != NULL_TREE);
116324 +
116325 + switch (gimple_num_ops(stmt)) {
116326 + case 2:
116327 + return check_ops(node, rhs1, 1);
116328 + case 3:
116329 + ret = check_ops(node, rhs1, 1);
116330 + if (ret != WRONG_NODE)
116331 + return ret;
116332 +
116333 + rhs2 = gimple_assign_rhs2(stmt);
116334 + gcc_assert(rhs2 != NULL_TREE);
116335 + return check_ops(node, rhs2, 2);
116336 + default:
116337 + gcc_unreachable();
116338 + }
116339 +}
116340 +
116341 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116342 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116343 +{
116344 + unsigned int i;
116345 +
116346 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116347 + return CANNOT_FIND_ARG;
116348 +
116349 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116350 + tree node;
116351 +
116352 + node = gimple_call_arg(stmt, i);
116353 + if (!operand_equal_p(arg, node, 0))
116354 + continue;
116355 + if (!skip_types(node))
116356 + return i + 1;
116357 + }
116358 +
116359 + return CANNOT_FIND_ARG;
116360 +}
116361 +
116362 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116363 + * any of return, call or assignment stmts (because of inlining).
116364 + */
116365 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116366 +{
116367 + use_operand_p use_p;
116368 + imm_use_iterator imm_iter;
116369 + unsigned int argnum;
116370 +
116371 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116372 +
116373 + if (pointer_set_insert(visited, node))
116374 + return head;
116375 +
116376 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116377 + gimple stmt = USE_STMT(use_p);
116378 +
116379 + if (stmt == NULL)
116380 + return head;
116381 + if (is_gimple_debug(stmt))
116382 + continue;
116383 +
116384 + switch (gimple_code(stmt)) {
116385 + case GIMPLE_CALL:
116386 + argnum = find_arg_number_gimple(node, stmt);
116387 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116388 + break;
116389 + case GIMPLE_RETURN:
116390 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116391 + break;
116392 + case GIMPLE_ASSIGN:
116393 + argnum = get_assign_ops_count(stmt, node);
116394 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116395 + break;
116396 + case GIMPLE_PHI: {
116397 + tree result = gimple_phi_result(stmt);
116398 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116399 + break;
116400 + }
116401 + case GIMPLE_ASM:
116402 + if (gimple_asm_noutputs(stmt) != 0)
116403 + break;
116404 + if (!is_size_overflow_asm(stmt))
116405 + break;
116406 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116407 + break;
116408 + case GIMPLE_COND:
116409 + case GIMPLE_SWITCH:
116410 + break;
116411 + default:
116412 + debug_gimple_stmt(stmt);
116413 + gcc_unreachable();
116414 + break;
116415 + }
116416 + }
116417 + return head;
116418 +}
116419 +
116420 +static void remove_size_overflow_asm(gimple stmt)
116421 +{
116422 + gimple_stmt_iterator gsi;
116423 + tree input, output;
116424 +
116425 + if (!is_size_overflow_asm(stmt))
116426 + return;
116427 +
116428 + if (gimple_asm_noutputs(stmt) == 0) {
116429 + gsi = gsi_for_stmt(stmt);
116430 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116431 + gsi_remove(&gsi, true);
116432 + return;
116433 + }
116434 +
116435 + input = gimple_asm_input_op(stmt, 0);
116436 + output = gimple_asm_output_op(stmt, 0);
116437 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116438 +}
116439 +
116440 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116441 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116442 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116443 + */
116444 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116445 +{
116446 + const_tree output;
116447 + struct pointer_set_t *visited;
116448 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116449 +
116450 + if (!is_size_overflow_asm(stmt))
116451 + return head;
116452 +
116453 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116454 + intentional_asm = stmt;
116455 +
116456 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116457 +
116458 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116459 + return head;
116460 +
116461 + if (gimple_asm_noutputs(stmt) == 0) {
116462 + const_tree input;
116463 +
116464 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116465 + return head;
116466 +
116467 + input = gimple_asm_input_op(stmt, 0);
116468 + remove_size_overflow_asm(stmt);
116469 + if (is_gimple_constant(TREE_VALUE(input)))
116470 + return head;
116471 + visited = pointer_set_create();
116472 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116473 + pointer_set_destroy(visited);
116474 + return head;
116475 + }
116476 +
116477 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116478 + remove_size_overflow_asm(stmt);
116479 +
116480 + visited = pointer_set_create();
116481 + output = gimple_asm_output_op(stmt, 0);
116482 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116483 + pointer_set_destroy(visited);
116484 + return head;
116485 +}
116486 +
116487 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116488 + * or a call stmt or a return stmt and store them in the interesting_node list
116489 + */
116490 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116491 +{
116492 + basic_block bb;
116493 + struct interesting_node *head = NULL;
116494 +
116495 + FOR_ALL_BB_FN(bb, cfun) {
116496 + gimple_stmt_iterator gsi;
116497 +
116498 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116499 + enum gimple_code code;
116500 + gimple stmt = gsi_stmt(gsi);
116501 +
116502 + code = gimple_code(stmt);
116503 +
116504 + if (code == GIMPLE_ASM)
116505 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116506 +
116507 + if (!next_node)
116508 + continue;
116509 + if (code == GIMPLE_CALL)
116510 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116511 + if (code == GIMPLE_RETURN)
116512 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116513 + }
116514 + }
116515 + return head;
116516 +}
116517 +
116518 +static void free_interesting_node(struct interesting_node *head)
116519 +{
116520 + struct interesting_node *cur;
116521 +
116522 + while (head) {
116523 + cur = head->next;
116524 +#if BUILDING_GCC_VERSION <= 4007
116525 + VEC_free(tree, gc, head->last_nodes);
116526 +#else
116527 + vec_free(head->last_nodes);
116528 +#endif
116529 + free(head);
116530 + head = cur;
116531 + }
116532 +}
116533 +
116534 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116535 +{
116536 + struct visited_fns *new_visited_fns;
116537 +
116538 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116539 + new_visited_fns->fndecl = cur_node->fndecl;
116540 + new_visited_fns->num = cur_node->num;
116541 + new_visited_fns->first_stmt = cur_node->first_stmt;
116542 + new_visited_fns->next = NULL;
116543 +
116544 + if (!head)
116545 + return new_visited_fns;
116546 +
116547 + new_visited_fns->next = head;
116548 + return new_visited_fns;
116549 +}
116550 +
116551 +/* 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
116552 + * it is a visited_fns function.
116553 + */
116554 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116555 +{
116556 + struct visited_fns *cur;
116557 +
116558 + if (!head)
116559 + return false;
116560 +
116561 + for (cur = head; cur; cur = cur->next) {
116562 + if (cur_node->first_stmt != cur->first_stmt)
116563 + continue;
116564 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116565 + continue;
116566 + if (cur_node->num == cur->num)
116567 + return true;
116568 + }
116569 + return false;
116570 +}
116571 +
116572 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116573 +{
116574 + struct next_cgraph_node *cur;
116575 +
116576 + while (head) {
116577 + cur = head->next;
116578 + free(head);
116579 + head = cur;
116580 + }
116581 +}
116582 +
116583 +static void remove_all_size_overflow_asm(void)
116584 +{
116585 + basic_block bb;
116586 +
116587 + FOR_ALL_BB_FN(bb, cfun) {
116588 + gimple_stmt_iterator si;
116589 +
116590 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116591 + remove_size_overflow_asm(gsi_stmt(si));
116592 + }
116593 +}
116594 +
116595 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116596 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116597 + * the newly collected interesting functions (they are interesting if there is control flow between
116598 + * the interesting stmts and them).
116599 + */
116600 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116601 +{
116602 + struct visited *visited;
116603 + struct interesting_node *head, *cur_node;
116604 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116605 +
116606 + set_current_function_decl(NODE_DECL(node));
116607 + call_count = 0;
116608 +
116609 + head = collect_interesting_stmts(next_node);
116610 +
116611 + visited = create_visited();
116612 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116613 + if (is_visited_fns_function(visited_fns, cur_node))
116614 + continue;
116615 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116616 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116617 + }
116618 +
116619 + free_visited(visited);
116620 + free_interesting_node(head);
116621 + remove_all_size_overflow_asm();
116622 + unset_current_function_decl();
116623 +
116624 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116625 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116626 +
116627 + free_next_cgraph_node(cnodes_head);
116628 + return visited_fns;
116629 +}
116630 +
116631 +static void free_visited_fns(struct visited_fns *head)
116632 +{
116633 + struct visited_fns *cur;
116634 +
116635 + while (head) {
116636 + cur = head->next;
116637 + free(head);
116638 + head = cur;
116639 + }
116640 +}
116641 +
116642 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116643 +unsigned int search_function(void)
116644 +{
116645 + struct cgraph_node *node;
116646 + struct visited_fns *visited_fns = NULL;
116647 +
116648 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116649 + gcc_assert(cgraph_function_flags_ready);
116650 +#if BUILDING_GCC_VERSION <= 4007
116651 + gcc_assert(node->reachable);
116652 +#endif
116653 +
116654 + visited_fns = handle_function(node, NULL, visited_fns);
116655 + }
116656 +
116657 + free_visited_fns(visited_fns);
116658 + return 0;
116659 +}
116660 +
116661 +#if BUILDING_GCC_VERSION >= 4009
116662 +static const struct pass_data insert_size_overflow_check_data = {
116663 +#else
116664 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116665 + .pass = {
116666 +#endif
116667 + .type = SIMPLE_IPA_PASS,
116668 + .name = "size_overflow",
116669 +#if BUILDING_GCC_VERSION >= 4008
116670 + .optinfo_flags = OPTGROUP_NONE,
116671 +#endif
116672 +#if BUILDING_GCC_VERSION >= 4009
116673 + .has_gate = false,
116674 + .has_execute = true,
116675 +#else
116676 + .gate = NULL,
116677 + .execute = search_function,
116678 + .sub = NULL,
116679 + .next = NULL,
116680 + .static_pass_number = 0,
116681 +#endif
116682 + .tv_id = TV_NONE,
116683 + .properties_required = 0,
116684 + .properties_provided = 0,
116685 + .properties_destroyed = 0,
116686 + .todo_flags_start = 0,
116687 + .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,
116688 +#if BUILDING_GCC_VERSION < 4009
116689 + },
116690 + .generate_summary = NULL,
116691 + .write_summary = NULL,
116692 + .read_summary = NULL,
116693 +#if BUILDING_GCC_VERSION >= 4006
116694 + .write_optimization_summary = NULL,
116695 + .read_optimization_summary = NULL,
116696 +#endif
116697 + .stmt_fixup = NULL,
116698 + .function_transform_todo_flags_start = 0,
116699 + .function_transform = NULL,
116700 + .variable_transform = NULL,
116701 +#endif
116702 +};
116703 +
116704 +#if BUILDING_GCC_VERSION >= 4009
116705 +namespace {
116706 +class insert_size_overflow_check : public ipa_opt_pass_d {
116707 +public:
116708 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116709 + unsigned int execute() { return search_function(); }
116710 +};
116711 +}
116712 +#endif
116713 +
116714 +struct opt_pass *make_insert_size_overflow_check(void)
116715 +{
116716 +#if BUILDING_GCC_VERSION >= 4009
116717 + return new insert_size_overflow_check();
116718 +#else
116719 + return &insert_size_overflow_check.pass;
116720 +#endif
116721 +}
116722 +
116723 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116724 new file mode 100644
116725 index 0000000..d71d72a
116726 --- /dev/null
116727 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116728 @@ -0,0 +1,736 @@
116729 +/*
116730 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116731 + * Licensed under the GPL v2, or (at your option) v3
116732 + *
116733 + * Homepage:
116734 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116735 + *
116736 + * Documentation:
116737 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116738 + *
116739 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116740 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116741 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116742 + *
116743 + * Usage:
116744 + * $ make
116745 + * $ make run
116746 + */
116747 +
116748 +#include "gcc-common.h"
116749 +#include "size_overflow.h"
116750 +
116751 +/* Get the param of the intentional_overflow attribute.
116752 + * * 0: MARK_NOT_INTENTIONAL
116753 + * * 1..MAX_PARAM: MARK_YES
116754 + * * -1: MARK_TURN_OFF
116755 + */
116756 +static tree get_attribute_param(const_tree decl)
116757 +{
116758 + const_tree attr;
116759 +
116760 + if (decl == NULL_TREE)
116761 + return NULL_TREE;
116762 +
116763 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116764 + if (!attr || !TREE_VALUE(attr))
116765 + return NULL_TREE;
116766 +
116767 + return TREE_VALUE(attr);
116768 +}
116769 +
116770 +// MARK_TURN_OFF
116771 +bool is_turn_off_intentional_attr(const_tree decl)
116772 +{
116773 + const_tree param_head;
116774 +
116775 + param_head = get_attribute_param(decl);
116776 + if (param_head == NULL_TREE)
116777 + return false;
116778 +
116779 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116780 + return true;
116781 + return false;
116782 +}
116783 +
116784 +// MARK_NOT_INTENTIONAL
116785 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116786 +{
116787 + const_tree param_head;
116788 +
116789 + if (argnum == 0)
116790 + return false;
116791 +
116792 + param_head = get_attribute_param(decl);
116793 + if (param_head == NULL_TREE)
116794 + return false;
116795 +
116796 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116797 + return true;
116798 + return false;
116799 +}
116800 +
116801 +// MARK_YES
116802 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116803 +{
116804 + tree param, param_head;
116805 +
116806 + if (argnum == 0)
116807 + return false;
116808 +
116809 + param_head = get_attribute_param(decl);
116810 + for (param = param_head; param; param = TREE_CHAIN(param))
116811 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116812 + return true;
116813 + return false;
116814 +}
116815 +
116816 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116817 +{
116818 + location_t loc;
116819 +
116820 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116821 + return;
116822 +
116823 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116824 + return;
116825 +
116826 + loc = DECL_SOURCE_LOCATION(decl);
116827 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116828 +}
116829 +
116830 +// Get the field decl of a component ref for intentional_overflow checking
116831 +static const_tree search_field_decl(const_tree comp_ref)
116832 +{
116833 + const_tree field = NULL_TREE;
116834 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116835 +
116836 + for (i = 0; i < len; i++) {
116837 + field = TREE_OPERAND(comp_ref, i);
116838 + if (TREE_CODE(field) == FIELD_DECL)
116839 + break;
116840 + }
116841 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116842 + return field;
116843 +}
116844 +
116845 +/* Get the type of the intentional_overflow attribute of a node
116846 + * * MARK_TURN_OFF
116847 + * * MARK_YES
116848 + * * MARK_NO
116849 + * * MARK_NOT_INTENTIONAL
116850 + */
116851 +enum mark get_intentional_attr_type(const_tree node)
116852 +{
116853 + const_tree cur_decl;
116854 +
116855 + if (node == NULL_TREE)
116856 + return MARK_NO;
116857 +
116858 + switch (TREE_CODE(node)) {
116859 + case COMPONENT_REF:
116860 + cur_decl = search_field_decl(node);
116861 + if (is_turn_off_intentional_attr(cur_decl))
116862 + return MARK_TURN_OFF;
116863 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116864 + return MARK_YES;
116865 + break;
116866 + case PARM_DECL: {
116867 + unsigned int argnum;
116868 +
116869 + cur_decl = DECL_ORIGIN(current_function_decl);
116870 + argnum = find_arg_number_tree(node, cur_decl);
116871 + if (argnum == CANNOT_FIND_ARG)
116872 + return MARK_NO;
116873 + if (is_yes_intentional_attr(cur_decl, argnum))
116874 + return MARK_YES;
116875 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116876 + return MARK_NOT_INTENTIONAL;
116877 + break;
116878 + }
116879 + case FUNCTION_DECL:
116880 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116881 + return MARK_TURN_OFF;
116882 + break;
116883 + default:
116884 + break;
116885 + }
116886 + return MARK_NO;
116887 +}
116888 +
116889 +// Search for the intentional_overflow attribute on the last nodes
116890 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116891 +{
116892 + unsigned int i;
116893 + tree last_node;
116894 + enum mark mark = MARK_NO;
116895 +
116896 +#if BUILDING_GCC_VERSION <= 4007
116897 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116898 +#else
116899 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116900 +#endif
116901 + mark = get_intentional_attr_type(last_node);
116902 + if (mark != MARK_NO)
116903 + break;
116904 + }
116905 + return mark;
116906 +}
116907 +
116908 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116909 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116910 + */
116911 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116912 +{
116913 + if (!cur_node->intentional_mark_from_gimple)
116914 + return false;
116915 +
116916 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116917 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116918 + else
116919 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116920 +
116921 + // skip param decls
116922 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116923 + return true;
116924 + return true;
116925 +}
116926 +
116927 +/* Search intentional_overflow attribute on caller and on callee too.
116928 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116929 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116930 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116931 +*/
116932 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116933 +{
116934 + const_tree fndecl;
116935 +
116936 + if (is_intentional_attribute_from_gimple(cur_node))
116937 + return;
116938 +
116939 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116940 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116941 + return;
116942 + }
116943 +
116944 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116945 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116946 + return;
116947 + }
116948 +
116949 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116950 + return;
116951 +
116952 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116953 + if (is_turn_off_intentional_attr(fndecl)) {
116954 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116955 + return;
116956 + }
116957 +
116958 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116959 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116960 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116961 + cur_node->intentional_attr_decl = MARK_YES;
116962 +
116963 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116964 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116965 +}
116966 +
116967 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
116968 +{
116969 + const_tree rhs1, lhs, rhs1_type, lhs_type;
116970 + enum machine_mode lhs_mode, rhs_mode;
116971 + gimple def_stmt = get_def_stmt(no_const_rhs);
116972 +
116973 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116974 + return false;
116975 +
116976 + rhs1 = gimple_assign_rhs1(def_stmt);
116977 + lhs = gimple_assign_lhs(def_stmt);
116978 + rhs1_type = TREE_TYPE(rhs1);
116979 + lhs_type = TREE_TYPE(lhs);
116980 + rhs_mode = TYPE_MODE(rhs1_type);
116981 + lhs_mode = TYPE_MODE(lhs_type);
116982 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
116983 + return false;
116984 +
116985 + return true;
116986 +}
116987 +
116988 +static unsigned int uses_num(tree node)
116989 +{
116990 + imm_use_iterator imm_iter;
116991 + use_operand_p use_p;
116992 + unsigned int num = 0;
116993 +
116994 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116995 + gimple use_stmt = USE_STMT(use_p);
116996 +
116997 + if (use_stmt == NULL)
116998 + return num;
116999 + if (is_gimple_debug(use_stmt))
117000 + continue;
117001 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117002 + continue;
117003 + num++;
117004 + }
117005 + return num;
117006 +}
117007 +
117008 +static bool no_uses(tree node)
117009 +{
117010 + return !uses_num(node);
117011 +}
117012 +
117013 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117014 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117015 +{
117016 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117017 + gimple def_stmt = get_def_stmt(lhs);
117018 +
117019 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117020 + return false;
117021 +
117022 + rhs1 = gimple_assign_rhs1(def_stmt);
117023 + rhs_type = TREE_TYPE(rhs1);
117024 + lhs_type = TREE_TYPE(lhs);
117025 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117026 + return false;
117027 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117028 + return false;
117029 +
117030 + def_stmt = get_def_stmt(rhs1);
117031 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117032 + return false;
117033 +
117034 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117035 + return false;
117036 +
117037 + rhs1 = gimple_assign_rhs1(def_stmt);
117038 + rhs2 = gimple_assign_rhs2(def_stmt);
117039 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117040 + return false;
117041 +
117042 + if (is_gimple_constant(rhs2))
117043 + not_const_rhs = rhs1;
117044 + else
117045 + not_const_rhs = rhs2;
117046 +
117047 + return no_uses(not_const_rhs);
117048 +}
117049 +
117050 +static bool is_lt_signed_type_max(const_tree rhs)
117051 +{
117052 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117053 +
117054 + if (!TYPE_UNSIGNED(type))
117055 + return true;
117056 +
117057 + switch (TYPE_MODE(type)) {
117058 + case QImode:
117059 + new_type = intQI_type_node;
117060 + break;
117061 + case HImode:
117062 + new_type = intHI_type_node;
117063 + break;
117064 + case SImode:
117065 + new_type = intSI_type_node;
117066 + break;
117067 + case DImode:
117068 + new_type = intDI_type_node;
117069 + break;
117070 + default:
117071 + debug_tree((tree)type);
117072 + gcc_unreachable();
117073 + }
117074 +
117075 + type_max = TYPE_MAX_VALUE(new_type);
117076 + if (!tree_int_cst_lt(type_max, rhs))
117077 + return true;
117078 +
117079 + return false;
117080 +}
117081 +
117082 +static bool is_gt_zero(const_tree rhs)
117083 +{
117084 + const_tree type = TREE_TYPE(rhs);
117085 +
117086 + if (TYPE_UNSIGNED(type))
117087 + return true;
117088 +
117089 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117090 + return true;
117091 +
117092 + return false;
117093 +}
117094 +
117095 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117096 +{
117097 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117098 + return false;
117099 + if (!is_gimple_constant(rhs))
117100 + return false;
117101 +
117102 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117103 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117104 + return false;
117105 +
117106 + return true;
117107 +}
117108 +
117109 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117110 +{
117111 + gimple assign;
117112 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117113 + tree origtype = TREE_TYPE(orig_rhs);
117114 +
117115 + gcc_assert(is_gimple_assign(stmt));
117116 +
117117 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117118 + pointer_set_insert(visited->my_stmts, assign);
117119 + return gimple_assign_lhs(assign);
117120 +}
117121 +
117122 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117123 +{
117124 + tree new_rhs, orig_rhs;
117125 + void (*gimple_assign_set_rhs)(gimple, tree);
117126 + tree rhs1 = gimple_assign_rhs1(stmt);
117127 + tree rhs2 = gimple_assign_rhs2(stmt);
117128 + tree lhs = gimple_assign_lhs(stmt);
117129 +
117130 + if (!check_overflow)
117131 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117132 +
117133 + if (change_rhs == NULL_TREE)
117134 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117135 +
117136 + if (new_rhs2 == NULL_TREE) {
117137 + orig_rhs = rhs1;
117138 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117139 + } else {
117140 + orig_rhs = rhs2;
117141 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117142 + }
117143 +
117144 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117145 +
117146 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117147 + gimple_assign_set_rhs(stmt, new_rhs);
117148 + update_stmt(stmt);
117149 +
117150 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117151 +}
117152 +
117153 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117154 +{
117155 + gimple rhs1_def_stmt, rhs2_def_stmt;
117156 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117157 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117158 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117159 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117160 +
117161 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117162 + return false;
117163 +
117164 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117165 +
117166 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117167 + return false;
117168 +
117169 + rhs1_def_stmt = get_def_stmt(rhs1);
117170 + rhs2_def_stmt = get_def_stmt(rhs2);
117171 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117172 + return false;
117173 +
117174 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117175 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117176 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117177 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117178 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117179 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117180 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117181 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117182 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117183 + return false;
117184 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117185 + return false;
117186 +
117187 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117188 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117189 + return true;
117190 +}
117191 +
117192 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117193 +{
117194 + gimple assign;
117195 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117196 + tree type = TREE_TYPE(rhs1);
117197 + tree lhs = create_new_var(type);
117198 +
117199 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117200 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117201 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117202 +
117203 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117204 + update_stmt(assign);
117205 + pointer_set_insert(visited->my_stmts, assign);
117206 + return assign;
117207 +}
117208 +
117209 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117210 +{
117211 + gimple_stmt_iterator gsi;
117212 + gimple cast_stmt;
117213 + tree type = TREE_TYPE(node);
117214 +
117215 + if (types_compatible_p(type, intTI_type_node))
117216 + return node;
117217 +
117218 + gsi = gsi_for_stmt(stmt);
117219 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117220 + pointer_set_insert(visited->my_stmts, cast_stmt);
117221 + return gimple_assign_lhs(cast_stmt);
117222 +}
117223 +
117224 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117225 +{
117226 + tree rhs1, def_stmt_rhs1;
117227 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117228 +
117229 + def_stmt = get_def_stmt(var);
117230 + if (!gimple_assign_cast_p(def_stmt))
117231 + return NULL_TREE;
117232 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117233 +
117234 + rhs1 = gimple_assign_rhs1(def_stmt);
117235 + rhs1_def_stmt = get_def_stmt(rhs1);
117236 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117237 + return rhs1;
117238 +
117239 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117240 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117241 +
117242 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117243 + case GIMPLE_CALL:
117244 + case GIMPLE_NOP:
117245 + case GIMPLE_ASM:
117246 + case GIMPLE_PHI:
117247 + return def_stmt_rhs1;
117248 + case GIMPLE_ASSIGN:
117249 + return rhs1;
117250 + default:
117251 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117252 + gcc_unreachable();
117253 + }
117254 +}
117255 +
117256 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117257 +{
117258 + tree new_rhs1, new_rhs2;
117259 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117260 + gimple assign, stmt = get_def_stmt(lhs);
117261 + tree rhs1 = gimple_assign_rhs1(stmt);
117262 + tree rhs2 = gimple_assign_rhs2(stmt);
117263 +
117264 + if (!is_subtraction_special(visited, stmt))
117265 + return NULL_TREE;
117266 +
117267 + new_rhs1 = expand(visited, caller_node, rhs1);
117268 + new_rhs2 = expand(visited, caller_node, rhs2);
117269 +
117270 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117271 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117272 +
117273 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117274 + return NULL_TREE;
117275 +
117276 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117277 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117278 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117279 + }
117280 +
117281 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117282 + new_lhs = gimple_assign_lhs(assign);
117283 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117284 +
117285 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117286 +}
117287 +
117288 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117289 +{
117290 + const_gimple def_stmt;
117291 +
117292 + if (TREE_CODE(rhs) != SSA_NAME)
117293 + return false;
117294 +
117295 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117296 + return false;
117297 +
117298 + def_stmt = get_def_stmt(rhs);
117299 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117300 + return false;
117301 +
117302 + return true;
117303 +}
117304 +
117305 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117306 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117307 + * fffffff * 16 > signed max -> truncate
117308 + */
117309 +static bool look_for_mult_and_add(const_gimple stmt)
117310 +{
117311 + const_tree res;
117312 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117313 + const_gimple def_stmt;
117314 +
117315 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117316 + return false;
117317 + if (!is_gimple_assign(stmt))
117318 + return false;
117319 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117320 + return false;
117321 +
117322 + rhs1 = gimple_assign_rhs1(stmt);
117323 + rhs2 = gimple_assign_rhs2(stmt);
117324 + if (is_gimple_constant(rhs1)) {
117325 + const_rhs = rhs1;
117326 + def_stmt = get_def_stmt(rhs2);
117327 + } else if (is_gimple_constant(rhs2)) {
117328 + const_rhs = rhs2;
117329 + def_stmt = get_def_stmt(rhs1);
117330 + } else
117331 + return false;
117332 +
117333 + if (!is_gimple_assign(def_stmt))
117334 + return false;
117335 +
117336 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117337 + return false;
117338 +
117339 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117340 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117341 + if (is_gimple_constant(def_rhs1))
117342 + def_const_rhs = def_rhs1;
117343 + else if (is_gimple_constant(def_rhs2))
117344 + def_const_rhs = def_rhs2;
117345 + else
117346 + return false;
117347 +
117348 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117349 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117350 + return false;
117351 + return true;
117352 +}
117353 +
117354 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117355 +{
117356 + const_gimple def_stmt_1, def_stmt_2;
117357 + const_tree rhs1, rhs2;
117358 + bool add_mul_rhs1, add_mul_rhs2;
117359 +
117360 + rhs1 = gimple_assign_rhs1(stmt);
117361 + def_stmt_1 = get_def_stmt(rhs1);
117362 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117363 +
117364 + rhs2 = gimple_assign_rhs2(stmt);
117365 + def_stmt_2 = get_def_stmt(rhs2);
117366 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117367 +
117368 + if (add_mul_rhs1)
117369 + return RHS1_INTENTIONAL_OVERFLOW;
117370 + if (add_mul_rhs2)
117371 + return RHS2_INTENTIONAL_OVERFLOW;
117372 + return NO_INTENTIONAL_OVERFLOW;
117373 +}
117374 +
117375 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117376 +{
117377 + gimple my_stmt;
117378 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117379 +
117380 + gsi_next(&gsi);
117381 + my_stmt = gsi_stmt(gsi);
117382 +
117383 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117384 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117385 +
117386 + return my_stmt;
117387 +}
117388 +
117389 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117390 + * unsigned type cast to signed type, unsigned type: no more uses
117391 + * e.g., lib/vsprintf.c:simple_strtol()
117392 + * _10 = (unsigned long int) _9
117393 + * _11 = -_10;
117394 + * _12 = (long int) _11; (_11_ no more uses)
117395 + */
117396 +static bool is_call_or_cast(gimple stmt)
117397 +{
117398 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117399 +}
117400 +
117401 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117402 +{
117403 + const_tree rhs;
117404 + gimple def_stmt;
117405 +
117406 + if (node == NULL_TREE)
117407 + return true;
117408 + if (is_gimple_constant(node))
117409 + return true;
117410 +
117411 + def_stmt = get_def_stmt(node);
117412 + if (!def_stmt)
117413 + return false;
117414 +
117415 + if (is_call_or_cast(def_stmt))
117416 + return true;
117417 +
117418 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117419 + return false;
117420 + rhs = gimple_assign_rhs1(def_stmt);
117421 + def_stmt = get_def_stmt(rhs);
117422 + if (!def_stmt)
117423 + return false;
117424 + return is_call_or_cast(def_stmt);
117425 +}
117426 +
117427 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117428 +{
117429 + unsigned int use_num;
117430 + gimple so_stmt;
117431 + const_gimple def_stmt;
117432 + const_tree rhs1, rhs2;
117433 + tree rhs = gimple_assign_rhs1(stmt);
117434 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117435 + const_tree rhs_type = TREE_TYPE(rhs);
117436 +
117437 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117438 + return;
117439 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117440 + return;
117441 + use_num = uses_num(rhs);
117442 + if (use_num != 1)
117443 + return;
117444 +
117445 + def_stmt = get_def_stmt(rhs);
117446 + if (!def_stmt)
117447 + return;
117448 + if (!is_gimple_assign(def_stmt))
117449 + return;
117450 +
117451 + rhs1 = gimple_assign_rhs1(def_stmt);
117452 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117453 + return;
117454 +
117455 + rhs2 = gimple_assign_rhs2(def_stmt);
117456 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117457 + return;
117458 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117459 + return;
117460 +
117461 + so_stmt = get_dup_stmt(visited, stmt);
117462 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117463 +}
117464 +
117465 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117466 new file mode 100644
117467 index 0000000..4bddad2
117468 --- /dev/null
117469 +++ b/tools/gcc/size_overflow_plugin/misc.c
117470 @@ -0,0 +1,203 @@
117471 +/*
117472 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117473 + * Licensed under the GPL v2, or (at your option) v3
117474 + *
117475 + * Homepage:
117476 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117477 + *
117478 + * Documentation:
117479 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117480 + *
117481 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117482 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117483 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117484 + *
117485 + * Usage:
117486 + * $ make
117487 + * $ make run
117488 + */
117489 +
117490 +#include "gcc-common.h"
117491 +#include "size_overflow.h"
117492 +
117493 +void set_current_function_decl(tree fndecl)
117494 +{
117495 + gcc_assert(fndecl != NULL_TREE);
117496 +
117497 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117498 + calculate_dominance_info(CDI_DOMINATORS);
117499 + current_function_decl = fndecl;
117500 +}
117501 +
117502 +void unset_current_function_decl(void)
117503 +{
117504 + free_dominance_info(CDI_DOMINATORS);
117505 + pop_cfun();
117506 + current_function_decl = NULL_TREE;
117507 +}
117508 +
117509 +static bool is_bool(const_tree node)
117510 +{
117511 + const_tree type;
117512 +
117513 + if (node == NULL_TREE)
117514 + return false;
117515 +
117516 + type = TREE_TYPE(node);
117517 + if (!INTEGRAL_TYPE_P(type))
117518 + return false;
117519 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117520 + return true;
117521 + if (TYPE_PRECISION(type) == 1)
117522 + return true;
117523 + return false;
117524 +}
117525 +
117526 +bool skip_types(const_tree var)
117527 +{
117528 + tree type;
117529 + enum tree_code code;
117530 +
117531 + if (is_gimple_constant(var))
117532 + return true;
117533 +
117534 + switch (TREE_CODE(var)) {
117535 + case ADDR_EXPR:
117536 +#if BUILDING_GCC_VERSION >= 4006
117537 + case MEM_REF:
117538 +#endif
117539 + case ARRAY_REF:
117540 + case BIT_FIELD_REF:
117541 + case INDIRECT_REF:
117542 + case TARGET_MEM_REF:
117543 + case COMPONENT_REF:
117544 + case VAR_DECL:
117545 + case VIEW_CONVERT_EXPR:
117546 + return true;
117547 + default:
117548 + break;
117549 + }
117550 +
117551 + code = TREE_CODE(var);
117552 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117553 +
117554 + type = TREE_TYPE(var);
117555 + switch (TREE_CODE(type)) {
117556 + case INTEGER_TYPE:
117557 + case ENUMERAL_TYPE:
117558 + return false;
117559 + case BOOLEAN_TYPE:
117560 + return is_bool(var);
117561 + default:
117562 + return true;
117563 + }
117564 +}
117565 +
117566 +gimple get_def_stmt(const_tree node)
117567 +{
117568 + gcc_assert(node != NULL_TREE);
117569 +
117570 + if (skip_types(node))
117571 + return NULL;
117572 +
117573 + if (TREE_CODE(node) != SSA_NAME)
117574 + return NULL;
117575 + return SSA_NAME_DEF_STMT(node);
117576 +}
117577 +
117578 +tree create_new_var(tree type)
117579 +{
117580 + tree new_var = create_tmp_var(type, "cicus");
117581 +
117582 + add_referenced_var(new_var);
117583 + return new_var;
117584 +}
117585 +
117586 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117587 +{
117588 + const_gimple def_stmt = get_def_stmt(rhs);
117589 +
117590 + if (force)
117591 + return false;
117592 +
117593 + if (is_gimple_constant(rhs))
117594 + return false;
117595 +
117596 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117597 + return false;
117598 +
117599 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117600 + return false;
117601 +
117602 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117603 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117604 + return false;
117605 +
117606 + return true;
117607 +}
117608 +
117609 +tree cast_a_tree(tree type, tree var)
117610 +{
117611 + gcc_assert(type != NULL_TREE);
117612 + gcc_assert(var != NULL_TREE);
117613 + gcc_assert(fold_convertible_p(type, var));
117614 +
117615 + return fold_convert(type, var);
117616 +}
117617 +
117618 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117619 +{
117620 + gimple assign, def_stmt;
117621 +
117622 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117623 + gcc_assert(!is_gimple_constant(rhs));
117624 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117625 + gcc_unreachable();
117626 +
117627 + def_stmt = get_def_stmt(rhs);
117628 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117629 + return def_stmt;
117630 +
117631 + if (lhs == CREATE_NEW_VAR)
117632 + lhs = create_new_var(dst_type);
117633 +
117634 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117635 +
117636 + if (!gsi_end_p(*gsi)) {
117637 + location_t loc = gimple_location(gsi_stmt(*gsi));
117638 + gimple_set_location(assign, loc);
117639 + }
117640 +
117641 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117642 +
117643 + if (before)
117644 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117645 + else
117646 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117647 + update_stmt(assign);
117648 + return assign;
117649 +}
117650 +
117651 +bool is_size_overflow_type(const_tree var)
117652 +{
117653 + const char *name;
117654 + const_tree type_name, type;
117655 +
117656 + if (var == NULL_TREE)
117657 + return false;
117658 +
117659 + type = TREE_TYPE(var);
117660 + type_name = TYPE_NAME(type);
117661 + if (type_name == NULL_TREE)
117662 + return false;
117663 +
117664 + if (DECL_P(type_name))
117665 + name = DECL_NAME_POINTER(type_name);
117666 + else
117667 + name = IDENTIFIER_POINTER(type_name);
117668 +
117669 + if (!strncmp(name, "size_overflow_type", 18))
117670 + return true;
117671 + return false;
117672 +}
117673 +
117674 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117675 new file mode 100644
117676 index 0000000..7c9e6d1
117677 --- /dev/null
117678 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117679 @@ -0,0 +1,138 @@
117680 +/*
117681 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117682 + * Licensed under the GPL v2, or (at your option) v3
117683 + *
117684 + * Homepage:
117685 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117686 + *
117687 + * Documentation:
117688 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117689 + *
117690 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117691 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117692 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117693 + *
117694 + * Usage:
117695 + * $ make
117696 + * $ make run
117697 + */
117698 +
117699 +#include "gcc-common.h"
117700 +#include "size_overflow.h"
117701 +
117702 +bool skip_expr_on_double_type(const_gimple stmt)
117703 +{
117704 + enum tree_code code = gimple_assign_rhs_code(stmt);
117705 +
117706 + switch (code) {
117707 + case RSHIFT_EXPR:
117708 + case TRUNC_DIV_EXPR:
117709 + case CEIL_DIV_EXPR:
117710 + case FLOOR_DIV_EXPR:
117711 + case ROUND_DIV_EXPR:
117712 + case EXACT_DIV_EXPR:
117713 + case RDIV_EXPR:
117714 + case TRUNC_MOD_EXPR:
117715 + case CEIL_MOD_EXPR:
117716 + case FLOOR_MOD_EXPR:
117717 + case ROUND_MOD_EXPR:
117718 + return true;
117719 + default:
117720 + return false;
117721 + }
117722 +}
117723 +
117724 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
117725 +{
117726 + const_tree orig_rhs1;
117727 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
117728 + gimple down_cast, up_cast;
117729 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
117730 +
117731 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117732 + down_lhs = gimple_assign_lhs(down_cast);
117733 +
117734 + gsi = gsi_for_stmt(use_stmt);
117735 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117736 + new_lhs = gimple_assign_lhs(up_cast);
117737 +
117738 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
117739 + if (operand_equal_p(orig_rhs1, rhs, 0))
117740 + gimple_assign_set_rhs1(use_stmt, new_lhs);
117741 + else
117742 + gimple_assign_set_rhs2(use_stmt, new_lhs);
117743 + update_stmt(use_stmt);
117744 +
117745 + pointer_set_insert(visited->my_stmts, up_cast);
117746 + pointer_set_insert(visited->my_stmts, down_cast);
117747 + pointer_set_insert(visited->skip_expr_casts, up_cast);
117748 + pointer_set_insert(visited->skip_expr_casts, down_cast);
117749 +}
117750 +
117751 +static tree get_proper_unsigned_half_type(const_tree node)
117752 +{
117753 + tree new_type, type;
117754 +
117755 + gcc_assert(is_size_overflow_type(node));
117756 +
117757 + type = TREE_TYPE(node);
117758 + switch (TYPE_MODE(type)) {
117759 + case HImode:
117760 + new_type = unsigned_intQI_type_node;
117761 + break;
117762 + case SImode:
117763 + new_type = unsigned_intHI_type_node;
117764 + break;
117765 + case DImode:
117766 + new_type = unsigned_intSI_type_node;
117767 + break;
117768 + case TImode:
117769 + new_type = unsigned_intDI_type_node;
117770 + break;
117771 + default:
117772 + gcc_unreachable();
117773 + }
117774 +
117775 + if (TYPE_QUALS(type) != 0)
117776 + return build_qualified_type(new_type, TYPE_QUALS(type));
117777 + return new_type;
117778 +}
117779 +
117780 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
117781 +{
117782 + tree type;
117783 +
117784 + if (rhs == NULL_TREE)
117785 + return;
117786 + if (!is_size_overflow_type(rhs))
117787 + return;
117788 +
117789 + type = get_proper_unsigned_half_type(rhs);
117790 + if (is_gimple_constant(rhs))
117791 + return;
117792 + create_up_and_down_cast(visited, stmt, type, rhs);
117793 +}
117794 +
117795 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
117796 +{
117797 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
117798 + return;
117799 + gcc_assert(is_size_overflow_type(rhs));
117800 + insert_cast_rhs(visited, stmt, rhs);
117801 +}
117802 +
117803 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
117804 +{
117805 + tree rhs1, rhs2;
117806 +
117807 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
117808 + rhs1 = gimple_assign_rhs1(stmt);
117809 + insert_cast(visited, stmt, rhs1);
117810 + }
117811 +
117812 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
117813 + rhs2 = gimple_assign_rhs2(stmt);
117814 + insert_cast(visited, stmt, rhs2);
117815 + }
117816 +}
117817 +
117818 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
117819 new file mode 100644
117820 index 0000000..e5b4e50
117821 --- /dev/null
117822 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
117823 @@ -0,0 +1,127 @@
117824 +#ifndef SIZE_OVERFLOW_H
117825 +#define SIZE_OVERFLOW_H
117826 +
117827 +#define CREATE_NEW_VAR NULL_TREE
117828 +#define CANNOT_FIND_ARG 32
117829 +#define MAX_PARAM 31
117830 +#define BEFORE_STMT true
117831 +#define AFTER_STMT false
117832 +
117833 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
117834 +#define YES_ASM_STR "# size_overflow MARK_YES "
117835 +#define OK_ASM_STR "# size_overflow "
117836 +
117837 +enum mark {
117838 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
117839 +};
117840 +
117841 +enum intentional_overflow_type {
117842 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
117843 +};
117844 +
117845 +struct visited {
117846 + struct pointer_set_t *stmts;
117847 + struct pointer_set_t *my_stmts;
117848 + struct pointer_set_t *skip_expr_casts;
117849 + struct pointer_set_t *no_cast_check;
117850 +};
117851 +
117852 +// size_overflow_plugin.c
117853 +extern tree report_size_overflow_decl;
117854 +extern tree size_overflow_type_HI;
117855 +extern tree size_overflow_type_SI;
117856 +extern tree size_overflow_type_DI;
117857 +extern tree size_overflow_type_TI;
117858 +
117859 +
117860 +// size_overflow_plugin_hash.c
117861 +struct size_overflow_hash {
117862 + const struct size_overflow_hash * const next;
117863 + const char * const name;
117864 + const unsigned int param;
117865 +};
117866 +
117867 +struct interesting_node {
117868 + struct interesting_node *next;
117869 + gimple first_stmt;
117870 + const_tree fndecl;
117871 + tree node;
117872 +#if BUILDING_GCC_VERSION <= 4007
117873 + VEC(tree, gc) *last_nodes;
117874 +#else
117875 + vec<tree, va_gc> *last_nodes;
117876 +#endif
117877 + unsigned int num;
117878 + enum mark intentional_attr_decl;
117879 + enum mark intentional_attr_cur_fndecl;
117880 + gimple intentional_mark_from_gimple;
117881 +};
117882 +
117883 +extern bool is_size_overflow_asm(const_gimple stmt);
117884 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
117885 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
117886 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
117887 +extern bool is_a_return_check(const_tree node);
117888 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
117889 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
117890 +
117891 +
117892 +// size_overflow_debug.c
117893 +extern struct opt_pass *make_dump_pass(void);
117894 +
117895 +
117896 +// intentional_overflow.c
117897 +extern enum mark get_intentional_attr_type(const_tree node);
117898 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
117899 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
117900 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
117901 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
117902 +extern bool is_turn_off_intentional_attr(const_tree decl);
117903 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
117904 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
117905 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
117906 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
117907 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
117908 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
117909 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
117910 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
117911 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
117912 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
117913 +
117914 +
117915 +// insert_size_overflow_check_ipa.c
117916 +extern unsigned int search_function(void);
117917 +extern unsigned int call_count;
117918 +extern struct opt_pass *make_insert_size_overflow_check(void);
117919 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
117920 +
117921 +
117922 +// insert_size_overflow_asm.c
117923 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
117924 +
117925 +
117926 +// misc.c
117927 +extern void set_current_function_decl(tree fndecl);
117928 +extern void unset_current_function_decl(void);
117929 +extern gimple get_def_stmt(const_tree node);
117930 +extern tree create_new_var(tree type);
117931 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
117932 +extern bool skip_types(const_tree var);
117933 +extern tree cast_a_tree(tree type, tree var);
117934 +extern bool is_size_overflow_type(const_tree var);
117935 +
117936 +
117937 +// insert_size_overflow_check_core.c
117938 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
117939 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
117940 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
117941 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
117942 +
117943 +
117944 +// remove_unnecessary_dup.c
117945 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
117946 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
117947 +extern bool skip_expr_on_double_type(const_gimple stmt);
117948 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
117949 +
117950 +#endif
117951 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117952 new file mode 100644
117953 index 0000000..4378111
117954 --- /dev/null
117955 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117956 @@ -0,0 +1,116 @@
117957 +/*
117958 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117959 + * Licensed under the GPL v2, or (at your option) v3
117960 + *
117961 + * Homepage:
117962 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117963 + *
117964 + * Documentation:
117965 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117966 + *
117967 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117968 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117969 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117970 + *
117971 + * Usage:
117972 + * $ make
117973 + * $ make run
117974 + */
117975 +
117976 +#include "gcc-common.h"
117977 +
117978 +static unsigned int dump_functions(void)
117979 +{
117980 + struct cgraph_node *node;
117981 +
117982 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117983 + basic_block bb;
117984 +
117985 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117986 + current_function_decl = NODE_DECL(node);
117987 +
117988 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117989 +
117990 + FOR_ALL_BB_FN(bb, cfun) {
117991 + gimple_stmt_iterator si;
117992 +
117993 + fprintf(stderr, "<bb %u>:\n", bb->index);
117994 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117995 + debug_gimple_stmt(gsi_stmt(si));
117996 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117997 + debug_gimple_stmt(gsi_stmt(si));
117998 + fprintf(stderr, "\n");
117999 + }
118000 +
118001 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118002 +
118003 + pop_cfun();
118004 + current_function_decl = NULL_TREE;
118005 + }
118006 +
118007 + fprintf(stderr, "###############################################################################\n");
118008 +
118009 + return 0;
118010 +}
118011 +
118012 +#if BUILDING_GCC_VERSION >= 4009
118013 +static const struct pass_data dump_pass_data = {
118014 +#else
118015 +static struct ipa_opt_pass_d dump_pass = {
118016 + .pass = {
118017 +#endif
118018 + .type = SIMPLE_IPA_PASS,
118019 + .name = "dump",
118020 +#if BUILDING_GCC_VERSION >= 4008
118021 + .optinfo_flags = OPTGROUP_NONE,
118022 +#endif
118023 +#if BUILDING_GCC_VERSION >= 4009
118024 + .has_gate = false,
118025 + .has_execute = true,
118026 +#else
118027 + .gate = NULL,
118028 + .execute = dump_functions,
118029 + .sub = NULL,
118030 + .next = NULL,
118031 + .static_pass_number = 0,
118032 +#endif
118033 + .tv_id = TV_NONE,
118034 + .properties_required = 0,
118035 + .properties_provided = 0,
118036 + .properties_destroyed = 0,
118037 + .todo_flags_start = 0,
118038 + .todo_flags_finish = 0,
118039 +#if BUILDING_GCC_VERSION < 4009
118040 + },
118041 + .generate_summary = NULL,
118042 + .write_summary = NULL,
118043 + .read_summary = NULL,
118044 +#if BUILDING_GCC_VERSION >= 4006
118045 + .write_optimization_summary = NULL,
118046 + .read_optimization_summary = NULL,
118047 +#endif
118048 + .stmt_fixup = NULL,
118049 + .function_transform_todo_flags_start = 0,
118050 + .function_transform = NULL,
118051 + .variable_transform = NULL,
118052 +#endif
118053 +};
118054 +
118055 +#if BUILDING_GCC_VERSION >= 4009
118056 +namespace {
118057 +class dump_pass : public ipa_opt_pass_d {
118058 +public:
118059 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118060 + unsigned int execute() { return dump_functions(); }
118061 +};
118062 +}
118063 +#endif
118064 +
118065 +struct opt_pass *make_dump_pass(void)
118066 +{
118067 +#if BUILDING_GCC_VERSION >= 4009
118068 + return new dump_pass();
118069 +#else
118070 + return &dump_pass.pass;
118071 +#endif
118072 +}
118073 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118074 new file mode 100644
118075 index 0000000..4dc6368
118076 --- /dev/null
118077 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118078 @@ -0,0 +1,5850 @@
118079 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118080 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118081 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118082 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118083 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118084 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118085 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118086 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118087 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118088 +load_msg_95 load_msg 2 95 NULL
118089 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118090 +init_q_132 init_q 4 132 NULL
118091 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118092 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118093 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118094 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118095 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118096 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118097 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118098 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118099 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118100 +br_port_info_size_268 br_port_info_size 0 268 NULL
118101 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118102 +SYSC_connect_304 SYSC_connect 3 304 NULL
118103 +syslog_print_307 syslog_print 2 307 NULL
118104 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118105 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118106 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118107 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118108 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118109 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118110 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118111 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118112 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118113 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118114 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118115 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118116 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118117 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118118 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118119 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118120 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118121 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118122 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118123 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118124 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118125 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118126 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118127 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118128 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118129 +unlink_queued_645 unlink_queued 4 645 NULL
118130 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118131 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118132 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118133 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118134 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118135 +dvb_video_write_754 dvb_video_write 3 754 NULL
118136 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118137 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118138 +if_writecmd_815 if_writecmd 2 815 NULL
118139 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118140 +error_state_read_859 error_state_read 6 859 NULL
118141 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118142 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118143 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118144 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118145 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118146 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118147 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118148 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118149 +readreg_1017 readreg 0-1 1017 NULL
118150 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118151 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118152 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118153 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118154 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118155 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118156 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118157 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118158 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118159 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118160 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118161 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118162 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118163 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118164 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118165 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118166 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118167 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118168 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118169 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118170 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118171 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118172 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118173 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118174 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118175 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118176 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118177 +ffs_1322 ffs 0 1322 NULL
118178 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118179 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118180 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118181 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118182 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118183 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118184 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118185 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118186 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118187 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118188 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118189 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118190 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118191 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118192 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118193 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118194 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118195 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118196 +fpregs_set_1497 fpregs_set 4 1497 NULL
118197 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118198 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118199 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118200 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118201 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118202 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118203 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118204 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118205 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118206 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118207 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118208 +rmap_add_1677 rmap_add 3 1677 NULL
118209 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118210 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118211 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118212 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118213 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118214 +internal_create_group_1733 internal_create_group 0 1733 NULL
118215 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118216 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118217 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118218 +cosa_write_1774 cosa_write 3 1774 NULL
118219 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118220 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118221 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118222 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118223 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118224 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118225 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118226 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118227 +azx_get_position_1927 azx_get_position 0 1927 NULL
118228 +bdev_erase_1933 bdev_erase 3 1933 NULL
118229 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118230 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118231 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118232 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118233 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118234 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118235 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118236 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118237 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118238 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118239 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118240 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118241 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118242 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118243 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118244 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118245 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118246 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118247 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118248 +audit_expand_2098 audit_expand 0 2098 NULL
118249 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118250 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118251 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118252 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118253 +enable_read_2117 enable_read 3 2117 NULL
118254 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118255 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118256 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118257 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118258 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118259 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118260 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118261 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118262 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118263 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118264 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118265 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118266 +do_update_counters_2259 do_update_counters 4 2259 NULL
118267 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118268 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118269 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118270 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118271 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118272 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118273 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118274 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118275 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118276 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118277 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118278 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118279 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118280 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118281 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118282 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118283 +raid1_size_2419 raid1_size 0-2 2419 NULL
118284 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118285 +wiphy_new_2482 wiphy_new 2 2482 NULL
118286 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118287 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118288 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118289 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118290 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118291 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118292 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118293 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118294 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118295 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118296 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118297 +slot_bytes_2609 slot_bytes 0 2609 NULL
118298 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118299 +switch_status_2629 switch_status 5 2629 NULL
118300 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118301 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118302 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118303 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118304 +oti6858_write_2692 oti6858_write 4 2692 NULL
118305 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118306 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118307 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118308 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118309 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118310 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118311 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118312 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118313 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118314 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118315 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118316 +sock_create_2838 sock_create 0 2838 NULL
118317 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118318 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118319 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118320 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118321 +nla_padlen_2883 nla_padlen 1 2883 NULL
118322 +cmm_write_2896 cmm_write 3 2896 NULL
118323 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118324 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118325 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118326 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118327 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118328 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118329 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118330 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118331 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118332 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118333 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118334 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118335 +depth_write_3021 depth_write 3 3021 NULL
118336 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118337 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118338 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118339 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118340 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118341 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118342 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118343 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118344 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118345 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118346 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118347 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118348 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118349 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118350 +rb_alloc_3102 rb_alloc 1 3102 NULL
118351 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118352 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118353 +print_time_3132 print_time 0 3132 NULL
118354 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118355 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118356 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118357 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118358 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118359 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118360 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118361 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118362 +alloc_context_3194 alloc_context 1 3194 NULL
118363 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118364 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118365 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118366 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118367 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118368 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118369 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118370 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118371 +key_key_read_3241 key_key_read 3 3241 NULL
118372 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118373 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118374 +cgroup_name_3300 cgroup_name 3 3300 NULL
118375 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118376 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118377 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118378 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118379 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118380 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118381 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118382 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118383 +scnprintf_3360 scnprintf 0-2 3360 NULL
118384 +sr_read_3366 sr_read 3 3366 NULL
118385 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118386 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118387 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118388 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118389 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118390 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118391 +softsynth_write_3455 softsynth_write 3 3455 NULL
118392 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118393 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118394 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118395 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118396 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118397 +SyS_readv_3539 SyS_readv 3 3539 NULL
118398 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118399 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118400 +evtchn_read_3569 evtchn_read 3 3569 NULL
118401 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118402 +vc_resize_3585 vc_resize 3-2 3585 NULL
118403 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118404 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118405 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118406 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118407 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118408 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118409 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118410 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118411 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118412 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118413 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118414 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118415 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118416 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118417 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118418 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118419 +get_fd_set_3866 get_fd_set 1 3866 NULL
118420 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118421 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118422 +nvram_write_3894 nvram_write 3 3894 NULL
118423 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118424 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118425 +vcs_write_3910 vcs_write 3 3910 NULL
118426 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118427 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118428 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118429 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118430 +do_add_counters_3992 do_add_counters 3 3992 NULL
118431 +userspace_status_4004 userspace_status 4 4004 NULL
118432 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118433 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118434 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118435 +blk_end_request_4024 blk_end_request 3 4024 NULL
118436 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118437 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118438 +read_file_queues_4078 read_file_queues 3 4078 NULL
118439 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118440 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118441 +tm6000_read_4151 tm6000_read 3 4151 NULL
118442 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118443 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118444 +get_alua_req_4166 get_alua_req 3 4166 NULL
118445 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118446 +read_file_bool_4180 read_file_bool 3 4180 NULL
118447 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118448 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118449 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118450 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118451 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118452 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118453 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118454 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118455 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118456 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118457 +count_strings_4315 count_strings 0 4315 NULL
118458 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118459 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118460 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118461 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118462 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118463 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118464 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118465 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118466 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118467 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118468 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118469 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118470 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118471 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118472 +set_link_security_4502 set_link_security 4 4502 NULL
118473 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118474 +tty_register_device_4544 tty_register_device 2 4544 NULL
118475 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118476 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118477 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118478 +bch_alloc_4593 bch_alloc 1 4593 NULL
118479 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118480 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118481 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118482 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118483 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118484 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118485 +kone_receive_4690 kone_receive 4 4690 NULL
118486 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118487 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118488 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118489 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118490 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118491 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118492 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118493 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118494 +create_subvol_4791 create_subvol 4 4791 NULL
118495 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118496 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118497 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118498 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118499 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118500 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118501 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118502 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118503 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118504 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118505 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118506 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118507 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118508 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118509 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118510 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118511 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118512 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118513 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118514 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118515 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118516 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118517 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118518 +sound_write_5102 sound_write 3 5102 NULL
118519 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118520 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118521 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118522 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118523 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118524 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118525 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118526 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118527 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118528 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118529 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118530 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118531 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118532 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118533 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118534 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118535 +cq_free_res_5355 cq_free_res 5 5355 NULL
118536 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118537 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118538 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118539 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118540 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118541 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118542 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118543 +tty_write_5494 tty_write 3 5494 NULL
118544 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118545 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118546 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118547 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118548 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118549 +le_readq_5557 le_readq 0 5557 NULL
118550 +inw_5558 inw 0 5558 NULL
118551 +bioset_create_5580 bioset_create 1 5580 NULL
118552 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118553 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118554 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118555 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118556 +get_arg_5694 get_arg 3 5694 NULL
118557 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118558 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118559 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118560 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118561 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118562 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
118563 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118564 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118565 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118566 +setup_req_5848 setup_req 3 5848 NULL
118567 +ria_page_count_5849 ria_page_count 0 5849 NULL
118568 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118569 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118570 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118571 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118572 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118573 +port_show_regs_5904 port_show_regs 3 5904 NULL
118574 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118575 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118576 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118577 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118578 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118579 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118580 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118581 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118582 +SyS_semop_5980 SyS_semop 3 5980 NULL
118583 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118584 +alloc_msg_6072 alloc_msg 1 6072 NULL
118585 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118586 +_random_read_6098 _random_read 3 6098 NULL
118587 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118588 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118589 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118590 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118591 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118592 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118593 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118594 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118595 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118596 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118597 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118598 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118599 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118600 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118601 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118602 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118603 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118604 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118605 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118606 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118607 +serial_port_in_6291 serial_port_in 0 6291 NULL
118608 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118609 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118610 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118611 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118612 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118613 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118614 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118615 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118616 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118617 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118618 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118619 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118620 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118621 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118622 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118623 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118624 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118625 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118626 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118627 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118628 +mei_read_6507 mei_read 3 6507 NULL
118629 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118630 +wdm_read_6549 wdm_read 3 6549 NULL
118631 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118632 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118633 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118634 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118635 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118636 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118637 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118638 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118639 +mpeg_read_6708 mpeg_read 3 6708 NULL
118640 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118641 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118642 +video_proc_write_6724 video_proc_write 3 6724 NULL
118643 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118644 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118645 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118646 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118647 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118648 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118649 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118650 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118651 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118652 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118653 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118654 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118655 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118656 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118657 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118658 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118659 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118660 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118661 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118662 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118663 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118664 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118665 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118666 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118667 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118668 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118669 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118670 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118671 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118672 +request_key_async_6990 request_key_async 4 6990 NULL
118673 +tpl_write_6998 tpl_write 3 6998 NULL
118674 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118675 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118676 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118677 +wimax_msg_7030 wimax_msg 4 7030 NULL
118678 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118679 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118680 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118681 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118682 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118683 +event_enable_read_7074 event_enable_read 3 7074 NULL
118684 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118685 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118686 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118687 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
118688 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
118689 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
118690 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
118691 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
118692 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
118693 +get_string_7302 get_string 0 7302 NULL
118694 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
118695 +mgmt_control_7349 mgmt_control 3 7349 NULL
118696 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
118697 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
118698 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
118699 +hweight_long_7388 hweight_long 0-1 7388 NULL
118700 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
118701 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
118702 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
118703 +readb_7401 readb 0 7401 NULL
118704 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
118705 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
118706 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
118707 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
118708 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
118709 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
118710 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
118711 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
118712 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
118713 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
118714 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
118715 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
118716 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
118717 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
118718 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
118719 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
118720 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
118721 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
118722 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
118723 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
118724 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
118725 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
118726 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
118727 +dev_write_7708 dev_write 3 7708 NULL
118728 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
118729 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
118730 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
118731 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
118732 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
118733 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
118734 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
118735 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
118736 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
118737 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
118738 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
118739 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
118740 +config_desc_7878 config_desc 0 7878 NULL
118741 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
118742 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
118743 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
118744 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
118745 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
118746 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
118747 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
118748 +vcs_read_8017 vcs_read 3 8017 NULL
118749 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
118750 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
118751 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
118752 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
118753 +venus_lookup_8121 venus_lookup 4 8121 NULL
118754 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
118755 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
118756 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
118757 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
118758 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
118759 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
118760 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
118761 +play_iframe_8219 play_iframe 3 8219 NULL
118762 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
118763 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
118764 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
118765 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
118766 +init_cdev_8274 init_cdev 1 8274 NULL
118767 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
118768 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
118769 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
118770 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
118771 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
118772 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
118773 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
118774 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
118775 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
118776 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
118777 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
118778 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
118779 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
118780 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
118781 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
118782 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
118783 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
118784 +dev_config_8506 dev_config 3 8506 NULL
118785 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
118786 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
118787 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
118788 +user_on_off_8552 user_on_off 2 8552 NULL
118789 +profile_remove_8556 profile_remove 3 8556 NULL
118790 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
118791 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
118792 +tower_write_8580 tower_write 3 8580 NULL
118793 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
118794 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
118795 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
118796 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
118797 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
118798 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
118799 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
118800 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
118801 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
118802 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
118803 +arcfb_write_8702 arcfb_write 3 8702 NULL
118804 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
118805 +init_header_8703 init_header 0 8703 &i_size_read_8703
118806 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
118807 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
118808 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
118809 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
118810 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
118811 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
118812 +compound_order_8750 compound_order 0 8750 NULL
118813 +yurex_write_8761 yurex_write 3 8761 NULL
118814 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
118815 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
118816 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
118817 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
118818 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
118819 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
118820 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
118821 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
118822 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
118823 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
118824 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
118825 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
118826 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
118827 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
118828 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
118829 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
118830 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
118831 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
118832 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
118833 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
118834 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
118835 +write_file_ani_8918 write_file_ani 3 8918 NULL
118836 +layout_commit_8926 layout_commit 3 8926 NULL
118837 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
118838 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
118839 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
118840 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
118841 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
118842 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
118843 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
118844 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
118845 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
118846 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
118847 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
118848 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
118849 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
118850 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
118851 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
118852 +nla_put_9042 nla_put 3 9042 NULL
118853 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
118854 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
118855 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
118856 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
118857 +create_queues_9088 create_queues 2-3 9088 NULL
118858 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
118859 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
118860 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
118861 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
118862 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
118863 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
118864 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
118865 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
118866 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
118867 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
118868 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
118869 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
118870 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
118871 +card_send_command_9215 card_send_command 3 9215 NULL
118872 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
118873 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
118874 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
118875 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
118876 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
118877 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
118878 +flakey_status_9274 flakey_status 5 9274 NULL
118879 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
118880 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
118881 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
118882 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
118883 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
118884 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
118885 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
118886 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
118887 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
118888 +read_9397 read 3 9397 NULL
118889 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
118890 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
118891 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
118892 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
118893 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
118894 +get_registers_9470 get_registers 4 9470 NULL nohasharray
118895 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
118896 +crypt_status_9492 crypt_status 5 9492 NULL
118897 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
118898 +lp_write_9511 lp_write 3 9511 NULL
118899 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
118900 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
118901 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
118902 +read_file_dma_9530 read_file_dma 3 9530 NULL
118903 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
118904 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
118905 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
118906 +fw_node_create_9559 fw_node_create 2 9559 NULL
118907 +kobj_map_9566 kobj_map 2-3 9566 NULL
118908 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
118909 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
118910 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
118911 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
118912 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
118913 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
118914 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
118915 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
118916 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
118917 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
118918 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
118919 +dns_query_9676 dns_query 3 9676 NULL
118920 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
118921 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
118922 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
118923 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
118924 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
118925 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
118926 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
118927 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
118928 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
118929 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
118930 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
118931 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
118932 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
118933 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
118934 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
118935 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
118936 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
118937 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
118938 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
118939 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
118940 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
118941 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
118942 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
118943 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
118944 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
118945 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
118946 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
118947 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
118948 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
118949 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
118950 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
118951 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
118952 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
118953 +read_file_misc_9948 read_file_misc 3 9948 NULL
118954 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
118955 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
118956 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
118957 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
118958 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
118959 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
118960 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
118961 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
118962 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
118963 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
118964 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
118965 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
118966 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
118967 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
118968 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
118969 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
118970 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
118971 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
118972 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
118973 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
118974 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
118975 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
118976 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
118977 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
118978 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
118979 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
118980 +read_emulate_10310 read_emulate 2-4 10310 NULL
118981 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
118982 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
118983 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
118984 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
118985 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
118986 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
118987 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
118988 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
118989 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
118990 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
118991 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
118992 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
118993 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
118994 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
118995 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
118996 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
118997 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
118998 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
118999 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119000 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119001 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119002 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119003 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119004 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119005 +otp_read_10594 otp_read 2-4-5 10594 NULL
119006 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119007 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119008 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119009 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119010 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119011 +parport_write_10669 parport_write 0 10669 NULL
119012 +edge_write_10692 edge_write 4 10692 NULL
119013 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119014 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119015 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119016 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119017 +spi_sync_10731 spi_sync 0 10731 NULL
119018 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119019 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119020 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119021 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119022 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119023 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119024 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119025 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119026 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119027 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119028 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119029 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119030 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119031 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119032 +get_scq_10897 get_scq 2 10897 NULL
119033 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119034 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119035 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119036 +kobject_add_10919 kobject_add 0 10919 NULL
119037 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119038 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119039 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119040 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119041 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119042 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119043 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119044 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119045 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119046 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
119047 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119048 +count_argc_11083 count_argc 0 11083 NULL
119049 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119050 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119051 +page_offset_11120 page_offset 0 11120 NULL
119052 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119053 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119054 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119055 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119056 +of_irq_count_11253 of_irq_count 0 11253 NULL
119057 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119058 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119059 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119060 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119061 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119062 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119063 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119064 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119065 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119066 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119067 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119068 +next_segment_11330 next_segment 0-2-1 11330 NULL
119069 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119070 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119071 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119072 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119073 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119074 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119075 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119076 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119077 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119078 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119079 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119080 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119081 +str_to_user_11411 str_to_user 2 11411 NULL
119082 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119083 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119084 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119085 +trace_options_read_11419 trace_options_read 3 11419 NULL
119086 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119087 +bttv_read_11432 bttv_read 3 11432 NULL
119088 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119089 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119090 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119091 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119092 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119093 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119094 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119095 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119096 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119097 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119098 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119099 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119100 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119101 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119102 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119103 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119104 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119105 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119106 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119107 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119108 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119109 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119110 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119111 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119112 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119113 +split_11691 split 2 11691 NULL
119114 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119115 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119116 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119117 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119118 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119119 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119120 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119121 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119122 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119123 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119124 +umc_device_register_11824 umc_device_register 0 11824 NULL
119125 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119126 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119127 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119128 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119129 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119130 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119131 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119132 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119133 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119134 +ti_write_11916 ti_write 4 11916 NULL
119135 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119136 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119137 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119138 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119139 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119140 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119141 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119142 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119143 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119144 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119145 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119146 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119147 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119148 +set_powered_12129 set_powered 4 12129 NULL
119149 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119150 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119151 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119152 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119153 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119154 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119155 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119156 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119157 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119158 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119159 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119160 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119161 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119162 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119163 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119164 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119165 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119166 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119167 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119168 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119169 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119170 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119171 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119172 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119173 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119174 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119175 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119176 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119177 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119178 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119179 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119180 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119181 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119182 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119183 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119184 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119185 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119186 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119187 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119188 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119189 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119190 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119191 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119192 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119193 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119194 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119195 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119196 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119197 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119198 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119199 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119200 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119201 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119202 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119203 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119204 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119205 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119206 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119207 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119208 +ivtv_write_12721 ivtv_write 3 12721 NULL
119209 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119210 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119211 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119212 +listxattr_12769 listxattr 3 12769 NULL
119213 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119214 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119215 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119216 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119217 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119218 +spidev_sync_12842 spidev_sync 0 12842 NULL
119219 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119220 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119221 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119222 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119223 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119224 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119225 +bm_status_write_12964 bm_status_write 3 12964 NULL
119226 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119227 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119228 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119229 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119230 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119231 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119232 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119233 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119234 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119235 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119236 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119237 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119238 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119239 +blk_update_request_13146 blk_update_request 3 13146 NULL
119240 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119241 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119242 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119243 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119244 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119245 +comedi_read_13199 comedi_read 3 13199 NULL
119246 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119247 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119248 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119249 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119250 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119251 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119252 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119253 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119254 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119255 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119256 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119257 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119258 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119259 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119260 +sd_major_13294 sd_major 0-1 13294 NULL
119261 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119262 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119263 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119264 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119265 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119266 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119267 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119268 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119269 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119270 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119271 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119272 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119273 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119274 +data_read_13494 data_read 3 13494 NULL nohasharray
119275 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119276 +core_status_13515 core_status 4 13515 NULL
119277 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119278 +bm_init_13529 bm_init 2 13529 NULL
119279 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119280 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119281 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119282 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119283 +cache_write_13589 cache_write 3 13589 NULL
119284 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119285 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119286 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119287 +packet_snd_13634 packet_snd 3 13634 NULL
119288 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119289 +cache_downcall_13666 cache_downcall 3 13666 NULL
119290 +usb_get_string_13693 usb_get_string 0 13693 NULL
119291 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119292 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119293 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119294 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119295 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119296 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119297 +random_read_13815 random_read 3 13815 NULL
119298 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119299 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119300 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119301 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119302 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119303 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119304 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119305 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119306 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119307 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119308 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119309 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119310 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119311 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119312 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119313 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119314 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119315 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119316 +qcam_read_13977 qcam_read 3 13977 NULL
119317 +dsp_read_13980 dsp_read 2 13980 NULL
119318 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119319 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119320 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119321 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119322 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119323 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119324 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119325 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119326 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119327 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119328 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119329 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119330 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119331 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119332 +em_canid_change_14150 em_canid_change 3 14150 NULL
119333 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119334 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119335 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119336 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119337 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119338 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119339 +alloc_async_14208 alloc_async 1 14208 NULL
119340 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119341 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119342 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119343 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119344 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119345 +rr_status_14293 rr_status 5 14293 NULL
119346 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119347 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119348 +oo_objects_14319 oo_objects 0 14319 NULL
119349 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119350 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119351 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119352 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119353 +lowpan_read_14369 lowpan_read 3 14369 NULL
119354 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119355 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119356 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119357 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119358 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119359 +block_size_14443 block_size 0 14443 NULL
119360 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119361 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119362 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119363 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119364 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119365 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119366 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119367 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119368 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119369 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119370 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119371 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119372 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119373 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119374 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119375 +dbJoin_14644 dbJoin 0 14644 NULL
119376 +profile_replace_14652 profile_replace 3 14652 NULL
119377 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119378 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119379 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119380 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119381 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119382 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119383 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119384 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119385 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119386 +vfd_write_14717 vfd_write 3 14717 NULL
119387 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119388 +raid1_resize_14740 raid1_resize 2 14740 NULL
119389 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119390 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119391 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119392 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119393 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119394 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119395 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119396 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119397 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119398 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119399 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119400 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119401 +lcd_write_14857 lcd_write 3 14857 NULL
119402 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119403 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119404 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119405 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119406 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119407 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119408 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119409 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119410 +queue_cnt_14951 queue_cnt 0 14951 NULL
119411 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119412 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119413 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119414 +setkey_14987 setkey 3 14987 NULL nohasharray
119415 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119416 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119417 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119418 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119419 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119420 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119421 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119422 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119423 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119424 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119425 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119426 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119427 +start_port_15124 start_port 0 15124 NULL
119428 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119429 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119430 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119431 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119432 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119433 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119434 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119435 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119436 +simple_strtol_15273 simple_strtol 0 15273 NULL
119437 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119438 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119439 +ioread16_15342 ioread16 0 15342 NULL
119440 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119441 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119442 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119443 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119444 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119445 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119446 +get_modalias_15406 get_modalias 2 15406 NULL
119447 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119448 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119449 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119450 +memweight_15450 memweight 2 15450 NULL
119451 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119452 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119453 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119454 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119455 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119456 +persistent_status_15574 persistent_status 4 15574 NULL
119457 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119458 +vme_user_write_15587 vme_user_write 3 15587 NULL
119459 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119460 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119461 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119462 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119463 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119464 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119465 +fs_path_add_15648 fs_path_add 3 15648 NULL
119466 +xsd_read_15653 xsd_read 3 15653 NULL
119467 +unix_bind_15668 unix_bind 3 15668 NULL
119468 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119469 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119470 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119471 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119472 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119473 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119474 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119475 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119476 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119477 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119478 +table_size_15851 table_size 0-1-2 15851 NULL
119479 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119480 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119481 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119482 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119483 +power_read_15939 power_read 3 15939 NULL
119484 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119485 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119486 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119487 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119488 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119489 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119490 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119491 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119492 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119493 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119494 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119495 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119496 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119497 +fsm_init_16134 fsm_init 2 16134 NULL
119498 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119499 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119500 +mapping_level_16188 mapping_level 2-0 16188 NULL
119501 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119502 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119503 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119504 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119505 +create_table_16213 create_table 2 16213 NULL
119506 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119507 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119508 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119509 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119510 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119511 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119512 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119513 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119514 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119515 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119516 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119517 +account_16283 account 0-4-2 16283 NULL nohasharray
119518 +mirror_status_16283 mirror_status 5 16283 &account_16283
119519 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119520 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119521 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119522 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119523 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119524 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119525 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119526 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119527 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119528 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119529 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119530 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119531 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119532 +cmdline_store_16442 cmdline_store 4 16442 NULL
119533 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119534 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119535 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119536 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119537 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119538 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119539 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119540 +raid10_resize_16537 raid10_resize 2 16537 NULL
119541 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119542 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119543 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119544 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119545 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119546 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119547 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119548 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119549 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119550 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119551 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119552 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119553 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119554 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119555 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119556 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119557 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119558 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119559 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119560 +st_write_16874 st_write 3 16874 NULL
119561 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119562 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119563 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119564 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119565 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119566 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119567 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119568 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119569 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119570 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119571 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119572 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119573 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119574 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119575 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119576 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119577 +entry_length_17093 entry_length 0 17093 NULL
119578 +write_mem_17114 write_mem 3 17114 NULL
119579 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119580 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119581 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119582 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119583 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119584 +sep_read_17161 sep_read 3 17161 NULL
119585 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119586 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119587 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119588 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119589 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119590 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119591 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119592 +sync_request_17208 sync_request 2 17208 NULL
119593 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119594 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119595 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119596 +alloc_ep_17269 alloc_ep 1 17269 NULL
119597 +pg_read_17276 pg_read 3 17276 NULL
119598 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119599 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119600 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119601 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119602 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119603 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119604 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119605 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119606 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119607 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119608 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119609 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119610 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119611 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119612 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119613 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119614 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119615 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119616 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119617 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119618 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119619 +qp_free_res_17541 qp_free_res 5 17541 NULL
119620 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119621 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119622 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119623 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119624 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119625 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119626 +osst_execute_17607 osst_execute 7-6 17607 NULL
119627 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119628 +dma_map_page_17628 dma_map_page 0 17628 NULL
119629 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119630 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119631 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119632 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119633 +venus_rename_17707 venus_rename 4-5 17707 NULL
119634 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119635 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119636 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119637 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119638 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119639 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119640 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119641 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119642 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119643 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119644 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119645 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119646 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119647 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119648 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119649 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119650 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119651 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119652 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119653 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119654 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119655 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119656 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119657 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119658 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119659 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119660 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119661 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119662 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119663 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119664 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119665 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119666 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
119667 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
119668 +fpregs_get_18066 fpregs_get 4 18066 NULL
119669 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
119670 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
119671 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
119672 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
119673 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
119674 +svc_getnl_18120 svc_getnl 0 18120 NULL
119675 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
119676 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
119677 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
119678 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
119679 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
119680 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
119681 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
119682 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
119683 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
119684 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
119685 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
119686 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
119687 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
119688 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
119689 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
119690 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
119691 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
119692 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
119693 +um_idi_write_18293 um_idi_write 3 18293 NULL
119694 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
119695 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
119696 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
119697 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
119698 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
119699 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
119700 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
119701 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
119702 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
119703 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
119704 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
119705 +ep_io_18367 ep_io 0 18367 NULL
119706 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
119707 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
119708 +ci_role_write_18388 ci_role_write 3 18388 NULL
119709 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
119710 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
119711 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
119712 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
119713 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
119714 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
119715 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
119716 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
119717 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL
119718 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
119719 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
119720 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
119721 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
119722 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
119723 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
119724 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
119725 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
119726 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
119727 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
119728 +debug_output_18575 debug_output 3 18575 NULL
119729 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
119730 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
119731 +from_buffer_18625 from_buffer 3 18625 NULL
119732 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
119733 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
119734 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
119735 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
119736 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
119737 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
119738 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
119739 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
119740 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
119741 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
119742 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
119743 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
119744 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
119745 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
119746 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
119747 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
119748 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
119749 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
119750 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
119751 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
119752 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
119753 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
119754 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
119755 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
119756 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
119757 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
119758 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
119759 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
119760 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
119761 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
119762 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
119763 +huge_page_size_19008 huge_page_size 0 19008 NULL
119764 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
119765 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
119766 +revalidate_19043 revalidate 2 19043 NULL
119767 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
119768 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
119769 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
119770 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
119771 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
119772 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
119773 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
119774 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
119775 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
119776 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
119777 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
119778 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
119779 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
119780 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
119781 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
119782 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
119783 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
119784 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
119785 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
119786 +ucma_query_19260 ucma_query 4 19260 NULL
119787 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
119788 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
119789 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
119790 +qc_capture_19298 qc_capture 3 19298 NULL
119791 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
119792 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
119793 +debug_read_19322 debug_read 3 19322 NULL
119794 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
119795 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
119796 +closure_sub_19359 closure_sub 2 19359 NULL
119797 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
119798 +read_zero_19366 read_zero 3 19366 NULL
119799 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
119800 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
119801 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
119802 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
119803 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
119804 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
119805 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
119806 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
119807 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
119808 +sky2_read16_19475 sky2_read16 0 19475 NULL
119809 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
119810 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
119811 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
119812 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
119813 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
119814 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
119815 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
119816 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
119817 +nfsd_read_19568 nfsd_read 5 19568 NULL
119818 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
119819 +bm_status_read_19583 bm_status_read 3 19583 NULL
119820 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
119821 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
119822 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
119823 +parser_init_19651 parser_init 2 19651 NULL
119824 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
119825 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
119826 +read_reg_19723 read_reg 0 19723 NULL
119827 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
119828 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
119829 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
119830 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
119831 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
119832 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
119833 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
119834 +readhscx_19769 readhscx 0 19769 NULL
119835 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
119836 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
119837 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
119838 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
119839 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
119840 +__nla_put_19857 __nla_put 3 19857 NULL
119841 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
119842 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
119843 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
119844 +mangle_name_19923 mangle_name 0 19923 NULL
119845 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
119846 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
119847 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
119848 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
119849 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
119850 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
119851 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
119852 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
119853 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
119854 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
119855 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
119856 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
119857 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
119858 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
119859 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
119860 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
119861 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
119862 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
119863 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
119864 +target_message_20072 target_message 2 20072 NULL
119865 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
119866 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
119867 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
119868 +team_options_register_20091 team_options_register 3 20091 NULL
119869 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
119870 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
119871 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
119872 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
119873 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
119874 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
119875 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
119876 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
119877 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
119878 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
119879 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
119880 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
119881 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
119882 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
119883 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
119884 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
119885 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
119886 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
119887 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
119888 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
119889 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
119890 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
119891 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
119892 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
119893 +read_buf_20469 read_buf 2 20469 NULL
119894 +bio_trim_20472 bio_trim 2 20472 NULL
119895 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
119896 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
119897 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
119898 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
119899 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
119900 +venus_create_20555 venus_create 4 20555 NULL
119901 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
119902 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
119903 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
119904 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
119905 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
119906 +lirc_write_20604 lirc_write 3 20604 NULL
119907 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
119908 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
119909 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
119910 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
119911 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
119912 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
119913 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
119914 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
119915 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
119916 +cpumask_size_20683 cpumask_size 0 20683 NULL
119917 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
119918 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
119919 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
119920 +__maestro_read_20700 __maestro_read 0 20700 NULL
119921 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
119922 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
119923 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
119924 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
119925 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
119926 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
119927 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
119928 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
119929 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
119930 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
119931 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
119932 +edid_write_20797 edid_write 3 20797 NULL
119933 +lowpan_write_20800 lowpan_write 3 20800 NULL
119934 +strndup_user_20819 strndup_user 2 20819 NULL
119935 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
119936 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
119937 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
119938 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
119939 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
119940 +get_name_20855 get_name 4 20855 NULL
119941 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
119942 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
119943 +srq_free_res_20868 srq_free_res 5 20868 NULL
119944 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
119945 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
119946 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
119947 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
119948 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
119949 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
119950 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
119951 +htable_bits_20933 htable_bits 0 20933 NULL
119952 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
119953 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
119954 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
119955 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
119956 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
119957 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
119958 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
119959 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
119960 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
119961 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
119962 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
119963 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
119964 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
119965 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
119966 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
119967 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
119968 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
119969 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
119970 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
119971 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
119972 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
119973 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
119974 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
119975 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
119976 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
119977 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
119978 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
119979 +input_ff_create_21240 input_ff_create 2 21240 NULL
119980 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
119981 +fru_length_21257 fru_length 0 21257 NULL
119982 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
119983 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
119984 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
119985 +add_res_range_21310 add_res_range 4 21310 NULL
119986 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
119987 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
119988 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
119989 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
119990 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
119991 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
119992 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
119993 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
119994 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
119995 +insert_ptr_21386 insert_ptr 6 21386 NULL
119996 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
119997 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
119998 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
119999 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120000 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120001 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120002 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120003 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120004 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120005 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120006 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120007 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120008 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120009 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120010 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120011 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120012 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120013 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120014 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120015 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120016 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120017 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120018 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120019 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
120020 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120021 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120022 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120023 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120024 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120025 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120026 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120027 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120028 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120029 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120030 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120031 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120032 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120033 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120034 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120035 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
120036 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120037 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120038 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120039 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120040 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120041 +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
120042 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120043 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120044 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120045 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120046 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120047 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120048 +mem_rw_22085 mem_rw 3 22085 NULL
120049 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120050 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120051 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120052 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120053 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120054 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120055 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120056 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120057 +mem_write_22232 mem_write 3 22232 NULL
120058 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120059 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120060 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120061 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120062 +add_res_tree_22263 add_res_tree 7 22263 NULL
120063 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120064 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120065 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120066 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120067 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120068 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120069 +atomic_read_22342 atomic_read 0 22342 NULL
120070 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120071 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120072 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120073 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120074 +zoran_write_22404 zoran_write 3 22404 NULL
120075 +queue_reply_22416 queue_reply 3 22416 NULL
120076 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120077 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120078 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120079 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120080 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
120081 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120082 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120083 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120084 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120085 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120086 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120087 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120088 +snapshot_read_22601 snapshot_read 3 22601 NULL
120089 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120090 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120091 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120092 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120093 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120094 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120095 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120096 +reg_umr_22686 reg_umr 5 22686 NULL
120097 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120098 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120099 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120100 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120101 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120102 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120103 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120104 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120105 +print_frame_22769 print_frame 0 22769 NULL
120106 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120107 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120108 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120109 +create_attr_set_22861 create_attr_set 1 22861 NULL
120110 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120111 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120112 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120113 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120114 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120115 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120116 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120117 +__set_xattr_22923 __set_xattr 0 22923 NULL
120118 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120119 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120120 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120121 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120122 +vme_get_size_22964 vme_get_size 0 22964 NULL
120123 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120124 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120125 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120126 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120127 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120128 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120129 +st_status_23032 st_status 5 23032 NULL
120130 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120131 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120132 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120133 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120134 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120135 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120136 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120137 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120138 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120139 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120140 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120141 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120142 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120143 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120144 +__clear_user_23118 __clear_user 0-2 23118 NULL
120145 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120146 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120147 +read_file_ani_23161 read_file_ani 3 23161 NULL
120148 +usblp_write_23178 usblp_write 3 23178 NULL
120149 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120150 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120151 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120152 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120153 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120154 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120155 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120156 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120157 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120158 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120159 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120160 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120161 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120162 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120163 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120164 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120165 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120166 +page_readlink_23346 page_readlink 3 23346 NULL
120167 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120168 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120169 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120170 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120171 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120172 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120173 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120174 +linear_conf_23485 linear_conf 2 23485 NULL
120175 +event_filter_read_23494 event_filter_read 3 23494 NULL
120176 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120177 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120178 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120179 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120180 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120181 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120182 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120183 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120184 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120185 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120186 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120187 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120188 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120189 +sInW_23663 sInW 0 23663 NULL
120190 +SyS_connect_23669 SyS_connect 3 23669 NULL
120191 +cx18_read_23699 cx18_read 3 23699 NULL
120192 +at_get_23708 at_get 0 23708 NULL
120193 +get_conn_info_23723 get_conn_info 4 23723 NULL
120194 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120195 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120196 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120197 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120198 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120199 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120200 +map_write_23795 map_write 3 23795 NULL
120201 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120202 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120203 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120204 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120205 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120206 +p54_init_common_23850 p54_init_common 1 23850 NULL
120207 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120208 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120209 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120210 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120211 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120212 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120213 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120214 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120215 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120216 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120217 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120218 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120219 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120220 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120221 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120222 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120223 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120224 +give_pages_24021 give_pages 3 24021 NULL
120225 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120226 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120227 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120228 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120229 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120230 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120231 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120232 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120233 +lov_brw_24122 lov_brw 4 24122 NULL
120234 +mpu401_read_24126 mpu401_read 3 24126 NULL
120235 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120236 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120237 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120238 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120239 +adu_read_24177 adu_read 3 24177 NULL
120240 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120241 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120242 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120243 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120244 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120245 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120246 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120247 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120248 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120249 +thin_status_24278 thin_status 5 24278 NULL
120250 +msg_size_24288 msg_size 0 24288 NULL
120251 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120252 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120253 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120254 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120255 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120256 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120257 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120258 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120259 +igetword_24373 igetword 0 24373 NULL
120260 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120261 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120262 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120263 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120264 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120265 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120266 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120267 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120268 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120269 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120270 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120271 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120272 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120273 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120274 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120275 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120276 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120277 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120278 +pd_video_read_24510 pd_video_read 3 24510 NULL
120279 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120280 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120281 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120282 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120283 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120284 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120285 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120286 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
120287 +SyS_poll_24620 SyS_poll 2 24620 NULL
120288 +context_alloc_24645 context_alloc 3 24645 NULL
120289 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120290 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120291 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120292 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120293 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120294 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120295 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120296 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120297 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120298 +cache_read_24790 cache_read 3 24790 NULL
120299 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120300 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120301 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120302 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120303 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120304 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120305 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120306 +queues_read_24877 queues_read 3 24877 NULL
120307 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120308 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120309 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120310 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120311 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120312 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120313 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120314 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
120315 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120316 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120317 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120318 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120319 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120320 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120321 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120322 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120323 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120324 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120325 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120326 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120327 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120328 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120329 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120330 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120331 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120332 +stripe_status_25259 stripe_status 5 25259 NULL
120333 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120334 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120335 +vfs_writev_25278 vfs_writev 3 25278 NULL
120336 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120337 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120338 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120339 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120340 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120341 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120342 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120343 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120344 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120345 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120346 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120347 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120348 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120349 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120350 +sb_permission_25523 sb_permission 0 25523 NULL
120351 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120352 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120353 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120354 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120355 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120356 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120357 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120358 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120359 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120360 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120361 +__direct_map_25647 __direct_map 6-5 25647 NULL
120362 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120363 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120364 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120365 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120366 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120367 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120368 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120369 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120370 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120371 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120372 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120373 +sg_read_25799 sg_read 3 25799 NULL
120374 +system_enable_read_25815 system_enable_read 3 25815 NULL
120375 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120376 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120377 +parport_read_25855 parport_read 0 25855 NULL
120378 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120379 +key_attr_size_25865 key_attr_size 0 25865 NULL
120380 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120381 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120382 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120383 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120384 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120385 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120386 +rcname_read_25919 rcname_read 3 25919 NULL
120387 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120388 +key_flags_read_25931 key_flags_read 3 25931 NULL
120389 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120390 +flush_25957 flush 2 25957 NULL
120391 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120392 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120393 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120394 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120395 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120396 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120397 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120398 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120399 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120400 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120401 +read_sb_page_26119 read_sb_page 5 26119 NULL
120402 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120403 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120404 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120405 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120406 +disk_devt_26180 disk_devt 0 26180 NULL
120407 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120408 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120409 +mce_write_26201 mce_write 3 26201 NULL
120410 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120411 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120412 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120413 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120414 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120415 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120416 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120417 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120418 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120419 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120420 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120421 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120422 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120423 +ntty_write_26404 ntty_write 3 26404 NULL
120424 +firmware_store_26408 firmware_store 4 26408 NULL
120425 +pagemap_read_26441 pagemap_read 3 26441 NULL
120426 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120427 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120428 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120429 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120430 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
120431 +read_vmcore_26501 read_vmcore 3 26501 NULL
120432 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120433 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120434 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120435 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120436 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120437 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120438 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120439 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120440 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120441 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120442 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120443 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120444 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120445 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120446 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120447 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120448 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120449 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120450 +bos_desc_26752 bos_desc 0 26752 NULL
120451 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120452 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120453 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120454 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120455 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120456 +smk_write_load_26829 smk_write_load 3 26829 NULL
120457 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120458 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120459 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120460 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120461 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120462 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120463 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120464 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120465 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120466 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120467 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120468 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120469 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120470 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120471 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120472 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120473 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120474 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120475 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120476 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120477 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120478 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120479 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120480 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120481 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120482 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120483 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120484 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120485 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120486 +pms_capture_27142 pms_capture 4 27142 NULL
120487 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120488 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120489 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120490 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120491 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120492 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120493 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120494 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120495 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120496 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120497 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120498 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120499 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120500 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120501 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120502 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120503 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120504 +seq_read_27411 seq_read 3 27411 NULL
120505 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120506 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120507 +cypress_write_27423 cypress_write 4 27423 NULL
120508 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120509 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120510 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120511 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120512 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120513 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
120514 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120515 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120516 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120517 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120518 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120519 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120520 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120521 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120522 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120523 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120524 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120525 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120526 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120527 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120528 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120529 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120530 +evm_write_key_27715 evm_write_key 3 27715 NULL
120531 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120532 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120533 +load_scode_27738 load_scode 2 27738 NULL
120534 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120535 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120536 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120537 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120538 +SyS_readv_27804 SyS_readv 3 27804 NULL
120539 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120540 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120541 +init_header_complete_27833 init_header_complete 0 27833 NULL
120542 +read_profile_27859 read_profile 3 27859 NULL
120543 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120544 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120545 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120546 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120547 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120548 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120549 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120550 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120551 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120552 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120553 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120554 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120555 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120556 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120557 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120558 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120559 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120560 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120561 +pool_status_28055 pool_status 5 28055 NULL
120562 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120563 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120564 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120565 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120566 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120567 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120568 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120569 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120570 +video_read_28148 video_read 3 28148 NULL
120571 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120572 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120573 +vread_28173 vread 0-3 28173 NULL
120574 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120575 +counter_free_res_28187 counter_free_res 5 28187 NULL
120576 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120577 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120578 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120579 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120580 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120581 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120582 +usemap_size_28281 usemap_size 0 28281 NULL
120583 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120584 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120585 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120586 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120587 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120588 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120589 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120590 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120591 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120592 +snapshot_write_28351 snapshot_write 3 28351 NULL
120593 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120594 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120595 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120596 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120597 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120598 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120599 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120600 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120601 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120602 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120603 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120604 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120605 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120606 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120607 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120608 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120609 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120610 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120611 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120612 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120613 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120614 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120615 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120616 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120617 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120618 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120619 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120620 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120621 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120622 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120623 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120624 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120625 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120626 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120627 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120628 +spi_execute_28736 spi_execute 5 28736 NULL
120629 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120630 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120631 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120632 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120633 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120634 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120635 +sel_write_member_28800 sel_write_member 3 28800 NULL
120636 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120637 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120638 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120639 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120640 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120641 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120642 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120643 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120644 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120645 +push_rx_28939 push_rx 3 28939 NULL
120646 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120647 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120648 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120649 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120650 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120651 +bin_uuid_28999 bin_uuid 3 28999 NULL
120652 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120653 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
120654 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
120655 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
120656 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
120657 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
120658 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
120659 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
120660 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
120661 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
120662 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
120663 +snprintf_29125 snprintf 0 29125 NULL
120664 +iov_shorten_29130 iov_shorten 0 29130 NULL
120665 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
120666 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
120667 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
120668 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
120669 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
120670 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
120671 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
120672 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
120673 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
120674 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
120675 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
120676 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
120677 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
120678 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
120679 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
120680 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
120681 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
120682 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
120683 +tun_put_user_29337 tun_put_user 5 29337 NULL
120684 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
120685 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
120686 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
120687 +mempool_create_29437 mempool_create 1 29437 NULL
120688 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
120689 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
120690 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
120691 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
120692 +do_register_entry_29478 do_register_entry 4 29478 NULL
120693 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
120694 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
120695 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
120696 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
120697 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
120698 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
120699 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
120700 +ftrace_write_29551 ftrace_write 3 29551 NULL
120701 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
120702 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
120703 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
120704 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
120705 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
120706 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
120707 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
120708 +slots_per_page_29601 slots_per_page 0 29601 NULL
120709 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
120710 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
120711 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
120712 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
120713 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
120714 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
120715 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
120716 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
120717 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
120718 +probes_write_29711 probes_write 3 29711 NULL
120719 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
120720 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
120721 +std_nic_write_29752 std_nic_write 3 29752 NULL
120722 +static_key_count_29771 static_key_count 0 29771 NULL
120723 +dbAlloc_29794 dbAlloc 0 29794 NULL
120724 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
120725 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
120726 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
120727 +count_partial_29850 count_partial 0 29850 NULL
120728 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
120729 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
120730 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
120731 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
120732 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
120733 +write_file_queue_29922 write_file_queue 3 29922 NULL
120734 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
120735 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
120736 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
120737 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
120738 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
120739 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
120740 +drp_wmove_30043 drp_wmove 4 30043 NULL
120741 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
120742 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
120743 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
120744 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
120745 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
120746 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
120747 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
120748 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
120749 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
120750 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
120751 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
120752 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
120753 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
120754 +SyS_semop_30227 SyS_semop 3 30227 NULL
120755 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
120756 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
120757 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
120758 +compat_readv_30273 compat_readv 3 30273 NULL
120759 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
120760 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
120761 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
120762 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
120763 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
120764 +resource_from_user_30341 resource_from_user 3 30341 NULL
120765 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
120766 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
120767 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
120768 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
120769 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
120770 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
120771 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
120772 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
120773 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
120774 +enable_write_30456 enable_write 3 30456 NULL
120775 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
120776 +urandom_read_30462 urandom_read 3 30462 NULL
120777 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
120778 +adu_write_30487 adu_write 3 30487 NULL
120779 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
120780 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
120781 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
120782 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
120783 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
120784 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
120785 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
120786 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
120787 +set_le_30581 set_le 4 30581 NULL
120788 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
120789 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
120790 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
120791 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
120792 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
120793 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
120794 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
120795 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
120796 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
120797 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
120798 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
120799 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
120800 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
120801 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
120802 +snapshot_status_30744 snapshot_status 5 30744 NULL
120803 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
120804 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
120805 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
120806 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
120807 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
120808 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
120809 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
120810 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
120811 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
120812 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
120813 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
120814 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
120815 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
120816 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
120817 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
120818 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
120819 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
120820 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
120821 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
120822 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
120823 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
120824 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
120825 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
120826 +depth_read_31112 depth_read 3 31112 NULL
120827 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
120828 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
120829 +size_inside_page_31141 size_inside_page 0 31141 NULL
120830 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
120831 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
120832 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
120833 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
120834 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
120835 +__read_reg_31216 __read_reg 0 31216 NULL
120836 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
120837 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
120838 +cyy_readb_31240 cyy_readb 0 31240 NULL
120839 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
120840 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
120841 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
120842 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
120843 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
120844 +command_file_write_31318 command_file_write 3 31318 NULL
120845 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
120846 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
120847 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
120848 +outlen_write_31358 outlen_write 3 31358 NULL
120849 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
120850 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
120851 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
120852 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
120853 +inb_31388 inb 0 31388 NULL
120854 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
120855 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
120856 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
120857 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
120858 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
120859 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
120860 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
120861 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
120862 +alg_setkey_31485 alg_setkey 3 31485 NULL
120863 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
120864 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
120865 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
120866 +hidraw_write_31536 hidraw_write 3 31536 NULL
120867 +usbvision_read_31555 usbvision_read 3 31555 NULL
120868 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
120869 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
120870 +osst_write_31581 osst_write 3 31581 NULL
120871 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
120872 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
120873 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
120874 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
120875 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
120876 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
120877 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
120878 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
120879 +__lgread_31668 __lgread 4 31668 NULL
120880 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
120881 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
120882 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
120883 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
120884 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
120885 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
120886 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
120887 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
120888 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
120889 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
120890 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
120891 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
120892 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
120893 +get_count_order_31800 get_count_order 0 31800 NULL
120894 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
120895 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
120896 +data_write_31805 data_write 3 31805 NULL
120897 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
120898 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
120899 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
120900 +clone_bio_31854 clone_bio 4-3 31854 NULL
120901 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
120902 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
120903 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
120904 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
120905 +xattr_permission_31907 xattr_permission 0 31907 NULL
120906 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
120907 +new_dir_31919 new_dir 3 31919 NULL
120908 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
120909 +era_status_31934 era_status 5 31934 NULL
120910 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
120911 +read_mem_31942 read_mem 3 31942 NULL
120912 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
120913 +vb2_write_31948 vb2_write 3 31948 NULL
120914 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
120915 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
120916 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
120917 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
120918 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
120919 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
120920 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
120921 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
120922 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
120923 +calc_hmac_32010 calc_hmac 3 32010 NULL
120924 +aead_len_32021 aead_len 0 32021 NULL
120925 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
120926 +stk_read_32038 stk_read 3 32038 NULL
120927 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
120928 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
120929 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
120930 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
120931 +bio_alloc_32095 bio_alloc 2 32095 NULL
120932 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
120933 +disk_status_32120 disk_status 4 32120 NULL
120934 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
120935 +venus_link_32165 venus_link 5 32165 NULL
120936 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
120937 +do_writepages_32173 do_writepages 0 32173 NULL
120938 +del_ptr_32197 del_ptr 4 32197 NULL
120939 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
120940 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
120941 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
120942 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
120943 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
120944 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
120945 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
120946 +SyS_select_32319 SyS_select 1 32319 NULL
120947 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
120948 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
120949 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
120950 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
120951 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
120952 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
120953 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
120954 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
120955 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
120956 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
120957 +cache_status_32462 cache_status 5 32462 NULL
120958 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
120959 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
120960 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
120961 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
120962 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
120963 +disconnect_32521 disconnect 4 32521 NULL
120964 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
120965 +ilo_read_32531 ilo_read 3 32531 NULL
120966 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
120967 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
120968 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
120969 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
120970 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
120971 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
120972 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
120973 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
120974 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
120975 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
120976 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
120977 +kvmalloc_32646 kvmalloc 1 32646 NULL
120978 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
120979 +generic_readlink_32654 generic_readlink 3 32654 NULL
120980 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
120981 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
120982 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
120983 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
120984 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
120985 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
120986 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
120987 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
120988 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
120989 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
120990 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
120991 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
120992 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
120993 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
120994 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
120995 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
120996 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
120997 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
120998 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
120999 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121000 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121001 +compat_filldir_32999 compat_filldir 3 32999 NULL
121002 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121003 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121004 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121005 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121006 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121007 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121008 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121009 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121010 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121011 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121012 +alloc_tio_33077 alloc_tio 3 33077 NULL
121013 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121014 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121015 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121016 +SyS_poll_33152 SyS_poll 2 33152 NULL
121017 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121018 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121019 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121020 +pp_read_33210 pp_read 3 33210 NULL
121021 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121022 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121023 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121024 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121025 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121026 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121027 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121028 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121029 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121030 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121031 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121032 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121033 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121034 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121035 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121036 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121037 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121038 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121039 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121040 +message_stats_list_33440 message_stats_list 5 33440 NULL
121041 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121042 +create_entry_33479 create_entry 2 33479 NULL
121043 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121044 +res_counter_read_33499 res_counter_read 4 33499 NULL
121045 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121046 +fb_read_33506 fb_read 3 33506 NULL
121047 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121048 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121049 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121050 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121051 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121052 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121053 +count_subheaders_33591 count_subheaders 0 33591 NULL
121054 +scsi_execute_33596 scsi_execute 5 33596 NULL
121055 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121056 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121057 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121058 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121059 +stride_page_count_33641 stride_page_count 2 33641 NULL
121060 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121061 +inw_p_33668 inw_p 0 33668 NULL
121062 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121063 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121064 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121065 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121066 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121067 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121068 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121069 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121070 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121071 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121072 +hashtab_create_33769 hashtab_create 3 33769 NULL
121073 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121074 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121075 +filter_write_33819 filter_write 3 33819 NULL
121076 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121077 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121078 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121079 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121080 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121081 +get_user_pages_33908 get_user_pages 0 33908 NULL
121082 +sg_nents_33909 sg_nents 0 33909 NULL
121083 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121084 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121085 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121086 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121087 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121088 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121089 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121090 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121091 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121092 +ppp_write_34034 ppp_write 3 34034 NULL
121093 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121094 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121095 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121096 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121097 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121098 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121099 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121100 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121101 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121102 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121103 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121104 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121105 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
121106 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121107 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121108 +device_private_init_34279 device_private_init 0 34279 NULL
121109 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121110 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121111 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121112 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121113 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121114 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121115 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121116 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121117 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121118 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121119 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121120 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121121 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121122 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121123 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121124 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121125 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121126 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121127 +security_socket_create_34439 security_socket_create 0 34439 NULL
121128 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121129 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121130 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121131 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121132 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121133 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121134 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121135 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121136 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121137 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121138 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121139 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121140 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121141 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121142 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121143 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121144 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121145 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121146 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121147 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121148 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121149 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121150 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121151 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121152 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121153 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121154 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121155 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121156 +port_print_34704 port_print 3 34704 NULL
121157 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121158 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121159 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121160 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121161 +bootmode_store_34762 bootmode_store 4 34762 NULL
121162 +device_add_34766 device_add 0 34766 NULL
121163 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121164 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121165 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121166 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121167 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121168 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121169 +file_page_index_34820 file_page_index 0-2 34820 NULL
121170 +bio_segments_34832 bio_segments 0 34832 NULL
121171 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121172 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121173 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121174 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121175 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121176 +msg_print_text_34889 msg_print_text 0 34889 NULL
121177 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121178 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121179 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121180 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121181 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121182 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121183 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121184 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121185 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121186 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121187 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121188 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121189 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121190 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121191 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121192 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121193 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121194 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121195 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121196 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121197 +message_stats_print_35158 message_stats_print 6 35158 NULL
121198 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121199 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121200 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121201 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121202 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121203 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121204 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121205 +set_fd_set_35249 set_fd_set 1 35249 NULL
121206 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121207 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121208 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121209 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121210 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121211 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
121212 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121213 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121214 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121215 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121216 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121217 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121218 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121219 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121220 +read_kmem_35372 read_kmem 3 35372 NULL
121221 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121222 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121223 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121224 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121225 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121226 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121227 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121228 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121229 +async_setkey_35521 async_setkey 3 35521 NULL
121230 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121231 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121232 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121233 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121234 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121235 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121236 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121237 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121238 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121239 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121240 +kernel_readv_35617 kernel_readv 3 35617 NULL
121241 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121242 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121243 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121244 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121245 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121246 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121247 +md_super_write_35703 md_super_write 4 35703 NULL
121248 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121249 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121250 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121251 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121252 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121253 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121254 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121255 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121256 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121257 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121258 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121259 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121260 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121261 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121262 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121263 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121264 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121265 +acl_alloc_35979 acl_alloc 1 35979 NULL
121266 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121267 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121268 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121269 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121270 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121271 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121272 +account_shadowed_36048 account_shadowed 2 36048 NULL
121273 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121274 +write_emulate_36065 write_emulate 2-4 36065 NULL
121275 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121276 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121277 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121278 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121279 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121280 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121281 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121282 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121283 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121284 +twl_set_36154 twl_set 2 36154 NULL
121285 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121286 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121287 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121288 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121289 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121290 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121291 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121292 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121293 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121294 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121295 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121296 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121297 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121298 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121299 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121300 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121301 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121302 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121303 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121304 +lc_create_36332 lc_create 4 36332 NULL
121305 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121306 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121307 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121308 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121309 +to_sector_36361 to_sector 0-1 36361 NULL
121310 +tunables_read_36385 tunables_read 3 36385 NULL
121311 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121312 +sierra_write_36402 sierra_write 4 36402 NULL
121313 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121314 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121315 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121316 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121317 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121318 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121319 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121320 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121321 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121322 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121323 +cmd_loop_36491 cmd_loop 0 36491 NULL
121324 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121325 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121326 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121327 +get_param_l_36518 get_param_l 0 36518 NULL
121328 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121329 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121330 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121331 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121332 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121333 +__erst_read_36579 __erst_read 0 36579 NULL
121334 +put_cmsg_36589 put_cmsg 4 36589 NULL
121335 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121336 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121337 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121338 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121339 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121340 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121341 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121342 +xillybus_read_36678 xillybus_read 3 36678 NULL
121343 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121344 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121345 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121346 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121347 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121348 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121349 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121350 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121351 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121352 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121353 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121354 +cm_write_36858 cm_write 3 36858 NULL
121355 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121356 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121357 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121358 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121359 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121360 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121361 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121362 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121363 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121364 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121365 +setxattr_37006 setxattr 4 37006 NULL
121366 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121367 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121368 +command_file_read_37038 command_file_read 3 37038 NULL
121369 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121370 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121371 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121372 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121373 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121374 +parse_command_37079 parse_command 2 37079 NULL
121375 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121376 +tun_get_user_37094 tun_get_user 5 37094 NULL
121377 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121378 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121379 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121380 +msg_word_37164 msg_word 0 37164 NULL
121381 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121382 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121383 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121384 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121385 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121386 +__do_replace_37227 __do_replace 5 37227 NULL
121387 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121388 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121389 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121390 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121391 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121392 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121393 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121394 +tipc_send_37315 tipc_send 3 37315 NULL
121395 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121396 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121397 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121398 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121399 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121400 +seek_firmware_37372 seek_firmware 2 37372 NULL
121401 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121402 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121403 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121404 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121405 +fru_alloc_37442 fru_alloc 1 37442 NULL
121406 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121407 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121408 +get_est_timing_37484 get_est_timing 0 37484 NULL
121409 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121410 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121411 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121412 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121413 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121414 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121415 +hdr_size_37536 hdr_size 0 37536 NULL
121416 +extent_map_end_37550 extent_map_end 0 37550 NULL
121417 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121418 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121419 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121420 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121421 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121422 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121423 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121424 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121425 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121426 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121427 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121428 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121429 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121430 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121431 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121432 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121433 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121434 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121435 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121436 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121437 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121438 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121439 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121440 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121441 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121442 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121443 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121444 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121445 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121446 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121447 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121448 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121449 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121450 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121451 +write_file_bool_37957 write_file_bool 3 37957 NULL
121452 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121453 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121454 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121455 +vfs_readv_38011 vfs_readv 3 38011 NULL
121456 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121457 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121458 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121459 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121460 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121461 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121462 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121463 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121464 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121465 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121466 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121467 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121468 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121469 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121470 +ep0_read_38095 ep0_read 3 38095 NULL
121471 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121472 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121473 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121474 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121475 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121476 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121477 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121478 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121479 +cdev_add_38176 cdev_add 2-3 38176 NULL
121480 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121481 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121482 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121483 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121484 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121485 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121486 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121487 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
121488 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121489 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121490 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121491 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121492 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121493 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121494 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121495 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121496 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121497 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121498 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121499 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121500 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121501 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121502 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121503 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121504 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121505 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121506 +dev_names_read_38509 dev_names_read 3 38509 NULL
121507 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121508 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121509 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121510 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121511 +kuc_len_38557 kuc_len 0-1 38557 NULL
121512 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121513 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121514 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121515 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121516 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121517 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121518 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121519 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121520 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121521 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121522 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121523 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121524 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121525 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121526 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121527 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121528 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121529 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121530 +udf_readpages_38761 udf_readpages 4 38761 NULL
121531 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121532 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121533 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121534 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121535 +err_decode_38804 err_decode 2 38804 NULL
121536 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121537 +direct_entry_38836 direct_entry 3 38836 NULL
121538 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121539 +interfaces_38859 interfaces 2 38859 NULL
121540 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121541 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121542 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121543 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121544 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121545 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121546 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121547 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121548 +get_nodes_39012 get_nodes 3 39012 NULL
121549 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121550 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121551 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121552 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121553 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121554 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121555 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121556 +ea_foreach_39133 ea_foreach 0 39133 NULL
121557 +generic_permission_39150 generic_permission 0 39150 NULL
121558 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121559 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121560 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121561 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121562 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121563 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121564 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121565 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121566 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121567 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121568 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121569 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121570 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121571 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121572 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121573 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121574 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121575 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121576 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121577 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121578 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121579 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121580 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121581 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121582 +__send_to_port_39386 __send_to_port 3 39386 NULL
121583 +user_power_read_39414 user_power_read 3 39414 NULL
121584 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121585 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121586 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121587 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121588 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121589 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121590 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121591 +int_proc_write_39542 int_proc_write 3 39542 NULL
121592 +pp_write_39554 pp_write 3 39554 NULL
121593 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121594 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121595 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121596 +ext_depth_39607 ext_depth 0 39607 NULL
121597 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121598 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121599 +sdio_readb_39618 sdio_readb 0 39618 NULL
121600 +set_dev_class_39645 set_dev_class 4 39645 NULL
121601 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121602 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121603 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121604 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121605 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121606 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121607 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121608 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121609 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121610 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121611 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121612 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121613 +pkt_add_39897 pkt_add 3 39897 NULL
121614 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121615 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121616 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121617 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121618 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121619 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121620 +__spi_async_39932 __spi_async 0 39932 NULL
121621 +__get_order_39935 __get_order 0 39935 NULL
121622 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121623 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121624 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121625 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121626 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121627 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121628 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121629 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121630 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121631 +server_name2svname_39998 server_name2svname 4 39998 NULL
121632 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121633 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121634 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121635 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121636 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121637 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121638 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121639 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121640 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121641 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121642 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121643 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
121644 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
121645 +pt_write_40159 pt_write 3 40159 NULL
121646 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
121647 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
121648 +allocate_probes_40204 allocate_probes 1 40204 NULL
121649 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
121650 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
121651 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
121652 +osst_read_40237 osst_read 3 40237 NULL
121653 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
121654 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
121655 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
121656 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
121657 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
121658 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
121659 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
121660 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
121661 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
121662 +SyS_bind_40303 SyS_bind 3 40303 NULL
121663 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
121664 +mmio_read_40348 mmio_read 4 40348 NULL
121665 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
121666 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
121667 +get_chars_40373 get_chars 3 40373 NULL
121668 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
121669 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
121670 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
121671 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
121672 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
121673 +SyS_writev_40467 SyS_writev 3 40467 NULL
121674 +SyS_select_40473 SyS_select 1 40473 NULL
121675 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
121676 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
121677 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
121678 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
121679 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
121680 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
121681 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
121682 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
121683 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
121684 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
121685 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
121686 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
121687 +fops_read_40672 fops_read 3 40672 NULL
121688 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
121689 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
121690 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
121691 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
121692 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
121693 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
121694 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
121695 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
121696 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
121697 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
121698 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
121699 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
121700 +card_send_command_40757 card_send_command 3 40757 NULL
121701 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
121702 +pg_write_40766 pg_write 3 40766 NULL
121703 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
121704 +show_list_40775 show_list 3-0 40775 NULL
121705 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
121706 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
121707 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
121708 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
121709 +add_action_40811 add_action 4 40811 NULL
121710 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
121711 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
121712 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
121713 +read_file_queue_40895 read_file_queue 3 40895 NULL
121714 +waiters_read_40902 waiters_read 3 40902 NULL
121715 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
121716 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
121717 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
121718 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
121719 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
121720 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
121721 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
121722 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
121723 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
121724 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
121725 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
121726 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
121727 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
121728 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
121729 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
121730 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
121731 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
121732 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
121733 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
121734 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
121735 +dma_attach_41094 dma_attach 5-6 41094 NULL
121736 +provide_user_output_41105 provide_user_output 3 41105 NULL
121737 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
121738 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
121739 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
121740 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
121741 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
121742 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
121743 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
121744 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
121745 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
121746 +erst_read_41260 erst_read 0 41260 NULL
121747 +alloc_context_41283 alloc_context 1 41283 NULL
121748 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
121749 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
121750 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
121751 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
121752 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
121753 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
121754 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
121755 +kmp_init_41373 kmp_init 2 41373 NULL
121756 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
121757 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
121758 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
121759 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
121760 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
121761 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
121762 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
121763 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
121764 +se_io_cb_41461 se_io_cb 3 41461 NULL
121765 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
121766 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
121767 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
121768 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
121769 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
121770 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
121771 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
121772 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
121773 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
121774 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
121775 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
121776 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
121777 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
121778 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
121779 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
121780 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
121781 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
121782 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
121783 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
121784 +a2mp_send_41615 a2mp_send 4 41615 NULL
121785 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
121786 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
121787 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
121788 +get_std_timing_41654 get_std_timing 0 41654 NULL
121789 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
121790 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
121791 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
121792 +connector_write_41709 connector_write 3 41709 NULL
121793 +fillonedir_41746 fillonedir 3 41746 NULL
121794 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
121795 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
121796 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
121797 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
121798 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
121799 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
121800 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
121801 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
121802 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
121803 +pci_map_single_41869 pci_map_single 0 41869 NULL
121804 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
121805 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
121806 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
121807 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
121808 +read_gssp_41947 read_gssp 3 41947 NULL
121809 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
121810 +portnames_read_41958 portnames_read 3 41958 NULL
121811 +dst_mtu_41969 dst_mtu 0 41969 NULL
121812 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
121813 +pool_allocate_42012 pool_allocate 3 42012 NULL
121814 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
121815 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
121816 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
121817 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
121818 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
121819 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
121820 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
121821 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
121822 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
121823 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
121824 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
121825 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
121826 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
121827 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
121828 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
121829 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
121830 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
121831 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
121832 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
121833 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
121834 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
121835 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
121836 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
121837 +find_last_bit_42260 find_last_bit 0 42260 NULL
121838 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
121839 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
121840 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
121841 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
121842 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
121843 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
121844 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
121845 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
121846 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
121847 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
121848 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
121849 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
121850 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
121851 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
121852 +krng_get_random_42420 krng_get_random 3 42420 NULL
121853 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
121854 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
121855 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
121856 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
121857 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
121858 +kuc_free_42455 kuc_free 2 42455 NULL
121859 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
121860 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
121861 +bypass_write_42498 bypass_write 3 42498 NULL
121862 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
121863 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
121864 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
121865 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
121866 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
121867 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
121868 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
121869 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
121870 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
121871 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
121872 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
121873 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
121874 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
121875 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
121876 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
121877 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
121878 +vb2_read_42703 vb2_read 3 42703 NULL
121879 +read_status_42722 read_status 0 42722 NULL
121880 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
121881 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
121882 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
121883 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
121884 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
121885 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
121886 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
121887 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
121888 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
121889 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
121890 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
121891 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
121892 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
121893 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
121894 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
121895 +set_arg_42824 set_arg 3 42824 NULL
121896 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
121897 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
121898 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
121899 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
121900 +hd_end_request_42904 hd_end_request 2 42904 NULL
121901 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
121902 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
121903 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
121904 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
121905 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
121906 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
121907 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
121908 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
121909 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
121910 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
121911 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
121912 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
121913 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
121914 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
121915 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
121916 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
121917 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
121918 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
121919 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
121920 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
121921 +uio_write_43202 uio_write 3 43202 NULL
121922 +iso_callback_43208 iso_callback 3 43208 NULL
121923 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
121924 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
121925 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
121926 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
121927 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
121928 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
121929 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
121930 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
121931 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
121932 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
121933 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
121934 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
121935 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
121936 +xenfb_write_43412 xenfb_write 3 43412 NULL
121937 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
121938 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
121939 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
121940 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
121941 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
121942 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
121943 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
121944 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
121945 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
121946 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
121947 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
121948 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
121949 +read_events_43534 read_events 3 43534 NULL
121950 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
121951 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
121952 +request_resource_43548 request_resource 0 43548 NULL
121953 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
121954 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
121955 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
121956 +proc_read_43614 proc_read 3 43614 NULL
121957 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
121958 +random_write_43656 random_write 3 43656 NULL
121959 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
121960 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
121961 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
121962 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
121963 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
121964 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
121965 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
121966 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
121967 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
121968 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
121969 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
121970 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
121971 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
121972 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
121973 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
121974 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
121975 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
121976 +read_flush_43851 read_flush 3 43851 NULL
121977 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
121978 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
121979 +SendString_43928 SendString 3 43928 NULL
121980 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
121981 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
121982 +nla_reserve_43984 nla_reserve 3 43984 NULL
121983 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
121984 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
121985 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
121986 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
121987 +emit_flags_44006 emit_flags 4-3 44006 NULL
121988 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
121989 +fru_strlen_44046 fru_strlen 0 44046 NULL
121990 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
121991 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
121992 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
121993 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
121994 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
121995 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
121996 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
121997 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
121998 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
121999 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122000 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122001 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122002 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122003 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122004 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122005 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122006 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122007 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122008 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122009 +device_create_file_44285 device_create_file 0 44285 NULL
122010 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122011 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122012 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122013 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122014 +rs_init_44327 rs_init 1 44327 NULL
122015 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122016 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122017 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122018 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122019 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122020 +strlcpy_44400 strlcpy 3 44400 NULL
122021 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122022 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122023 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122024 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122025 +write_file_debug_44476 write_file_debug 3 44476 NULL
122026 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122027 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122028 +bio_advance_44496 bio_advance 2 44496 NULL
122029 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122030 +ac_register_board_44504 ac_register_board 3 44504 NULL
122031 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122032 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122033 +spidev_write_44510 spidev_write 3 44510 NULL
122034 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122035 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122036 +comm_write_44537 comm_write 3 44537 NULL
122037 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122038 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122039 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122040 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122041 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122042 +mpi_resize_44674 mpi_resize 2 44674 NULL
122043 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122044 +ts_read_44687 ts_read 3 44687 NULL
122045 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122046 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122047 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122048 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122049 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122050 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122051 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122052 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122053 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122054 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122055 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122056 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122057 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122058 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122059 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122060 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122061 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122062 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122063 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122064 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122065 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122066 +sisusb_write_44834 sisusb_write 3 44834 NULL
122067 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122068 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122069 +copydesc_user_44855 copydesc_user 3 44855 NULL
122070 +set_advertising_44870 set_advertising 4 44870 NULL
122071 +init_rs_44873 init_rs 1 44873 NULL
122072 +skb_availroom_44883 skb_availroom 0 44883 NULL
122073 +do_tty_write_44896 do_tty_write 5 44896 NULL
122074 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122075 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122076 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122077 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122078 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122079 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122080 +sel_write_user_45060 sel_write_user 3 45060 NULL
122081 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122082 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122083 +snd_card_new_45104 snd_card_new 5 45104 NULL
122084 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122085 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122086 +usbdev_read_45114 usbdev_read 3 45114 NULL
122087 +send_to_tty_45141 send_to_tty 3 45141 NULL
122088 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122089 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122090 +device_write_45156 device_write 3 45156 NULL nohasharray
122091 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
122092 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122093 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122094 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122095 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122096 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122097 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122098 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122099 +event_enable_write_45238 event_enable_write 3 45238 NULL
122100 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122101 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122102 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122103 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122104 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122105 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122106 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122107 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122108 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122109 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122110 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122111 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122112 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122113 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122114 +__node_remap_45458 __node_remap 4 45458 NULL
122115 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122116 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122117 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122118 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122119 +copy_macs_45534 copy_macs 4 45534 NULL
122120 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122121 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122122 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122123 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122124 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122125 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122126 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122127 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122128 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122129 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122130 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122131 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122132 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122133 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122134 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122135 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122136 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122137 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122138 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122139 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122140 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122141 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122142 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122143 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122144 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122145 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122146 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122147 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122148 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122149 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122150 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122151 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122152 +isdn_write_45863 isdn_write 3 45863 NULL
122153 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122154 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122155 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122156 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122157 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122158 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122159 +alloc_mr_45935 alloc_mr 1 45935 NULL
122160 +copy_to_45969 copy_to 3 45969 NULL
122161 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122162 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122163 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122164 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122165 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122166 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122167 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122168 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122169 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122170 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122171 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122172 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122173 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122174 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122175 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122176 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122177 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122178 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122179 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122180 +fq_resize_46195 fq_resize 2 46195 NULL
122181 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122182 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122183 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122184 +dsp_write_46218 dsp_write 2 46218 NULL
122185 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122186 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122187 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122188 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122189 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122190 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122191 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122192 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122193 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122194 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122195 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122196 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122197 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122198 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122199 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122200 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122201 +filldir64_46469 filldir64 3 46469 NULL
122202 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122203 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122204 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122205 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122206 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122207 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122208 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122209 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122210 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122211 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122212 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122213 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122214 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122215 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122216 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122217 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122218 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122219 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122220 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122221 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122222 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122223 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122224 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122225 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122226 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122227 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122228 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122229 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122230 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122231 +readreg_46845 readreg 0 46845 NULL
122232 +spi_async_46857 spi_async 0 46857 NULL
122233 +vsnprintf_46863 vsnprintf 0 46863 NULL
122234 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122235 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122236 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122237 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122238 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122239 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122240 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122241 +fb_write_46924 fb_write 3 46924 NULL
122242 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122243 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122244 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122245 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122246 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122247 +strlcat_46985 strlcat 3 46985 NULL
122248 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122249 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122250 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122251 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122252 +fs_path_len_47060 fs_path_len 0 47060 NULL
122253 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122254 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122255 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122256 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122257 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122258 +mousedev_read_47123 mousedev_read 3 47123 NULL
122259 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122260 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122261 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122262 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122263 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122264 +options_write_47243 options_write 3 47243 NULL
122265 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122266 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122267 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122268 +vsnprintf_47291 vsnprintf 0 47291 NULL
122269 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122270 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122271 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122272 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122273 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122274 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122275 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122276 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122277 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122278 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122279 +nametbl_list_47391 nametbl_list 2 47391 NULL
122280 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122281 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122282 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122283 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122284 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122285 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122286 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122287 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122288 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122289 +newpart_47485 newpart 6-4 47485 NULL
122290 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122291 +core_sys_select_47494 core_sys_select 1 47494 NULL
122292 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122293 +unlink_simple_47506 unlink_simple 3 47506 NULL
122294 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122295 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122296 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122297 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122298 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122299 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122300 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122301 +read_ldt_47570 read_ldt 2 47570 NULL
122302 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122303 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122304 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122305 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122306 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122307 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122308 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122309 +get_size_47644 get_size 1-2 47644 NULL
122310 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122311 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122312 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122313 +save_microcode_47717 save_microcode 3 47717 NULL
122314 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122315 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122316 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122317 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122318 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122319 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122320 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122321 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122322 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122323 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122324 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122325 +lov_packmd_47810 lov_packmd 0 47810 NULL
122326 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122327 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122328 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122329 +vhci_read_47878 vhci_read 3 47878 NULL
122330 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122331 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122332 +comedi_write_47926 comedi_write 3 47926 NULL
122333 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122334 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122335 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122336 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122337 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122338 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122339 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122340 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122341 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122342 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122343 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122344 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122345 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122346 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122347 +disc_write_48070 disc_write 3 48070 NULL
122348 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122349 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122350 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122351 +load_firmware_48128 load_firmware 2 48128 NULL
122352 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122353 +set_discoverable_48141 set_discoverable 4 48141 NULL
122354 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122355 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122356 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122357 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122358 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122359 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122360 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122361 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122362 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122363 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122364 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122365 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122366 +read_file_recv_48232 read_file_recv 3 48232 NULL
122367 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122368 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122369 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122370 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122371 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122372 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122373 +trace_options_write_48275 trace_options_write 3 48275 NULL
122374 +send_set_info_48288 send_set_info 7 48288 NULL
122375 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122376 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122377 +hash_setkey_48310 hash_setkey 3 48310 NULL
122378 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122379 +skb_add_data_48363 skb_add_data 3 48363 NULL
122380 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122381 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122382 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122383 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122384 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122385 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122386 +print_filtered_48442 print_filtered 2-0 48442 NULL
122387 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122388 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122389 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122390 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122391 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122392 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122393 +send_control_msg_48498 send_control_msg 6 48498 NULL
122394 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122395 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122396 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122397 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122398 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122399 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122400 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122401 +llog_data_len_48607 llog_data_len 1 48607 NULL
122402 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122403 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122404 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122405 +mtd_read_48655 mtd_read 0 48655 NULL
122406 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122407 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122408 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122409 +altera_drscan_48698 altera_drscan 2 48698 NULL
122410 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122411 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122412 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122413 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122414 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122415 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122416 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122417 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122418 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122419 +azx_get_position_48841 azx_get_position 0 48841 NULL
122420 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122421 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122422 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122423 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122424 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122425 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122426 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122427 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122428 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122429 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122430 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122431 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122432 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122433 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122434 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122435 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122436 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122437 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122438 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122439 +transient_status_49027 transient_status 4 49027 NULL
122440 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122441 +scsi_register_49094 scsi_register 2 49094 NULL
122442 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122443 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122444 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122445 +pt_read_49136 pt_read 3 49136 NULL
122446 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122447 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122448 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122449 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122450 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122451 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122452 +print_queue_49191 print_queue 0-4 49191 NULL
122453 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122454 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122455 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122456 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122457 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122458 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122459 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122460 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122461 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122462 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122463 +uio_read_49300 uio_read 3 49300 NULL
122464 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122465 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122466 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122467 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122468 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122469 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122470 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122471 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122472 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122473 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122474 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122475 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122476 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122477 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122478 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122479 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122480 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122481 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122482 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122483 +smk_write_access_49561 smk_write_access 3 49561 NULL
122484 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122485 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122486 +readfifo_49583 readfifo 1 49583 NULL
122487 +tap_write_49595 tap_write 3 49595 NULL
122488 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122489 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122490 +heap_init_49617 heap_init 2 49617 NULL
122491 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122492 +port_fops_read_49626 port_fops_read 3 49626 NULL
122493 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122494 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122495 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122496 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122497 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122498 +write_pool_49718 write_pool 3 49718 NULL
122499 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122500 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122501 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122502 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122503 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122504 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122505 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122506 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122507 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122508 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122509 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122510 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122511 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122512 +add_uuid_49831 add_uuid 4 49831 NULL
122513 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122514 +twl4030_write_49846 twl4030_write 2 49846 NULL
122515 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122516 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122517 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122518 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122519 +osc_brw_49896 osc_brw 4 49896 NULL
122520 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122521 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122522 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122523 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122524 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122525 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122526 +isdn_read_50021 isdn_read 3 50021 NULL
122527 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122528 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122529 +ioread8_50049 ioread8 0 50049 NULL
122530 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122531 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122532 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122533 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122534 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122535 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122536 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122537 +read_file_slot_50111 read_file_slot 3 50111 NULL
122538 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122539 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122540 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122541 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122542 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122543 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122544 +odev_update_50169 odev_update 2 50169 NULL
122545 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122546 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122547 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122548 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122549 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122550 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122551 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122552 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122553 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122554 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122555 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122556 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122557 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122558 +do_launder_page_50329 do_launder_page 0 50329 NULL
122559 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122560 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122561 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122562 +tpm_read_50344 tpm_read 3 50344 NULL
122563 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122564 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122565 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122566 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122567 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122568 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122569 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122570 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122571 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122572 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122573 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122574 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122575 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122576 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122577 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122578 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122579 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122580 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122581 +fat_readpages_50582 fat_readpages 4 50582 NULL
122582 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122583 +xillybus_write_50605 xillybus_write 3 50605 NULL
122584 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122585 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122586 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122587 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122588 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122589 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122590 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122591 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122592 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122593 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122594 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122595 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122596 +tpm_write_50798 tpm_write 3 50798 NULL
122597 +tun_do_read_50800 tun_do_read 4 50800 NULL
122598 +write_flush_50803 write_flush 3 50803 NULL
122599 +dvb_play_50814 dvb_play 3 50814 NULL
122600 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122601 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122602 +SetArea_50835 SetArea 4 50835 NULL
122603 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122604 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122605 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122606 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122607 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122608 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122609 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122610 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122611 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122612 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122613 +show_device_status_50947 show_device_status 0 50947 NULL
122614 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122615 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122616 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122617 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122618 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122619 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122620 +timeout_write_50991 timeout_write 3 50991 NULL
122621 +proc_write_51003 proc_write 3 51003 NULL
122622 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122623 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122624 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122625 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122626 +dump_midi_51040 dump_midi 3 51040 NULL
122627 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122628 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122629 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122630 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122631 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122632 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122633 +ti_recv_51110 ti_recv 3 51110 NULL
122634 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
122635 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
122636 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
122637 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
122638 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
122639 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
122640 +drm_property_create_51239 drm_property_create 4 51239 NULL
122641 +st_read_51251 st_read 3 51251 NULL
122642 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
122643 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
122644 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
122645 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
122646 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
122647 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
122648 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
122649 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
122650 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
122651 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
122652 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
122653 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
122654 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
122655 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
122656 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
122657 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
122658 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
122659 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
122660 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
122661 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
122662 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
122663 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
122664 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
122665 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
122666 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
122667 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
122668 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
122669 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
122670 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
122671 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
122672 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
122673 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
122674 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
122675 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
122676 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
122677 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
122678 +sel_write_access_51704 sel_write_access 3 51704 NULL
122679 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
122680 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
122681 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
122682 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
122683 +str_read_51731 str_read 4 51731 NULL
122684 +cm4040_read_51732 cm4040_read 3 51732 NULL
122685 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
122686 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
122687 +if_write_51756 if_write 3 51756 NULL
122688 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
122689 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
122690 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
122691 +ioread32_51847 ioread32 0 51847 NULL nohasharray
122692 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
122693 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
122694 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
122695 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
122696 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
122697 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
122698 +user_read_51881 user_read 3 51881 NULL
122699 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
122700 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
122701 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
122702 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
122703 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
122704 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
122705 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
122706 +get_clock_info_51952 get_clock_info 4 51952 NULL
122707 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
122708 +get_zone_51981 get_zone 0-1 51981 NULL
122709 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
122710 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
122711 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
122712 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
122713 +rdmalt_52022 rdmalt 0 52022 NULL
122714 +override_release_52032 override_release 2 52032 NULL
122715 +end_port_52042 end_port 0 52042 NULL
122716 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
122717 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
122718 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
122719 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
122720 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
122721 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
122722 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
122723 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
122724 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
122725 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
122726 +retry_count_read_52129 retry_count_read 3 52129 NULL
122727 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
122728 +sub_alloc_52140 sub_alloc 0 52140 NULL
122729 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
122730 +htable_size_52148 htable_size 0-1 52148 NULL
122731 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
122732 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
122733 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
122734 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
122735 +print_prefix_52176 print_prefix 0 52176 NULL
122736 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
122737 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
122738 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
122739 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
122740 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
122741 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
122742 +shrink_slab_52261 shrink_slab 2 52261 NULL
122743 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
122744 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
122745 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
122746 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
122747 +read_file_reset_52310 read_file_reset 3 52310 NULL
122748 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
122749 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
122750 +hwflags_read_52318 hwflags_read 3 52318 NULL
122751 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
122752 +hur_len_52339 hur_len 0 52339 NULL
122753 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
122754 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
122755 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
122756 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
122757 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
122758 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
122759 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
122760 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
122761 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
122762 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
122763 +delay_status_52431 delay_status 5 52431 NULL
122764 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
122765 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
122766 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
122767 +bt_alloc_52457 bt_alloc 2 52457 NULL
122768 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
122769 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
122770 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
122771 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
122772 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
122773 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
122774 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
122775 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
122776 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
122777 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
122778 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
122779 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
122780 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
122781 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
122782 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
122783 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
122784 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
122785 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
122786 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
122787 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
122788 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
122789 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
122790 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
122791 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
122792 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
122793 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
122794 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
122795 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
122796 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
122797 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
122798 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
122799 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
122800 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
122801 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
122802 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
122803 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
122804 +twlreg_write_52880 twlreg_write 3 52880 NULL
122805 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
122806 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
122807 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
122808 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
122809 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
122810 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
122811 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
122812 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
122813 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
122814 +num_node_state_52989 num_node_state 0 52989 NULL
122815 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
122816 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
122817 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
122818 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
122819 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
122820 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
122821 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
122822 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
122823 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
122824 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
122825 +verity_status_53120 verity_status 5 53120 NULL
122826 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
122827 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
122828 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
122829 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
122830 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
122831 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
122832 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
122833 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
122834 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
122835 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
122836 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
122837 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
122838 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
122839 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
122840 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
122841 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
122842 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
122843 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
122844 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
122845 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
122846 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
122847 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
122848 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
122849 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
122850 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
122851 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
122852 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
122853 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
122854 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
122855 +check_acl_53512 check_acl 0 53512 NULL nohasharray
122856 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
122857 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
122858 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
122859 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
122860 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
122861 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
122862 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
122863 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
122864 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
122865 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
122866 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
122867 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
122868 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
122869 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
122870 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
122871 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
122872 +wdm_write_53735 wdm_write 3 53735 NULL
122873 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
122874 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
122875 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
122876 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
122877 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
122878 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
122879 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
122880 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
122881 +setup_data_read_53822 setup_data_read 3 53822 NULL
122882 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
122883 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
122884 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
122885 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
122886 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
122887 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
122888 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
122889 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
122890 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
122891 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
122892 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
122893 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
122894 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
122895 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
122896 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
122897 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
122898 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
122899 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
122900 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
122901 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
122902 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
122903 +strn_len_54122 strn_len 0 54122 NULL
122904 +isku_receive_54130 isku_receive 4 54130 NULL
122905 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
122906 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
122907 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
122908 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
122909 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
122910 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
122911 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
122912 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
122913 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
122914 +reada_add_block_54247 reada_add_block 2 54247 NULL
122915 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
122916 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
122917 +audio_write_54261 audio_write 4 54261 NULL nohasharray
122918 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
122919 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
122920 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
122921 +sizeof_long_54276 sizeof_long 0 54276 NULL
122922 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
122923 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
122924 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
122925 +sprintf_54306 sprintf 0 54306 NULL
122926 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
122927 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
122928 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
122929 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
122930 +readlink_copy_54366 readlink_copy 2 54366 NULL
122931 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
122932 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
122933 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
122934 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
122935 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
122936 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
122937 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
122938 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
122939 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
122940 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
122941 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
122942 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
122943 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
122944 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
122945 +viacam_read_54526 viacam_read 3 54526 NULL
122946 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
122947 +setsockopt_54539 setsockopt 5 54539 NULL
122948 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
122949 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
122950 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
122951 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
122952 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
122953 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
122954 +port_fops_write_54627 port_fops_write 3 54627 NULL
122955 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
122956 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
122957 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
122958 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
122959 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
122960 +bus_add_device_54665 bus_add_device 0 54665 NULL
122961 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
122962 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
122963 +evm_read_key_54674 evm_read_key 3 54674 NULL
122964 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
122965 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
122966 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
122967 +kzalloc_54740 kzalloc 1 54740 NULL
122968 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
122969 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
122970 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
122971 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
122972 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
122973 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
122974 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
122975 +nfsd_write_54809 nfsd_write 6 54809 NULL
122976 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
122977 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
122978 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
122979 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
122980 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
122981 +write_rio_54837 write_rio 3 54837 NULL
122982 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
122983 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
122984 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
122985 +printer_read_54851 printer_read 3 54851 NULL
122986 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
122987 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
122988 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
122989 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
122990 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
122991 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
122992 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
122993 +add_port_54941 add_port 2 54941 NULL
122994 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
122995 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
122996 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
122997 +c4_add_card_54968 c4_add_card 3 54968 NULL
122998 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
122999 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123000 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123001 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123002 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123003 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123004 +read_dma_55086 read_dma 3 55086 NULL
123005 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123006 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123007 +filldir_55137 filldir 3 55137 NULL
123008 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123009 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123010 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123011 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123012 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123013 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123014 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123015 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123016 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123017 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123018 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123019 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123020 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123021 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123022 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123023 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123024 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123025 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123026 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123027 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123028 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123029 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123030 +vme_user_read_55338 vme_user_read 3 55338 NULL
123031 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123032 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123033 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123034 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123035 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123036 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123037 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123038 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123039 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123040 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123041 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123042 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123043 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123044 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123045 +ea_get_55522 ea_get 3-0 55522 NULL
123046 +buffer_size_55534 buffer_size 0 55534 NULL
123047 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123048 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123049 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123050 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123051 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123052 +add_partition_55588 add_partition 2 55588 NULL
123053 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123054 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123055 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123056 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123057 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123058 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123059 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123060 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123061 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123062 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123063 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123064 +get_info_55681 get_info 3 55681 NULL
123065 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123066 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123067 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123068 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123069 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123070 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123071 +set_local_name_55757 set_local_name 4 55757 NULL
123072 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123073 +strlen_55778 strlen 0 55778 NULL
123074 +set_spte_55783 set_spte 4-5 55783 NULL
123075 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123076 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123077 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123078 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123079 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123080 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123081 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123082 +hsc_write_55875 hsc_write 3 55875 NULL
123083 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123084 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123085 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123086 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123087 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123088 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123089 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123090 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123091 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123092 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123093 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123094 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123095 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123096 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123097 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123098 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123099 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123100 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123101 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123102 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123103 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123104 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123105 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123106 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123107 +fd_copyin_56247 fd_copyin 3 56247 NULL
123108 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123109 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123110 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123111 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123112 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123113 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123114 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123115 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123116 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123117 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123118 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123119 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123120 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123121 +dev_read_56369 dev_read 3 56369 NULL
123122 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123123 +lnet_ping_56378 lnet_ping 4 56378 NULL
123124 +write_gssp_56404 write_gssp 3 56404 NULL
123125 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123126 +store_msg_56417 store_msg 3 56417 NULL
123127 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123128 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
123129 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123130 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123131 +fl_create_56435 fl_create 5 56435 NULL
123132 +gnttab_map_56439 gnttab_map 2 56439 NULL
123133 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123134 +set_connectable_56458 set_connectable 4 56458 NULL
123135 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123136 +putused_user_56467 putused_user 3 56467 NULL
123137 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123138 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123139 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123140 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123141 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123142 +init_map_ip_56508 init_map_ip 5 56508 NULL
123143 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123144 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123145 +ip_options_get_56538 ip_options_get 4 56538 NULL
123146 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123147 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123148 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123149 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123150 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123151 +event_filter_write_56609 event_filter_write 3 56609 NULL
123152 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123153 +gather_array_56641 gather_array 3 56641 NULL
123154 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123155 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123156 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123157 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123158 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123159 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123160 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123161 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123162 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123163 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123164 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123165 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123166 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123167 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123168 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123169 +do_syslog_56807 do_syslog 3 56807 NULL
123170 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123171 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123172 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123173 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123174 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123175 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123176 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123177 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123178 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123179 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123180 +strcspn_56913 strcspn 0 56913 NULL
123181 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123182 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123183 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123184 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123185 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123186 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123187 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123188 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123189 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123190 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123191 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123192 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123193 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123194 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123195 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123196 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123197 +altera_get_note_57099 altera_get_note 6 57099 NULL
123198 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123199 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123200 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123201 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123202 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123203 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123204 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123205 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123206 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123207 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123208 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123209 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123210 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123211 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123212 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123213 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123214 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123215 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123216 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123217 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123218 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123219 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123220 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123221 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123222 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123223 +write_file_regval_57313 write_file_regval 3 57313 NULL
123224 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123225 +usblp_read_57342 usblp_read 3 57342 NULL
123226 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123227 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123228 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123229 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123230 +read_file_blob_57406 read_file_blob 3 57406 NULL
123231 +enclosure_register_57412 enclosure_register 3 57412 NULL
123232 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123233 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123234 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123235 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123236 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123237 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123238 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123239 +skb_headlen_57501 skb_headlen 0 57501 NULL
123240 +copy_in_user_57502 copy_in_user 3 57502 NULL
123241 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123242 +init_tag_map_57515 init_tag_map 3 57515 NULL
123243 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123244 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123245 +cmm_read_57520 cmm_read 3 57520 NULL
123246 +inode_permission_57531 inode_permission 0 57531 NULL
123247 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123248 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123249 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123250 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123251 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123252 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123253 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123254 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123255 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123256 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123257 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123258 +mem_read_57631 mem_read 3 57631 NULL
123259 +r3964_write_57662 r3964_write 4 57662 NULL
123260 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123261 +__lgwrite_57669 __lgwrite 4 57669 NULL
123262 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123263 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123264 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123265 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123266 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123267 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123268 +ld2_57794 ld2 0 57794 NULL
123269 +ivtv_read_57796 ivtv_read 3 57796 NULL
123270 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123271 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123272 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123273 +flash_read_57843 flash_read 3 57843 NULL
123274 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123275 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123276 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123277 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123278 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123279 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123280 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123281 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123282 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123283 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123284 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123285 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123286 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123287 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123288 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123289 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123290 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123291 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123292 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123293 +mce_async_out_58056 mce_async_out 3 58056 NULL
123294 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123295 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123296 +cm4040_write_58079 cm4040_write 3 58079 NULL
123297 +savemem_58129 savemem 3 58129 NULL
123298 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123299 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123300 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123301 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123302 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123303 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123304 +read_file_debug_58256 read_file_debug 3 58256 NULL
123305 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123306 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123307 +profile_load_58267 profile_load 3 58267 NULL
123308 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123309 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123310 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123311 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123312 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123313 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123314 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123315 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123316 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123317 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123318 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123319 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123320 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123321 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123322 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123323 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123324 +capabilities_read_58457 capabilities_read 3 58457 NULL
123325 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123326 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123327 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123328 +nv_rd08_58472 nv_rd08 0 58472 NULL
123329 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123330 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123331 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123332 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123333 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123334 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123335 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123336 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123337 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123338 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123339 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123340 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123341 +xip_file_read_58592 xip_file_read 3 58592 NULL
123342 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123343 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123344 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123345 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123346 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123347 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123348 +find_zero_58685 find_zero 0-1 58685 NULL
123349 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123350 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123351 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123352 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123353 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123354 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123355 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123356 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123357 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123358 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123359 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123360 +ep_read_58813 ep_read 3 58813 NULL
123361 +command_write_58841 command_write 3 58841 NULL
123362 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123363 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123364 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123365 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123366 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123367 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123368 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123369 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123370 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123371 +init_list_set_59005 init_list_set 3 59005 NULL
123372 +ep_write_59008 ep_write 3 59008 NULL
123373 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123374 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123375 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123376 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123377 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123378 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123379 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123380 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123381 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123382 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123383 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123384 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123385 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123386 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123387 +ksize_59176 ksize 0 59176 NULL
123388 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123389 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123390 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123391 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123392 +dt3155_read_59226 dt3155_read 3 59226 NULL
123393 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123394 +nla_len_59258 nla_len 0 59258 NULL
123395 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123396 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123397 +fd_copyout_59323 fd_copyout 3 59323 NULL
123398 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123399 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123400 +__map_request_59350 __map_request 0 59350 NULL
123401 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123402 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123403 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123404 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123405 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123406 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123407 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123408 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123409 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123410 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123411 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123412 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123413 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123414 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123415 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123416 +tunables_write_59563 tunables_write 3 59563 NULL
123417 +bio_split_59564 bio_split 2 59564 NULL
123418 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123419 +write_pbl_59583 write_pbl 4 59583 NULL
123420 +memdup_user_59590 memdup_user 2 59590 NULL
123421 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123422 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123423 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123424 +mtrr_write_59622 mtrr_write 3 59622 NULL
123425 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123426 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123427 +hidraw_read_59650 hidraw_read 3 59650 NULL
123428 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123429 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123430 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123431 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123432 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123433 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123434 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123435 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
123436 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123437 +strnlen_59746 strnlen 0 59746 NULL
123438 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123439 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123440 +venus_remove_59781 venus_remove 4 59781 NULL
123441 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123442 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123443 +ipw_write_59807 ipw_write 3 59807 NULL
123444 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123445 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123446 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123447 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123448 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123449 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123450 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123451 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123452 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123453 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123454 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123455 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123456 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123457 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123458 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123459 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123460 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123461 +copy_items_60009 copy_items 7 60009 NULL
123462 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123463 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123464 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123465 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123466 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123467 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123468 +vcs_size_60050 vcs_size 0 60050 NULL
123469 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123470 +compat_writev_60063 compat_writev 3 60063 NULL
123471 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123472 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123473 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123474 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123475 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123476 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123477 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123478 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123479 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123480 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123481 +init_state_60165 init_state 2 60165 NULL
123482 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123483 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123484 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123485 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
123486 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123487 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123488 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123489 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123490 +printer_write_60276 printer_write 3 60276 NULL
123491 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123492 +getDataLength_60301 getDataLength 0 60301 NULL
123493 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123494 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123495 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123496 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123497 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123498 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123499 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123500 +driver_names_read_60399 driver_names_read 3 60399 NULL
123501 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123502 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123503 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123504 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123505 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123506 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123507 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123508 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123509 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123510 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123511 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123512 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123513 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123514 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123515 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123516 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123517 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123518 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123519 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123520 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123521 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123522 +raid_status_60755 raid_status 5 60755 NULL
123523 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123524 +opticon_write_60775 opticon_write 4 60775 NULL
123525 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123526 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123527 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123528 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123529 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123530 +generic_writepages_60871 generic_writepages 0 60871 NULL
123531 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123532 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123533 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123534 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123535 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123536 +pti_char_write_60960 pti_char_write 3 60960 NULL
123537 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123538 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123539 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123540 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123541 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123542 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123543 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123544 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123545 +symtab_init_61050 symtab_init 2 61050 NULL
123546 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123547 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123548 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123549 +get_derived_key_61100 get_derived_key 4 61100 NULL
123550 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123551 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123552 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123553 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123554 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123555 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123556 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123557 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123558 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123559 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123560 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123561 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123562 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123563 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123564 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123565 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123566 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123567 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123568 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123569 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123570 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123571 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123572 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123573 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123574 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123575 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123576 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123577 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123578 +system_enable_write_61396 system_enable_write 3 61396 NULL
123579 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123580 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123581 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123582 +erst_errno_61526 erst_errno 0 61526 NULL
123583 +proc_write_device_61541 proc_write_device 3 61541 NULL
123584 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123585 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123586 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123587 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123588 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123589 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123590 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123591 +seq_open_private_61589 seq_open_private 3 61589 NULL
123592 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123593 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123594 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123595 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123596 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123597 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123598 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123599 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123600 +resize_stripes_61650 resize_stripes 2 61650 NULL
123601 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123602 +insert_one_name_61668 insert_one_name 7 61668 NULL
123603 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123604 +lock_loop_61681 lock_loop 1 61681 NULL
123605 +filter_read_61692 filter_read 3 61692 NULL
123606 +iov_length_61716 iov_length 0 61716 NULL
123607 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123608 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123609 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123610 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123611 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123612 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123613 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123614 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123615 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123616 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123617 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123618 +get_fw_name_61874 get_fw_name 3 61874 NULL
123619 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123620 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123621 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123622 +kernfs_name_61910 kernfs_name 3 61910 NULL
123623 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
123624 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
123625 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
123626 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
123627 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
123628 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
123629 +fix_read_error_61965 fix_read_error 4 61965 NULL
123630 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
123631 +cow_file_range_61979 cow_file_range 3 61979 NULL
123632 +dequeue_event_62000 dequeue_event 3 62000 NULL
123633 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
123634 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
123635 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
123636 +SYSC_select_62024 SYSC_select 1 62024 NULL
123637 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
123638 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
123639 +do_pselect_62061 do_pselect 1 62061 NULL
123640 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
123641 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
123642 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
123643 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
123644 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
123645 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
123646 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
123647 +ql_status_62135 ql_status 5 62135 NULL nohasharray
123648 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
123649 +video_usercopy_62151 video_usercopy 2 62151 NULL
123650 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
123651 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
123652 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
123653 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
123654 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
123655 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
123656 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
123657 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
123658 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
123659 +get_random_int_62279 get_random_int 0 62279 NULL
123660 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
123661 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
123662 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
123663 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
123664 +subseq_list_62332 subseq_list 3-0 62332 NULL
123665 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
123666 +flash_write_62354 flash_write 3 62354 NULL
123667 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
123668 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
123669 +altera_irscan_62396 altera_irscan 2 62396 NULL
123670 +set_ssp_62411 set_ssp 4 62411 NULL
123671 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
123672 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
123673 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
123674 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
123675 +debugfs_read_62535 debugfs_read 3 62535 NULL
123676 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
123677 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
123678 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
123679 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
123680 +get_subdir_62581 get_subdir 3 62581 NULL
123681 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
123682 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
123683 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
123684 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
123685 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
123686 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
123687 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
123688 +rdm_62719 rdm 0 62719 NULL
123689 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
123690 +key_replays_read_62746 key_replays_read 3 62746 NULL
123691 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
123692 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
123693 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
123694 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
123695 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
123696 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
123697 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
123698 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
123699 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
123700 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
123701 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
123702 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
123703 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
123704 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
123705 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
123706 +aoechr_write_62883 aoechr_write 3 62883 NULL
123707 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
123708 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
123709 +getdqbuf_62908 getdqbuf 1 62908 NULL
123710 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
123711 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
123712 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
123713 +hwdep_read_62992 hwdep_read 3 62992 NULL
123714 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
123715 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
123716 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
123717 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
123718 +unlink1_63059 unlink1 3 63059 NULL
123719 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
123720 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
123721 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
123722 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
123723 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
123724 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
123725 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
123726 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
123727 +vme_master_read_63221 vme_master_read 0 63221 NULL
123728 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
123729 +ptp_read_63251 ptp_read 4 63251 NULL
123730 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
123731 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
123732 +raid5_resize_63306 raid5_resize 2 63306 NULL
123733 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
123734 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
123735 +proc_info_read_63344 proc_info_read 3 63344 NULL
123736 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
123737 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
123738 +idmouse_read_63374 idmouse_read 3 63374 NULL
123739 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
123740 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
123741 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
123742 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
123743 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
123744 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
123745 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
123746 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
123747 +read_kcore_63488 read_kcore 3 63488 NULL
123748 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
123749 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
123750 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
123751 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
123752 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
123753 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
123754 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
123755 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
123756 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
123757 +write_debug_level_63613 write_debug_level 3 63613 NULL
123758 +__spi_validate_63618 __spi_validate 0 63618 NULL
123759 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
123760 +hid_report_len_63637 hid_report_len 0 63637 NULL
123761 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
123762 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
123763 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
123764 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
123765 +vbi_read_63673 vbi_read 3 63673 NULL
123766 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
123767 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
123768 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
123769 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
123770 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
123771 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
123772 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
123773 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
123774 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
123775 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
123776 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
123777 +sel_write_load_63830 sel_write_load 3 63830 NULL
123778 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
123779 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
123780 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
123781 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
123782 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
123783 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
123784 +__team_options_register_63941 __team_options_register 3 63941 NULL
123785 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
123786 +set_bredr_63975 set_bredr 4 63975 NULL
123787 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
123788 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
123789 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
123790 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
123791 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
123792 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
123793 +__sock_create_64069 __sock_create 0 64069 NULL
123794 +get_u8_64076 get_u8 0 64076 NULL
123795 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
123796 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
123797 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
123798 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
123799 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
123800 +to_bytes_64103 to_bytes 0-1 64103 NULL
123801 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
123802 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
123803 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
123804 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
123805 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
123806 +init_bch_64130 init_bch 1-2 64130 NULL
123807 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
123808 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
123809 +number_of_tds_64156 number_of_tds 0 64156 NULL
123810 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
123811 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
123812 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
123813 +read_pulse_64227 read_pulse 0-3 64227 NULL
123814 +ea_len_64229 ea_len 0 64229 NULL
123815 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
123816 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
123817 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
123818 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
123819 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
123820 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
123821 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
123822 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
123823 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
123824 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
123825 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
123826 +ts_write_64336 ts_write 3 64336 NULL
123827 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
123828 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
123829 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
123830 +reg_create_64372 reg_create 5 64372 NULL
123831 +ilo_write_64378 ilo_write 3 64378 NULL
123832 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
123833 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
123834 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
123835 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
123836 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
123837 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
123838 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
123839 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
123840 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
123841 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
123842 +single_open_size_64483 single_open_size 4 64483 NULL
123843 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
123844 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
123845 +remove_uuid_64505 remove_uuid 4 64505 NULL
123846 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
123847 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
123848 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
123849 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
123850 +SyS_bind_64544 SyS_bind 3 64544 NULL
123851 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
123852 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
123853 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
123854 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
123855 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
123856 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
123857 +do_erase_64574 do_erase 4 64574 NULL
123858 +fanotify_write_64623 fanotify_write 3 64623 NULL
123859 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
123860 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
123861 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
123862 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
123863 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
123864 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
123865 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
123866 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
123867 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
123868 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
123869 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
123870 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
123871 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
123872 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
123873 +hwdep_write_64776 hwdep_write 3 64776 NULL
123874 +message_for_md_64777 message_for_md 5 64777 NULL
123875 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
123876 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
123877 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
123878 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
123879 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
123880 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
123881 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
123882 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
123883 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
123884 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
123885 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
123886 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
123887 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
123888 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
123889 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
123890 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
123891 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
123892 +insert_dent_65034 insert_dent 7 65034 NULL
123893 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
123894 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
123895 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
123896 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
123897 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
123898 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
123899 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
123900 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
123901 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
123902 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
123903 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
123904 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
123905 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
123906 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
123907 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
123908 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
123909 +get_var_len_65304 get_var_len 0 65304 NULL
123910 +unpack_array_65318 unpack_array 0 65318 NULL
123911 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
123912 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
123913 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
123914 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
123915 +SyS_writev_65372 SyS_writev 3 65372 NULL
123916 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
123917 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
123918 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
123919 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
123920 +device_add_groups_65423 device_add_groups 0 65423 NULL
123921 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
123922 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
123923 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
123924 +clear_user_65470 clear_user 2 65470 NULL
123925 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
123926 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
123927 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
123928 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
123929 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123930 new file mode 100644
123931 index 0000000..560cd7b
123932 --- /dev/null
123933 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123934 @@ -0,0 +1,92 @@
123935 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
123936 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
123937 +mappedread_2627 mappedread 2 2627 NULL
123938 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
123939 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
123940 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
123941 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
123942 +dmu_write_6048 dmu_write 4-3 6048 NULL
123943 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
123944 +update_pages_6225 update_pages 2-3 6225 NULL
123945 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
123946 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
123947 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
123948 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
123949 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
123950 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
123951 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
123952 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
123953 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
123954 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
123955 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
123956 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
123957 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
123958 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
123959 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
123960 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
123961 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
123962 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
123963 +uiocopy_18680 uiocopy 2 18680 NULL
123964 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
123965 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
123966 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
123967 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
123968 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
123969 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
123970 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
123971 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
123972 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
123973 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
123974 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
123975 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
123976 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
123977 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
123978 +splat_write_30943 splat_write 3 30943 NULL
123979 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
123980 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
123981 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
123982 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
123983 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
123984 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
123985 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
123986 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
123987 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
123988 +copyinstr_36980 copyinstr 3 36980 NULL
123989 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
123990 +splat_read_38116 splat_read 3 38116 NULL
123991 +sa_setup_38756 sa_setup 4 38756 NULL
123992 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
123993 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
123994 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
123995 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
123996 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
123997 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
123998 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
123999 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124000 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124001 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124002 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124003 +kcopy_write_43683 kcopy_write 3 43683 NULL
124004 +uiomove_44355 uiomove 2 44355 NULL
124005 +dmu_read_44418 dmu_read 4-3 44418 NULL
124006 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124007 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124008 +copyin_45945 copyin 3 45945 NULL
124009 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124010 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124011 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124012 +spa_history_write_49650 spa_history_write 3 49650 NULL
124013 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124014 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124015 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124016 +copyout_51409 copyout 3 51409 NULL
124017 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124018 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124019 +get_nvlist_56685 get_nvlist 2 56685 NULL
124020 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124021 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124022 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124023 +zpios_write_61823 zpios_write 3 61823 NULL
124024 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124025 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124026 +zpios_read_64734 zpios_read 3 64734 NULL
124027 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124028 new file mode 100644
124029 index 0000000..95f7abd
124030 --- /dev/null
124031 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124032 @@ -0,0 +1,259 @@
124033 +/*
124034 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124035 + * Licensed under the GPL v2, or (at your option) v3
124036 + *
124037 + * Homepage:
124038 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124039 + *
124040 + * Documentation:
124041 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124042 + *
124043 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124044 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124045 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124046 + *
124047 + * Usage:
124048 + * $ make
124049 + * $ make run
124050 + */
124051 +
124052 +#include "gcc-common.h"
124053 +#include "size_overflow.h"
124054 +
124055 +int plugin_is_GPL_compatible;
124056 +
124057 +tree report_size_overflow_decl;
124058 +
124059 +tree size_overflow_type_HI;
124060 +tree size_overflow_type_SI;
124061 +tree size_overflow_type_DI;
124062 +tree size_overflow_type_TI;
124063 +
124064 +static struct plugin_info size_overflow_plugin_info = {
124065 + .version = "20140725",
124066 + .help = "no-size-overflow\tturn off size overflow checking\n",
124067 +};
124068 +
124069 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124070 +{
124071 + unsigned int arg_count;
124072 + enum tree_code code = TREE_CODE(*node);
124073 +
124074 + switch (code) {
124075 + case FUNCTION_DECL:
124076 + arg_count = type_num_arguments(TREE_TYPE(*node));
124077 + break;
124078 + case FUNCTION_TYPE:
124079 + case METHOD_TYPE:
124080 + arg_count = type_num_arguments(*node);
124081 + break;
124082 + default:
124083 + *no_add_attrs = true;
124084 + error("%s: %qE attribute only applies to functions", __func__, name);
124085 + return NULL_TREE;
124086 + }
124087 +
124088 + for (; args; args = TREE_CHAIN(args)) {
124089 + tree position = TREE_VALUE(args);
124090 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124091 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124092 + *no_add_attrs = true;
124093 + }
124094 + }
124095 + return NULL_TREE;
124096 +}
124097 +
124098 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124099 +{
124100 + unsigned int arg_count;
124101 + enum tree_code code = TREE_CODE(*node);
124102 +
124103 + switch (code) {
124104 + case FUNCTION_DECL:
124105 + arg_count = type_num_arguments(TREE_TYPE(*node));
124106 + break;
124107 + case FUNCTION_TYPE:
124108 + case METHOD_TYPE:
124109 + arg_count = type_num_arguments(*node);
124110 + break;
124111 + case FIELD_DECL:
124112 + return NULL_TREE;
124113 + default:
124114 + *no_add_attrs = true;
124115 + error("%qE attribute only applies to functions", name);
124116 + return NULL_TREE;
124117 + }
124118 +
124119 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124120 + return NULL_TREE;
124121 +
124122 + for (; args; args = TREE_CHAIN(args)) {
124123 + tree position = TREE_VALUE(args);
124124 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124125 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124126 + *no_add_attrs = true;
124127 + }
124128 + }
124129 + return NULL_TREE;
124130 +}
124131 +
124132 +static struct attribute_spec size_overflow_attr = {
124133 + .name = "size_overflow",
124134 + .min_length = 1,
124135 + .max_length = -1,
124136 + .decl_required = true,
124137 + .type_required = false,
124138 + .function_type_required = false,
124139 + .handler = handle_size_overflow_attribute,
124140 +#if BUILDING_GCC_VERSION >= 4007
124141 + .affects_type_identity = false
124142 +#endif
124143 +};
124144 +
124145 +static struct attribute_spec intentional_overflow_attr = {
124146 + .name = "intentional_overflow",
124147 + .min_length = 1,
124148 + .max_length = -1,
124149 + .decl_required = true,
124150 + .type_required = false,
124151 + .function_type_required = false,
124152 + .handler = handle_intentional_overflow_attribute,
124153 +#if BUILDING_GCC_VERSION >= 4007
124154 + .affects_type_identity = false
124155 +#endif
124156 +};
124157 +
124158 +static void register_attributes(void __unused *event_data, void __unused *data)
124159 +{
124160 + register_attribute(&size_overflow_attr);
124161 + register_attribute(&intentional_overflow_attr);
124162 +}
124163 +
124164 +static tree create_typedef(tree type, const char* ident)
124165 +{
124166 + tree new_type, decl;
124167 +
124168 + new_type = build_variant_type_copy(type);
124169 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124170 + DECL_ORIGINAL_TYPE(decl) = type;
124171 + TYPE_NAME(new_type) = decl;
124172 + return new_type;
124173 +}
124174 +
124175 +// Create the noreturn report_size_overflow() function decl.
124176 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124177 +{
124178 + tree const_char_ptr_type_node;
124179 + tree fntype;
124180 +
124181 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124182 +
124183 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124184 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124185 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124186 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124187 +
124188 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124189 + fntype = build_function_type_list(void_type_node,
124190 + const_char_ptr_type_node,
124191 + unsigned_type_node,
124192 + const_char_ptr_type_node,
124193 + const_char_ptr_type_node,
124194 + NULL_TREE);
124195 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124196 +
124197 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124198 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124199 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124200 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124201 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124202 +}
124203 +
124204 +
124205 +extern struct gimple_opt_pass pass_dce;
124206 +
124207 +static struct opt_pass *make_dce_pass(void)
124208 +{
124209 +#if BUILDING_GCC_VERSION >= 4009
124210 + return make_pass_dce(g);
124211 +#else
124212 + return &pass_dce.pass;
124213 +#endif
124214 +}
124215 +
124216 +
124217 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124218 +{
124219 + int i;
124220 + const char * const plugin_name = plugin_info->base_name;
124221 + const int argc = plugin_info->argc;
124222 + const struct plugin_argument * const argv = plugin_info->argv;
124223 + bool enable = true;
124224 + struct register_pass_info insert_size_overflow_asm_pass_info;
124225 + struct register_pass_info __unused dump_before_pass_info;
124226 + struct register_pass_info __unused dump_after_pass_info;
124227 + struct register_pass_info insert_size_overflow_check_info;
124228 + struct register_pass_info dce_pass_info;
124229 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124230 + {
124231 + .base = &report_size_overflow_decl,
124232 + .nelt = 1,
124233 + .stride = sizeof(report_size_overflow_decl),
124234 + .cb = &gt_ggc_mx_tree_node,
124235 + .pchw = &gt_pch_nx_tree_node
124236 + },
124237 + LAST_GGC_ROOT_TAB
124238 + };
124239 +
124240 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124241 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124242 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124243 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124244 +
124245 + dump_before_pass_info.pass = make_dump_pass();
124246 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124247 + dump_before_pass_info.ref_pass_instance_number = 1;
124248 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124249 +
124250 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124251 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124252 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124253 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124254 +
124255 + dump_after_pass_info.pass = make_dump_pass();
124256 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124257 + dump_after_pass_info.ref_pass_instance_number = 1;
124258 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124259 +
124260 + dce_pass_info.pass = make_dce_pass();
124261 + dce_pass_info.reference_pass_name = "vrp";
124262 + dce_pass_info.ref_pass_instance_number = 1;
124263 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124264 +
124265 + if (!plugin_default_version_check(version, &gcc_version)) {
124266 + error(G_("incompatible gcc/plugin versions"));
124267 + return 1;
124268 + }
124269 +
124270 + for (i = 0; i < argc; ++i) {
124271 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124272 + enable = false;
124273 + continue;
124274 + }
124275 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124276 + }
124277 +
124278 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124279 + if (enable) {
124280 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124281 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124282 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124283 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124284 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124285 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124286 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124287 + }
124288 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124289 +
124290 + return 0;
124291 +}
124292 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124293 new file mode 100644
124294 index 0000000..0888f6c
124295 --- /dev/null
124296 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124297 @@ -0,0 +1,364 @@
124298 +/*
124299 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124300 + * Licensed under the GPL v2, or (at your option) v3
124301 + *
124302 + * Homepage:
124303 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124304 + *
124305 + * Documentation:
124306 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124307 + *
124308 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124309 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124310 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124311 + *
124312 + * Usage:
124313 + * $ make
124314 + * $ make run
124315 + */
124316 +
124317 +#include "gcc-common.h"
124318 +#include "size_overflow.h"
124319 +
124320 +#include "size_overflow_hash.h"
124321 +#include "size_overflow_hash_aux.h"
124322 +
124323 +#define CODES_LIMIT 32
124324 +
124325 +static unsigned char get_tree_code(const_tree type)
124326 +{
124327 + switch (TREE_CODE(type)) {
124328 + case ARRAY_TYPE:
124329 + return 0;
124330 + case BOOLEAN_TYPE:
124331 + return 1;
124332 + case ENUMERAL_TYPE:
124333 + return 2;
124334 + case FUNCTION_TYPE:
124335 + return 3;
124336 + case INTEGER_TYPE:
124337 + return 4;
124338 + case POINTER_TYPE:
124339 + return 5;
124340 + case RECORD_TYPE:
124341 + return 6;
124342 + case UNION_TYPE:
124343 + return 7;
124344 + case VOID_TYPE:
124345 + return 8;
124346 + case REAL_TYPE:
124347 + return 9;
124348 + case VECTOR_TYPE:
124349 + return 10;
124350 + case REFERENCE_TYPE:
124351 + return 11;
124352 + case OFFSET_TYPE:
124353 + return 12;
124354 + case COMPLEX_TYPE:
124355 + return 13;
124356 + default:
124357 + debug_tree((tree)type);
124358 + gcc_unreachable();
124359 + }
124360 +}
124361 +
124362 +struct function_hash {
124363 + size_t tree_codes_len;
124364 + unsigned char tree_codes[CODES_LIMIT];
124365 + const_tree fndecl;
124366 + unsigned int hash;
124367 +};
124368 +
124369 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124370 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124371 +{
124372 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124373 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124374 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124375 +
124376 + unsigned int m = 0x57559429;
124377 + unsigned int n = 0x5052acdb;
124378 + const unsigned int *key4 = (const unsigned int *)key;
124379 + unsigned int h = len;
124380 + unsigned int k = len + seed + n;
124381 + unsigned long long p;
124382 +
124383 + while (len >= 8) {
124384 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124385 + len -= 8;
124386 + }
124387 + if (len >= 4) {
124388 + cwmixb(key4[0]) key4 += 1;
124389 + len -= 4;
124390 + }
124391 + if (len)
124392 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124393 + cwmixb(h ^ (k + n));
124394 + return k ^ h;
124395 +
124396 +#undef cwfold
124397 +#undef cwmixa
124398 +#undef cwmixb
124399 +}
124400 +
124401 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124402 +{
124403 + unsigned int fn, codes, seed = 0;
124404 +
124405 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124406 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124407 +
124408 + fn_hash_data->hash = fn ^ codes;
124409 +}
124410 +
124411 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124412 +{
124413 + gcc_assert(type != NULL_TREE);
124414 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124415 +
124416 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124417 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124418 + fn_hash_data->tree_codes_len++;
124419 + type = TREE_TYPE(type);
124420 + }
124421 +}
124422 +
124423 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124424 +{
124425 + const_tree result;
124426 +
124427 + gcc_assert(node != NULL_TREE);
124428 +
124429 + if (DECL_P(node)) {
124430 + result = DECL_RESULT(node);
124431 + if (result != NULL_TREE)
124432 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124433 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124434 + }
124435 +
124436 + gcc_assert(TYPE_P(node));
124437 +
124438 + if (TREE_CODE(node) == FUNCTION_TYPE)
124439 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124440 +
124441 + return set_node_codes(node, fn_hash_data);
124442 +}
124443 +
124444 +static void set_function_codes(struct function_hash *fn_hash_data)
124445 +{
124446 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124447 + enum tree_code code = TREE_CODE(type);
124448 +
124449 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124450 +
124451 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124452 +
124453 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124454 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124455 +}
124456 +
124457 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124458 +{
124459 + while (entry) {
124460 + if (!strcmp(entry->name, func_name))
124461 + return entry;
124462 + entry = entry->next;
124463 + }
124464 + return NULL;
124465 +}
124466 +
124467 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124468 +{
124469 + const struct size_overflow_hash *entry;
124470 + struct function_hash fn_hash_data;
124471 + const char *func_name;
124472 +
124473 + // skip builtins __builtin_constant_p
124474 + if (DECL_BUILT_IN(fndecl))
124475 + return NULL;
124476 +
124477 + fn_hash_data.fndecl = fndecl;
124478 + fn_hash_data.tree_codes_len = 0;
124479 +
124480 + set_function_codes(&fn_hash_data);
124481 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124482 +
124483 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124484 + set_hash(func_name, &fn_hash_data);
124485 +
124486 + entry = size_overflow_hash[fn_hash_data.hash];
124487 + entry = get_proper_hash_chain(entry, func_name);
124488 + if (entry)
124489 + return entry;
124490 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124491 + return get_proper_hash_chain(entry, func_name);
124492 +}
124493 +
124494 +static void print_missing_msg(const_tree func, unsigned int argnum)
124495 +{
124496 + location_t loc;
124497 + const char *curfunc;
124498 + struct function_hash fn_hash_data;
124499 +
124500 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124501 + fn_hash_data.tree_codes_len = 0;
124502 +
124503 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124504 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124505 +
124506 + set_function_codes(&fn_hash_data);
124507 + set_hash(curfunc, &fn_hash_data);
124508 +
124509 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124510 +}
124511 +
124512 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124513 +{
124514 + tree var;
124515 + unsigned int argnum = 1;
124516 +
124517 + if (TREE_CODE(arg) == SSA_NAME)
124518 + arg = SSA_NAME_VAR(arg);
124519 +
124520 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124521 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124522 + continue;
124523 + if (!skip_types(var))
124524 + return argnum;
124525 + }
124526 +
124527 + return CANNOT_FIND_ARG;
124528 +}
124529 +
124530 +static const char *get_asm_string(const_gimple stmt)
124531 +{
124532 + if (!stmt)
124533 + return NULL;
124534 + if (gimple_code(stmt) != GIMPLE_ASM)
124535 + return NULL;
124536 +
124537 + return gimple_asm_string(stmt);
124538 +}
124539 +
124540 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124541 +{
124542 + const char *str;
124543 +
124544 + str = get_asm_string(stmt);
124545 + if (!str)
124546 + return false;
124547 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124548 +}
124549 +
124550 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124551 +{
124552 + const char *str;
124553 +
124554 + str = get_asm_string(stmt);
124555 + if (!str)
124556 + return false;
124557 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124558 +}
124559 +
124560 +bool is_size_overflow_asm(const_gimple stmt)
124561 +{
124562 + const char *str;
124563 +
124564 + str = get_asm_string(stmt);
124565 + if (!str)
124566 + return false;
124567 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124568 +}
124569 +
124570 +bool is_a_return_check(const_tree node)
124571 +{
124572 + if (TREE_CODE(node) == FUNCTION_DECL)
124573 + return true;
124574 +
124575 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124576 + return false;
124577 +}
124578 +
124579 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124580 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124581 +{
124582 + if (is_a_return_check(node))
124583 + return 0;
124584 + else
124585 + return find_arg_number_tree(node, orig_fndecl);
124586 +}
124587 +
124588 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124589 +{
124590 + const struct size_overflow_hash *hash;
124591 + unsigned int new_argnum;
124592 + tree arg;
124593 + const_tree origarg;
124594 +
124595 + if (argnum == 0)
124596 + return argnum;
124597 +
124598 + hash = get_function_hash(fndecl);
124599 + if (hash && hash->param & (1U << argnum))
124600 + return argnum;
124601 +
124602 + if (DECL_EXTERNAL(fndecl))
124603 + return argnum;
124604 +
124605 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124606 + argnum--;
124607 + while (origarg && argnum) {
124608 + origarg = TREE_CHAIN(origarg);
124609 + argnum--;
124610 + }
124611 + gcc_assert(argnum == 0);
124612 + gcc_assert(origarg != NULL_TREE);
124613 +
124614 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124615 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124616 + return new_argnum;
124617 +
124618 + return CANNOT_FIND_ARG;
124619 +}
124620 +
124621 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
124622 +{
124623 + const struct size_overflow_hash *hash;
124624 +
124625 + hash = get_function_hash(fndecl);
124626 + if (hash && (hash->param & (1U << num)))
124627 + return true;
124628 + return false;
124629 +}
124630 +
124631 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
124632 + * If the function is missing everywhere then print the missing message into stderr.
124633 + */
124634 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
124635 +{
124636 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
124637 +#if BUILDING_GCC_VERSION >= 4008
124638 + case BUILT_IN_BSWAP16:
124639 +#endif
124640 + case BUILT_IN_BSWAP32:
124641 + case BUILT_IN_BSWAP64:
124642 + case BUILT_IN_EXPECT:
124643 + case BUILT_IN_MEMCMP:
124644 + return false;
124645 + default:
124646 + break;
124647 + }
124648 +
124649 + // skip test.c
124650 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
124651 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
124652 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
124653 + }
124654 +
124655 + if (is_in_hash_table(orig_fndecl, num))
124656 + return false;
124657 +
124658 + print_missing_msg(orig_fndecl, num);
124659 + return true;
124660 +}
124661 +
124662 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
124663 new file mode 100644
124664 index 0000000..924652b
124665 --- /dev/null
124666 +++ b/tools/gcc/stackleak_plugin.c
124667 @@ -0,0 +1,395 @@
124668 +/*
124669 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
124670 + * Licensed under the GPL v2
124671 + *
124672 + * Note: the choice of the license means that the compilation process is
124673 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124674 + * but for the kernel it doesn't matter since it doesn't link against
124675 + * any of the gcc libraries
124676 + *
124677 + * gcc plugin to help implement various PaX features
124678 + *
124679 + * - track lowest stack pointer
124680 + *
124681 + * TODO:
124682 + * - initialize all local variables
124683 + *
124684 + * BUGS:
124685 + * - none known
124686 + */
124687 +
124688 +#include "gcc-common.h"
124689 +
124690 +int plugin_is_GPL_compatible;
124691 +
124692 +static int track_frame_size = -1;
124693 +static const char track_function[] = "pax_track_stack";
124694 +static const char check_function[] = "pax_check_alloca";
124695 +static tree track_function_decl, check_function_decl;
124696 +static bool init_locals;
124697 +
124698 +static struct plugin_info stackleak_plugin_info = {
124699 + .version = "201408011900",
124700 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
124701 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
124702 +};
124703 +
124704 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
124705 +{
124706 + gimple check_alloca;
124707 + tree alloca_size;
124708 +
124709 + // insert call to void pax_check_alloca(unsigned long size)
124710 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
124711 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
124712 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
124713 +}
124714 +
124715 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
124716 +{
124717 + gimple track_stack;
124718 +
124719 + // insert call to void pax_track_stack(void)
124720 + track_stack = gimple_build_call(track_function_decl, 0);
124721 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
124722 +}
124723 +
124724 +static bool is_alloca(gimple stmt)
124725 +{
124726 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
124727 + return true;
124728 +
124729 +#if BUILDING_GCC_VERSION >= 4007
124730 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
124731 + return true;
124732 +#endif
124733 +
124734 + return false;
124735 +}
124736 +
124737 +static unsigned int execute_stackleak_tree_instrument(void)
124738 +{
124739 + basic_block bb, entry_bb;
124740 + bool prologue_instrumented = false, is_leaf = true;
124741 +
124742 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
124743 +
124744 + // 1. loop through BBs and GIMPLE statements
124745 + FOR_EACH_BB_FN(bb, cfun) {
124746 + gimple_stmt_iterator gsi;
124747 +
124748 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124749 + gimple stmt;
124750 +
124751 + stmt = gsi_stmt(gsi);
124752 +
124753 + if (is_gimple_call(stmt))
124754 + is_leaf = false;
124755 +
124756 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
124757 + if (!is_alloca(stmt))
124758 + continue;
124759 +
124760 + // 2. insert stack overflow check before each __builtin_alloca call
124761 + stackleak_check_alloca(&gsi);
124762 +
124763 + // 3. insert track call after each __builtin_alloca call
124764 + stackleak_add_instrumentation(&gsi);
124765 + if (bb == entry_bb)
124766 + prologue_instrumented = true;
124767 + }
124768 + }
124769 +
124770 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
124771 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
124772 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
124773 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
124774 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
124775 + return 0;
124776 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
124777 + return 0;
124778 +
124779 + // 4. insert track call at the beginning
124780 + if (!prologue_instrumented) {
124781 + gimple_stmt_iterator gsi;
124782 +
124783 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124784 + if (dom_info_available_p(CDI_DOMINATORS))
124785 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124786 + gsi = gsi_start_bb(bb);
124787 + stackleak_add_instrumentation(&gsi);
124788 + }
124789 +
124790 + return 0;
124791 +}
124792 +
124793 +static unsigned int execute_stackleak_final(void)
124794 +{
124795 + rtx insn, next;
124796 +
124797 + if (cfun->calls_alloca)
124798 + return 0;
124799 +
124800 + // keep calls only if function frame is big enough
124801 + if (get_frame_size() >= track_frame_size)
124802 + return 0;
124803 +
124804 + // 1. find pax_track_stack calls
124805 + for (insn = get_insns(); insn; insn = next) {
124806 + // 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))
124807 + rtx body;
124808 +
124809 + next = NEXT_INSN(insn);
124810 + if (!CALL_P(insn))
124811 + continue;
124812 + body = PATTERN(insn);
124813 + if (GET_CODE(body) != CALL)
124814 + continue;
124815 + body = XEXP(body, 0);
124816 + if (GET_CODE(body) != MEM)
124817 + continue;
124818 + body = XEXP(body, 0);
124819 + if (GET_CODE(body) != SYMBOL_REF)
124820 + continue;
124821 +// if (strcmp(XSTR(body, 0), track_function))
124822 + if (SYMBOL_REF_DECL(body) != track_function_decl)
124823 + continue;
124824 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124825 + // 2. delete call
124826 + delete_insn_and_edges(insn);
124827 +#if BUILDING_GCC_VERSION >= 4007
124828 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
124829 + insn = next;
124830 + next = NEXT_INSN(insn);
124831 + delete_insn_and_edges(insn);
124832 + }
124833 +#endif
124834 + }
124835 +
124836 +// print_simple_rtl(stderr, get_insns());
124837 +// print_rtl(stderr, get_insns());
124838 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124839 +
124840 + return 0;
124841 +}
124842 +
124843 +static bool gate_stackleak_track_stack(void)
124844 +{
124845 + tree section;
124846 +
124847 + if (ix86_cmodel != CM_KERNEL)
124848 + return false;
124849 +
124850 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
124851 + if (section && TREE_VALUE(section)) {
124852 + section = TREE_VALUE(TREE_VALUE(section));
124853 +
124854 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
124855 + return false;
124856 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
124857 + return false;
124858 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
124859 + return false;
124860 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
124861 + return false;
124862 + }
124863 +
124864 + return track_frame_size >= 0;
124865 +}
124866 +
124867 +static void stackleak_start_unit(void *gcc_data, void *user_data)
124868 +{
124869 + tree fntype;
124870 +
124871 + // void pax_track_stack(void)
124872 + fntype = build_function_type_list(void_type_node, NULL_TREE);
124873 + track_function_decl = build_fn_decl(track_function, fntype);
124874 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
124875 + TREE_PUBLIC(track_function_decl) = 1;
124876 + DECL_EXTERNAL(track_function_decl) = 1;
124877 + DECL_ARTIFICIAL(track_function_decl) = 1;
124878 +
124879 + // void pax_check_alloca(unsigned long)
124880 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
124881 + check_function_decl = build_fn_decl(check_function, fntype);
124882 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
124883 + TREE_PUBLIC(check_function_decl) = 1;
124884 + DECL_EXTERNAL(check_function_decl) = 1;
124885 + DECL_ARTIFICIAL(check_function_decl) = 1;
124886 +}
124887 +
124888 +#if BUILDING_GCC_VERSION >= 4009
124889 +static const struct pass_data stackleak_tree_instrument_pass_data = {
124890 +#else
124891 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
124892 + .pass = {
124893 +#endif
124894 + .type = GIMPLE_PASS,
124895 + .name = "stackleak_tree_instrument",
124896 +#if BUILDING_GCC_VERSION >= 4008
124897 + .optinfo_flags = OPTGROUP_NONE,
124898 +#endif
124899 +#if BUILDING_GCC_VERSION >= 4009
124900 + .has_gate = true,
124901 + .has_execute = true,
124902 +#else
124903 + .gate = gate_stackleak_track_stack,
124904 + .execute = execute_stackleak_tree_instrument,
124905 + .sub = NULL,
124906 + .next = NULL,
124907 + .static_pass_number = 0,
124908 +#endif
124909 + .tv_id = TV_NONE,
124910 + .properties_required = PROP_gimple_leh | PROP_cfg,
124911 + .properties_provided = 0,
124912 + .properties_destroyed = 0,
124913 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
124914 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
124915 +#if BUILDING_GCC_VERSION < 4009
124916 + }
124917 +#endif
124918 +};
124919 +
124920 +#if BUILDING_GCC_VERSION >= 4009
124921 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
124922 +#else
124923 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
124924 + .pass = {
124925 +#endif
124926 + .type = RTL_PASS,
124927 + .name = "stackleak_final",
124928 +#if BUILDING_GCC_VERSION >= 4008
124929 + .optinfo_flags = OPTGROUP_NONE,
124930 +#endif
124931 +#if BUILDING_GCC_VERSION >= 4009
124932 + .has_gate = true,
124933 + .has_execute = true,
124934 +#else
124935 + .gate = gate_stackleak_track_stack,
124936 + .execute = execute_stackleak_final,
124937 + .sub = NULL,
124938 + .next = NULL,
124939 + .static_pass_number = 0,
124940 +#endif
124941 + .tv_id = TV_NONE,
124942 + .properties_required = 0,
124943 + .properties_provided = 0,
124944 + .properties_destroyed = 0,
124945 + .todo_flags_start = 0,
124946 + .todo_flags_finish = TODO_dump_func
124947 +#if BUILDING_GCC_VERSION < 4009
124948 + }
124949 +#endif
124950 +};
124951 +
124952 +#if BUILDING_GCC_VERSION >= 4009
124953 +namespace {
124954 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
124955 +public:
124956 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
124957 + bool gate() { return gate_stackleak_track_stack(); }
124958 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
124959 +};
124960 +
124961 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
124962 +public:
124963 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
124964 + bool gate() { return gate_stackleak_track_stack(); }
124965 + unsigned int execute() { return execute_stackleak_final(); }
124966 +};
124967 +}
124968 +
124969 +static opt_pass *make_stackleak_tree_instrument_pass(void)
124970 +{
124971 + return new stackleak_tree_instrument_pass();
124972 +}
124973 +
124974 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
124975 +{
124976 + return new stackleak_final_rtl_opt_pass();
124977 +}
124978 +#else
124979 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
124980 +{
124981 + return &stackleak_tree_instrument_pass.pass;
124982 +}
124983 +
124984 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
124985 +{
124986 + return &stackleak_final_rtl_opt_pass.pass;
124987 +}
124988 +#endif
124989 +
124990 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124991 +{
124992 + const char * const plugin_name = plugin_info->base_name;
124993 + const int argc = plugin_info->argc;
124994 + const struct plugin_argument * const argv = plugin_info->argv;
124995 + int i;
124996 + struct register_pass_info stackleak_tree_instrument_pass_info;
124997 + struct register_pass_info stackleak_final_pass_info;
124998 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
124999 + {
125000 + .base = &track_function_decl,
125001 + .nelt = 1,
125002 + .stride = sizeof(track_function_decl),
125003 + .cb = &gt_ggc_mx_tree_node,
125004 + .pchw = &gt_pch_nx_tree_node
125005 + },
125006 + {
125007 + .base = &check_function_decl,
125008 + .nelt = 1,
125009 + .stride = sizeof(check_function_decl),
125010 + .cb = &gt_ggc_mx_tree_node,
125011 + .pchw = &gt_pch_nx_tree_node
125012 + },
125013 + LAST_GGC_ROOT_TAB
125014 + };
125015 +
125016 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125017 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125018 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125019 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125020 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125021 +
125022 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125023 + stackleak_final_pass_info.reference_pass_name = "final";
125024 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125025 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125026 +
125027 + if (!plugin_default_version_check(version, &gcc_version)) {
125028 + error(G_("incompatible gcc/plugin versions"));
125029 + return 1;
125030 + }
125031 +
125032 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125033 +
125034 + for (i = 0; i < argc; ++i) {
125035 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125036 + if (!argv[i].value) {
125037 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125038 + continue;
125039 + }
125040 + track_frame_size = atoi(argv[i].value);
125041 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125042 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125043 + continue;
125044 + }
125045 + if (!strcmp(argv[i].key, "initialize-locals")) {
125046 + if (argv[i].value) {
125047 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125048 + continue;
125049 + }
125050 + init_locals = true;
125051 + continue;
125052 + }
125053 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125054 + }
125055 +
125056 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125057 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125058 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125059 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125060 +
125061 + return 0;
125062 +}
125063 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125064 new file mode 100644
125065 index 0000000..4ee2231
125066 --- /dev/null
125067 +++ b/tools/gcc/structleak_plugin.c
125068 @@ -0,0 +1,274 @@
125069 +/*
125070 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125071 + * Licensed under the GPL v2
125072 + *
125073 + * Note: the choice of the license means that the compilation process is
125074 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125075 + * but for the kernel it doesn't matter since it doesn't link against
125076 + * any of the gcc libraries
125077 + *
125078 + * gcc plugin to forcibly initialize certain local variables that could
125079 + * otherwise leak kernel stack to userland if they aren't properly initialized
125080 + * by later code
125081 + *
125082 + * Homepage: http://pax.grsecurity.net/
125083 + *
125084 + * Usage:
125085 + * $ # for 4.5/4.6/C based 4.7
125086 + * $ 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
125087 + * $ # for C++ based 4.7/4.8+
125088 + * $ 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
125089 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125090 + *
125091 + * TODO: eliminate redundant initializers
125092 + * increase type coverage
125093 + */
125094 +
125095 +#include "gcc-common.h"
125096 +
125097 +// unused C type flag in all versions 4.5-4.9
125098 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125099 +
125100 +int plugin_is_GPL_compatible;
125101 +
125102 +static struct plugin_info structleak_plugin_info = {
125103 + .version = "201401260140",
125104 + .help = "disable\tdo not activate plugin\n",
125105 +};
125106 +
125107 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125108 +{
125109 + *no_add_attrs = true;
125110 +
125111 + // check for types? for now accept everything linux has to offer
125112 + if (TREE_CODE(*node) != FIELD_DECL)
125113 + return NULL_TREE;
125114 +
125115 + *no_add_attrs = false;
125116 + return NULL_TREE;
125117 +}
125118 +
125119 +static struct attribute_spec user_attr = {
125120 + .name = "user",
125121 + .min_length = 0,
125122 + .max_length = 0,
125123 + .decl_required = false,
125124 + .type_required = false,
125125 + .function_type_required = false,
125126 + .handler = handle_user_attribute,
125127 +#if BUILDING_GCC_VERSION >= 4007
125128 + .affects_type_identity = true
125129 +#endif
125130 +};
125131 +
125132 +static void register_attributes(void *event_data, void *data)
125133 +{
125134 + register_attribute(&user_attr);
125135 +// register_attribute(&force_attr);
125136 +}
125137 +
125138 +static tree get_field_type(tree field)
125139 +{
125140 + return strip_array_types(TREE_TYPE(field));
125141 +}
125142 +
125143 +static bool is_userspace_type(tree type)
125144 +{
125145 + tree field;
125146 +
125147 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125148 + tree fieldtype = get_field_type(field);
125149 + enum tree_code code = TREE_CODE(fieldtype);
125150 +
125151 + if (code == RECORD_TYPE || code == UNION_TYPE)
125152 + if (is_userspace_type(fieldtype))
125153 + return true;
125154 +
125155 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125156 + return true;
125157 + }
125158 + return false;
125159 +}
125160 +
125161 +static void finish_type(void *event_data, void *data)
125162 +{
125163 + tree type = (tree)event_data;
125164 +
125165 + if (TYPE_USERSPACE(type))
125166 + return;
125167 +
125168 + if (is_userspace_type(type))
125169 + TYPE_USERSPACE(type) = 1;
125170 +}
125171 +
125172 +static void initialize(tree var)
125173 +{
125174 + basic_block bb;
125175 + gimple_stmt_iterator gsi;
125176 + tree initializer;
125177 + gimple init_stmt;
125178 +
125179 + // this is the original entry bb before the forced split
125180 + // TODO: check further BBs in case more splits occured before us
125181 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125182 +
125183 + // first check if the variable is already initialized, warn otherwise
125184 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125185 + gimple stmt = gsi_stmt(gsi);
125186 + tree rhs1;
125187 +
125188 + // we're looking for an assignment of a single rhs...
125189 + if (!gimple_assign_single_p(stmt))
125190 + continue;
125191 + rhs1 = gimple_assign_rhs1(stmt);
125192 +#if BUILDING_GCC_VERSION >= 4007
125193 + // ... of a non-clobbering expression...
125194 + if (TREE_CLOBBER_P(rhs1))
125195 + continue;
125196 +#endif
125197 + // ... to our variable...
125198 + if (gimple_get_lhs(stmt) != var)
125199 + continue;
125200 + // if it's an initializer then we're good
125201 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125202 + return;
125203 + }
125204 +
125205 + // these aren't the 0days you're looking for
125206 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125207 +
125208 + // build the initializer expression
125209 + initializer = build_constructor(TREE_TYPE(var), NULL);
125210 +
125211 + // build the initializer stmt
125212 + init_stmt = gimple_build_assign(var, initializer);
125213 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125214 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125215 + update_stmt(init_stmt);
125216 +}
125217 +
125218 +static unsigned int handle_function(void)
125219 +{
125220 + basic_block bb;
125221 + unsigned int ret = 0;
125222 + tree var;
125223 + unsigned int i;
125224 +
125225 + // split the first bb where we can put the forced initializers
125226 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125227 + if (dom_info_available_p(CDI_DOMINATORS))
125228 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125229 +
125230 + // enumarate all local variables and forcibly initialize our targets
125231 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125232 + tree type = TREE_TYPE(var);
125233 +
125234 + gcc_assert(DECL_P(var));
125235 + if (!auto_var_in_fn_p(var, current_function_decl))
125236 + continue;
125237 +
125238 + // only care about structure types
125239 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125240 + continue;
125241 +
125242 + // if the type is of interest, examine the variable
125243 + if (TYPE_USERSPACE(type))
125244 + initialize(var);
125245 + }
125246 +
125247 + return ret;
125248 +}
125249 +
125250 +#if BUILDING_GCC_VERSION >= 4009
125251 +static const struct pass_data structleak_pass_data = {
125252 +#else
125253 +static struct gimple_opt_pass structleak_pass = {
125254 + .pass = {
125255 +#endif
125256 + .type = GIMPLE_PASS,
125257 + .name = "structleak",
125258 +#if BUILDING_GCC_VERSION >= 4008
125259 + .optinfo_flags = OPTGROUP_NONE,
125260 +#endif
125261 +#if BUILDING_GCC_VERSION >= 4009
125262 + .has_gate = false,
125263 + .has_execute = true,
125264 +#else
125265 + .gate = NULL,
125266 + .execute = handle_function,
125267 + .sub = NULL,
125268 + .next = NULL,
125269 + .static_pass_number = 0,
125270 +#endif
125271 + .tv_id = TV_NONE,
125272 + .properties_required = PROP_cfg,
125273 + .properties_provided = 0,
125274 + .properties_destroyed = 0,
125275 + .todo_flags_start = 0,
125276 + .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
125277 +#if BUILDING_GCC_VERSION < 4009
125278 + }
125279 +#endif
125280 +};
125281 +
125282 +#if BUILDING_GCC_VERSION >= 4009
125283 +namespace {
125284 +class structleak_pass : public gimple_opt_pass {
125285 +public:
125286 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125287 + unsigned int execute() { return handle_function(); }
125288 +};
125289 +}
125290 +
125291 +static opt_pass *make_structleak_pass(void)
125292 +{
125293 + return new structleak_pass();
125294 +}
125295 +#else
125296 +static struct opt_pass *make_structleak_pass(void)
125297 +{
125298 + return &structleak_pass.pass;
125299 +}
125300 +#endif
125301 +
125302 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125303 +{
125304 + int i;
125305 + const char * const plugin_name = plugin_info->base_name;
125306 + const int argc = plugin_info->argc;
125307 + const struct plugin_argument * const argv = plugin_info->argv;
125308 + bool enable = true;
125309 + struct register_pass_info structleak_pass_info;
125310 +
125311 + structleak_pass_info.pass = make_structleak_pass();
125312 + structleak_pass_info.reference_pass_name = "ssa";
125313 + structleak_pass_info.ref_pass_instance_number = 1;
125314 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125315 +
125316 + if (!plugin_default_version_check(version, &gcc_version)) {
125317 + error(G_("incompatible gcc/plugin versions"));
125318 + return 1;
125319 + }
125320 +
125321 + if (strcmp(lang_hooks.name, "GNU C")) {
125322 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125323 + enable = false;
125324 + }
125325 +
125326 + for (i = 0; i < argc; ++i) {
125327 + if (!strcmp(argv[i].key, "disable")) {
125328 + enable = false;
125329 + continue;
125330 + }
125331 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125332 + }
125333 +
125334 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125335 + if (enable) {
125336 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125337 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125338 + }
125339 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125340 +
125341 + return 0;
125342 +}
125343 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125344 index 88461f0..6fb70a0 100644
125345 --- a/tools/include/linux/compiler.h
125346 +++ b/tools/include/linux/compiler.h
125347 @@ -35,6 +35,14 @@
125348 # define unlikely(x) __builtin_expect(!!(x), 0)
125349 #endif
125350
125351 +#ifndef __size_overflow
125352 +# define __size_overflow(...)
125353 +#endif
125354 +
125355 +#ifndef __intentional_overflow
125356 +# define __intentional_overflow(...)
125357 +#endif
125358 +
125359 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125360
125361 #endif /* _TOOLS_LINUX_COMPILER_H */
125362 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125363 index ce00f7e..0aca5e4 100644
125364 --- a/tools/lib/api/Makefile
125365 +++ b/tools/lib/api/Makefile
125366 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
125367
125368 LIBFILE = libapikfs.a
125369
125370 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125371 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125372 EXTLIBS = -lelf -lpthread -lrt -lm
125373 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125374 ALL_LDFLAGS = $(LDFLAGS)
125375 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125376 index 6789d788..4afd019e 100644
125377 --- a/tools/perf/util/include/asm/alternative-asm.h
125378 +++ b/tools/perf/util/include/asm/alternative-asm.h
125379 @@ -5,4 +5,7 @@
125380
125381 #define altinstruction_entry #
125382
125383 + .macro pax_force_retaddr rip=0, reload=0
125384 + .endm
125385 +
125386 #endif
125387 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125388 index 0a578fe..b81f62d 100644
125389 --- a/tools/virtio/linux/uaccess.h
125390 +++ b/tools/virtio/linux/uaccess.h
125391 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125392 ({ \
125393 typeof(ptr) __pu_ptr = (ptr); \
125394 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125395 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125396 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125397 0; \
125398 })
125399
125400 diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
125401 index 714b949..1f0dc1e 100644
125402 --- a/virt/kvm/iommu.c
125403 +++ b/virt/kvm/iommu.c
125404 @@ -43,13 +43,13 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
125405 gfn_t base_gfn, unsigned long npages);
125406
125407 static pfn_t kvm_pin_pages(struct kvm_memory_slot *slot, gfn_t gfn,
125408 - unsigned long size)
125409 + unsigned long npages)
125410 {
125411 gfn_t end_gfn;
125412 pfn_t pfn;
125413
125414 pfn = gfn_to_pfn_memslot(slot, gfn);
125415 - end_gfn = gfn + (size >> PAGE_SHIFT);
125416 + end_gfn = gfn + npages;
125417 gfn += 1;
125418
125419 if (is_error_noslot_pfn(pfn))
125420 @@ -119,7 +119,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
125421 * Pin all pages we are about to map in memory. This is
125422 * important because we unmap and unpin in 4kb steps later.
125423 */
125424 - pfn = kvm_pin_pages(slot, gfn, page_size);
125425 + pfn = kvm_pin_pages(slot, gfn, page_size >> PAGE_SHIFT);
125426 if (is_error_noslot_pfn(pfn)) {
125427 gfn += 1;
125428 continue;
125429 @@ -131,7 +131,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
125430 if (r) {
125431 printk(KERN_ERR "kvm_iommu_map_address:"
125432 "iommu failed to map pfn=%llx\n", pfn);
125433 - kvm_unpin_pages(kvm, pfn, page_size);
125434 + kvm_unpin_pages(kvm, pfn, page_size >> PAGE_SHIFT);
125435 goto unmap_pages;
125436 }
125437
125438 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125439 index 95519bc..43f5d42 100644
125440 --- a/virt/kvm/kvm_main.c
125441 +++ b/virt/kvm/kvm_main.c
125442 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
125443
125444 static cpumask_var_t cpus_hardware_enabled;
125445 static int kvm_usage_count = 0;
125446 -static atomic_t hardware_enable_failed;
125447 +static atomic_unchecked_t hardware_enable_failed;
125448
125449 struct kmem_cache *kvm_vcpu_cache;
125450 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125451
125452 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125453 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125454 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125455 +static struct preempt_ops kvm_preempt_ops = {
125456 + .sched_in = kvm_sched_in,
125457 + .sched_out = kvm_sched_out,
125458 +};
125459
125460 struct dentry *kvm_debugfs_dir;
125461
125462 @@ -763,7 +768,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125463 /* We can read the guest memory with __xxx_user() later on. */
125464 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125465 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125466 - !access_ok(VERIFY_WRITE,
125467 + !access_ok_noprefault(VERIFY_WRITE,
125468 (void __user *)(unsigned long)mem->userspace_addr,
125469 mem->memory_size)))
125470 goto out;
125471 @@ -1620,9 +1625,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125472
125473 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125474 {
125475 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125476 + int r;
125477 + unsigned long addr;
125478
125479 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125480 + addr = gfn_to_hva(kvm, gfn);
125481 + if (kvm_is_error_hva(addr))
125482 + return -EFAULT;
125483 + r = __clear_user((void __user *)addr + offset, len);
125484 + if (r)
125485 + return -EFAULT;
125486 + mark_page_dirty(kvm, gfn);
125487 + return 0;
125488 }
125489 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125490
125491 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125492 return 0;
125493 }
125494
125495 -static struct file_operations kvm_vcpu_fops = {
125496 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125497 .release = kvm_vcpu_release,
125498 .unlocked_ioctl = kvm_vcpu_ioctl,
125499 #ifdef CONFIG_COMPAT
125500 @@ -2573,7 +2586,7 @@ out:
125501 }
125502 #endif
125503
125504 -static struct file_operations kvm_vm_fops = {
125505 +static file_operations_no_const kvm_vm_fops __read_only = {
125506 .release = kvm_vm_release,
125507 .unlocked_ioctl = kvm_vm_ioctl,
125508 #ifdef CONFIG_COMPAT
125509 @@ -2646,7 +2659,7 @@ out:
125510 return r;
125511 }
125512
125513 -static struct file_operations kvm_chardev_ops = {
125514 +static file_operations_no_const kvm_chardev_ops __read_only = {
125515 .unlocked_ioctl = kvm_dev_ioctl,
125516 .compat_ioctl = kvm_dev_ioctl,
125517 .llseek = noop_llseek,
125518 @@ -2672,7 +2685,7 @@ static void hardware_enable_nolock(void *junk)
125519
125520 if (r) {
125521 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125522 - atomic_inc(&hardware_enable_failed);
125523 + atomic_inc_unchecked(&hardware_enable_failed);
125524 printk(KERN_INFO "kvm: enabling virtualization on "
125525 "CPU%d failed\n", cpu);
125526 }
125527 @@ -2728,10 +2741,10 @@ static int hardware_enable_all(void)
125528
125529 kvm_usage_count++;
125530 if (kvm_usage_count == 1) {
125531 - atomic_set(&hardware_enable_failed, 0);
125532 + atomic_set_unchecked(&hardware_enable_failed, 0);
125533 on_each_cpu(hardware_enable_nolock, NULL, 1);
125534
125535 - if (atomic_read(&hardware_enable_failed)) {
125536 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125537 hardware_disable_all_nolock();
125538 r = -EBUSY;
125539 }
125540 @@ -3136,7 +3149,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125541 kvm_arch_vcpu_put(vcpu);
125542 }
125543
125544 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125545 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125546 struct module *module)
125547 {
125548 int r;
125549 @@ -3183,7 +3196,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125550 if (!vcpu_align)
125551 vcpu_align = __alignof__(struct kvm_vcpu);
125552 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125553 - 0, NULL);
125554 + SLAB_USERCOPY, NULL);
125555 if (!kvm_vcpu_cache) {
125556 r = -ENOMEM;
125557 goto out_free_3;
125558 @@ -3193,9 +3206,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125559 if (r)
125560 goto out_free;
125561
125562 + pax_open_kernel();
125563 kvm_chardev_ops.owner = module;
125564 kvm_vm_fops.owner = module;
125565 kvm_vcpu_fops.owner = module;
125566 + pax_close_kernel();
125567
125568 r = misc_register(&kvm_dev);
125569 if (r) {
125570 @@ -3205,9 +3220,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125571
125572 register_syscore_ops(&kvm_syscore_ops);
125573
125574 - kvm_preempt_ops.sched_in = kvm_sched_in;
125575 - kvm_preempt_ops.sched_out = kvm_sched_out;
125576 -
125577 r = kvm_init_debug();
125578 if (r) {
125579 printk(KERN_ERR "kvm: create debugfs files failed\n");